diff options
author | Péter Szilágyi <peterke@gmail.com> | 2015-06-05 17:37:48 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2015-06-05 17:37:48 +0800 |
commit | 328ef60b856f75bf664fb103bc54674d962bef2e (patch) | |
tree | ebae5e70aa3b3b95dc193b71319288d4d53a32b2 /eth/downloader/queue.go | |
parent | 94e4aa6ea9aabb5bf6244d9b38607b336703af98 (diff) | |
download | go-tangerine-328ef60b856f75bf664fb103bc54674d962bef2e.tar go-tangerine-328ef60b856f75bf664fb103bc54674d962bef2e.tar.gz go-tangerine-328ef60b856f75bf664fb103bc54674d962bef2e.tar.bz2 go-tangerine-328ef60b856f75bf664fb103bc54674d962bef2e.tar.lz go-tangerine-328ef60b856f75bf664fb103bc54674d962bef2e.tar.xz go-tangerine-328ef60b856f75bf664fb103bc54674d962bef2e.tar.zst go-tangerine-328ef60b856f75bf664fb103bc54674d962bef2e.zip |
eth/downloader: differentiate stale and nonexistent deliveries
Diffstat (limited to 'eth/downloader/queue.go')
-rw-r--r-- | eth/downloader/queue.go | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/eth/downloader/queue.go b/eth/downloader/queue.go index 02fa667f1..671ffe51b 100644 --- a/eth/downloader/queue.go +++ b/eth/downloader/queue.go @@ -20,6 +20,11 @@ const ( blockCacheLimit = 8 * MaxBlockFetch // Maximum number of blocks to cache before throttling the download ) +var ( + errNoFetchesPending = errors.New("no fetches pending") + errStaleDelivery = errors.New("stale delivery") +) + // fetchRequest is a currently running block retrieval operation. type fetchRequest struct { Peer *peer // Peer to which the request was sent @@ -293,7 +298,7 @@ func (q *queue) Deliver(id string, blocks []*types.Block) (err error) { // Short circuit if the blocks were never requested request := q.pendPool[id] if request == nil { - return errors.New("no fetches pending") + return errNoFetchesPending } delete(q.pendPool, id) @@ -309,7 +314,7 @@ func (q *queue) Deliver(id string, blocks []*types.Block) (err error) { // Skip any blocks that were not requested hash := block.Hash() if _, ok := request.Hashes[hash]; !ok { - errs = append(errs, fmt.Errorf("non-requested block %v", hash)) + errs = append(errs, fmt.Errorf("non-requested block %x", hash)) continue } // If a requested block falls out of the range, the hash chain is invalid @@ -326,11 +331,15 @@ func (q *queue) Deliver(id string, blocks []*types.Block) (err error) { delete(q.hashPool, hash) q.blockPool[hash] = int(block.NumberU64()) } - // Return all failed fetches to the queue + // Return all failed or missing fetches to the queue for hash, index := range request.Hashes { q.hashQueue.Push(hash, float32(index)) } + // If none of the blocks were good, it's a stale delivery if len(errs) != 0 { + if len(errs) == len(blocks) { + return errStaleDelivery + } return fmt.Errorf("multiple failures: %v", errs) } return nil |