aboutsummaryrefslogtreecommitdiffstats
path: root/eth/downloader/queue.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-06-03 19:39:21 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-06-03 19:40:11 +0800
commitc9a546c310d82eb00e0e76a5e73d2ff7d601f8f0 (patch)
tree763680b8b27c61352ad53a34a0f865aac9e6d126 /eth/downloader/queue.go
parent9085b10508f1a3a5830549037f033ca58d184a0e (diff)
downloaddexon-c9a546c310d82eb00e0e76a5e73d2ff7d601f8f0.tar
dexon-c9a546c310d82eb00e0e76a5e73d2ff7d601f8f0.tar.gz
dexon-c9a546c310d82eb00e0e76a5e73d2ff7d601f8f0.tar.bz2
dexon-c9a546c310d82eb00e0e76a5e73d2ff7d601f8f0.tar.lz
dexon-c9a546c310d82eb00e0e76a5e73d2ff7d601f8f0.tar.xz
dexon-c9a546c310d82eb00e0e76a5e73d2ff7d601f8f0.tar.zst
dexon-c9a546c310d82eb00e0e76a5e73d2ff7d601f8f0.zip
eth/downloader: add a basic block download congestion control
Diffstat (limited to 'eth/downloader/queue.go')
-rw-r--r--eth/downloader/queue.go10
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)