|
|
|
@ -18,6 +18,7 @@ package core |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"fmt" |
|
|
|
|
"math/big" |
|
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
|
"github.com/ethereum/go-ethereum/consensus" |
|
|
|
@ -60,6 +61,8 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg |
|
|
|
|
receipts types.Receipts |
|
|
|
|
usedGas = new(uint64) |
|
|
|
|
header = block.Header() |
|
|
|
|
blockHash = block.Hash() |
|
|
|
|
blockNumber = block.Number() |
|
|
|
|
allLogs []*types.Log |
|
|
|
|
gp = new(GasPool).AddGas(block.GasLimit()) |
|
|
|
|
) |
|
|
|
@ -75,8 +78,8 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err) |
|
|
|
|
} |
|
|
|
|
statedb.Prepare(tx.Hash(), block.Hash(), i) |
|
|
|
|
receipt, err := applyTransaction(msg, p.config, p.bc, nil, gp, statedb, header, tx, usedGas, vmenv) |
|
|
|
|
statedb.Prepare(tx.Hash(), i) |
|
|
|
|
receipt, err := applyTransaction(msg, p.config, p.bc, nil, gp, statedb, blockNumber, blockHash, tx, usedGas, vmenv) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err) |
|
|
|
|
} |
|
|
|
@ -89,7 +92,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg |
|
|
|
|
return receipts, allLogs, *usedGas, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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) { |
|
|
|
|
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) { |
|
|
|
|
// Create a new context to be used in the EVM environment.
|
|
|
|
|
txContext := NewEVMTxContext(msg) |
|
|
|
|
evm.Reset(txContext, statedb) |
|
|
|
@ -102,10 +105,10 @@ func applyTransaction(msg types.Message, config *params.ChainConfig, bc ChainCon |
|
|
|
|
|
|
|
|
|
// Update the state with pending changes.
|
|
|
|
|
var root []byte |
|
|
|
|
if config.IsByzantium(header.Number) { |
|
|
|
|
if config.IsByzantium(blockNumber) { |
|
|
|
|
statedb.Finalise(true) |
|
|
|
|
} else { |
|
|
|
|
root = statedb.IntermediateRoot(config.IsEIP158(header.Number)).Bytes() |
|
|
|
|
root = statedb.IntermediateRoot(config.IsEIP158(blockNumber)).Bytes() |
|
|
|
|
} |
|
|
|
|
*usedGas += result.UsedGas |
|
|
|
|
|
|
|
|
@ -126,10 +129,10 @@ func applyTransaction(msg types.Message, config *params.ChainConfig, bc ChainCon |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Set the receipt logs and create the bloom filter.
|
|
|
|
|
receipt.Logs = statedb.GetLogs(tx.Hash()) |
|
|
|
|
receipt.Logs = statedb.GetLogs(tx.Hash(), blockHash) |
|
|
|
|
receipt.Bloom = types.CreateBloom(types.Receipts{receipt}) |
|
|
|
|
receipt.BlockHash = statedb.BlockHash() |
|
|
|
|
receipt.BlockNumber = header.Number |
|
|
|
|
receipt.BlockHash = blockHash |
|
|
|
|
receipt.BlockNumber = blockNumber |
|
|
|
|
receipt.TransactionIndex = uint(statedb.TxIndex()) |
|
|
|
|
return receipt, err |
|
|
|
|
} |
|
|
|
@ -146,5 +149,5 @@ func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *commo |
|
|
|
|
// Create a new context to be used in the EVM environment
|
|
|
|
|
blockContext := NewEVMBlockContext(header, bc, author) |
|
|
|
|
vmenv := vm.NewEVM(blockContext, vm.TxContext{}, statedb, config, cfg) |
|
|
|
|
return applyTransaction(msg, config, bc, author, gp, statedb, header, tx, usedGas, vmenv) |
|
|
|
|
return applyTransaction(msg, config, bc, author, gp, statedb, header.Number, header.Hash(), tx, usedGas, vmenv) |
|
|
|
|
} |
|
|
|
|