From 82199692b04ba0fa9976977e282080c727828c52 Mon Sep 17 00:00:00 2001 From: Henning Diedrich Date: Thu, 21 Jul 2016 11:52:18 +0200 Subject: [PATCH] eth/downloader: fix #2841 spikes by block fetches Ignore a reportedly higher total difficulty when a peer's best block is already present in local chain. Makes robust against inaccurately reported height or total difficulty. --- eth/downloader/downloader.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 01c0818a01..1dafb46dc0 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -412,6 +412,14 @@ func (d *Downloader) syncWithPeer(p *peer, hash common.Hash, td *big.Int) (err e ) case p.version >= 62: + // essentially double check the peer-reported height. If its + // block at that height turns out to already be in our chain, + // stop search and ignore the alleged higher total difficulty + if d.hasBlockAndState(p.head) { + glog.Infof("%v: advertised a head already in our chain. Ignoring reported higher total difficulty", p) + return nil + } + // Look up the sync boundaries: the common ancestor and the target block latest, err := d.fetchHeight(p) if err != nil {