diff --git a/core/blockchain.go b/core/blockchain.go index 553be35e53..8bb43aa189 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -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()