@@ -20,6 +20,7 @@ import (
2020 "context"
2121 "fmt"
2222 "math/big"
23+ "sync/atomic"
2324
2425 "github.com/ethereum/go-ethereum/common"
2526 cmath "github.com/ethereum/go-ethereum/common/math"
@@ -69,6 +70,11 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
6970 gp = new (GasPool ).AddGas (block .GasLimit ())
7071 )
7172
73+ // Set an empty context if nil
74+ if interruptCtx == nil {
75+ interruptCtx = context .Background ()
76+ }
77+
7278 // Mutate the block and state according to any hard-fork specs
7379 if p .config .DAOForkSupport && p .config .DAOForkBlock != nil && p .config .DAOForkBlock .Cmp (block .Number ()) == 0 {
7480 misc .ApplyDAOHardFork (statedb )
@@ -96,21 +102,21 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
96102
97103 // Iterate over and process the individual transactions
98104 for i , tx := range block .Transactions () {
99- if interruptCtx != nil {
100- select {
101- case <- interruptCtx .Done ():
102- return nil , interruptCtx .Err ()
103- default :
104- }
105+ // Check if execution should be cancelled or not
106+ select {
107+ case <- interruptCtx .Done ():
108+ return nil , interruptCtx .Err ()
109+ default :
105110 }
111+
106112 msg , err := TransactionToMessage (tx , signer , header .BaseFee )
107113 if err != nil {
108114 return nil , fmt .Errorf ("could not apply tx %d [%v]: %w" , i , tx .Hash ().Hex (), err )
109115 }
110116
111117 statedb .SetTxContext (tx .Hash (), i )
112118
113- receipt , err := ApplyTransactionWithEVM (msg , gp , statedb , blockNumber , blockHash , tx , usedGas , evm , interruptCtx )
119+ receipt , err := ApplyTransactionWithEVM (msg , gp , statedb , blockNumber , blockHash , tx , usedGas , evm , nil )
114120 if err != nil {
115121 return nil , fmt .Errorf ("could not apply tx %d [%v]: %w" , i , tx .Hash ().Hex (), err )
116122 }
@@ -154,7 +160,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
154160// ApplyTransactionWithEVM attempts to apply a transaction to the given state database
155161// and uses the input parameters for its environment similar to ApplyTransaction. However,
156162// this method takes an already created EVM instance as input.
157- func ApplyTransactionWithEVM (msg * Message , gp * GasPool , statedb * state.StateDB , blockNumber * big.Int , blockHash common.Hash , tx * types.Transaction , usedGas * uint64 , evm * vm.EVM , interruptCtx context. Context ) (receipt * types.Receipt , err error ) {
163+ func ApplyTransactionWithEVM (msg * Message , gp * GasPool , statedb * state.StateDB , blockNumber * big.Int , blockHash common.Hash , tx * types.Transaction , usedGas * uint64 , evm * vm.EVM , interrupt * atomic. Bool ) (receipt * types.Receipt , err error ) {
158164 if hooks := evm .Config .Tracer ; hooks != nil {
159165 if hooks .OnTxStart != nil {
160166 hooks .OnTxStart (evm .GetVMContext (), tx , msg .From )
@@ -180,7 +186,7 @@ func ApplyTransactionWithEVM(msg *Message, gp *GasPool, statedb *state.StateDB,
180186 // resume recording read and write
181187 statedb .SetMVHashmap (backupMVHashMap )
182188
183- result , err = ApplyMessageNoFeeBurnOrTip (evm , * msg , gp , interruptCtx )
189+ result , err = ApplyMessageNoFeeBurnOrTip (evm , * msg , gp , interrupt )
184190 if err != nil {
185191 return nil , err
186192 }
@@ -272,13 +278,13 @@ func MakeReceipt(evm *vm.EVM, result *ExecutionResult, statedb *state.StateDB, b
272278// and uses the input parameters for its environment. It returns the receipt
273279// for the transaction, gas used and an error if the transaction failed,
274280// indicating the block was invalid.
275- func ApplyTransaction (evm * vm.EVM , gp * GasPool , statedb * state.StateDB , header * types.Header , tx * types.Transaction , usedGas * uint64 , interruptCtx context. Context ) (* types.Receipt , error ) {
281+ func ApplyTransaction (evm * vm.EVM , gp * GasPool , statedb * state.StateDB , header * types.Header , tx * types.Transaction , usedGas * uint64 , interrupt * atomic. Bool ) (* types.Receipt , error ) {
276282 msg , err := TransactionToMessage (tx , types .MakeSigner (evm .ChainConfig (), header .Number , header .Time ), header .BaseFee )
277283 if err != nil {
278284 return nil , err
279285 }
280286 // Create a new context to be used in the EVM environment
281- return ApplyTransactionWithEVM (msg , gp , statedb , header .Number , header .Hash (), tx , usedGas , evm , interruptCtx )
287+ return ApplyTransactionWithEVM (msg , gp , statedb , header .Number , header .Hash (), tx , usedGas , evm , interrupt )
282288}
283289
284290// ProcessBeaconBlockRoot applies the EIP-4788 system call to the beacon block root
0 commit comments