@@ -18,6 +18,7 @@ package core
1818
1919import (
2020 "fmt"
21+ "math/big"
2122
2223 "github.com/ethereum/go-ethereum/common"
2324 "github.com/ethereum/go-ethereum/consensus"
@@ -57,11 +58,13 @@ func NewStateProcessor(config *params.ChainConfig, bc *BlockChain, engine consen
5758// transactions failed to execute due to insufficient gas it will return an error.
5859func (p * StateProcessor ) Process (block * types.Block , statedb * state.StateDB , cfg vm.Config ) (types.Receipts , []* types.Log , uint64 , error ) {
5960 var (
60- receipts types.Receipts
61- usedGas = new (uint64 )
62- header = block .Header ()
63- allLogs []* types.Log
64- gp = new (GasPool ).AddGas (block .GasLimit ())
61+ receipts types.Receipts
62+ usedGas = new (uint64 )
63+ header = block .Header ()
64+ blockHash = block .Hash ()
65+ blockNumber = block .Number ()
66+ allLogs []* types.Log
67+ gp = new (GasPool ).AddGas (block .GasLimit ())
6568 )
6669 // Mutate the block and state according to any hard-fork specs
6770 if p .config .DAOForkSupport && p .config .DAOForkBlock != nil && p .config .DAOForkBlock .Cmp (block .Number ()) == 0 {
@@ -75,8 +78,8 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
7578 if err != nil {
7679 return nil , nil , 0 , fmt .Errorf ("could not apply tx %d [%v]: %w" , i , tx .Hash ().Hex (), err )
7780 }
78- statedb .Prepare (tx .Hash (), block . Hash (), i )
79- receipt , err := applyTransaction (msg , p .config , p .bc , nil , gp , statedb , header , tx , usedGas , vmenv )
81+ statedb .Prepare (tx .Hash (), i )
82+ receipt , err := applyTransaction (msg , p .config , p .bc , nil , gp , statedb , blockNumber , blockHash , tx , usedGas , vmenv )
8083 if err != nil {
8184 return nil , nil , 0 , fmt .Errorf ("could not apply tx %d [%v]: %w" , i , tx .Hash ().Hex (), err )
8285 }
@@ -89,7 +92,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
8992 return receipts , allLogs , * usedGas , nil
9093}
9194
92- func applyTransaction (msg types.Message , config * params.ChainConfig , bc ChainContext , author * common.Address , gp * GasPool , statedb * state.StateDB , header * types. Header , tx * types.Transaction , usedGas * uint64 , evm * vm.EVM ) (* types.Receipt , error ) {
95+ func applyTransaction (msg types.Message , config * params.ChainConfig , bc ChainContext , author * common.Address , gp * GasPool , statedb * state.StateDB , blockNumber * big. Int , blockHash common. Hash , tx * types.Transaction , usedGas * uint64 , evm * vm.EVM ) (* types.Receipt , error ) {
9396 // Create a new context to be used in the EVM environment.
9497 txContext := NewEVMTxContext (msg )
9598 evm .Reset (txContext , statedb )
@@ -102,10 +105,10 @@ func applyTransaction(msg types.Message, config *params.ChainConfig, bc ChainCon
102105
103106 // Update the state with pending changes.
104107 var root []byte
105- if config .IsByzantium (header . Number ) {
108+ if config .IsByzantium (blockNumber ) {
106109 statedb .Finalise (true )
107110 } else {
108- root = statedb .IntermediateRoot (config .IsEIP158 (header . Number )).Bytes ()
111+ root = statedb .IntermediateRoot (config .IsEIP158 (blockNumber )).Bytes ()
109112 }
110113 * usedGas += result .UsedGas
111114
@@ -126,10 +129,10 @@ func applyTransaction(msg types.Message, config *params.ChainConfig, bc ChainCon
126129 }
127130
128131 // Set the receipt logs and create the bloom filter.
129- receipt .Logs = statedb .GetLogs (tx .Hash ())
132+ receipt .Logs = statedb .GetLogs (tx .Hash (), blockHash )
130133 receipt .Bloom = types .CreateBloom (types.Receipts {receipt })
131- receipt .BlockHash = statedb . BlockHash ()
132- receipt .BlockNumber = header . Number
134+ receipt .BlockHash = blockHash
135+ receipt .BlockNumber = blockNumber
133136 receipt .TransactionIndex = uint (statedb .TxIndex ())
134137 return receipt , err
135138}
@@ -146,5 +149,5 @@ func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *commo
146149 // Create a new context to be used in the EVM environment
147150 blockContext := NewEVMBlockContext (header , bc , author )
148151 vmenv := vm .NewEVM (blockContext , vm.TxContext {}, statedb , config , cfg )
149- return applyTransaction (msg , config , bc , author , gp , statedb , header , tx , usedGas , vmenv )
152+ return applyTransaction (msg , config , bc , author , gp , statedb , header . Number , header . Hash () , tx , usedGas , vmenv )
150153}
0 commit comments