eth: don't import propagated blocks during fastsync

release/1.6
Péter Szilágyi 8 years ago
parent cb809c03da
commit afdd23b5ca
No known key found for this signature in database
GPG Key ID: E9AE538CEDF8293D
  1. 5
      eth/handler.go
  2. 1
      eth/sync.go

@ -171,6 +171,11 @@ func NewProtocolManager(config *params.ChainConfig, mode downloader.SyncMode, ne
return blockchain.CurrentBlock().NumberU64() return blockchain.CurrentBlock().NumberU64()
} }
inserter := func(blocks types.Blocks) (int, error) { inserter := func(blocks types.Blocks) (int, error) {
// If fast sync is running, deny importing weird blocks
if atomic.LoadUint32(&manager.fastSync) == 1 {
log.Warn("Discarded bad propagated block", "number", blocks[0].Number(), "hash", blocks[0].Hash())
return 0, nil
}
atomic.StoreUint32(&manager.acceptTxs, 1) // Mark initial sync done on any fetcher import atomic.StoreUint32(&manager.acceptTxs, 1) // Mark initial sync done on any fetcher import
return manager.blockchain.InsertChain(blocks) return manager.blockchain.InsertChain(blocks)
} }

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

Loading…
Cancel
Save