mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
core: few final cleanups
This commit is contained in:
parent
c0ca97f96a
commit
93de27d9d4
5 changed files with 22 additions and 19 deletions
|
|
@ -100,12 +100,10 @@ func genValueTx(nbytes int) func(int, *BlockGen) {
|
||||||
Nonce: gen.TxNonce(benchRootAddr),
|
Nonce: gen.TxNonce(benchRootAddr),
|
||||||
To: &toaddr,
|
To: &toaddr,
|
||||||
Value: big.NewInt(1),
|
Value: big.NewInt(1),
|
||||||
Gas: params.TxGas,
|
|
||||||
Data: data,
|
Data: data,
|
||||||
GasPrice: gasPrice,
|
GasPrice: gasPrice,
|
||||||
}
|
}
|
||||||
gas := types.IntrinsicGas(txdata, &rules)
|
txdata.Gas = types.IntrinsicGas(txdata, &rules)
|
||||||
txdata.Gas = gas
|
|
||||||
tx, _ := types.SignNewTx(benchRootKey, signer, txdata)
|
tx, _ := types.SignNewTx(benchRootKey, signer, txdata)
|
||||||
gen.AddTx(tx)
|
gen.AddTx(tx)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -376,16 +376,15 @@ func (st *stateTransition) execute() (*ExecutionResult, error) {
|
||||||
rules = st.evm.ChainConfig().Rules(st.evm.Context.BlockNumber, st.evm.Context.Random != nil, st.evm.Context.Time)
|
rules = st.evm.ChainConfig().Rules(st.evm.Context.BlockNumber, st.evm.Context.Random != nil, st.evm.Context.Time)
|
||||||
contractCreation = msg.To == nil
|
contractCreation = msg.To == nil
|
||||||
floorDataGas uint64
|
floorDataGas uint64
|
||||||
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
gas := msg.IntrinsicGas
|
|
||||||
// Check clauses 4-5, subtract intrinsic gas if everything is correct
|
// Check clauses 4-5, subtract intrinsic gas if everything is correct
|
||||||
if st.gasRemaining < gas {
|
if st.gasRemaining < msg.IntrinsicGas {
|
||||||
return nil, fmt.Errorf("%w: have %d, want %d", ErrIntrinsicGas, st.gasRemaining, gas)
|
return nil, fmt.Errorf("%w: have %d, want %d", ErrIntrinsicGas, st.gasRemaining, msg.IntrinsicGas)
|
||||||
}
|
}
|
||||||
// Gas limit suffices for the floor data cost (EIP-7623)
|
// Gas limit suffices for the floor data cost (EIP-7623)
|
||||||
if rules.IsPrague {
|
if rules.IsPrague {
|
||||||
var err error
|
|
||||||
floorDataGas, err = FloorDataGas(msg.Data)
|
floorDataGas, err = FloorDataGas(msg.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -395,9 +394,9 @@ func (st *stateTransition) execute() (*ExecutionResult, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if t := st.evm.Config.Tracer; t != nil && t.OnGasChange != nil {
|
if t := st.evm.Config.Tracer; t != nil && t.OnGasChange != nil {
|
||||||
t.OnGasChange(st.gasRemaining, st.gasRemaining-gas, tracing.GasChangeTxIntrinsicGas)
|
t.OnGasChange(st.gasRemaining, st.gasRemaining-msg.IntrinsicGas, tracing.GasChangeTxIntrinsicGas)
|
||||||
}
|
}
|
||||||
st.gasRemaining -= gas
|
st.gasRemaining -= msg.IntrinsicGas
|
||||||
|
|
||||||
if rules.IsEIP4762 {
|
if rules.IsEIP4762 {
|
||||||
st.evm.AccessEvents.AddTxOrigin(msg.From)
|
st.evm.AccessEvents.AddTxOrigin(msg.From)
|
||||||
|
|
|
||||||
|
|
@ -581,12 +581,12 @@ func (tx *Transaction) WithSignature(signer Signer, sig []byte) (*Transaction, e
|
||||||
return &Transaction{inner: cpy, time: tx.time}, nil
|
return &Transaction{inner: cpy, time: tx.time}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IntrinsicGas returns the 'intrinsic gas' computed for a message with the given data.
|
// IntrinsicGas returns the calculated intrinsic gas for the given transaction.
|
||||||
func (tx *Transaction) IntrinsicGas(rules *params.Rules) (uint64, error) {
|
func (tx *Transaction) IntrinsicGas(rules *params.Rules) (uint64, error) {
|
||||||
return calcIntrinsicGas(tx.inner, rules)
|
return calcIntrinsicGas(tx.inner, rules)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IntrinsicGas computes the 'intrinsic gas' for a message with the given data.
|
// IntrinsicGas returns the calculated intrinsic gas for the given transaction.
|
||||||
func IntrinsicGas(txdata TxData, rules *params.Rules) uint64 {
|
func IntrinsicGas(txdata TxData, rules *params.Rules) uint64 {
|
||||||
gas, err := calcIntrinsicGas(txdata, rules)
|
gas, err := calcIntrinsicGas(txdata, rules)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -591,8 +591,10 @@ func (evm *EVM) resolveCodeHash(addr common.Address) common.Hash {
|
||||||
// ChainConfig returns the environment's chain configuration
|
// ChainConfig returns the environment's chain configuration
|
||||||
func (evm *EVM) ChainConfig() *params.ChainConfig { return evm.chainConfig }
|
func (evm *EVM) ChainConfig() *params.ChainConfig { return evm.chainConfig }
|
||||||
|
|
||||||
|
// Rules returns the rules for the EVM given the current block's context.
|
||||||
func (evm *EVM) Rules() *params.Rules {
|
func (evm *EVM) Rules() *params.Rules {
|
||||||
rules := evm.ChainConfig().Rules(evm.Context.BlockNumber, evm.Context.Random != nil, evm.Context.Time)
|
bctx := evm.Context
|
||||||
|
rules := evm.ChainConfig().Rules(bctx.BlockNumber, bctx.Random != nil, bctx.Time)
|
||||||
return &rules
|
return &rules
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -536,12 +536,12 @@ func (api *API) IntermediateRoots(ctx context.Context, hash common.Hash, config
|
||||||
chainConfig = api.backend.ChainConfig()
|
chainConfig = api.backend.ChainConfig()
|
||||||
vmctx = core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), nil)
|
vmctx = core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), nil)
|
||||||
deleteEmptyObjects = chainConfig.IsEIP158(block.Number())
|
deleteEmptyObjects = chainConfig.IsEIP158(block.Number())
|
||||||
|
evm = vm.NewEVM(vmctx, statedb, chainConfig, vm.Config{})
|
||||||
|
rules = evm.Rules()
|
||||||
)
|
)
|
||||||
evm := vm.NewEVM(vmctx, statedb, chainConfig, vm.Config{})
|
|
||||||
if beaconRoot := block.BeaconRoot(); beaconRoot != nil {
|
if beaconRoot := block.BeaconRoot(); beaconRoot != nil {
|
||||||
core.ProcessBeaconBlockRoot(*beaconRoot, evm)
|
core.ProcessBeaconBlockRoot(*beaconRoot, evm)
|
||||||
}
|
}
|
||||||
rules := evm.Rules()
|
|
||||||
if rules.IsPrague {
|
if rules.IsPrague {
|
||||||
core.ProcessParentBlockHash(block.ParentHash(), evm)
|
core.ProcessParentBlockHash(block.ParentHash(), evm)
|
||||||
}
|
}
|
||||||
|
|
@ -601,12 +601,14 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac
|
||||||
}
|
}
|
||||||
defer release()
|
defer release()
|
||||||
|
|
||||||
blockCtx := core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), nil)
|
var (
|
||||||
evm := vm.NewEVM(blockCtx, statedb, api.backend.ChainConfig(), vm.Config{})
|
blockCtx = core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), nil)
|
||||||
|
evm = vm.NewEVM(blockCtx, statedb, api.backend.ChainConfig(), vm.Config{})
|
||||||
|
rules = evm.Rules()
|
||||||
|
)
|
||||||
if beaconRoot := block.BeaconRoot(); beaconRoot != nil {
|
if beaconRoot := block.BeaconRoot(); beaconRoot != nil {
|
||||||
core.ProcessBeaconBlockRoot(*beaconRoot, evm)
|
core.ProcessBeaconBlockRoot(*beaconRoot, evm)
|
||||||
}
|
}
|
||||||
rules := evm.Rules()
|
|
||||||
if rules.IsPrague {
|
if rules.IsPrague {
|
||||||
core.ProcessParentBlockHash(block.ParentHash(), evm)
|
core.ProcessParentBlockHash(block.ParentHash(), evm)
|
||||||
}
|
}
|
||||||
|
|
@ -781,11 +783,13 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
|
||||||
// Note: This copies the config, to not screw up the main config
|
// Note: This copies the config, to not screw up the main config
|
||||||
chainConfig, canon = overrideConfig(chainConfig, config.Overrides)
|
chainConfig, canon = overrideConfig(chainConfig, config.Overrides)
|
||||||
}
|
}
|
||||||
evm := vm.NewEVM(vmctx, statedb, chainConfig, vm.Config{})
|
var (
|
||||||
|
evm = vm.NewEVM(vmctx, statedb, chainConfig, vm.Config{})
|
||||||
|
rules = evm.Rules()
|
||||||
|
)
|
||||||
if beaconRoot := block.BeaconRoot(); beaconRoot != nil {
|
if beaconRoot := block.BeaconRoot(); beaconRoot != nil {
|
||||||
core.ProcessBeaconBlockRoot(*beaconRoot, evm)
|
core.ProcessBeaconBlockRoot(*beaconRoot, evm)
|
||||||
}
|
}
|
||||||
rules := evm.Rules()
|
|
||||||
if rules.IsPrague {
|
if rules.IsPrague {
|
||||||
core.ProcessParentBlockHash(block.ParentHash(), evm)
|
core.ProcessParentBlockHash(block.ParentHash(), evm)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue