From 6bd6799a1e38cadeed301217545de0347278c06e Mon Sep 17 00:00:00 2001 From: healthykim Date: Mon, 20 Apr 2026 09:49:26 +0200 Subject: [PATCH] eth/downloader: refactor --- eth/downloader/fetchers_concurrent.go | 46 ++++++++++++++------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/eth/downloader/fetchers_concurrent.go b/eth/downloader/fetchers_concurrent.go index 9d95eec3ee..e01b8df048 100644 --- a/eth/downloader/fetchers_concurrent.go +++ b/eth/downloader/fetchers_concurrent.go @@ -325,30 +325,25 @@ func (d *Downloader) concurrentFetch(queue typedQueue) error { // If the peer was previously banned and failed to deliver its pack // in a reasonable time frame, ignore its message. - if peer := d.peers.Peer(res.Req.Peer); peer != nil { - // Deliver the received chunk of data and check chain validity - accepted, err := queue.deliver(peer, res) - if errors.Is(err, errInvalidChain) { - res.Done <- err - res.Req.Close() - return err - } - if errors.Is(err, errInvalidBody) || errors.Is(err, errInvalidReceipt) { - // Signal the dispatcher with the error to drop the peer. - res.Done <- err - res.Req.Close() - continue - } - // Unless a peer delivered something completely else than requested (usually - // caused by a timed out request which came through in the end), set it to - // idle. If the delivery's stale, the peer should have already been idled. - if !errors.Is(err, errStaleDelivery) { - queue.updateCapacity(peer, accepted, res.Time) - } + peer := d.peers.Peer(res.Req.Peer) + if peer == nil { + res.Done <- nil + res.Req.Close() + continue } - // Signal the dispatcher that the round trip is done. - res.Done <- nil + // Deliver the received chunk of data and check chain validity + accepted, err := queue.deliver(peer, res) + // Unless a peer delivered something completely else than requested (usually + // caused by a timed out request which came through in the end), set it to + // idle. If the delivery's stale, the peer should have already been idled. + if !errors.Is(err, errStaleDelivery) { + queue.updateCapacity(peer, accepted, res.Time) + } + res.Done <- errorOfRequest(err) res.Req.Close() + if errors.Is(err, errInvalidChain) { + return err + } case cont := <-queue.waker(): // The header fetcher sent a continuation flag, check if it's done @@ -358,3 +353,10 @@ func (d *Downloader) concurrentFetch(queue typedQueue) error { } } } + +func errorOfRequest(err error) error { + if errors.Is(err, errInvalidBody) || errors.Is(err, errInvalidReceipt) { + return err + } + return nil +}