Skip to content

Commit 920c49d

Browse files
committed
eth: avoid useless sync in fast sync
1 parent ea04ad0 commit 920c49d

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

eth/downloader/downloader.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,7 @@ func (d *Downloader) processHeaders(origin uint64, pivot uint64, td *big.Int) er
13001300
// Update the highest block number we know if a higher one is found.
13011301
d.syncStatsLock.Lock()
13021302
if d.syncStatsChainHeight < origin {
1303-
d.syncStatsChainHeight = origin
1303+
d.syncStatsChainHeight = origin - 1
13041304
}
13051305
d.syncStatsLock.Unlock()
13061306

eth/sync.go

+8
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
188188
atomic.StoreUint32(&pm.fastSync, 1)
189189
mode = downloader.FastSync
190190
}
191+
192+
if mode == downloader.FastSync {
193+
// Make sure the peer's total difficulty we are synchronizing is higher.
194+
if pm.blockchain.GetTdByHash(pm.blockchain.CurrentFastBlock().Hash()).Cmp(pTd) >= 0 {
195+
return
196+
}
197+
}
198+
191199
// Run the sync cycle, and disable fast sync if we've went past the pivot block
192200
if err := pm.downloader.Synchronise(peer.id, pHead, pTd, mode); err != nil {
193201
return

internal/ethapi/api.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (s *PublicEthereumAPI) Syncing() (interface{}, error) {
8080
progress := s.b.Downloader().Progress()
8181

8282
// Return not syncing if the synchronisation already completed
83-
if !s.b.Downloader().Synchronising() {
83+
if progress.CurrentBlock >= progress.HighestBlock {
8484
return false, nil
8585
}
8686
// Otherwise gather the block sync stats

0 commit comments

Comments
 (0)