diff options
author | Péter Szilágyi <peterke@gmail.com> | 2015-05-06 20:32:53 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2015-05-07 15:57:34 +0800 |
commit | 4800c94392e814a2cb9d343aab4706be0cd0851d (patch) | |
tree | bff7b3bf3763d58451dcee85961e05895da3ca5d /eth/downloader/peer.go | |
parent | 97c37356fdcfac8b704c3d75b33e322a737c4e55 (diff) | |
download | go-tangerine-4800c94392e814a2cb9d343aab4706be0cd0851d.tar go-tangerine-4800c94392e814a2cb9d343aab4706be0cd0851d.tar.gz go-tangerine-4800c94392e814a2cb9d343aab4706be0cd0851d.tar.bz2 go-tangerine-4800c94392e814a2cb9d343aab4706be0cd0851d.tar.lz go-tangerine-4800c94392e814a2cb9d343aab4706be0cd0851d.tar.xz go-tangerine-4800c94392e814a2cb9d343aab4706be0cd0851d.tar.zst go-tangerine-4800c94392e814a2cb9d343aab4706be0cd0851d.zip |
eth/downloader: prioritize block fetch based on chain position, cap memory use
Diffstat (limited to 'eth/downloader/peer.go')
-rw-r--r-- | eth/downloader/peer.go | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/eth/downloader/peer.go b/eth/downloader/peer.go index 91977f592..45ec1cbfd 100644 --- a/eth/downloader/peer.go +++ b/eth/downloader/peer.go @@ -78,7 +78,7 @@ func newPeer(id string, hash common.Hash, getHashes hashFetcherFn, getBlocks blo } // fetch a chunk using the peer -func (p *peer) fetch(chunk *chunk) error { +func (p *peer) fetch(request *fetchRequest) error { p.mu.Lock() defer p.mu.Unlock() @@ -88,13 +88,12 @@ func (p *peer) fetch(chunk *chunk) error { // set working state p.state = workingState - // convert the set to a fetchable slice - hashes, i := make([]common.Hash, chunk.hashes.Size()), 0 - chunk.hashes.Each(func(v interface{}) bool { - hashes[i] = v.(common.Hash) - i++ - return true - }) + + // Convert the hash set to a fetchable slice + hashes := make([]common.Hash, 0, len(request.Hashes)) + for hash, _ := range request.Hashes { + hashes = append(hashes, hash) + } p.getBlocks(hashes) return nil |