mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-25 17:29:27 +00:00
core: address comments from sina
This commit is contained in:
parent
7646bd6227
commit
3a20c033b0
7 changed files with 22 additions and 22 deletions
|
|
@ -423,7 +423,7 @@ func (st *stateTransition) buyGas() error {
|
||||||
if st.evm.Config.Tracer.HasGasHook() {
|
if st.evm.Config.Tracer.HasGasHook() {
|
||||||
empty := vm.GasBudget{}
|
empty := vm.GasBudget{}
|
||||||
initial := vm.NewGasBudget(st.msg.GasLimit)
|
initial := vm.NewGasBudget(st.msg.GasLimit)
|
||||||
st.evm.Config.Tracer.FireGasChange(empty.AsTracing(), initial.AsTracing(), tracing.GasChangeTxInitialBalance)
|
st.evm.Config.Tracer.EmitGasChange(empty.AsTracing(), initial.AsTracing(), tracing.GasChangeTxInitialBalance)
|
||||||
}
|
}
|
||||||
st.gasRemaining = vm.NewGasBudget(st.msg.GasLimit)
|
st.gasRemaining = vm.NewGasBudget(st.msg.GasLimit)
|
||||||
st.initialBudget = st.gasRemaining.Copy()
|
st.initialBudget = st.gasRemaining.Copy()
|
||||||
|
|
@ -569,7 +569,7 @@ func (st *stateTransition) execute() (*ExecutionResult, error) {
|
||||||
return nil, fmt.Errorf("%w: have %d, want %d", ErrIntrinsicGas, st.gasRemaining.RegularGas, cost.RegularGas)
|
return nil, fmt.Errorf("%w: have %d, want %d", ErrIntrinsicGas, st.gasRemaining.RegularGas, cost.RegularGas)
|
||||||
}
|
}
|
||||||
if st.evm.Config.Tracer.HasGasHook() {
|
if st.evm.Config.Tracer.HasGasHook() {
|
||||||
st.evm.Config.Tracer.FireGasChange(prior.AsTracing(), st.gasRemaining.AsTracing(), tracing.GasChangeTxIntrinsicGas)
|
st.evm.Config.Tracer.EmitGasChange(prior.AsTracing(), st.gasRemaining.AsTracing(), tracing.GasChangeTxIntrinsicGas)
|
||||||
}
|
}
|
||||||
// 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 {
|
||||||
|
|
@ -654,7 +654,7 @@ func (st *stateTransition) execute() (*ExecutionResult, error) {
|
||||||
if used := st.gasUsed(); used < floorDataGas {
|
if used := st.gasUsed(); used < floorDataGas {
|
||||||
prior, _ := st.gasRemaining.Charge(vm.GasCosts{RegularGas: floorDataGas - used})
|
prior, _ := st.gasRemaining.Charge(vm.GasCosts{RegularGas: floorDataGas - used})
|
||||||
if st.evm.Config.Tracer.HasGasHook() {
|
if st.evm.Config.Tracer.HasGasHook() {
|
||||||
st.evm.Config.Tracer.FireGasChange(prior.AsTracing(), st.gasRemaining.AsTracing(), tracing.GasChangeTxDataFloor)
|
st.evm.Config.Tracer.EmitGasChange(prior.AsTracing(), st.gasRemaining.AsTracing(), tracing.GasChangeTxDataFloor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if peakGasUsed < floorDataGas {
|
if peakGasUsed < floorDataGas {
|
||||||
|
|
@ -786,7 +786,7 @@ func (st *stateTransition) calcRefund() vm.GasBudget {
|
||||||
after := st.gasRemaining
|
after := st.gasRemaining
|
||||||
after.RegularGas += refund
|
after.RegularGas += refund
|
||||||
|
|
||||||
st.evm.Config.Tracer.FireGasChange(st.gasRemaining.AsTracing(), after.AsTracing(), tracing.GasChangeTxRefunds)
|
st.evm.Config.Tracer.EmitGasChange(st.gasRemaining.AsTracing(), after.AsTracing(), tracing.GasChangeTxRefunds)
|
||||||
}
|
}
|
||||||
return vm.NewGasBudget(refund)
|
return vm.NewGasBudget(refund)
|
||||||
}
|
}
|
||||||
|
|
@ -801,7 +801,7 @@ func (st *stateTransition) returnGas() {
|
||||||
if st.gasRemaining.RegularGas > 0 && st.evm.Config.Tracer.HasGasHook() {
|
if st.gasRemaining.RegularGas > 0 && st.evm.Config.Tracer.HasGasHook() {
|
||||||
after := st.gasRemaining
|
after := st.gasRemaining
|
||||||
after.RegularGas = 0
|
after.RegularGas = 0
|
||||||
st.evm.Config.Tracer.FireGasChange(st.gasRemaining.AsTracing(), after.AsTracing(), tracing.GasChangeTxLeftOverReturned)
|
st.evm.Config.Tracer.EmitGasChange(st.gasRemaining.AsTracing(), after.AsTracing(), tracing.GasChangeTxLeftOverReturned)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -309,13 +309,13 @@ type Hooks struct {
|
||||||
|
|
||||||
// HasGasHook reports whether any gas-change hook is registered. Call sites
|
// HasGasHook reports whether any gas-change hook is registered. Call sites
|
||||||
// should use this to short-circuit before constructing the Gas / GasBudget
|
// should use this to short-circuit before constructing the Gas / GasBudget
|
||||||
// arguments to FireGasChange when tracing is off — the dispatch is otherwise
|
// arguments to EmitGasChange when tracing is off — the dispatch is otherwise
|
||||||
// always paid the cost of evaluating those args.
|
// always paid the cost of evaluating those args.
|
||||||
func (h *Hooks) HasGasHook() bool {
|
func (h *Hooks) HasGasHook() bool {
|
||||||
return h != nil && (h.OnGasChangeV2 != nil || h.OnGasChange != nil)
|
return h != nil && (h.OnGasChangeV2 != nil || h.OnGasChange != nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FireGasChange dispatches a gas change event to the registered hooks. If the
|
// EmitGasChange dispatches a gas change event to the registered hooks. If the
|
||||||
// multi-dimensional OnGasChangeV2 hook is set it is invoked with the full Gas
|
// multi-dimensional OnGasChangeV2 hook is set it is invoked with the full Gas
|
||||||
// vectors; otherwise the single-dimensional OnGasChange hook is invoked with
|
// vectors; otherwise the single-dimensional OnGasChange hook is invoked with
|
||||||
// the regular-gas dimension only. The call is a no-op when the receiver is
|
// the regular-gas dimension only. The call is a no-op when the receiver is
|
||||||
|
|
@ -323,7 +323,7 @@ func (h *Hooks) HasGasHook() bool {
|
||||||
//
|
//
|
||||||
// Call sites SHOULD use this helper instead of invoking the hooks directly so
|
// Call sites SHOULD use this helper instead of invoking the hooks directly so
|
||||||
// that both variants stay consistent across the Amsterdam fork boundary.
|
// that both variants stay consistent across the Amsterdam fork boundary.
|
||||||
func (h *Hooks) FireGasChange(old, new Gas, reason GasChangeReason) {
|
func (h *Hooks) EmitGasChange(old, new Gas, reason GasChangeReason) {
|
||||||
if h == nil || reason == GasChangeIgnored {
|
if h == nil || reason == GasChangeIgnored {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ func (c *Contract) UseGas(cost GasCosts, logger *tracing.Hooks, reason tracing.G
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if logger.HasGasHook() && reason != tracing.GasChangeIgnored {
|
if logger.HasGasHook() && reason != tracing.GasChangeIgnored {
|
||||||
logger.FireGasChange(prior.AsTracing(), c.Gas.AsTracing(), reason)
|
logger.EmitGasChange(prior.AsTracing(), c.Gas.AsTracing(), reason)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
@ -144,7 +144,7 @@ func (c *Contract) RefundGas(refund GasBudget, logger *tracing.Hooks, reason tra
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if logger.HasGasHook() && reason != tracing.GasChangeIgnored {
|
if logger.HasGasHook() && reason != tracing.GasChangeIgnored {
|
||||||
logger.FireGasChange(prior.AsTracing(), c.Gas.AsTracing(), reason)
|
logger.EmitGasChange(prior.AsTracing(), c.Gas.AsTracing(), reason)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -270,7 +270,7 @@ func RunPrecompiledContract(stateDB StateDB, p PrecompiledContract, address comm
|
||||||
return nil, gas, ErrOutOfGas
|
return nil, gas, ErrOutOfGas
|
||||||
}
|
}
|
||||||
if logger.HasGasHook() {
|
if logger.HasGasHook() {
|
||||||
logger.FireGasChange(prior.AsTracing(), gas.AsTracing(), tracing.GasChangeCallPrecompiledContract)
|
logger.EmitGasChange(prior.AsTracing(), gas.AsTracing(), tracing.GasChangeCallPrecompiledContract)
|
||||||
}
|
}
|
||||||
// Touch the precompile for block-level accessList recording once Amsterdam
|
// Touch the precompile for block-level accessList recording once Amsterdam
|
||||||
// fork is activated.
|
// fork is activated.
|
||||||
|
|
|
||||||
|
|
@ -318,7 +318,7 @@ func (evm *EVM) Call(caller common.Address, addr common.Address, input []byte, g
|
||||||
evm.StateDB.RevertToSnapshot(snapshot)
|
evm.StateDB.RevertToSnapshot(snapshot)
|
||||||
if err != ErrExecutionReverted {
|
if err != ErrExecutionReverted {
|
||||||
if evm.Config.Tracer.HasGasHook() {
|
if evm.Config.Tracer.HasGasHook() {
|
||||||
evm.Config.Tracer.FireGasChange(gas.AsTracing(), tracing.Gas{}, tracing.GasChangeCallFailedExecution)
|
evm.Config.Tracer.EmitGasChange(gas.AsTracing(), tracing.Gas{}, tracing.GasChangeCallFailedExecution)
|
||||||
}
|
}
|
||||||
gas.Exhaust()
|
gas.Exhaust()
|
||||||
}
|
}
|
||||||
|
|
@ -372,7 +372,7 @@ func (evm *EVM) CallCode(caller common.Address, addr common.Address, input []byt
|
||||||
evm.StateDB.RevertToSnapshot(snapshot)
|
evm.StateDB.RevertToSnapshot(snapshot)
|
||||||
if err != ErrExecutionReverted {
|
if err != ErrExecutionReverted {
|
||||||
if evm.Config.Tracer.HasGasHook() {
|
if evm.Config.Tracer.HasGasHook() {
|
||||||
evm.Config.Tracer.FireGasChange(gas.AsTracing(), tracing.Gas{}, tracing.GasChangeCallFailedExecution)
|
evm.Config.Tracer.EmitGasChange(gas.AsTracing(), tracing.Gas{}, tracing.GasChangeCallFailedExecution)
|
||||||
}
|
}
|
||||||
gas.Exhaust()
|
gas.Exhaust()
|
||||||
}
|
}
|
||||||
|
|
@ -416,7 +416,7 @@ func (evm *EVM) DelegateCall(originCaller common.Address, caller common.Address,
|
||||||
evm.StateDB.RevertToSnapshot(snapshot)
|
evm.StateDB.RevertToSnapshot(snapshot)
|
||||||
if err != ErrExecutionReverted {
|
if err != ErrExecutionReverted {
|
||||||
if evm.Config.Tracer.HasGasHook() {
|
if evm.Config.Tracer.HasGasHook() {
|
||||||
evm.Config.Tracer.FireGasChange(gas.AsTracing(), tracing.Gas{}, tracing.GasChangeCallFailedExecution)
|
evm.Config.Tracer.EmitGasChange(gas.AsTracing(), tracing.Gas{}, tracing.GasChangeCallFailedExecution)
|
||||||
}
|
}
|
||||||
gas.Exhaust()
|
gas.Exhaust()
|
||||||
}
|
}
|
||||||
|
|
@ -471,7 +471,7 @@ func (evm *EVM) StaticCall(caller common.Address, addr common.Address, input []b
|
||||||
evm.StateDB.RevertToSnapshot(snapshot)
|
evm.StateDB.RevertToSnapshot(snapshot)
|
||||||
if err != ErrExecutionReverted {
|
if err != ErrExecutionReverted {
|
||||||
if evm.Config.Tracer.HasGasHook() {
|
if evm.Config.Tracer.HasGasHook() {
|
||||||
evm.Config.Tracer.FireGasChange(gas.AsTracing(), tracing.Gas{}, tracing.GasChangeCallFailedExecution)
|
evm.Config.Tracer.EmitGasChange(gas.AsTracing(), tracing.Gas{}, tracing.GasChangeCallFailedExecution)
|
||||||
}
|
}
|
||||||
gas.Exhaust()
|
gas.Exhaust()
|
||||||
}
|
}
|
||||||
|
|
@ -510,7 +510,7 @@ func (evm *EVM) create(caller common.Address, code []byte, gas GasBudget, value
|
||||||
return nil, common.Address{}, gas, ErrOutOfGas
|
return nil, common.Address{}, gas, ErrOutOfGas
|
||||||
}
|
}
|
||||||
if evm.Config.Tracer.HasGasHook() {
|
if evm.Config.Tracer.HasGasHook() {
|
||||||
evm.Config.Tracer.FireGasChange(prior.AsTracing(), gas.AsTracing(), tracing.GasChangeWitnessContractCollisionCheck)
|
evm.Config.Tracer.EmitGasChange(prior.AsTracing(), gas.AsTracing(), tracing.GasChangeWitnessContractCollisionCheck)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -529,7 +529,7 @@ func (evm *EVM) create(caller common.Address, code []byte, gas GasBudget, value
|
||||||
(contractHash != (common.Hash{}) && contractHash != types.EmptyCodeHash) || // non-empty code
|
(contractHash != (common.Hash{}) && contractHash != types.EmptyCodeHash) || // non-empty code
|
||||||
isEIP7610RejectedAccount(evm.ChainConfig().ChainID, address, evm.chainRules.IsEIP158) {
|
isEIP7610RejectedAccount(evm.ChainConfig().ChainID, address, evm.chainRules.IsEIP158) {
|
||||||
if evm.Config.Tracer.HasGasHook() {
|
if evm.Config.Tracer.HasGasHook() {
|
||||||
evm.Config.Tracer.FireGasChange(gas.AsTracing(), tracing.Gas{}, tracing.GasChangeCallFailedExecution)
|
evm.Config.Tracer.EmitGasChange(gas.AsTracing(), tracing.Gas{}, tracing.GasChangeCallFailedExecution)
|
||||||
}
|
}
|
||||||
gas.Exhaust()
|
gas.Exhaust()
|
||||||
return nil, common.Address{}, gas, ErrContractAddressCollision
|
return nil, common.Address{}, gas, ErrContractAddressCollision
|
||||||
|
|
@ -559,7 +559,7 @@ func (evm *EVM) create(caller common.Address, code []byte, gas GasBudget, value
|
||||||
}
|
}
|
||||||
prior, _ := gas.Charge(GasCosts{RegularGas: consumed})
|
prior, _ := gas.Charge(GasCosts{RegularGas: consumed})
|
||||||
if evm.Config.Tracer.HasGasHook() {
|
if evm.Config.Tracer.HasGasHook() {
|
||||||
evm.Config.Tracer.FireGasChange(prior.AsTracing(), gas.AsTracing(), tracing.GasChangeWitnessContractInit)
|
evm.Config.Tracer.EmitGasChange(prior.AsTracing(), gas.AsTracing(), tracing.GasChangeWitnessContractInit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
evm.Context.Transfer(evm.StateDB, caller, address, value, &evm.chainRules)
|
evm.Context.Transfer(evm.StateDB, caller, address, value, &evm.chainRules)
|
||||||
|
|
@ -675,7 +675,7 @@ func (evm *EVM) captureBegin(depth int, typ OpCode, from common.Address, to comm
|
||||||
}
|
}
|
||||||
if tracer.HasGasHook() {
|
if tracer.HasGasHook() {
|
||||||
initial := NewGasBudget(startGas)
|
initial := NewGasBudget(startGas)
|
||||||
tracer.FireGasChange(tracing.Gas{}, initial.AsTracing(), tracing.GasChangeCallInitialBalance)
|
tracer.EmitGasChange(tracing.Gas{}, initial.AsTracing(), tracing.GasChangeCallInitialBalance)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -683,7 +683,7 @@ func (evm *EVM) captureEnd(depth int, startGas uint64, leftOverGas uint64, ret [
|
||||||
tracer := evm.Config.Tracer
|
tracer := evm.Config.Tracer
|
||||||
if leftOverGas != 0 && tracer.HasGasHook() {
|
if leftOverGas != 0 && tracer.HasGasHook() {
|
||||||
leftover := NewGasBudget(leftOverGas)
|
leftover := NewGasBudget(leftOverGas)
|
||||||
tracer.FireGasChange(leftover.AsTracing(), tracing.Gas{}, tracing.GasChangeCallLeftOverReturned)
|
tracer.EmitGasChange(leftover.AsTracing(), tracing.Gas{}, tracing.GasChangeCallLeftOverReturned)
|
||||||
}
|
}
|
||||||
var reverted bool
|
var reverted bool
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,6 @@ func (g *GasBudget) Refund(other GasBudget) (GasBudget, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AsTracing converts the GasBudget into the tracing-facing Gas vector.
|
// AsTracing converts the GasBudget into the tracing-facing Gas vector.
|
||||||
func (g *GasBudget) AsTracing() tracing.Gas {
|
func (g GasBudget) AsTracing() tracing.Gas {
|
||||||
return tracing.Gas{Regular: g.RegularGas, State: g.StateGas}
|
return tracing.Gas{Regular: g.RegularGas, State: g.StateGas}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -235,7 +235,7 @@ func (evm *EVM) Run(contract *Contract, input []byte, readOnly bool) (ret []byte
|
||||||
// Do tracing before potential memory expansion
|
// Do tracing before potential memory expansion
|
||||||
if debug {
|
if debug {
|
||||||
if evm.Config.Tracer.HasGasHook() {
|
if evm.Config.Tracer.HasGasHook() {
|
||||||
evm.Config.Tracer.FireGasChange(
|
evm.Config.Tracer.EmitGasChange(
|
||||||
tracing.Gas{Regular: gasCopy, State: contract.Gas.StateGas},
|
tracing.Gas{Regular: gasCopy, State: contract.Gas.StateGas},
|
||||||
tracing.Gas{Regular: gasCopy - cost, State: contract.Gas.StateGas},
|
tracing.Gas{Regular: gasCopy - cost, State: contract.Gas.StateGas},
|
||||||
tracing.GasChangeCallOpCode,
|
tracing.GasChangeCallOpCode,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue