downloader: only attempt common ancestor negotiation if > 0 local head

Eliminates a redundant negotiation if we can already
deduce that our only common block is genesis.

Signed-off-by: meows <b5c6@protonmail.com>
This commit is contained in:
meows 2020-05-11 15:30:23 -05:00
parent 12f6c7642c
commit db63f1ee42
No known key found for this signature in database
GPG key ID: 5786AEA5C8D5A520

View file

@ -441,10 +441,18 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td *big.I
} }
height := latest.Number.Uint64() height := latest.Number.Uint64()
origin, err := d.findAncestor(p, latest) var origin = uint64(0)
if err != nil {
return err if d.blockchain != nil &&
d.blockchain.CurrentHeader() != nil &&
d.blockchain.CurrentHeader().Number != nil &&
d.blockchain.CurrentHeader().Number.Uint64() > 0 {
origin, err = d.findAncestor(p, latest)
if err != nil {
return err
}
} }
d.syncStatsLock.Lock() d.syncStatsLock.Lock()
if d.syncStatsChainHeight <= origin || d.syncStatsChainOrigin > origin { if d.syncStatsChainHeight <= origin || d.syncStatsChainOrigin > origin {
d.syncStatsChainOrigin = origin d.syncStatsChainOrigin = origin