Skip to content

Commit f30179d

Browse files
committed
eth: disable fast sync after pivot is committed
1 parent c4d21bc commit f30179d

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

‎eth/downloader/downloader.go‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ func (d *Downloader) processHeaders(origin uint64, td *big.Int) error {
11701170

11711171
// If we're already past the pivot point, this could be an attack, thread carefully
11721172
if rollback[len(rollback)-1].Number.Uint64() > pivot {
1173-
// If we didn't ever fail, lock in te pivot header (must! not! change!)
1173+
// If we didn't ever fail, lock in the pivot header (must! not! change!)
11741174
if atomic.LoadUint32(&d.fsPivotFails) == 0 {
11751175
for _, header := range rollback {
11761176
if header.Number.Uint64() == pivot {
@@ -1392,7 +1392,6 @@ func (d *Downloader) processFastSyncContent(latest *types.Header) error {
13921392
stateSync.Cancel()
13931393
if err := d.commitPivotBlock(P); err != nil {
13941394
return err
1395-
13961395
}
13971396
}
13981397
if err := d.importBlockResults(afterP); err != nil {

‎eth/sync.go‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,17 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
188188
atomic.StoreUint32(&pm.fastSync, 1)
189189
mode = downloader.FastSync
190190
}
191-
if err := pm.downloader.Synchronise(peer.id, pHead, pTd, mode); err != nil {
191+
// Run the sync cycle, and disable fast sync if we've went past the pivot block
192+
err := pm.downloader.Synchronise(peer.id, pHead, pTd, mode)
193+
194+
if atomic.LoadUint32(&pm.fastSync) == 1 {
195+
// Disable fast sync if we indeed have something in our chain
196+
if pm.blockchain.CurrentBlock().NumberU64() > 0 {
197+
log.Info("Fast sync complete, auto disabling")
198+
atomic.StoreUint32(&pm.fastSync, 0)
199+
}
200+
}
201+
if err != nil {
192202
return
193203
}
194204
atomic.StoreUint32(&pm.acceptTxs, 1) // Mark initial sync done
@@ -201,12 +211,4 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
201211
// more reliably update peers or the local TD state.
202212
go pm.BroadcastBlock(head, false)
203213
}
204-
// If fast sync was enabled, and we synced up, disable it
205-
if atomic.LoadUint32(&pm.fastSync) == 1 {
206-
// Disable fast sync if we indeed have something in our chain
207-
if pm.blockchain.CurrentBlock().NumberU64() > 0 {
208-
log.Info("Fast sync complete, auto disabling")
209-
atomic.StoreUint32(&pm.fastSync, 0)
210-
}
211-
}
212214
}

0 commit comments

Comments
 (0)