rename tracer methods to On pattern

This commit is contained in:
Sina Mahmoodi 2024-03-06 16:34:18 +01:00
parent 37ce159500
commit 8b3cddabb5
13 changed files with 142 additions and 193 deletions

View file

@ -178,8 +178,8 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
res []byte // result of the opcode execution function
debug = in.evm.Config.Tracer != nil
)
// Don't move this deferred function, it's placed before the capturestate-deferred method,
// so that it gets executed _after_: the capturestate needs the stacks before
// Don't move this deferred function, it's placed before the OnOpcode-deferred method,
// so that it gets executed _after_: the OnOpcode needs the stacks before
// they are returned to the pools
defer func() {
returnStack(stack)

View file

@ -38,13 +38,13 @@ func newNoopTracer(ctx *Context, _ json.RawMessage) (*Tracer, error) {
t := &NoopTracer{}
return &Tracer{
Hooks: &tracing.Hooks{
OnTxStart: t.CaptureTxStart,
OnTxEnd: t.CaptureTxEnd,
OnEnter: t.CaptureEnter,
OnExit: t.CaptureExit,
OnOpcode: t.CaptureState,
OnFault: t.CaptureFault,
OnKeccakPreimage: t.CaptureKeccakPreimage,
OnTxStart: t.OnTxStart,
OnTxEnd: t.OnTxEnd,
OnEnter: t.OnEnter,
OnExit: t.OnExit,
OnOpcode: t.OnOpcode,
OnFault: t.OnFault,
OnKeccakPreimage: t.OnKeccakPreimage,
OnGasChange: t.OnGasChange,
OnBalanceChange: t.OnBalanceChange,
OnNonceChange: t.OnNonceChange,
@ -57,41 +57,26 @@ func newNoopTracer(ctx *Context, _ json.RawMessage) (*Tracer, error) {
}, nil
}
// CaptureStart implements the EVMLogger interface to initialize the tracing operation.
func (t *NoopTracer) CaptureStart(from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) {
func (t *NoopTracer) OnOpcode(pc uint64, op tracing.OpCode, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
}
// CaptureEnd is called after the call finishes to finalize the tracing.
func (t *NoopTracer) CaptureEnd(output []byte, gasUsed uint64, err error, reverted bool) {
func (t *NoopTracer) OnFault(pc uint64, op tracing.OpCode, gas, cost uint64, _ tracing.OpContext, depth int, err error) {
}
// CaptureState implements the EVMLogger interface to trace a single step of VM execution.
func (t *NoopTracer) CaptureState(pc uint64, op tracing.OpCode, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
}
func (t *NoopTracer) OnKeccakPreimage(hash common.Hash, data []byte) {}
// CaptureFault implements the EVMLogger interface to trace an execution fault.
func (t *NoopTracer) CaptureFault(pc uint64, op tracing.OpCode, gas, cost uint64, _ tracing.OpContext, depth int, err error) {
}
// CaptureKeccakPreimage is called during the KECCAK256 opcode.
func (t *NoopTracer) CaptureKeccakPreimage(hash common.Hash, data []byte) {}
// OnGasChange is called when gas is either consumed or refunded.
func (t *NoopTracer) OnGasChange(old, new uint64, reason tracing.GasChangeReason) {}
// CaptureEnter is called when EVM enters a new scope (via call, create or selfdestruct).
func (t *NoopTracer) CaptureEnter(depth int, typ tracing.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
func (t *NoopTracer) OnEnter(depth int, typ tracing.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
}
// CaptureExit is called when EVM exits a scope, even if the scope didn't
// execute any code.
func (t *NoopTracer) CaptureExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
func (t *NoopTracer) OnExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
}
func (*NoopTracer) CaptureTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
func (*NoopTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
}
func (*NoopTracer) CaptureTxEnd(receipt *types.Receipt, err error) {}
func (*NoopTracer) OnTxEnd(receipt *types.Receipt, err error) {}
func (*NoopTracer) OnBalanceChange(a common.Address, prev, new *big.Int, reason tracing.BalanceChangeReason) {
}

View file

@ -224,21 +224,21 @@ func newJsTracer(code string, ctx *directory.Context, cfg json.RawMessage) (*dir
return &directory.Tracer{
Hooks: &tracing.Hooks{
OnTxStart: t.CaptureTxStart,
OnTxEnd: t.CaptureTxEnd,
OnEnter: t.CaptureEnter,
OnExit: t.CaptureExit,
OnOpcode: t.CaptureState,
OnFault: t.CaptureFault,
OnTxStart: t.OnTxStart,
OnTxEnd: t.OnTxEnd,
OnEnter: t.OnEnter,
OnExit: t.OnExit,
OnOpcode: t.OnOpcode,
OnFault: t.OnFault,
},
GetResult: t.GetResult,
Stop: t.Stop,
}, nil
}
// CaptureTxStart implements the Tracer interface and is invoked at the beginning of
// OnTxStart implements the Tracer interface and is invoked at the beginning of
// transaction processing.
func (t *jsTracer) CaptureTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
func (t *jsTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
t.env = env
// Need statedb access for db object
db := &dbObj{db: env.StateDB, vm: t.vm, toBig: t.toBig, toBuf: t.toBuf, fromBuf: t.fromBuf}
@ -257,9 +257,9 @@ func (t *jsTracer) CaptureTxStart(env *tracing.VMContext, tx *types.Transaction,
t.ctx["gasPrice"] = gasPriceBig
}
// CaptureTxEnd implements the Tracer interface and is invoked at the end of
// OnTxEnd implements the Tracer interface and is invoked at the end of
// transaction processing.
func (t *jsTracer) CaptureTxEnd(receipt *types.Receipt, err error) {
func (t *jsTracer) OnTxEnd(receipt *types.Receipt, err error) {
if err != nil {
// Don't override vm error
if _, ok := t.ctx["error"]; !ok {
@ -270,8 +270,8 @@ func (t *jsTracer) CaptureTxEnd(receipt *types.Receipt, err error) {
t.ctx["gasUsed"] = t.vm.ToValue(receipt.GasUsed)
}
// CaptureStart implements the Tracer interface to initialize the tracing operation.
func (t *jsTracer) captureStart(from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) {
// onStart implements the Tracer interface to initialize the tracing operation.
func (t *jsTracer) onStart(from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) {
cancel := func(err error) {
t.err = err
t.env.VM.Cancel()
@ -307,8 +307,8 @@ func (t *jsTracer) captureStart(from common.Address, to common.Address, create b
t.ctx["value"] = valueBig
}
// CaptureState implements the Tracer interface to trace a single step of VM execution.
func (t *jsTracer) CaptureState(pc uint64, op tracing.OpCode, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
// OnOpcode implements the Tracer interface to trace a single step of VM execution.
func (t *jsTracer) OnOpcode(pc uint64, op tracing.OpCode, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
if !t.traceStep {
return
}
@ -332,8 +332,8 @@ func (t *jsTracer) CaptureState(pc uint64, op tracing.OpCode, gas, cost uint64,
}
}
// CaptureFault implements the Tracer interface to trace an execution fault
func (t *jsTracer) CaptureFault(pc uint64, op tracing.OpCode, gas, cost uint64, scope tracing.OpContext, depth int, err error) {
// OnFault implements the Tracer interface to trace an execution fault
func (t *jsTracer) OnFault(pc uint64, op tracing.OpCode, gas, cost uint64, scope tracing.OpContext, depth int, err error) {
if t.err != nil {
return
}
@ -344,8 +344,8 @@ func (t *jsTracer) CaptureFault(pc uint64, op tracing.OpCode, gas, cost uint64,
}
}
// CaptureEnd is called after the call finishes to finalize the tracing.
func (t *jsTracer) captureEnd(output []byte, gasUsed uint64, err error, reverted bool) {
// onEnd is called after the call finishes to finalize the tracing.
func (t *jsTracer) onEnd(output []byte, gasUsed uint64, err error, reverted bool) {
if err != nil {
t.ctx["error"] = t.vm.ToValue(err.Error())
}
@ -357,10 +357,10 @@ func (t *jsTracer) captureEnd(output []byte, gasUsed uint64, err error, reverted
t.ctx["output"] = outputVal
}
// CaptureEnter is called when EVM enters a new scope (via call, create or selfdestruct).
func (t *jsTracer) CaptureEnter(depth int, typ tracing.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
// OnEnter is called when EVM enters a new scope (via call, create or selfdestruct).
func (t *jsTracer) OnEnter(depth int, typ tracing.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
if depth == 0 {
t.captureStart(from, to, vm.OpCode(typ) == vm.CREATE, input, gas, value)
t.onStart(from, to, vm.OpCode(typ) == vm.CREATE, input, gas, value)
return
}
if !t.traceFrame {
@ -385,11 +385,11 @@ func (t *jsTracer) CaptureEnter(depth int, typ tracing.OpCode, from common.Addre
}
}
// CaptureExit is called when EVM exits a scope, even if the scope didn't
// OnExit is called when EVM exits a scope, even if the scope didn't
// execute any code.
func (t *jsTracer) CaptureExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
func (t *jsTracer) OnExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
if depth == 0 {
t.captureEnd(output, gasUsed, err, reverted)
t.onEnd(output, gasUsed, err, reverted)
return
}
if !t.traceFrame {

View file

@ -24,13 +24,13 @@ type noop struct{}
func newNoopTracer(_ json.RawMessage) (*tracing.Hooks, error) {
t := &noop{}
return &tracing.Hooks{
OnTxStart: t.CaptureTxStart,
OnTxEnd: t.CaptureTxEnd,
OnEnter: t.CaptureEnter,
OnExit: t.CaptureExit,
OnOpcode: t.CaptureState,
OnFault: t.CaptureFault,
OnKeccakPreimage: t.CaptureKeccakPreimage,
OnTxStart: t.OnTxStart,
OnTxEnd: t.OnTxEnd,
OnEnter: t.OnEnter,
OnExit: t.OnExit,
OnOpcode: t.OnOpcode,
OnFault: t.OnFault,
OnKeccakPreimage: t.OnKeccakPreimage,
OnGasChange: t.OnGasChange,
OnBlockchainInit: t.OnBlockchainInit,
OnBlockStart: t.OnBlockStart,
@ -45,38 +45,24 @@ func newNoopTracer(_ json.RawMessage) (*tracing.Hooks, error) {
}, nil
}
// CaptureStart implements the EVMLogger interface to initialize the tracing operation.
func (t *noop) CaptureStart(from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) {
func (t *noop) OnOpcode(pc uint64, op tracing.OpCode, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
}
// CaptureEnd is called after the call finishes to finalize the tracing.
func (t *noop) CaptureEnd(output []byte, gasUsed uint64, err error, reverted bool) {
func (t *noop) OnFault(pc uint64, op tracing.OpCode, gas, cost uint64, _ tracing.OpContext, depth int, err error) {
}
// CaptureState implements the EVMLogger interface to trace a single step of VM execution.
func (t *noop) CaptureState(pc uint64, op tracing.OpCode, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
func (t *noop) OnKeccakPreimage(hash common.Hash, data []byte) {}
func (t *noop) OnEnter(depth int, typ tracing.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
}
// CaptureFault implements the EVMLogger interface to trace an execution fault.
func (t *noop) CaptureFault(pc uint64, op tracing.OpCode, gas, cost uint64, _ tracing.OpContext, depth int, err error) {
func (t *noop) OnExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
}
// CaptureKeccakPreimage is called during the KECCAK256 opcode.
func (t *noop) CaptureKeccakPreimage(hash common.Hash, data []byte) {}
// CaptureEnter is called when EVM enters a new scope (via call, create or selfdestruct).
func (t *noop) CaptureEnter(depth int, typ tracing.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
func (t *noop) OnTxStart(vm *tracing.VMContext, tx *types.Transaction, from common.Address) {
}
// CaptureExit is called when EVM exits a scope, even if the scope didn't
// execute any code.
func (t *noop) CaptureExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
}
func (t *noop) CaptureTxStart(vm *tracing.VMContext, tx *types.Transaction, from common.Address) {
}
func (t *noop) CaptureTxEnd(receipt *types.Receipt, err error) {
func (t *noop) OnTxEnd(receipt *types.Receipt, err error) {
}
func (t *noop) OnBlockStart(ev tracing.BlockEvent) {

View file

@ -135,12 +135,12 @@ func NewAccessListTracer(acl types.AccessList, from, to common.Address, precompi
func (a *AccessListTracer) Hooks() *tracing.Hooks {
return &tracing.Hooks{
OnOpcode: a.CaptureState,
OnOpcode: a.OnOpcode,
}
}
// CaptureState captures all opcodes that touch storage or addresses and adds them to the accesslist.
func (a *AccessListTracer) CaptureState(pc uint64, opcode tracing.OpCode, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
// OnOpcode captures all opcodes that touch storage or addresses and adds them to the accesslist.
func (a *AccessListTracer) OnOpcode(pc uint64, opcode tracing.OpCode, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
stackData := scope.StackData()
stackLen := len(stackData)
op := vm.OpCode(opcode)

View file

@ -136,10 +136,10 @@ func NewStructLogger(cfg *Config) *StructLogger {
func (l *StructLogger) Hooks() *tracing.Hooks {
return &tracing.Hooks{
OnTxStart: l.CaptureTxStart,
OnTxEnd: l.CaptureTxEnd,
OnExit: l.CaptureExit,
OnOpcode: l.CaptureState,
OnTxStart: l.OnTxStart,
OnTxEnd: l.OnTxEnd,
OnExit: l.OnExit,
OnOpcode: l.OnOpcode,
}
}
@ -159,10 +159,10 @@ func (l *StructLogger) Reset() {
l.err = nil
}
// CaptureState logs a new structured log message and pushes it out to the environment
// OnOpcode logs a new structured log message and pushes it out to the environment
//
// CaptureState also tracks SLOAD/SSTORE ops to track storage change.
func (l *StructLogger) CaptureState(pc uint64, opcode tracing.OpCode, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
// OnOpcode also tracks SLOAD/SSTORE ops to track storage change.
func (l *StructLogger) OnOpcode(pc uint64, opcode tracing.OpCode, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
// If tracing was interrupted, set the error and stop
if l.interrupt.Load() {
return
@ -227,8 +227,8 @@ func (l *StructLogger) CaptureState(pc uint64, opcode tracing.OpCode, gas, cost
l.logs = append(l.logs, log)
}
// CaptureExit is called a call frame finishes processing.
func (l *StructLogger) CaptureExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
// OnExit is called a call frame finishes processing.
func (l *StructLogger) OnExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
if depth != 0 {
return
}
@ -268,11 +268,11 @@ func (l *StructLogger) Stop(err error) {
l.interrupt.Store(true)
}
func (l *StructLogger) CaptureTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
func (l *StructLogger) OnTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
l.env = env
}
func (l *StructLogger) CaptureTxEnd(receipt *types.Receipt, err error) {
func (l *StructLogger) OnTxEnd(receipt *types.Receipt, err error) {
if err != nil {
// Don't override vm error
if l.err == nil {
@ -358,19 +358,19 @@ func NewMarkdownLogger(cfg *Config, writer io.Writer) *mdLogger {
func (t *mdLogger) Hooks() *tracing.Hooks {
return &tracing.Hooks{
OnTxStart: t.CaptureTxStart,
OnEnter: t.CaptureEnter,
OnExit: t.CaptureExit,
OnOpcode: t.CaptureState,
OnFault: t.CaptureFault,
OnTxStart: t.OnTxStart,
OnEnter: t.OnEnter,
OnExit: t.OnExit,
OnOpcode: t.OnOpcode,
OnFault: t.OnFault,
}
}
func (t *mdLogger) CaptureTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
func (t *mdLogger) OnTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
t.env = env
}
func (t *mdLogger) CaptureEnter(depth int, typ tracing.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
func (t *mdLogger) OnEnter(depth int, typ tracing.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
if depth != 0 {
return
}
@ -391,15 +391,15 @@ func (t *mdLogger) CaptureEnter(depth int, typ tracing.OpCode, from common.Addre
`)
}
func (t *mdLogger) CaptureExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
func (t *mdLogger) OnExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
if depth == 0 {
fmt.Fprintf(t.out, "\nOutput: `%#x`\nConsumed gas: `%d`\nError: `%v`\n",
output, gasUsed, err)
}
}
// CaptureState also tracks SLOAD/SSTORE ops to track storage change.
func (t *mdLogger) CaptureState(pc uint64, op tracing.OpCode, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
// OnOpcode also tracks SLOAD/SSTORE ops to track storage change.
func (t *mdLogger) OnOpcode(pc uint64, op tracing.OpCode, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
stack := scope.StackData()
fmt.Fprintf(t.out, "| %4d | %10v | %3d |", pc, op, cost)
@ -419,7 +419,7 @@ func (t *mdLogger) CaptureState(pc uint64, op tracing.OpCode, gas, cost uint64,
}
}
func (t *mdLogger) CaptureFault(pc uint64, op tracing.OpCode, gas, cost uint64, scope tracing.OpContext, depth int, err error) {
func (t *mdLogger) OnFault(pc uint64, op tracing.OpCode, gas, cost uint64, scope tracing.OpContext, depth int, err error) {
fmt.Fprintf(t.out, "\nError: at pc=%d, op=%v: %v\n", pc, op, err)
}

View file

@ -47,20 +47,19 @@ func NewJSONLogger(cfg *Config, writer io.Writer) *JSONLogger {
func (l *JSONLogger) Hooks() *tracing.Hooks {
return &tracing.Hooks{
OnTxStart: l.CaptureTxStart,
OnExit: l.CaptureExit,
OnOpcode: l.CaptureState,
OnFault: l.CaptureFault,
OnTxStart: l.OnTxStart,
OnExit: l.OnExit,
OnOpcode: l.OnOpcode,
OnFault: l.OnFault,
}
}
func (l *JSONLogger) CaptureFault(pc uint64, op tracing.OpCode, gas uint64, cost uint64, scope tracing.OpContext, depth int, err error) {
func (l *JSONLogger) OnFault(pc uint64, op tracing.OpCode, gas uint64, cost uint64, scope tracing.OpContext, depth int, err error) {
// TODO: Add rData to this interface as well
l.CaptureState(pc, op, gas, cost, scope, nil, depth, err)
l.OnOpcode(pc, op, gas, cost, scope, nil, depth, err)
}
// CaptureState outputs state information on the logger.
func (l *JSONLogger) CaptureState(pc uint64, op tracing.OpCode, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
func (l *JSONLogger) OnOpcode(pc uint64, op tracing.OpCode, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
memory := scope.MemoryData()
stack := scope.StackData()
@ -86,8 +85,7 @@ func (l *JSONLogger) CaptureState(pc uint64, op tracing.OpCode, gas, cost uint64
l.encoder.Encode(log)
}
// CaptureEnd is triggered at end of execution.
func (l *JSONLogger) CaptureExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
func (l *JSONLogger) OnExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
if depth > 0 {
return
}
@ -103,6 +101,6 @@ func (l *JSONLogger) CaptureExit(depth int, output []byte, gasUsed uint64, err e
l.encoder.Encode(endLog{common.Bytes2Hex(output), math.HexOrDecimal64(gasUsed), errMsg})
}
func (l *JSONLogger) CaptureTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
func (l *JSONLogger) OnTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
l.env = env
}

View file

@ -61,8 +61,7 @@ func TestStoreCapture(t *testing.T) {
)
contract.Code = []byte{byte(vm.PUSH1), 0x1, byte(vm.PUSH1), 0x0, byte(vm.SSTORE)}
var index common.Hash
logger.CaptureTxStart(env.GetVMContext(), nil, common.Address{})
logger.CaptureStart(common.Address{}, contract.Address(), false, nil, 0, nil)
logger.OnTxStart(env.GetVMContext(), nil, common.Address{})
_, err := env.Interpreter().Run(contract, []byte{}, false)
if err != nil {
t.Fatal(err)

View file

@ -52,7 +52,7 @@ type fourByteTracer struct {
ids map[string]int // ids aggregates the 4byte ids found
interrupt atomic.Bool // Atomic flag to signal execution interruption
reason error // Textual reason for the interruption
activePrecompiles []common.Address // Updated on CaptureStart based on given rules
activePrecompiles []common.Address // Updated on tx start based on given rules
}
// newFourByteTracer returns a native go tracer which collects
@ -63,8 +63,8 @@ func newFourByteTracer(ctx *directory.Context, _ json.RawMessage) (*directory.Tr
}
return &directory.Tracer{
Hooks: &tracing.Hooks{
OnTxStart: t.CaptureTxStart,
OnEnter: t.CaptureEnter,
OnTxStart: t.OnTxStart,
OnEnter: t.OnEnter,
},
GetResult: t.GetResult,
Stop: t.Stop,
@ -87,14 +87,14 @@ func (t *fourByteTracer) store(id []byte, size int) {
t.ids[key] += 1
}
func (t *fourByteTracer) CaptureTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
func (t *fourByteTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
// Update list of precompiles based on current block
rules := env.ChainConfig.Rules(env.BlockNumber, env.Random != nil, env.Time)
t.activePrecompiles = vm.ActivePrecompiles(rules)
}
// CaptureEnter is called when EVM enters a new scope (via call, create or selfdestruct).
func (t *fourByteTracer) CaptureEnter(depth int, opcode tracing.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
// OnEnter is called when EVM enters a new scope (via call, create or selfdestruct).
func (t *fourByteTracer) OnEnter(depth int, opcode tracing.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
// Skip if tracing was interrupted
if t.interrupt.Load() {
return

View file

@ -128,10 +128,10 @@ func newCallTracer(ctx *directory.Context, cfg json.RawMessage) (*directory.Trac
}
return &directory.Tracer{
Hooks: &tracing.Hooks{
OnTxStart: t.CaptureTxStart,
OnTxEnd: t.CaptureTxEnd,
OnEnter: t.CaptureEnter,
OnExit: t.CaptureExit,
OnTxStart: t.OnTxStart,
OnTxEnd: t.OnTxEnd,
OnEnter: t.OnEnter,
OnExit: t.OnExit,
OnLog: t.OnLog,
},
GetResult: t.GetResult,
@ -151,8 +151,8 @@ func newCallTracerObject(ctx *directory.Context, cfg json.RawMessage) (*callTrac
return &callTracer{callstack: make([]callFrame, 0, 1), config: config}, nil
}
// CaptureEnter is called when EVM enters a new scope (via call, create or selfdestruct).
func (t *callTracer) CaptureEnter(depth int, typ tracing.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
// OnEnter is called when EVM enters a new scope (via call, create or selfdestruct).
func (t *callTracer) OnEnter(depth int, typ tracing.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
t.depth = depth
if t.config.OnlyTopCall && depth > 0 {
return
@ -177,9 +177,9 @@ func (t *callTracer) CaptureEnter(depth int, typ tracing.OpCode, from common.Add
t.callstack = append(t.callstack, call)
}
// CaptureExit is called when EVM exits a scope, even if the scope didn't
// OnExit is called when EVM exits a scope, even if the scope didn't
// execute any code.
func (t *callTracer) CaptureExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
func (t *callTracer) OnExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
if depth == 0 {
t.captureEnd(output, gasUsed, err, reverted)
return
@ -212,11 +212,11 @@ func (t *callTracer) captureEnd(output []byte, gasUsed uint64, err error, revert
t.callstack[0].processOutput(output, err, reverted)
}
func (t *callTracer) CaptureTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
func (t *callTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
t.gasLimit = tx.Gas()
}
func (t *callTracer) CaptureTxEnd(receipt *types.Receipt, err error) {
func (t *callTracer) OnTxEnd(receipt *types.Receipt, err error) {
// Error happened during tx validation.
if err != nil {
return

View file

@ -115,7 +115,7 @@ type flatCallTracer struct {
config flatCallTracerConfig
ctx *directory.Context // Holds tracer context data
reason error // Textual reason for the interruption
activePrecompiles []common.Address // Updated on CaptureStart based on given rules
activePrecompiles []common.Address // Updated on tx start based on given rules
}
type flatCallTracerConfig struct {
@ -142,31 +142,19 @@ func newFlatCallTracer(ctx *directory.Context, cfg json.RawMessage) (*directory.
ft := &flatCallTracer{tracer: t, ctx: ctx, config: config}
return &directory.Tracer{
Hooks: &tracing.Hooks{
OnTxStart: ft.CaptureTxStart,
OnTxEnd: ft.CaptureTxEnd,
OnEnter: ft.CaptureEnter,
OnExit: ft.CaptureExit,
OnOpcode: ft.CaptureState,
OnFault: ft.CaptureFault,
OnTxStart: ft.OnTxStart,
OnTxEnd: ft.OnTxEnd,
OnEnter: ft.OnEnter,
OnExit: ft.OnExit,
},
Stop: ft.Stop,
GetResult: ft.GetResult,
}, nil
}
// CaptureState implements the EVMLogger interface to trace a single step of VM execution.
func (t *flatCallTracer) CaptureState(pc uint64, op tracing.OpCode, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
t.tracer.CaptureState(pc, op, gas, cost, scope, rData, depth, err)
}
// CaptureFault implements the EVMLogger interface to trace an execution fault.
func (t *flatCallTracer) CaptureFault(pc uint64, op tracing.OpCode, gas, cost uint64, scope tracing.OpContext, depth int, err error) {
t.tracer.CaptureFault(pc, op, gas, cost, scope, depth, err)
}
// CaptureEnter is called when EVM enters a new scope (via call, create or selfdestruct).
func (t *flatCallTracer) CaptureEnter(depth int, typ tracing.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
t.tracer.CaptureEnter(depth, typ, from, to, input, gas, value)
// OnEnter is called when EVM enters a new scope (via call, create or selfdestruct).
func (t *flatCallTracer) OnEnter(depth int, typ tracing.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
t.tracer.OnEnter(depth, typ, from, to, input, gas, value)
if depth == 0 {
return
@ -178,10 +166,10 @@ func (t *flatCallTracer) CaptureEnter(depth int, typ tracing.OpCode, from common
}
}
// CaptureExit is called when EVM exits a scope, even if the scope didn't
// OnExit is called when EVM exits a scope, even if the scope didn't
// execute any code.
func (t *flatCallTracer) CaptureExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
t.tracer.CaptureExit(depth, output, gasUsed, err, reverted)
func (t *flatCallTracer) OnExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
t.tracer.OnExit(depth, output, gasUsed, err, reverted)
if depth == 0 {
return
@ -205,15 +193,15 @@ func (t *flatCallTracer) CaptureExit(depth int, output []byte, gasUsed uint64, e
}
}
func (t *flatCallTracer) CaptureTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
t.tracer.CaptureTxStart(env, tx, from)
func (t *flatCallTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
t.tracer.OnTxStart(env, tx, from)
// Update list of precompiles based on current block
rules := env.ChainConfig.Rules(env.BlockNumber, env.Random != nil, env.Time)
t.activePrecompiles = vm.ActivePrecompiles(rules)
}
func (t *flatCallTracer) CaptureTxEnd(receipt *types.Receipt, err error) {
t.tracer.CaptureTxEnd(receipt, err)
func (t *flatCallTracer) OnTxEnd(receipt *types.Receipt, err error) {
t.tracer.OnTxEnd(receipt, err)
}
// GetResult returns an empty json object.

View file

@ -59,13 +59,13 @@ func newMuxTracer(ctx *directory.Context, cfg json.RawMessage) (*directory.Trace
t := &muxTracer{names: names, tracers: objects}
return &directory.Tracer{
Hooks: &tracing.Hooks{
OnTxStart: t.CaptureTxStart,
OnTxEnd: t.CaptureTxEnd,
OnEnter: t.CaptureEnter,
OnExit: t.CaptureExit,
OnOpcode: t.CaptureState,
OnFault: t.CaptureFault,
OnKeccakPreimage: t.CaptureKeccakPreimage,
OnTxStart: t.OnTxStart,
OnTxEnd: t.OnTxEnd,
OnEnter: t.OnEnter,
OnExit: t.OnExit,
OnOpcode: t.OnOpcode,
OnFault: t.OnFault,
OnKeccakPreimage: t.OnKeccakPreimage,
OnGasChange: t.OnGasChange,
OnBalanceChange: t.OnBalanceChange,
OnNonceChange: t.OnNonceChange,
@ -78,8 +78,7 @@ func newMuxTracer(ctx *directory.Context, cfg json.RawMessage) (*directory.Trace
}, nil
}
// 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) {
func (t *muxTracer) OnOpcode(pc uint64, op tracing.OpCode, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
for _, t := range t.tracers {
if t.OnOpcode != nil {
t.OnOpcode(pc, op, gas, cost, scope, rData, depth, err)
@ -87,8 +86,7 @@ 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) {
func (t *muxTracer) OnFault(pc uint64, op tracing.OpCode, gas, cost uint64, scope tracing.OpContext, depth int, err error) {
for _, t := range t.tracers {
if t.OnFault != nil {
t.OnFault(pc, op, gas, cost, scope, depth, err)
@ -96,8 +94,7 @@ 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) {
func (t *muxTracer) OnKeccakPreimage(hash common.Hash, data []byte) {
for _, t := range t.tracers {
if t.OnKeccakPreimage != nil {
t.OnKeccakPreimage(hash, data)
@ -105,7 +102,6 @@ func (t *muxTracer) CaptureKeccakPreimage(hash common.Hash, data []byte) {
}
}
// CaptureGasConsumed is called when gas is consumed.
func (t *muxTracer) OnGasChange(old, new uint64, reason tracing.GasChangeReason) {
for _, t := range t.tracers {
if t.OnGasChange != nil {
@ -114,8 +110,7 @@ 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(depth int, typ tracing.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
func (t *muxTracer) OnEnter(depth int, typ tracing.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
for _, t := range t.tracers {
if t.OnEnter != nil {
t.OnEnter(depth, typ, from, to, input, gas, value)
@ -123,9 +118,7 @@ func (t *muxTracer) CaptureEnter(depth int, typ tracing.OpCode, from common.Addr
}
}
// CaptureExit is called when EVM exits a scope, even if the scope didn't
// execute any code.
func (t *muxTracer) CaptureExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
func (t *muxTracer) OnExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
for _, t := range t.tracers {
if t.OnExit != nil {
t.OnExit(depth, output, gasUsed, err, reverted)
@ -133,7 +126,7 @@ func (t *muxTracer) CaptureExit(depth int, output []byte, gasUsed uint64, err er
}
}
func (t *muxTracer) CaptureTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
func (t *muxTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
for _, t := range t.tracers {
if t.OnTxStart != nil {
t.OnTxStart(env, tx, from)
@ -141,7 +134,7 @@ func (t *muxTracer) CaptureTxStart(env *tracing.VMContext, tx *types.Transaction
}
}
func (t *muxTracer) CaptureTxEnd(receipt *types.Receipt, err error) {
func (t *muxTracer) OnTxEnd(receipt *types.Receipt, err error) {
for _, t := range t.tracers {
if t.OnTxEnd != nil {
t.OnTxEnd(receipt, err)

View file

@ -90,17 +90,17 @@ func newPrestateTracer(ctx *directory.Context, cfg json.RawMessage) (*directory.
}
return &directory.Tracer{
Hooks: &tracing.Hooks{
OnTxStart: t.CaptureTxStart,
OnTxEnd: t.CaptureTxEnd,
OnOpcode: t.CaptureState,
OnTxStart: t.OnTxStart,
OnTxEnd: t.OnTxEnd,
OnOpcode: t.OnOpcode,
},
GetResult: t.GetResult,
Stop: t.Stop,
}, nil
}
// CaptureState implements the EVMLogger interface to trace a single step of VM execution.
func (t *prestateTracer) CaptureState(pc uint64, opcode tracing.OpCode, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
// OnOpcode implements the EVMLogger interface to trace a single step of VM execution.
func (t *prestateTracer) OnOpcode(pc uint64, opcode tracing.OpCode, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
if err != nil {
return
}
@ -146,7 +146,7 @@ func (t *prestateTracer) CaptureState(pc uint64, opcode tracing.OpCode, gas, cos
}
}
func (t *prestateTracer) CaptureTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
func (t *prestateTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
t.env = env
if tx.To() == nil {
t.to = crypto.CreateAddress(from, env.StateDB.GetNonce(from))
@ -160,7 +160,7 @@ func (t *prestateTracer) CaptureTxStart(env *tracing.VMContext, tx *types.Transa
t.lookupAccount(env.Coinbase)
}
func (t *prestateTracer) CaptureTxEnd(receipt *types.Receipt, err error) {
func (t *prestateTracer) OnTxEnd(receipt *types.Receipt, err error) {
if err != nil {
return
}