eth/downloader: refactor

This commit is contained in:
healthykim 2026-04-20 09:49:26 +02:00
parent 1360c80623
commit 6bd6799a1e

View file

@ -325,30 +325,25 @@ func (d *Downloader) concurrentFetch(queue typedQueue) error {
// If the peer was previously banned and failed to deliver its pack // If the peer was previously banned and failed to deliver its pack
// in a reasonable time frame, ignore its message. // in a reasonable time frame, ignore its message.
if peer := d.peers.Peer(res.Req.Peer); peer != nil { peer := d.peers.Peer(res.Req.Peer)
// Deliver the received chunk of data and check chain validity if peer == nil {
accepted, err := queue.deliver(peer, res) res.Done <- nil
if errors.Is(err, errInvalidChain) { res.Req.Close()
res.Done <- err continue
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)
}
} }
// Signal the dispatcher that the round trip is done. // Deliver the received chunk of data and check chain validity
res.Done <- nil 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() res.Req.Close()
if errors.Is(err, errInvalidChain) {
return err
}
case cont := <-queue.waker(): case cont := <-queue.waker():
// The header fetcher sent a continuation flag, check if it's done // 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
}