Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth/downloader: bypass peer validation if remote peer is far away #1167

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions eth/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -894,13 +894,6 @@
// In the rare scenario when we ended up on a long reorganisation (i.e. none of
// the head links match), we do a binary search to find the common ancestor.
func (d *Downloader) findAncestor(p *peerConnection, remoteHeader *types.Header) (uint64, error) {
// Check the validity of peer from which the chain is to be downloaded
if d.ChainValidator != nil {
if _, err := d.IsValidPeer(d.getFetchHeadersByNumber(p)); err != nil {
return 0, err
}
}

// Figure out the valid ancestor range to prevent rewrite attacks
var (
floor = int64(-1)
Expand All @@ -918,6 +911,23 @@
localHeight = d.lightchain.CurrentHeader().Number.Uint64()
}

// Check the validity of peer from which the chain is to be downloaded
if d.ChainValidator != nil {
_, err := d.IsValidPeer(d.getFetchHeadersByNumber(p))
if errors.Is(err, whitelist.ErrMismatch) {
return 0, err
}

// Assuming that `remoteHeight` is always greater than `localHeight`, we won't
// check peer validity if the remote header is far ahead of us.
if errors.Is(err, whitelist.ErrNoRemote) && localHeight > remoteHeight-1024 {
log.Info("Remote peer didn't respond but is far ahead, skipping validation", "id", p.id, "local", localHeight, "remote", remoteHeight, "err", err)

Check warning on line 924 in eth/downloader/downloader.go

View check run for this annotation

Codecov / codecov/patch

eth/downloader/downloader.go#L924

Added line #L924 was not covered by tests
} else if errors.Is(err, whitelist.ErrNoRemote) {
log.Info("Remote peer didn't respond", "id", p.id, "local", localHeight, "remote", remoteHeight, "err", err)
return 0, err
}
}

p.log.Debug("Looking for common ancestor", "local", localHeight, "remote", remoteHeight)

// Recap floor value for binary search
Expand Down
Loading