aboutsummaryrefslogtreecommitdiffstats
path: root/eth/downloader/downloader.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-06-08 19:06:36 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-06-08 19:12:00 +0800
commit63c6cedb14cbd461733e33ffac016dc7d8e431ae (patch)
treea1593178989ed92561b37dceb90fbf7401af4b10 /eth/downloader/downloader.go
parent4b2dd44711a04c639ecde68806455ccf7244acce (diff)
downloaddexon-63c6cedb14cbd461733e33ffac016dc7d8e431ae.tar
dexon-63c6cedb14cbd461733e33ffac016dc7d8e431ae.tar.gz
dexon-63c6cedb14cbd461733e33ffac016dc7d8e431ae.tar.bz2
dexon-63c6cedb14cbd461733e33ffac016dc7d8e431ae.tar.lz
dexon-63c6cedb14cbd461733e33ffac016dc7d8e431ae.tar.xz
dexon-63c6cedb14cbd461733e33ffac016dc7d8e431ae.tar.zst
dexon-63c6cedb14cbd461733e33ffac016dc7d8e431ae.zip
eth/downloader: cap the hash ban set, add test for it
Diffstat (limited to 'eth/downloader/downloader.go')
-rw-r--r--eth/downloader/downloader.go23
1 files changed, 16 insertions, 7 deletions
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go
index cd2fd81f1..7eda49186 100644
--- a/eth/downloader/downloader.go
+++ b/eth/downloader/downloader.go
@@ -17,18 +17,17 @@ import (
"gopkg.in/fatih/set.v0"
)
-const (
+var (
MinHashFetch = 512 // Minimum amount of hashes to not consider a peer stalling
MaxHashFetch = 2048 // Amount of hashes to be fetched per retrieval request
MaxBlockFetch = 128 // Amount of blocks to be fetched per retrieval request
- hashTTL = 5 * time.Second // Time it takes for a hash request to time out
-)
-
-var (
+ hashTTL = 5 * time.Second // Time it takes for a hash request to time out
blockSoftTTL = 3 * time.Second // Request completion threshold for increasing or decreasing a peer's bandwidth
blockHardTTL = 3 * blockSoftTTL // Maximum time allowance before a block request is considered expired
crossCheckCycle = time.Second // Period after which to check for expired cross checks
+
+ maxBannedHashes = 4096 // Number of bannable hashes before phasing old ones out
)
var (
@@ -602,9 +601,19 @@ func (d *Downloader) banBlocks(peerId string, head common.Hash) error {
}
index++
}
+ // Ban the head hash and phase out any excess
d.banned.Add(blocks[index].Hash())
-
- glog.V(logger.Debug).Infof("Banned %d blocks from: %s\n", index+1, peerId)
+ for d.banned.Size() > maxBannedHashes {
+ d.banned.Each(func(item interface{}) bool {
+ // Skip any hard coded bans
+ if core.BadHashes[item.(common.Hash)] {
+ return true
+ }
+ d.banned.Remove(item)
+ return false
+ })
+ }
+ glog.V(logger.Debug).Infof("Banned %d blocks from: %s", index+1, peerId)
return nil
}
}