core: fast exit if inserting stopped

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
jsvisa 2025-06-18 23:16:02 +08:00
parent cc1293b8f1
commit ff0f3c50e9

View file

@ -1914,6 +1914,11 @@ func (bc *BlockChain) processBlock(parentRoot common.Hash, block *types.Block, s
)
defer interrupt.Store(true) // terminate the prefetch at the end
// Check for termination before starting block processing
if bc.insertStopped() {
return nil, errInsertionInterrupted
}
if bc.cacheConfig.TrieCleanNoPrefetch {
statedb, err = state.New(parentRoot, bc.statedb)
if err != nil {
@ -1981,6 +1986,11 @@ func (bc *BlockChain) processBlock(parentRoot common.Hash, block *types.Block, s
}()
}
// Check for termination before starting transaction processing
if bc.insertStopped() {
return nil, errInsertionInterrupted
}
// Process block using the parent state as reference point
pstart := time.Now()
res, err := bc.processor.Process(block, statedb, bc.vmConfig)
@ -1990,6 +2000,11 @@ func (bc *BlockChain) processBlock(parentRoot common.Hash, block *types.Block, s
}
ptime := time.Since(pstart)
// Check for termination before validation
if bc.insertStopped() {
return nil, errInsertionInterrupted
}
vstart := time.Now()
if err := bc.validator.ValidateState(block, statedb, res, false); err != nil {
bc.reportBlock(block, res, err)
@ -2046,6 +2061,11 @@ func (bc *BlockChain) processBlock(parentRoot common.Hash, block *types.Block, s
blockValidationTimer.Update(vtime - (triehash + trieUpdate)) // The time spent on block validation
blockCrossValidationTimer.Update(xvtime) // The time spent on stateless cross validation
// Check for termination before writing to database
if bc.insertStopped() {
return nil, errInsertionInterrupted
}
// Write the block to the chain and get the status.
var (
wstart = time.Now()