From 410e731beacba2d6b8bb6f8ee3c42c954c04b3b4 Mon Sep 17 00:00:00 2001 From: "XuDon9 Liu AKA Rapper Of CN background diablo & revelations, a man optimistic, negative, silent, active, Taoism" <33193253+r1cs@users.noreply.github.com> Date: Mon, 1 Nov 2021 02:38:48 +0800 Subject: [PATCH] optimize the judge of invalide notification.number (#22658) Don't bother fetching genesis Co-authored-by: wuff1996 <33193253+wuff1996@users.noreply.github.com> --- eth/fetcher/block_fetcher.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/eth/fetcher/block_fetcher.go b/eth/fetcher/block_fetcher.go index 45983c97c..7624268a7 100644 --- a/eth/fetcher/block_fetcher.go +++ b/eth/fetcher/block_fetcher.go @@ -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 {