diff --git a/eth/sync.go b/eth/sync.go index 9e180ee200..0ba46e84a5 100644 --- a/eth/sync.go +++ b/eth/sync.go @@ -171,6 +171,10 @@ func (pm *ProtocolManager) synchronise(peer *peer) { td := pm.blockchain.GetTd(currentBlock.Hash(), currentBlock.NumberU64()) pHead, pTd := peer.Head() + if pTd := nil { + return + } + if pTd.Cmp(td) <= 0 { return } @@ -181,10 +185,18 @@ func (pm *ProtocolManager) synchronise(peer *peer) { 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 - } + // Make sure the peer's total difficulty we are synchronizing is higher. + fastTd := pm.blockchain.GetTdByHash(pm.blockchain.CurrentFastBlock().Hash()) + if fastTd == nil { + log.Warn("Fast total difficulty is nil, switch to full sync mode", "hash", pm.blockchain.CurrentFastBlock().Hash().Hex()) + //return + mode = downloader.FullSync + atomic.StoreUint32(&pm.fastSync, 0) + } else { + if fastTd.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 {