eth/downloader: add comments

This commit is contained in:
Felix Lange 2026-04-30 10:11:10 +02:00
parent a03afefe2e
commit a10be21b19
2 changed files with 10 additions and 3 deletions

View file

@ -122,7 +122,7 @@ func (dl *downloadTester) dropPeer(id string) {
type downloadTesterPeer struct { type downloadTesterPeer struct {
dl *downloadTester dl *downloadTester
withholdBodies map[common.Hash]struct{} withholdBodies map[common.Hash]struct{}
corruptBodies bool corruptBodies bool // if set, the peer serves incorrect blocks
id string id string
chain *core.BlockChain chain *core.BlockChain

View file

@ -339,9 +339,15 @@ func (d *Downloader) concurrentFetch(queue typedQueue) error {
if !errors.Is(err, errStaleDelivery) { if !errors.Is(err, errStaleDelivery) {
queue.updateCapacity(peer, accepted, res.Time) queue.updateCapacity(peer, accepted, res.Time)
} }
res.Done <- errorOfRequest(err) res.Done <- validityErrorOfRequest(err)
res.Req.Close() res.Req.Close()
if errors.Is(err, errInvalidChain) { if errors.Is(err, errInvalidChain) {
// errInvalidChain is the signal that processing of items failed internally,
// even though the items were validly encoded.
//
// This can be due to invalid blocks, or a database error.
// The sync cycle should be aborted for such errors, so we return it here.
return err return err
} }
@ -354,7 +360,8 @@ func (d *Downloader) concurrentFetch(queue typedQueue) error {
} }
} }
func errorOfRequest(err error) error { // validityErrorOfRequest returns err if it is related to block validity, and nil otherwise.
func validityErrorOfRequest(err error) error {
if errors.Is(err, errInvalidBody) || errors.Is(err, errInvalidReceipt) { if errors.Is(err, errInvalidBody) || errors.Is(err, errInvalidReceipt) {
return err return err
} }