Skip to content

Commit 2146e4f

Browse files
rjl493456442mariameda
authored andcommitted
eth: update higest block we know during the sync if a higher was found (ethereum#16283)
* eth: update higest block we know during the sync if a higher was found * eth: avoid useless sync in fast sync
1 parent bcdcc90 commit 2146e4f

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

eth/downloader/downloader.go

+8
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,14 @@ func (d *Downloader) processHeaders(origin uint64, pivot uint64, td *big.Int) er
12961296
headers = headers[limit:]
12971297
origin += uint64(limit)
12981298
}
1299+
1300+
// Update the highest block number we know if a higher one is found.
1301+
d.syncStatsLock.Lock()
1302+
if d.syncStatsChainHeight < origin {
1303+
d.syncStatsChainHeight = origin - 1
1304+
}
1305+
d.syncStatsLock.Unlock()
1306+
12991307
// Signal the content downloaders of the availablility of new tasks
13001308
for _, ch := range []chan bool{d.bodyWakeCh, d.receiptWakeCh} {
13011309
select {

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

0 commit comments

Comments
 (0)