aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-06-10 17:30:35 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-06-11 00:47:59 +0800
commit355b1e3bb1c749d8ecb19e967db988a34aa36788 (patch)
treefb2abf5932e316d0a352b869add536c01eb0abc8 /eth
parentb9affbf9fe1ca8e76aef5efdc456a43dff38dc8d (diff)
downloaddexon-355b1e3bb1c749d8ecb19e967db988a34aa36788.tar.gz
dexon-355b1e3bb1c749d8ecb19e967db988a34aa36788.tar.zst
dexon-355b1e3bb1c749d8ecb19e967db988a34aa36788.zip
eth: randomly fetch announced block (don't hammer origin)
Diffstat (limited to 'eth')
-rw-r--r--eth/sync.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/eth/sync.go b/eth/sync.go
index 7a3b5fcd4..7817266f8 100644
--- a/eth/sync.go
+++ b/eth/sync.go
@@ -127,7 +127,7 @@ func (pm *ProtocolManager) txsyncLoop() {
// fetcher is responsible for collecting hash notifications, and periodically
// checking all unknown ones and individually fetching them.
func (pm *ProtocolManager) fetcher() {
- announces := make(map[common.Hash]*blockAnnounce)
+ announces := make(map[common.Hash][]*blockAnnounce)
request := make(map[*peer][]common.Hash)
pending := make(map[common.Hash]*blockAnnounce)
cycle := time.Tick(notifyCheckCycle)
@@ -139,7 +139,7 @@ func (pm *ProtocolManager) fetcher() {
// A batch of hashes the notified, schedule them for retrieval
glog.V(logger.Debug).Infof("Scheduling %d hash announcements from %s", len(notifications), notifications[0].peer.id)
for _, announce := range notifications {
- announces[announce.hash] = announce
+ announces[announce.hash] = append(announces[announce.hash], announce)
}
case <-cycle:
@@ -150,8 +150,9 @@ func (pm *ProtocolManager) fetcher() {
}
}
// Check if any notified blocks failed to arrive
- for hash, announce := range announces {
- if time.Since(announce.time) > notifyArriveTimeout {
+ for hash, all := range announces {
+ if time.Since(all[0].time) > notifyArriveTimeout {
+ announce := all[rand.Intn(len(all))]
if !pm.chainman.HasBlock(hash) {
request[announce.peer] = append(request[announce.peer], hash)
pending[hash] = announce