eth: update higest block we know during the sync if a higher was found (#16283)

* eth: update higest block we know during the sync if a higher was found

* eth: avoid useless sync in fast sync
This commit is contained in:
gary rong
2018-03-09 17:51:30 +08:00
committed by Péter Szilágyi
parent 307846d046
commit 77da203547
2 changed files with 16 additions and 0 deletions

View File

@ -188,6 +188,14 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
atomic.StoreUint32(&pm.fastSync, 1)
mode = downloader.FastSync
}
if mode == downloader.FastSync {
// Make sure the peer's total difficulty we are synchronizing is higher.
if pm.blockchain.GetTdByHash(pm.blockchain.CurrentFastBlock().Hash()).Cmp(pTd) >= 0 {
return
}
}
// Run the sync cycle, and disable fast sync if we've went past the pivot block
if err := pm.downloader.Synchronise(peer.id, pHead, pTd, mode); err != nil {
return