diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 30316dfb66..62842adbc6 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -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. d.syncStatsLock.Lock() if d.syncStatsChainHeight < origin { - d.syncStatsChainHeight = origin + d.syncStatsChainHeight = origin - 1 } d.syncStatsLock.Unlock() diff --git a/eth/sync.go b/eth/sync.go index 2da1464bc5..e49e40087e 100644 --- a/eth/sync.go +++ b/eth/sync.go @@ -188,6 +188,14 @@ func (pm *ProtocolManager) synchronise(peer *peer) { atomic.StoreUint32(&pm.fastSync, 1) 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 if err := pm.downloader.Synchronise(peer.id, pHead, pTd, mode); err != nil { return diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index c8f73b0810..e492444042 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -80,7 +80,7 @@ func (s *PublicEthereumAPI) Syncing() (interface{}, error) { progress := s.b.Downloader().Progress() // Return not syncing if the synchronisation already completed - if !s.b.Downloader().Synchronising() { + if progress.CurrentBlock >= progress.HighestBlock { return false, nil } // Otherwise gather the block sync stats