aboutsummaryrefslogtreecommitdiffstats
path: root/eth/downloader/queue.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-04-19 19:30:34 +0800
committerobscuren <geffobscura@gmail.com>2015-04-19 19:30:34 +0800
commitc58918c84ad6825ca20cc9170b0a79eb1033c50a (patch)
tree6ff82b5cf2bb1764a383e68a0e6155fad2bc3eb9 /eth/downloader/queue.go
parent4340996572a3cab2a4c985710c06ec956832e082 (diff)
downloaddexon-c58918c84ad6825ca20cc9170b0a79eb1033c50a.tar
dexon-c58918c84ad6825ca20cc9170b0a79eb1033c50a.tar.gz
dexon-c58918c84ad6825ca20cc9170b0a79eb1033c50a.tar.bz2
dexon-c58918c84ad6825ca20cc9170b0a79eb1033c50a.tar.lz
dexon-c58918c84ad6825ca20cc9170b0a79eb1033c50a.tar.xz
dexon-c58918c84ad6825ca20cc9170b0a79eb1033c50a.tar.zst
dexon-c58918c84ad6825ca20cc9170b0a79eb1033c50a.zip
downloader: moved chunk ignoring. Fixes issue with catching up
Diffstat (limited to 'eth/downloader/queue.go')
-rw-r--r--eth/downloader/queue.go22
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
}