Fix sync crash for nil pointer about td

This commit is contained in:
ucwong 2019-07-30 00:55:43 +08:00 committed by GitHub
parent f34a3a6805
commit 15fbed5197
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 {