From f3ae8f50a5dfafa667fbe5e6a6574e69162d5ee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Fri, 15 May 2015 20:54:10 +0300 Subject: eth/downloader: circumvent download race between crosscheck and hashes --- eth/downloader/downloader.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'eth') 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 -- cgit v1.2.3