rename Capture hooks to On

# Conflicts:
#	cmd/evm/internal/t8ntool/execution.go
#	core/vm/instructions.go
#	eth/tracers/directory/noop.go
#	eth/tracers/internal/tracetest/calltrace_test.go
#	eth/tracers/internal/tracetest/flat_calltrace_test.go
#	eth/tracers/internal/tracetest/prestate_test.go
#	eth/tracers/js/goja.go
#	eth/tracers/js/tracer_test.go
#	eth/tracers/live/noop.go
#	eth/tracers/native/4byte.go
#	eth/tracers/native/call.go
#	eth/tracers/native/call_flat.go
#	eth/tracers/native/mux.go
#	eth/tracers/native/prestate.go
This commit is contained in:
Sina Mahmoodi 2024-02-29 17:18:43 +01:00 committed by Matthieu Vachon
parent a2ad953d21
commit 25a3a744c3
24 changed files with 207 additions and 195 deletions

View file

@ -241,7 +241,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
evm := vm.NewEVM(vmContext, txContext, statedb, chainConfig, vmConfig)
if tracer != nil {
tracer.CaptureTxStart(evm.GetVMContext(), tx, msg.From)
tracer.OnTxStart(evm.GetVMContext(), tx, msg.From)
}
// (ret []byte, usedGas uint64, failed bool, err error)
msgResult, err := core.ApplyMessage(evm, msg, gaspool)
@ -251,7 +251,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
rejectedTxs = append(rejectedTxs, &rejectedTx{i, err.Error()})
gaspool.SetGas(prevGas)
if tracer != nil {
tracer.CaptureTxEnd(nil, err)
tracer.OnTxEnd(nil, err)
if err := writeTraceResult(tracer, traceOutput); err != nil {
log.Warn("Error writing tracer output", "err", err)
}
@ -298,7 +298,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
receipt.TransactionIndex = uint(txIndex)
receipts = append(receipts, receipt)
if tracer != nil {
tracer.LiveLogger.CaptureTxEnd(receipt, nil)
tracer.Hooks.OnTxEnd(receipt, nil)
writeTraceResult(tracer, traceOutput)
}
}

View file

@ -111,8 +111,8 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
// and uses the input parameters for its environment similar to ApplyTransaction. However,
// this method takes an already created EVM instance as input.
func ApplyTransactionWithEVM(msg *Message, config *params.ChainConfig, gp *GasPool, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, evm *vm.EVM) (receipt *types.Receipt, err error) {
if evm.Config.Tracer != nil && evm.Config.Tracer.CaptureTxStart != nil {
evm.Config.Tracer.CaptureTxStart(&tracing.VMContext{
if evm.Config.Tracer != nil && evm.Config.Tracer.OnTxStart != nil {
evm.Config.Tracer.OnTxStart(&tracing.VMContext{
ChainConfig: evm.ChainConfig(),
StateDB: statedb,
BlockNumber: evm.Context.BlockNumber,
@ -120,9 +120,9 @@ func ApplyTransactionWithEVM(msg *Message, config *params.ChainConfig, gp *GasPo
Coinbase: evm.Context.Coinbase,
Random: evm.Context.Random,
}, tx, msg.From)
if evm.Config.Tracer.CaptureTxEnd != nil {
if evm.Config.Tracer.OnTxEnd != nil {
defer func() {
evm.Config.Tracer.CaptureTxEnd(receipt, err)
evm.Config.Tracer.OnTxEnd(receipt, err)
}()
}
}

View file

@ -109,8 +109,8 @@ type (
// be indicated by `reverted == false` and `err == ErrCodeStoreOutOfGas`.
ExitHook = func(output []byte, gasUsed uint64, err error, reverted bool)
// StateHook is invoked just prior to the execution of an opcode.
StateHook = func(pc uint64, op OpCode, gas, cost uint64, scope OpContext, rData []byte, depth int, err error)
// OpcodeHook is invoked just prior to the execution of an opcode.
OpcodeHook = func(pc uint64, op OpCode, gas, cost uint64, scope OpContext, rData []byte, depth int, err error)
// FaultHook is invoked when an error occurs during the execution of an opcode.
FaultHook = func(pc uint64, op OpCode, gas, cost uint64, scope OpContext, depth int, err error)
@ -165,16 +165,16 @@ type (
type Hooks struct {
// VM events
CaptureTxStart TxStartHook
CaptureTxEnd TxEndHook
CaptureStart StartHook
CaptureEnd EndHook
CaptureEnter EnterHook
CaptureExit ExitHook
CaptureState StateHook
CaptureFault FaultHook
CaptureKeccakPreimage KeccakPreimageHook
OnGasChange GasChangeHook
OnTxStart TxStartHook
OnTxEnd TxEndHook
OnStart StartHook
OnEnd EndHook
OnEnter EnterHook
OnExit ExitHook
OnOpcode OpcodeHook
OnFault FaultHook
OnKeccakPreimage KeccakPreimageHook
OnGasChange GasChangeHook
// Chain events
OnBlockchainInit BlockchainInitHook
OnBlockStart BlockStartHook
@ -284,7 +284,7 @@ const (
// GasChangeCallCodeStorage is the amount of gas that will be charged for code storage.
GasChangeCallCodeStorage GasChangeReason = 10
// GasChangeCallOpCode is the amount of gas that will be charged for an opcode executed by the EVM, exact opcode that was
// performed can be check by `CaptureState` handling.
// performed can be check by `OnOpcode` handling.
GasChangeCallOpCode GasChangeReason = 11
// GasChangeCallPrecompiledContract is the amount of gas that will be charged for a precompiled contract execution.
GasChangeCallPrecompiledContract GasChangeReason = 12

View file

@ -522,11 +522,11 @@ func (evm *EVM) captureBegin(isRoot bool, typ OpCode, from common.Address, to co
tracer := evm.Config.Tracer
if isRoot {
if tracer.CaptureStart != nil {
tracer.CaptureStart(from, to, typ == CREATE || typ == CREATE2, input, startGas, value)
if tracer.OnStart != nil {
tracer.OnStart(from, to, typ == CREATE || typ == CREATE2, input, startGas, value)
}
} else if tracer.CaptureEnter != nil {
tracer.CaptureEnter(tracing.OpCode(typ), from, to, input, startGas, value)
} else if tracer.OnEnter != nil {
tracer.OnEnter(tracing.OpCode(typ), from, to, input, startGas, value)
}
if tracer.OnGasChange != nil {
@ -548,11 +548,11 @@ func (evm *EVM) captureEnd(isRoot bool, typ OpCode, startGas uint64, leftOverGas
reverted = false
}
if isRoot {
if tracer.CaptureEnd != nil {
tracer.CaptureEnd(ret, startGas-leftOverGas, VMErrorFromErr(err), reverted)
if tracer.OnEnd != nil {
tracer.OnEnd(ret, startGas-leftOverGas, VMErrorFromErr(err), reverted)
}
} else if tracer.CaptureExit != nil {
tracer.CaptureExit(ret, startGas-leftOverGas, VMErrorFromErr(err), reverted)
} else if tracer.OnExit != nil {
tracer.OnExit(ret, startGas-leftOverGas, VMErrorFromErr(err), reverted)
}
}

View file

@ -248,8 +248,8 @@ func opKeccak256(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) (
if evm.Config.EnablePreimageRecording {
evm.StateDB.AddPreimage(interpreter.hasherBuf, data)
}
if interpreter.evm.Config.Tracer != nil && interpreter.evm.Config.Tracer.CaptureKeccakPreimage != nil {
interpreter.evm.Config.Tracer.CaptureKeccakPreimage(common.BytesToHash(interpreter.hasherBuf[:]), data)
if interpreter.evm.Config.Tracer != nil && interpreter.evm.Config.Tracer.OnKeccakPreimage != nil {
interpreter.evm.Config.Tracer.OnKeccakPreimage(common.BytesToHash(interpreter.hasherBuf[:]), data)
}
size.SetBytes(interpreter.hasherBuf[:])
return nil, nil
@ -858,11 +858,11 @@ func opSelfdestruct(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext
interpreter.evm.StateDB.AddBalance(beneficiary.Bytes20(), balance, tracing.BalanceIncreaseSelfdestruct)
interpreter.evm.StateDB.SelfDestruct(scope.Contract.Address())
if tracer := interpreter.evm.Config.Tracer; tracer != nil {
if tracer.CaptureEnter != nil {
tracer.CaptureEnter(tracing.OpCode(SELFDESTRUCT), scope.Contract.Address(), beneficiary.Bytes20(), []byte{}, 0, balance)
if tracer.OnEnter != nil {
tracer.OnEnter(tracing.OpCode(SELFDESTRUCT), scope.Contract.Address(), beneficiary.Bytes20(), []byte{}, 0, balance)
}
if tracer.CaptureExit != nil {
tracer.CaptureExit([]byte{}, 0, nil, false)
if tracer.OnExit != nil {
tracer.OnExit([]byte{}, 0, nil, false)
}
}
return nil, errStopToken
@ -878,11 +878,11 @@ func opSelfdestruct6780(pc *uint64, interpreter *EVMInterpreter, scope *ScopeCon
interpreter.evm.StateDB.AddBalance(beneficiary.Bytes20(), balance, tracing.BalanceIncreaseSelfdestruct)
interpreter.evm.StateDB.Selfdestruct6780(scope.Contract.Address())
if tracer := interpreter.evm.Config.Tracer; tracer != nil {
if tracer.CaptureEnter != nil {
tracer.CaptureEnter(tracing.OpCode(SELFDESTRUCT), scope.Contract.Address(), beneficiary.Bytes20(), []byte{}, 0, balance)
if tracer.OnEnter != nil {
tracer.OnEnter(tracing.OpCode(SELFDESTRUCT), scope.Contract.Address(), beneficiary.Bytes20(), []byte{}, 0, balance)
}
if tracer.CaptureExit != nil {
tracer.CaptureExit([]byte{}, 0, nil, false)
if tracer.OnExit != nil {
tracer.OnExit([]byte{}, 0, nil, false)
}
}
return nil, errStopToken

View file

@ -190,11 +190,11 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
defer func() {
if err != nil {
if !logged {
if in.evm.Config.Tracer.CaptureState != nil {
in.evm.Config.Tracer.CaptureState(pcCopy, tracing.OpCode(op), gasCopy, cost, callContext, in.returnData, in.evm.depth, VMErrorFromErr(err))
if in.evm.Config.Tracer.OnOpcode != nil {
in.evm.Config.Tracer.OnOpcode(pcCopy, tracing.OpCode(op), gasCopy, cost, callContext, in.returnData, in.evm.depth, VMErrorFromErr(err))
}
} else if in.evm.Config.Tracer.CaptureFault != nil {
in.evm.Config.Tracer.CaptureFault(pcCopy, tracing.OpCode(op), gasCopy, cost, callContext, in.evm.depth, VMErrorFromErr(err))
} else if in.evm.Config.Tracer.OnFault != nil {
in.evm.Config.Tracer.OnFault(pcCopy, tracing.OpCode(op), gasCopy, cost, callContext, in.evm.depth, VMErrorFromErr(err))
}
}
}()
@ -255,8 +255,8 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
if in.evm.Config.Tracer.OnGasChange != nil {
in.evm.Config.Tracer.OnGasChange(gasCopy, gasCopy-cost, tracing.GasChangeCallOpCode)
}
if in.evm.Config.Tracer.CaptureState != nil {
in.evm.Config.Tracer.CaptureState(pc, tracing.OpCode(op), gasCopy, cost, callContext, in.returnData, in.evm.depth, VMErrorFromErr(err))
if in.evm.Config.Tracer.OnOpcode != nil {
in.evm.Config.Tracer.OnOpcode(pc, tracing.OpCode(op), gasCopy, cost, callContext, in.returnData, in.evm.depth, VMErrorFromErr(err))
logged = true
}
}
@ -267,8 +267,8 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
if in.evm.Config.Tracer.OnGasChange != nil {
in.evm.Config.Tracer.OnGasChange(gasCopy, gasCopy-cost, tracing.GasChangeCallOpCode)
}
if in.evm.Config.Tracer.CaptureState != nil {
in.evm.Config.Tracer.CaptureState(pc, tracing.OpCode(op), gasCopy, cost, callContext, in.returnData, in.evm.depth, VMErrorFromErr(err))
if in.evm.Config.Tracer.OnOpcode != nil {
in.evm.Config.Tracer.OnOpcode(pc, tracing.OpCode(op), gasCopy, cost, callContext, in.returnData, in.evm.depth, VMErrorFromErr(err))
logged = true
}
}

View file

@ -123,7 +123,7 @@ func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) {
rules = cfg.ChainConfig.Rules(vmenv.Context.BlockNumber, vmenv.Context.Random != nil, vmenv.Context.Time)
)
if cfg.EVMConfig.Tracer != nil {
cfg.EVMConfig.Tracer.CaptureTxStart(vmenv.GetVMContext(), types.NewTx(&types.LegacyTx{To: &address, Data: input, Value: cfg.Value, Gas: cfg.GasLimit}), cfg.Origin)
cfg.EVMConfig.Tracer.OnTxStart(vmenv.GetVMContext(), types.NewTx(&types.LegacyTx{To: &address, Data: input, Value: cfg.Value, Gas: cfg.GasLimit}), cfg.Origin)
}
// Execute the preparatory steps for state transition which includes:
// - prepare accessList(post-berlin)
@ -159,7 +159,7 @@ func Create(input []byte, cfg *Config) ([]byte, common.Address, uint64, error) {
rules = cfg.ChainConfig.Rules(vmenv.Context.BlockNumber, vmenv.Context.Random != nil, vmenv.Context.Time)
)
if cfg.EVMConfig.Tracer != nil {
cfg.EVMConfig.Tracer.CaptureTxStart(vmenv.GetVMContext(), types.NewTx(&types.LegacyTx{Data: input, Value: cfg.Value, Gas: cfg.GasLimit}), cfg.Origin)
cfg.EVMConfig.Tracer.OnTxStart(vmenv.GetVMContext(), types.NewTx(&types.LegacyTx{Data: input, Value: cfg.Value, Gas: cfg.GasLimit}), cfg.Origin)
}
// Execute the preparatory steps for state transition which includes:
// - prepare accessList(post-berlin)
@ -190,7 +190,7 @@ func Call(address common.Address, input []byte, cfg *Config) ([]byte, uint64, er
rules = cfg.ChainConfig.Rules(vmenv.Context.BlockNumber, vmenv.Context.Random != nil, vmenv.Context.Time)
)
if cfg.EVMConfig.Tracer != nil {
cfg.EVMConfig.Tracer.CaptureTxStart(vmenv.GetVMContext(), types.NewTx(&types.LegacyTx{To: &address, Data: input, Value: cfg.Value, Gas: cfg.GasLimit}), cfg.Origin)
cfg.EVMConfig.Tracer.OnTxStart(vmenv.GetVMContext(), types.NewTx(&types.LegacyTx{To: &address, Data: input, Value: cfg.Value, Gas: cfg.GasLimit}), cfg.Origin)
}
// Execute the preparatory steps for state transition which includes:
// - prepare accessList(post-berlin)

View file

@ -335,7 +335,7 @@ func benchmarkNonModifyingCode(gas uint64, code []byte, name string, tracerCode
b.Fatal(err)
}
cfg.EVMConfig = vm.Config{
Tracer: tracer.LiveLogger,
Tracer: tracer.Hooks,
}
}
var (
@ -510,7 +510,7 @@ func TestEip2929Cases(t *testing.T) {
code, ops)
Execute(code, nil, &Config{
EVMConfig: vm.Config{
Tracer: logger.NewMarkdownLogger(nil, os.Stdout).Logger(),
Tracer: logger.NewMarkdownLogger(nil, os.Stdout).Hooks(),
ExtraEips: []int{2929},
},
})
@ -663,7 +663,7 @@ func TestColdAccountAccessCost(t *testing.T) {
tracer := logger.NewStructLogger(nil)
Execute(tc.code, nil, &Config{
EVMConfig: vm.Config{
Tracer: tracer.GetTracer().LiveLogger,
Tracer: tracer.Hooks(),
},
})
have := tracer.StructLogs()[tc.step].GasCost
@ -834,7 +834,7 @@ func TestRuntimeJSTracer(t *testing.T) {
GasLimit: 1000000,
State: statedb,
EVMConfig: vm.Config{
Tracer: tracer.LiveLogger,
Tracer: tracer.Hooks,
}})
if err != nil {
t.Fatal("didn't expect error", err)
@ -868,7 +868,7 @@ func TestJSTracerCreateTx(t *testing.T) {
_, _, _, err = Create(code, &Config{
State: statedb,
EVMConfig: vm.Config{
Tracer: tracer.LiveLogger,
Tracer: tracer.Hooks,
}})
if err != nil {
t.Fatal(err)

View file

@ -784,9 +784,9 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
// Execute the transaction and flush any traces to disk
vmenv := vm.NewEVM(vmctx, txContext, statedb, chainConfig, vmConf)
statedb.SetTxContext(tx.Hash(), i)
vmConf.Tracer.CaptureTxStart(vmenv.GetVMContext(), tx, msg.From)
vmConf.Tracer.OnTxStart(vmenv.GetVMContext(), tx, msg.From)
vmRet, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.GasLimit))
vmConf.Tracer.CaptureTxEnd(&types.Receipt{GasUsed: vmRet.UsedGas}, err)
vmConf.Tracer.OnTxEnd(&types.Receipt{GasUsed: vmRet.UsedGas}, err)
if writer != nil {
writer.Flush()
}

View file

@ -37,22 +37,22 @@ type NoopTracer struct{}
func newNoopTracer(ctx *Context, _ json.RawMessage) (*Tracer, error) {
t := &NoopTracer{}
return &Tracer{
LiveLogger: &tracing.LiveLogger{
CaptureTxStart: t.CaptureTxStart,
CaptureTxEnd: t.CaptureTxEnd,
CaptureStart: t.CaptureStart,
CaptureEnd: t.CaptureEnd,
CaptureEnter: t.CaptureEnter,
CaptureExit: t.CaptureExit,
CaptureState: t.CaptureState,
CaptureFault: t.CaptureFault,
CaptureKeccakPreimage: t.CaptureKeccakPreimage,
OnGasChange: t.OnGasChange,
OnBalanceChange: t.OnBalanceChange,
OnNonceChange: t.OnNonceChange,
OnCodeChange: t.OnCodeChange,
OnStorageChange: t.OnStorageChange,
OnLog: t.OnLog,
Hooks: &tracing.Hooks{
OnTxStart: t.CaptureTxStart,
OnTxEnd: t.CaptureTxEnd,
OnStart: t.CaptureStart,
OnEnd: t.CaptureEnd,
OnEnter: t.CaptureEnter,
OnExit: t.CaptureExit,
OnOpcode: t.CaptureState,
OnFault: t.CaptureFault,
OnKeccakPreimage: t.CaptureKeccakPreimage,
OnGasChange: t.OnGasChange,
OnBalanceChange: t.OnBalanceChange,
OnNonceChange: t.OnNonceChange,
OnCodeChange: t.OnCodeChange,
OnStorageChange: t.OnStorageChange,
OnLog: t.OnLog,
},
GetResult: t.GetResult,
Stop: t.Stop,

View file

@ -149,13 +149,13 @@ func testCallTracer(tracerName string, dirPath string, t *testing.T) {
if err != nil {
t.Fatalf("failed to prepare transaction for tracing: %v", err)
}
evm := vm.NewEVM(context, core.NewEVMTxContext(msg), statedb, test.Genesis.Config, vm.Config{Tracer: tracer.LiveLogger})
tracer.CaptureTxStart(evm.GetVMContext(), tx, msg.From)
evm := vm.NewEVM(context, core.NewEVMTxContext(msg), statedb, test.Genesis.Config, vm.Config{Tracer: tracer.Hooks})
tracer.OnTxStart(evm.GetVMContext(), tx, msg.From)
vmRet, err := core.ApplyMessage(evm, msg, new(core.GasPool).AddGas(tx.Gas()))
if err != nil {
t.Fatalf("failed to execute transaction: %v", err)
}
tracer.CaptureTxEnd(&types.Receipt{GasUsed: vmRet.UsedGas}, nil)
tracer.OnTxEnd(&types.Receipt{GasUsed: vmRet.UsedGas}, nil)
// Retrieve the trace result and compare against the expected.
res, err := tracer.GetResult()
if err != nil {
@ -398,12 +398,12 @@ func TestInternals(t *testing.T) {
if err != nil {
t.Fatalf("test %v: failed to create message: %v", tc.name, err)
}
tc.tracer.CaptureTxStart(evm.GetVMContext(), tx, msg.From)
tc.tracer.OnTxStart(evm.GetVMContext(), tx, msg.From)
vmRet, err := core.ApplyMessage(evm, msg, new(core.GasPool).AddGas(tx.Gas()))
if err != nil {
t.Fatalf("test %v: failed to execute transaction: %v", tc.name, err)
}
tc.tracer.CaptureTxEnd(&types.Receipt{GasUsed: vmRet.UsedGas}, nil)
tc.tracer.OnTxEnd(&types.Receipt{GasUsed: vmRet.UsedGas}, nil)
// Retrieve the trace result and compare against the expected
res, err := tc.tracer.GetResult()
if err != nil {

View file

@ -107,13 +107,13 @@ func flatCallTracerTestRunner(tracerName string, filename string, dirPath string
if err != nil {
return fmt.Errorf("failed to prepare transaction for tracing: %v", err)
}
evm := vm.NewEVM(context, core.NewEVMTxContext(msg), statedb, test.Genesis.Config, vm.Config{Tracer: tracer.LiveLogger})
tracer.CaptureTxStart(evm.GetVMContext(), tx, msg.From)
evm := vm.NewEVM(context, core.NewEVMTxContext(msg), statedb, test.Genesis.Config, vm.Config{Tracer: tracer.Hooks})
tracer.OnTxStart(evm.GetVMContext(), tx, msg.From)
vmRet, err := core.ApplyMessage(evm, msg, new(core.GasPool).AddGas(tx.Gas()))
if err != nil {
return fmt.Errorf("failed to execute transaction: %v", err)
}
tracer.CaptureTxEnd(&types.Receipt{GasUsed: vmRet.UsedGas}, nil)
tracer.OnTxEnd(&types.Receipt{GasUsed: vmRet.UsedGas}, nil)
// Retrieve the trace result and compare against the etalon
res, err := tracer.GetResult()

View file

@ -117,13 +117,13 @@ func testPrestateDiffTracer(tracerName string, dirPath string, t *testing.T) {
if err != nil {
t.Fatalf("failed to prepare transaction for tracing: %v", err)
}
evm := vm.NewEVM(context, core.NewEVMTxContext(msg), statedb, test.Genesis.Config, vm.Config{Tracer: tracer.LiveLogger})
tracer.CaptureTxStart(evm.GetVMContext(), tx, msg.From)
evm := vm.NewEVM(context, core.NewEVMTxContext(msg), statedb, test.Genesis.Config, vm.Config{Tracer: tracer.Hooks})
tracer.OnTxStart(evm.GetVMContext(), tx, msg.From)
vmRet, err := core.ApplyMessage(evm, msg, new(core.GasPool).AddGas(tx.Gas()))
if err != nil {
t.Fatalf("failed to execute transaction: %v", err)
}
tracer.CaptureTxEnd(&types.Receipt{GasUsed: vmRet.UsedGas}, nil)
tracer.OnTxEnd(&types.Receipt{GasUsed: vmRet.UsedGas}, nil)
// Retrieve the trace result and compare against the expected
res, err := tracer.GetResult()
if err != nil {

View file

@ -213,15 +213,15 @@ func newJsTracer(code string, ctx *directory.Context, cfg json.RawMessage) (*dir
t.logValue = t.log.setupObject()
return &directory.Tracer{
LiveLogger: &tracing.LiveLogger{
CaptureTxStart: t.CaptureTxStart,
CaptureTxEnd: t.CaptureTxEnd,
CaptureStart: t.CaptureStart,
CaptureEnd: t.CaptureEnd,
CaptureEnter: t.CaptureEnter,
CaptureExit: t.CaptureExit,
CaptureState: t.CaptureState,
CaptureFault: t.CaptureFault,
Hooks: &tracing.Hooks{
OnTxStart: t.CaptureTxStart,
OnTxEnd: t.CaptureTxEnd,
OnStart: t.CaptureStart,
OnEnd: t.CaptureEnd,
OnEnter: t.CaptureEnter,
OnExit: t.CaptureExit,
OnOpcode: t.CaptureState,
OnFault: t.CaptureFault,
},
GetResult: t.GetResult,
Stop: t.Stop,
@ -329,7 +329,7 @@ func (t *jsTracer) CaptureFault(pc uint64, op tracing.OpCode, gas, cost uint64,
if t.err != nil {
return
}
// Other log fields have been already set as part of the last CaptureState.
// Other log fields have been already set as part of the last OnOpcode.
t.log.err = err
if _, err := t.fault(t.obj, t.logValue, t.dbValue); err != nil {
t.onError("fault", err)
@ -407,7 +407,7 @@ func (t *jsTracer) Stop(err error) {
// execution.
func (t *jsTracer) onError(context string, err error) {
t.err = wrapError(context, err)
// `env` is set on CaptureStart which comes before any JS execution.
// `env` is set on OnStart which comes before any JS execution.
// So it should be non-nil.
t.env.VM.Cancel()
}

View file

@ -75,12 +75,12 @@ func runTrace(tracer *directory.Tracer, vmctx *vmContext, chaincfg *params.Chain
contract.Code = contractCode
}
tracer.CaptureTxStart(env.GetVMContext(), types.NewTx(&types.LegacyTx{Gas: gasLimit}), contract.Caller())
tracer.CaptureStart(contract.Caller(), contract.Address(), false, []byte{}, startGas, value)
tracer.OnTxStart(env.GetVMContext(), types.NewTx(&types.LegacyTx{Gas: gasLimit}), contract.Caller())
tracer.OnStart(contract.Caller(), contract.Address(), false, []byte{}, startGas, value)
ret, err := env.Interpreter().Run(contract, []byte{}, false)
tracer.CaptureEnd(ret, startGas-contract.Gas, err, true)
tracer.OnEnd(ret, startGas-contract.Gas, err, true)
// Rest gas assumes no refund
tracer.CaptureTxEnd(&types.Receipt{GasUsed: gasLimit - contract.Gas}, nil)
tracer.OnTxEnd(&types.Receipt{GasUsed: gasLimit - contract.Gas}, nil)
if err != nil {
return nil, err
}
@ -185,13 +185,13 @@ func TestHaltBetweenSteps(t *testing.T) {
scope := &vm.ScopeContext{
Contract: vm.NewContract(&account{}, &account{}, big.NewInt(0), 0),
}
env := vm.NewEVM(vm.BlockContext{BlockNumber: big.NewInt(1)}, vm.TxContext{GasPrice: big.NewInt(1)}, &dummyStatedb{}, params.TestChainConfig, vm.Config{Tracer: tracer.LiveLogger})
tracer.CaptureTxStart(env.GetVMContext(), types.NewTx(&types.LegacyTx{}), common.Address{})
tracer.CaptureStart(common.Address{}, common.Address{}, false, []byte{}, 0, big.NewInt(0))
tracer.CaptureState(0, 0, 0, 0, scope, nil, 0, nil)
env := vm.NewEVM(vm.BlockContext{BlockNumber: big.NewInt(1)}, vm.TxContext{GasPrice: big.NewInt(1)}, &dummyStatedb{}, params.TestChainConfig, vm.Config{Tracer: tracer.Hooks})
tracer.OnTxStart(env.GetVMContext(), types.NewTx(&types.LegacyTx{}), common.Address{})
tracer.OnStart(common.Address{}, common.Address{}, false, []byte{}, 0, big.NewInt(0))
tracer.OnOpcode(0, 0, 0, 0, scope, nil, 0, nil)
timeout := errors.New("stahp")
tracer.Stop(timeout)
tracer.CaptureState(0, 0, 0, 0, scope, nil, 0, nil)
tracer.OnOpcode(0, 0, 0, 0, scope, nil, 0, nil)
if _, err := tracer.GetResult(); !strings.Contains(err.Error(), timeout.Error()) {
t.Errorf("Expected timeout error, got %v", err)
@ -207,10 +207,10 @@ func TestNoStepExec(t *testing.T) {
if err != nil {
t.Fatal(err)
}
env := vm.NewEVM(vm.BlockContext{BlockNumber: big.NewInt(1)}, vm.TxContext{GasPrice: big.NewInt(100)}, &dummyStatedb{}, params.TestChainConfig, vm.Config{Tracer: tracer.LiveLogger})
tracer.CaptureTxStart(env.GetVMContext(), types.NewTx(&types.LegacyTx{}), common.Address{})
tracer.CaptureStart(common.Address{}, common.Address{}, false, []byte{}, 1000, big.NewInt(0))
tracer.CaptureEnd(nil, 0, nil, false)
env := vm.NewEVM(vm.BlockContext{BlockNumber: big.NewInt(1)}, vm.TxContext{GasPrice: big.NewInt(100)}, &dummyStatedb{}, params.TestChainConfig, vm.Config{Tracer: tracer.Hooks})
tracer.OnTxStart(env.GetVMContext(), types.NewTx(&types.LegacyTx{}), common.Address{})
tracer.OnStart(common.Address{}, common.Address{}, false, []byte{}, 1000, big.NewInt(0))
tracer.OnEnd(nil, 0, nil, false)
ret, err := tracer.GetResult()
if err != nil {
t.Fatal(err)
@ -279,8 +279,8 @@ func TestEnterExit(t *testing.T) {
scope := &vm.ScopeContext{
Contract: vm.NewContract(&account{}, &account{}, big.NewInt(0), 0),
}
tracer.CaptureEnter(tracing.OpCode(vm.CALL), scope.Contract.Caller(), scope.Contract.Address(), []byte{}, 1000, new(big.Int))
tracer.CaptureExit([]byte{}, 400, nil, false)
tracer.OnEnter(tracing.OpCode(vm.CALL), scope.Contract.Caller(), scope.Contract.Address(), []byte{}, 1000, new(big.Int))
tracer.OnExit([]byte{}, 400, nil, false)
have, err := tracer.GetResult()
if err != nil {

View file

@ -23,27 +23,27 @@ type noop struct{}
func newNoopTracer(_ json.RawMessage) (*tracing.LiveLogger, error) {
t := &noop{}
return &tracing.LiveLogger{
CaptureTxStart: t.CaptureTxStart,
CaptureTxEnd: t.CaptureTxEnd,
CaptureStart: t.CaptureStart,
CaptureEnd: t.CaptureEnd,
CaptureEnter: t.CaptureEnter,
CaptureExit: t.CaptureExit,
CaptureState: t.CaptureState,
CaptureFault: t.CaptureFault,
CaptureKeccakPreimage: t.CaptureKeccakPreimage,
OnGasChange: t.OnGasChange,
OnBlockchainInit: t.OnBlockchainInit,
OnBlockStart: t.OnBlockStart,
OnBlockEnd: t.OnBlockEnd,
OnSkippedBlock: t.OnSkippedBlock,
OnGenesisBlock: t.OnGenesisBlock,
OnBalanceChange: t.OnBalanceChange,
OnNonceChange: t.OnNonceChange,
OnCodeChange: t.OnCodeChange,
OnStorageChange: t.OnStorageChange,
OnLog: t.OnLog,
return &tracing.Hooks{
OnTxStart: t.CaptureTxStart,
OnTxEnd: t.CaptureTxEnd,
OnStart: t.CaptureStart,
OnEnd: t.CaptureEnd,
OnEnter: t.CaptureEnter,
OnExit: t.CaptureExit,
OnOpcode: t.CaptureState,
OnFault: t.CaptureFault,
OnKeccakPreimage: t.CaptureKeccakPreimage,
OnGasChange: t.OnGasChange,
OnBlockchainInit: t.OnBlockchainInit,
OnBlockStart: t.OnBlockStart,
OnBlockEnd: t.OnBlockEnd,
OnSkippedBlock: t.OnSkippedBlock,
OnGenesisBlock: t.OnGenesisBlock,
OnBalanceChange: t.OnBalanceChange,
OnNonceChange: t.OnNonceChange,
OnCodeChange: t.OnCodeChange,
OnStorageChange: t.OnStorageChange,
OnLog: t.OnLog,
}, nil
}

View file

@ -135,7 +135,7 @@ func NewAccessListTracer(acl types.AccessList, from, to common.Address, precompi
func (a *AccessListTracer) Hooks() *tracing.Hooks {
return &tracing.Hooks{
CaptureState: a.CaptureState,
OnOpcode: a.CaptureState,
}
}

View file

@ -135,10 +135,10 @@ func NewStructLogger(cfg *Config) *StructLogger {
func (l *StructLogger) Hooks() *tracing.Hooks {
return &tracing.Hooks{
CaptureTxStart: l.CaptureTxStart,
CaptureTxEnd: l.CaptureTxEnd,
CaptureEnd: l.CaptureEnd,
CaptureState: l.CaptureState,
OnTxStart: l.CaptureTxStart,
OnTxEnd: l.CaptureTxEnd,
OnEnd: l.CaptureEnd,
OnOpcode: l.CaptureState,
}
}
@ -354,11 +354,11 @@ func NewMarkdownLogger(cfg *Config, writer io.Writer) *mdLogger {
func (t *mdLogger) Hooks() *tracing.Hooks {
return &tracing.Hooks{
CaptureTxStart: t.CaptureTxStart,
CaptureStart: t.CaptureStart,
CaptureState: t.CaptureState,
CaptureFault: t.CaptureFault,
CaptureEnd: t.CaptureEnd,
OnTxStart: t.CaptureTxStart,
OnStart: t.CaptureStart,
OnOpcode: t.CaptureState,
OnFault: t.CaptureFault,
OnEnd: t.CaptureEnd,
}
}

View file

@ -47,10 +47,10 @@ func NewJSONLogger(cfg *Config, writer io.Writer) *JSONLogger {
func (l *JSONLogger) Hooks() *tracing.Hooks {
return &tracing.Hooks{
CaptureTxStart: l.CaptureTxStart,
CaptureEnd: l.CaptureEnd,
CaptureState: l.CaptureState,
CaptureFault: l.CaptureFault,
OnTxStart: l.CaptureTxStart,
OnEnd: l.CaptureEnd,
OnOpcode: l.CaptureState,
OnFault: l.CaptureFault,
}
}

View file

@ -62,10 +62,10 @@ func newFourByteTracer(ctx *directory.Context, _ json.RawMessage) (*directory.Tr
ids: make(map[string]int),
}
return &directory.Tracer{
LiveLogger: &tracing.LiveLogger{
CaptureTxStart: t.CaptureTxStart,
CaptureStart: t.CaptureStart,
CaptureEnter: t.CaptureEnter,
Hooks: &tracing.Hooks{
OnTxStart: t.CaptureTxStart,
OnStart: t.CaptureStart,
OnEnter: t.CaptureEnter,
},
GetResult: t.GetResult,
Stop: t.Stop,

View file

@ -127,6 +127,7 @@ func newCallTracer(ctx *directory.Context, cfg json.RawMessage) (*directory.Trac
return nil, err
}
return &directory.Tracer{
<<<<<<< HEAD
LiveLogger: &tracing.LiveLogger{
CaptureTxStart: t.CaptureTxStart,
CaptureTxEnd: t.CaptureTxEnd,
@ -136,6 +137,17 @@ func newCallTracer(ctx *directory.Context, cfg json.RawMessage) (*directory.Trac
CaptureExit: t.CaptureExit,
CaptureState: t.CaptureState,
OnLog: t.OnLog,
=======
Hooks: &tracing.Hooks{
OnTxStart: t.CaptureTxStart,
OnTxEnd: t.CaptureTxEnd,
OnStart: t.CaptureStart,
OnEnd: t.CaptureEnd,
OnEnter: t.CaptureEnter,
OnExit: t.CaptureExit,
OnOpcode: t.CaptureState,
OnLog: t.OnLog,
>>>>>>> 923c180058 (rename Capture hooks to On)
},
GetResult: t.GetResult,
Stop: t.Stop,

View file

@ -141,15 +141,15 @@ func newFlatCallTracer(ctx *directory.Context, cfg json.RawMessage) (*directory.
ft := &flatCallTracer{tracer: t, ctx: ctx, config: config}
return &directory.Tracer{
LiveLogger: &tracing.LiveLogger{
CaptureTxStart: ft.CaptureTxStart,
CaptureTxEnd: ft.CaptureTxEnd,
CaptureStart: ft.CaptureStart,
CaptureEnd: ft.CaptureEnd,
CaptureEnter: ft.CaptureEnter,
CaptureExit: ft.CaptureExit,
CaptureState: ft.CaptureState,
CaptureFault: ft.CaptureFault,
Hooks: &tracing.Hooks{
OnTxStart: ft.CaptureTxStart,
OnTxEnd: ft.CaptureTxEnd,
OnStart: ft.CaptureStart,
OnEnd: ft.CaptureEnd,
OnEnter: ft.CaptureEnter,
OnExit: ft.CaptureExit,
OnOpcode: ft.CaptureState,
OnFault: ft.CaptureFault,
},
Stop: ft.Stop,
GetResult: ft.GetResult,

View file

@ -58,22 +58,22 @@ func newMuxTracer(ctx *directory.Context, cfg json.RawMessage) (*directory.Trace
t := &muxTracer{names: names, tracers: objects}
return &directory.Tracer{
LiveLogger: &tracing.LiveLogger{
CaptureTxStart: t.CaptureTxStart,
CaptureTxEnd: t.CaptureTxEnd,
CaptureStart: t.CaptureStart,
CaptureEnd: t.CaptureEnd,
CaptureEnter: t.CaptureEnter,
CaptureExit: t.CaptureExit,
CaptureState: t.CaptureState,
CaptureFault: t.CaptureFault,
CaptureKeccakPreimage: t.CaptureKeccakPreimage,
OnGasChange: t.OnGasChange,
OnBalanceChange: t.OnBalanceChange,
OnNonceChange: t.OnNonceChange,
OnCodeChange: t.OnCodeChange,
OnStorageChange: t.OnStorageChange,
OnLog: t.OnLog,
Hooks: &tracing.Hooks{
OnTxStart: t.CaptureTxStart,
OnTxEnd: t.CaptureTxEnd,
OnStart: t.CaptureStart,
OnEnd: t.CaptureEnd,
OnEnter: t.CaptureEnter,
OnExit: t.CaptureExit,
OnOpcode: t.CaptureState,
OnFault: t.CaptureFault,
OnKeccakPreimage: t.CaptureKeccakPreimage,
OnGasChange: t.OnGasChange,
OnBalanceChange: t.OnBalanceChange,
OnNonceChange: t.OnNonceChange,
OnCodeChange: t.OnCodeChange,
OnStorageChange: t.OnStorageChange,
OnLog: t.OnLog,
},
GetResult: t.GetResult,
Stop: t.Stop,
@ -83,8 +83,8 @@ func newMuxTracer(ctx *directory.Context, cfg json.RawMessage) (*directory.Trace
// CaptureStart implements the EVMLogger interface to initialize the tracing operation.
func (t *muxTracer) CaptureStart(from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) {
for _, t := range t.tracers {
if t.CaptureStart != nil {
t.CaptureStart(from, to, create, input, gas, value)
if t.OnStart != nil {
t.OnStart(from, to, create, input, gas, value)
}
}
}
@ -92,8 +92,8 @@ func (t *muxTracer) CaptureStart(from common.Address, to common.Address, create
// CaptureEnd is called after the call finishes to finalize the tracing.
func (t *muxTracer) CaptureEnd(output []byte, gasUsed uint64, err error, reverted bool) {
for _, t := range t.tracers {
if t.CaptureEnd != nil {
t.CaptureEnd(output, gasUsed, err, reverted)
if t.OnEnd != nil {
t.OnEnd(output, gasUsed, err, reverted)
}
}
}
@ -101,8 +101,8 @@ func (t *muxTracer) CaptureEnd(output []byte, gasUsed uint64, err error, reverte
// CaptureState implements the EVMLogger interface to trace a single step of VM execution.
func (t *muxTracer) CaptureState(pc uint64, op tracing.OpCode, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
for _, t := range t.tracers {
if t.CaptureState != nil {
t.CaptureState(pc, op, gas, cost, scope, rData, depth, err)
if t.OnOpcode != nil {
t.OnOpcode(pc, op, gas, cost, scope, rData, depth, err)
}
}
}
@ -110,8 +110,8 @@ func (t *muxTracer) CaptureState(pc uint64, op tracing.OpCode, gas, cost uint64,
// CaptureFault implements the EVMLogger interface to trace an execution fault.
func (t *muxTracer) CaptureFault(pc uint64, op tracing.OpCode, gas, cost uint64, scope tracing.OpContext, depth int, err error) {
for _, t := range t.tracers {
if t.CaptureFault != nil {
t.CaptureFault(pc, op, gas, cost, scope, depth, err)
if t.OnFault != nil {
t.OnFault(pc, op, gas, cost, scope, depth, err)
}
}
}
@ -119,8 +119,8 @@ func (t *muxTracer) CaptureFault(pc uint64, op tracing.OpCode, gas, cost uint64,
// CaptureKeccakPreimage is called during the KECCAK256 opcode.
func (t *muxTracer) CaptureKeccakPreimage(hash common.Hash, data []byte) {
for _, t := range t.tracers {
if t.CaptureKeccakPreimage != nil {
t.CaptureKeccakPreimage(hash, data)
if t.OnKeccakPreimage != nil {
t.OnKeccakPreimage(hash, data)
}
}
}
@ -137,8 +137,8 @@ func (t *muxTracer) OnGasChange(old, new uint64, reason tracing.GasChangeReason)
// CaptureEnter is called when EVM enters a new scope (via call, create or selfdestruct).
func (t *muxTracer) CaptureEnter(typ tracing.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
for _, t := range t.tracers {
if t.CaptureEnter != nil {
t.CaptureEnter(typ, from, to, input, gas, value)
if t.OnEnter != nil {
t.OnEnter(typ, from, to, input, gas, value)
}
}
}
@ -147,24 +147,24 @@ func (t *muxTracer) CaptureEnter(typ tracing.OpCode, from common.Address, to com
// execute any code.
func (t *muxTracer) CaptureExit(output []byte, gasUsed uint64, err error, reverted bool) {
for _, t := range t.tracers {
if t.CaptureExit != nil {
t.CaptureExit(output, gasUsed, err, reverted)
if t.OnExit != nil {
t.OnExit(output, gasUsed, err, reverted)
}
}
}
func (t *muxTracer) CaptureTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
for _, t := range t.tracers {
if t.CaptureTxStart != nil {
t.CaptureTxStart(env, tx, from)
if t.OnTxStart != nil {
t.OnTxStart(env, tx, from)
}
}
}
func (t *muxTracer) CaptureTxEnd(receipt *types.Receipt, err error) {
for _, t := range t.tracers {
if t.CaptureTxEnd != nil {
t.CaptureTxEnd(receipt, err)
if t.OnTxEnd != nil {
t.OnTxEnd(receipt, err)
}
}
}

View file

@ -89,10 +89,10 @@ func newPrestateTracer(ctx *directory.Context, cfg json.RawMessage) (*directory.
deleted: make(map[common.Address]bool),
}
return &directory.Tracer{
LiveLogger: &tracing.LiveLogger{
CaptureTxStart: t.CaptureTxStart,
CaptureTxEnd: t.CaptureTxEnd,
CaptureState: t.CaptureState,
Hooks: &tracing.Hooks{
OnTxStart: t.CaptureTxStart,
OnTxEnd: t.CaptureTxEnd,
OnOpcode: t.CaptureState,
},
GetResult: t.GetResult,
Stop: t.Stop,