Skip to content

Commit

Permalink
optimize the judge of invalide notification.number (ethereum#22658)
Browse files Browse the repository at this point in the history
Don't bother fetching genesis

Co-authored-by: wuff1996 <33193253+wuff1996@users.noreply.github.com>
  • Loading branch information
2 people authored and zzyalbert committed Nov 26, 2021
1 parent a7e5c73 commit addc64d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions eth/fetcher/block_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,14 @@ func (f *BlockFetcher) loop() {
blockAnnounceDOSMeter.Mark(1)
break
}
if notification.number == 0 {
break
}
// If we have a valid block number, check that it's potentially useful
if notification.number > 0 {
if dist := int64(notification.number) - int64(f.chainHeight()); dist < -maxUncleDist || dist > maxQueueDist {
log.Debug("Peer discarded announcement", "peer", notification.origin, "number", notification.number, "hash", notification.hash, "distance", dist)
blockAnnounceDropMeter.Mark(1)
break
}
if dist := int64(notification.number) - int64(f.chainHeight()); dist < -maxUncleDist || dist > maxQueueDist {
log.Debug("Peer discarded announcement", "peer", notification.origin, "number", notification.number, "hash", notification.hash, "distance", dist)
blockAnnounceDropMeter.Mark(1)
break
}
// All is well, schedule the announce if block's not yet downloading
if _, ok := f.fetching[notification.hash]; ok {
Expand Down

0 comments on commit addc64d

Please sign in to comment.