mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +00:00
eth: avoid useless sync in fast sync
This commit is contained in:
parent
ea04ad00fa
commit
920c49de87
3 changed files with 10 additions and 2 deletions
|
|
@ -1300,7 +1300,7 @@ func (d *Downloader) processHeaders(origin uint64, pivot uint64, td *big.Int) er
|
||||||
// Update the highest block number we know if a higher one is found.
|
// Update the highest block number we know if a higher one is found.
|
||||||
d.syncStatsLock.Lock()
|
d.syncStatsLock.Lock()
|
||||||
if d.syncStatsChainHeight < origin {
|
if d.syncStatsChainHeight < origin {
|
||||||
d.syncStatsChainHeight = origin
|
d.syncStatsChainHeight = origin - 1
|
||||||
}
|
}
|
||||||
d.syncStatsLock.Unlock()
|
d.syncStatsLock.Unlock()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -188,6 +188,14 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
|
||||||
atomic.StoreUint32(&pm.fastSync, 1)
|
atomic.StoreUint32(&pm.fastSync, 1)
|
||||||
mode = downloader.FastSync
|
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
|
// 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
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ func (s *PublicEthereumAPI) Syncing() (interface{}, error) {
|
||||||
progress := s.b.Downloader().Progress()
|
progress := s.b.Downloader().Progress()
|
||||||
|
|
||||||
// Return not syncing if the synchronisation already completed
|
// Return not syncing if the synchronisation already completed
|
||||||
if !s.b.Downloader().Synchronising() {
|
if progress.CurrentBlock >= progress.HighestBlock {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
// Otherwise gather the block sync stats
|
// Otherwise gather the block sync stats
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue