@@ -181,13 +181,30 @@ func NewProtocolManager(config *params.ChainConfig, mode downloader.SyncMode, ne
181181 return blockchain .CurrentBlock ().NumberU64 ()
182182 }
183183 inserter := func (blocks types.Blocks ) (int , error ) {
184- // If fast sync is running, deny importing weird blocks
184+ // If sync hasn't reached the checkpoint yet, deny importing weird blocks.
185+ //
186+ // Ideally we would also compare the head block's timestamp and similarly reject
187+ // the propagated block if the head is too old. Unfortunately there is a corner
188+ // case when starting new networks, where the genesis might be ancient (0 unix)
189+ // which would prevent full nodes from accepting it.
190+ if manager .blockchain .CurrentBlock ().NumberU64 () < manager .checkpointNumber {
191+ log .Warn ("Unsynced yet, discarded propagated block" , "number" , blocks [0 ].Number (), "hash" , blocks [0 ].Hash ())
192+ return 0 , nil
193+ }
194+ // If fast sync is running, deny importing weird blocks. This is a problematic
195+ // clause when starting up a new network, because fast-syncing miners might not
196+ // accept each others' blocks until a restart. Unfortunately we haven't figured
197+ // out a way yet where nodes can decide unilaterally whether the network is new
198+ // or not. This should be fixed if we figure out a solution.
185199 if atomic .LoadUint32 (& manager .fastSync ) == 1 {
186- log .Warn ("Discarded bad propagated block" , "number" , blocks [0 ].Number (), "hash" , blocks [0 ].Hash ())
200+ log .Warn ("Fast syncing, discarded propagated block" , "number" , blocks [0 ].Number (), "hash" , blocks [0 ].Hash ())
187201 return 0 , nil
188202 }
189- atomic .StoreUint32 (& manager .acceptTxs , 1 ) // Mark initial sync done on any fetcher import
190- return manager .blockchain .InsertChain (blocks )
203+ n , err := manager .blockchain .InsertChain (blocks )
204+ if err == nil {
205+ atomic .StoreUint32 (& manager .acceptTxs , 1 ) // Mark initial sync done on any fetcher import
206+ }
207+ return n , err
191208 }
192209 manager .fetcher = fetcher .New (blockchain .GetBlockByHash , validator , manager .BroadcastBlock , heighter , inserter , manager .removePeer )
193210
0 commit comments