diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-06-03 23:24:52 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-06-03 23:24:52 +0800 |
commit | 0cd72369f788dd6ef9e515370e049a7447a41a10 (patch) | |
tree | b89fcb6427e045ac4e1c0a658c48d331a62d20df /eth/downloader/queue.go | |
parent | 02f785af70d9d91d38ce44163a79c16ab288d55f (diff) | |
parent | 3ec159ab6be4dfcc51e339da562466eea38ce8b5 (diff) | |
download | go-tangerine-0cd72369f788dd6ef9e515370e049a7447a41a10.tar go-tangerine-0cd72369f788dd6ef9e515370e049a7447a41a10.tar.gz go-tangerine-0cd72369f788dd6ef9e515370e049a7447a41a10.tar.bz2 go-tangerine-0cd72369f788dd6ef9e515370e049a7447a41a10.tar.lz go-tangerine-0cd72369f788dd6ef9e515370e049a7447a41a10.tar.xz go-tangerine-0cd72369f788dd6ef9e515370e049a7447a41a10.tar.zst go-tangerine-0cd72369f788dd6ef9e515370e049a7447a41a10.zip |
Merge pull request #1176 from karalabe/congestion-control
eth/downloader: add a basic block download congestion control
Diffstat (limited to 'eth/downloader/queue.go')
-rw-r--r-- | eth/downloader/queue.go | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/eth/downloader/queue.go b/eth/downloader/queue.go index 7ea400dc4..69d91512a 100644 --- a/eth/downloader/queue.go +++ b/eth/downloader/queue.go @@ -203,7 +203,7 @@ func (q *queue) TakeBlocks() []*Block { // Reserve reserves a set of hashes for the given peer, skipping any previously // failed download. -func (q *queue) Reserve(p *peer, max int) *fetchRequest { +func (q *queue) Reserve(p *peer) *fetchRequest { q.lock.Lock() defer q.lock.Unlock() @@ -215,11 +215,17 @@ func (q *queue) Reserve(p *peer, max int) *fetchRequest { if _, ok := q.pendPool[p.id]; ok { return nil } + // Calculate an upper limit on the hashes we might fetch (i.e. throttling) + space := len(q.blockCache) - len(q.blockPool) + for _, request := range q.pendPool { + space -= len(request.Hashes) + } // Retrieve a batch of hashes, skipping previously failed ones send := make(map[common.Hash]int) skip := make(map[common.Hash]int) - for len(send) < max && !q.hashQueue.Empty() { + capacity := p.Capacity() + for len(send) < space && len(send) < capacity && !q.hashQueue.Empty() { hash, priority := q.hashQueue.Pop() if p.ignored.Has(hash) { skip[hash.(common.Hash)] = int(priority) |