Skip to content

Commit afdd23b

Browse files
committed
eth: don't import propagated blocks during fastsync
1 parent cb809c0 commit afdd23b

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

eth/handler.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ func NewProtocolManager(config *params.ChainConfig, mode downloader.SyncMode, ne
171171
return blockchain.CurrentBlock().NumberU64()
172172
}
173173
inserter := func(blocks types.Blocks) (int, error) {
174+
// If fast sync is running, deny importing weird blocks
175+
if atomic.LoadUint32(&manager.fastSync) == 1 {
176+
log.Warn("Discarded bad propagated block", "number", blocks[0].Number(), "hash", blocks[0].Hash())
177+
return 0, nil
178+
}
174179
atomic.StoreUint32(&manager.acceptTxs, 1) // Mark initial sync done on any fetcher import
175180
return manager.blockchain.InsertChain(blocks)
176181
}

eth/sync.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
183183
// The only scenario where this can happen is if the user manually (or via a
184184
// bad block) rolled back a fast sync node below the sync point. In this case
185185
// however it's safe to reenable fast sync.
186+
atomic.StoreUint32(&pm.fastSync, 1)
186187
mode = downloader.FastSync
187188
}
188189
if err := pm.downloader.Synchronise(peer.id, pHead, pTd, mode); err != nil {

0 commit comments

Comments
 (0)