aboutsummaryrefslogtreecommitdiffstats
path: root/eth/downloader
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-05-16 02:23:44 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-05-16 02:23:44 +0800
commit82c0780f81bef8c88db9dff4bb34917f2934c71d (patch)
tree5a1aef81f1229de4e6ac7dc6025c69cdf238cffd /eth/downloader
parentcea1723c68375a1109a4fe606848d5c822321779 (diff)
parentf3ae8f50a5dfafa667fbe5e6a6574e69162d5ee6 (diff)
downloadgo-tangerine-82c0780f81bef8c88db9dff4bb34917f2934c71d.tar.gz
go-tangerine-82c0780f81bef8c88db9dff4bb34917f2934c71d.tar.zst
go-tangerine-82c0780f81bef8c88db9dff4bb34917f2934c71d.zip
Merge pull request #996 from karalabe/fix-potential-crosscheck-race
eth/downloader: circumvent download race between crosscheck and hashes
Diffstat (limited to 'eth/downloader')
-rw-r--r--eth/downloader/downloader.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go
index a0a5b20a2..1bc81406c 100644
--- a/eth/downloader/downloader.go
+++ b/eth/downloader/downloader.go
@@ -284,12 +284,14 @@ func (d *Downloader) fetchHashes(p *peer, h common.Hash) error {
}
if !done {
// Try and fetch a random block to verify the hash batch
- cross := inserts[rand.Intn(len(inserts))]
- glog.V(logger.Detail).Infof("Cross checking (%s) with %x", active.id, cross)
-
- d.checks[cross] = time.Now().Add(blockTTL)
- active.getBlocks([]common.Hash{cross})
+ // Skip the last hash as the cross check races with the next hash fetch
+ if len(inserts) > 1 {
+ cross := inserts[rand.Intn(len(inserts)-1)]
+ glog.V(logger.Detail).Infof("Cross checking (%s) with %x", active.id, cross)
+ d.checks[cross] = time.Now().Add(blockTTL)
+ active.getBlocks([]common.Hash{cross})
+ }
// Also fetch a fresh
active.getHashes(head)
continue