diff options
author | obscuren <geffobscura@gmail.com> | 2015-04-19 19:30:34 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-04-19 19:30:34 +0800 |
commit | c58918c84ad6825ca20cc9170b0a79eb1033c50a (patch) | |
tree | 6ff82b5cf2bb1764a383e68a0e6155fad2bc3eb9 /eth/downloader/queue.go | |
parent | 4340996572a3cab2a4c985710c06ec956832e082 (diff) | |
download | go-tangerine-c58918c84ad6825ca20cc9170b0a79eb1033c50a.tar go-tangerine-c58918c84ad6825ca20cc9170b0a79eb1033c50a.tar.gz go-tangerine-c58918c84ad6825ca20cc9170b0a79eb1033c50a.tar.bz2 go-tangerine-c58918c84ad6825ca20cc9170b0a79eb1033c50a.tar.lz go-tangerine-c58918c84ad6825ca20cc9170b0a79eb1033c50a.tar.xz go-tangerine-c58918c84ad6825ca20cc9170b0a79eb1033c50a.tar.zst go-tangerine-c58918c84ad6825ca20cc9170b0a79eb1033c50a.zip |
downloader: moved chunk ignoring. Fixes issue with catching up
Diffstat (limited to 'eth/downloader/queue.go')
-rw-r--r-- | eth/downloader/queue.go | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/eth/downloader/queue.go b/eth/downloader/queue.go index ce3aa9850..adbc2a0d0 100644 --- a/eth/downloader/queue.go +++ b/eth/downloader/queue.go @@ -56,16 +56,18 @@ func (c *queue) get(p *peer, max int) *chunk { // Create a new set of hashes hashes, i := set.New(), 0 c.hashPool.Each(func(v interface{}) bool { + // break on limit if i == limit { return false } - - // Skip any hashes that have previously been requested from the peer - if !p.requested.Has(v) { - hashes.Add(v) - i++ + // skip any hashes that have previously been requested from the peer + if p.ignored.Has(v) { + return true } + hashes.Add(v) + i++ + return true }) // if no hashes can be requested return a nil chunk @@ -79,7 +81,7 @@ func (c *queue) get(p *peer, max int) *chunk { // Create a new chunk for the seperated hashes. The time is being used // to reset the chunk (timeout) - chunk := &chunk{hashes, time.Now()} + chunk := &chunk{p, hashes, time.Now()} // register as 'fetching' state c.fetching[p.id] = chunk @@ -111,6 +113,12 @@ func (c *queue) deliver(id string, blocks []*types.Block) { // If the chunk was never requested simply ignore it if chunk != nil { delete(c.fetching, id) + // check the length of the returned blocks. If the length of blocks is 0 + // we'll assume the peer doesn't know about the chain. + if len(blocks) == 0 { + // So we can ignore the blocks we didn't know about + chunk.peer.ignored.Merge(chunk.hashes) + } // seperate the blocks and the hashes blockHashes := chunk.fetchedHashes(blocks) @@ -118,7 +126,6 @@ func (c *queue) deliver(id string, blocks []*types.Block) { c.blockHashes.Merge(blockHashes) // Add the blocks c.blocks = append(c.blocks, blocks...) - // Add back whatever couldn't be delivered c.hashPool.Merge(chunk.hashes) c.fetchPool.Separate(chunk.hashes) @@ -134,6 +141,7 @@ func (c *queue) put(hashes *set.Set) { } type chunk struct { + peer *peer hashes *set.Set itime time.Time } |