mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
Fix sync crash for nil pointer about td
This commit is contained in:
parent
f34a3a6805
commit
15fbed5197
1 changed files with 16 additions and 4 deletions
14
eth/sync.go
14
eth/sync.go
|
|
@ -171,6 +171,10 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
|
||||||
td := pm.blockchain.GetTd(currentBlock.Hash(), currentBlock.NumberU64())
|
td := pm.blockchain.GetTd(currentBlock.Hash(), currentBlock.NumberU64())
|
||||||
|
|
||||||
pHead, pTd := peer.Head()
|
pHead, pTd := peer.Head()
|
||||||
|
if pTd := nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if pTd.Cmp(td) <= 0 {
|
if pTd.Cmp(td) <= 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -182,10 +186,18 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
|
||||||
}
|
}
|
||||||
if mode == downloader.FastSync {
|
if mode == downloader.FastSync {
|
||||||
// Make sure the peer's total difficulty we are synchronizing is higher.
|
// Make sure the peer's total difficulty we are synchronizing is higher.
|
||||||
if pm.blockchain.GetTdByHash(pm.blockchain.CurrentFastBlock().Hash()).Cmp(pTd) >= 0 {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Run the sync cycle, and disable fast sync if we've went past the pivot block
|
// 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 {
|
if err := pm.downloader.Synchronise(peer.id, pHead, pTd, mode); err != nil {
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue