From 6fd9a5305aed176432bc5ee6bb9243707a60fd05 Mon Sep 17 00:00:00 2001 From: Gary Date: Tue, 19 Mar 2024 20:38:57 +0800 Subject: [PATCH] fix: Future Blocks Are Always Verified Instead Of Queued --- core/blockchain.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 63e401ad90..d4e3736d47 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1436,7 +1436,7 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types. // // After insertion is done, all accumulated events will be fired. func (bc *BlockChain) InsertChain(chain types.Blocks) (int, error) { - n, events, logs, err := bc.insertChain(chain) + n, events, logs, err := bc.insertChain(chain, true) bc.PostChainEvents(events, logs) return n, err } @@ -1444,7 +1444,7 @@ func (bc *BlockChain) InsertChain(chain types.Blocks) (int, error) { // insertChain will execute the actual chain insertion and event aggregation. The // only reason this method exists as a separate one is to make locking cleaner // with deferred statements. -func (bc *BlockChain) insertChain(chain types.Blocks) (int, []interface{}, []*types.Log, error) { +func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []interface{}, []*types.Log, error) { engine, _ := bc.Engine().(*XDPoS.XDPoS) // Do a sanity check that the provided chain is actually ordered and linked @@ -1480,7 +1480,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks) (int, []interface{}, []*ty for i, block := range chain { headers[i] = block.Header() - seals[i] = false + seals[i] = verifySeals bc.downloadingBlock.Add(block.Hash(), true) } abort, results := bc.engine.VerifyHeaders(bc, headers, seals) @@ -1556,7 +1556,8 @@ func (bc *BlockChain) insertChain(chain types.Blocks) (int, []interface{}, []*ty log.Debug("Number block need calculated again", "number", block.NumberU64(), "hash", block.Hash().Hex(), "winners", len(winner)) // Import all the pruned blocks to make the state available bc.chainmu.Unlock() - _, evs, logs, err := bc.insertChain(winner) + // During reorg, we use verifySeals=false + _, evs, logs, err := bc.insertChain(winner, false) bc.chainmu.Lock() events, coalescedLogs = evs, logs @@ -1843,7 +1844,8 @@ func (bc *BlockChain) getResultBlock(block *types.Block, verifiedM2 bool) (*Resu } log.Debug("Number block need calculated again", "number", block.NumberU64(), "hash", block.Hash().Hex(), "winners", len(winner)) // Import all the pruned blocks to make the state available - _, _, _, err := bc.insertChain(winner) + // During reorg, we use verifySeals=false + _, _, _, err := bc.insertChain(winner, false) if err != nil { return nil, err }