eth/tracers: small refactor for native tracers (#26196)

Use noopTracer as a base for other native tracers to avoid extra boilerplate for unimplemented hooks.
This commit is contained in:
Sina Mahmoodi 2022-11-17 09:27:48 +01:00 committed by GitHub
parent add337e0f7
commit 64067fbdc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 39 deletions

View File

@ -21,7 +21,6 @@ import (
"math/big" "math/big"
"strconv" "strconv"
"sync/atomic" "sync/atomic"
"time"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
@ -47,6 +46,7 @@ func init() {
// 0xc281d19e-0: 1 // 0xc281d19e-0: 1
// } // }
type fourByteTracer struct { type fourByteTracer struct {
noopTracer
ids map[string]int // ids aggregates the 4byte ids found ids map[string]int // ids aggregates the 4byte ids found
interrupt uint32 // Atomic flag to signal execution interruption interrupt uint32 // Atomic flag to signal execution interruption
reason error // Textual reason for the interruption reason error // Textual reason for the interruption
@ -90,10 +90,6 @@ func (t *fourByteTracer) CaptureStart(env *vm.EVM, from common.Address, to commo
} }
} }
// CaptureState implements the EVMLogger interface to trace a single step of VM execution.
func (t *fourByteTracer) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, rData []byte, depth int, err error) {
}
// CaptureEnter is called when EVM enters a new scope (via call, create or selfdestruct). // CaptureEnter is called when EVM enters a new scope (via call, create or selfdestruct).
func (t *fourByteTracer) CaptureEnter(op vm.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) { func (t *fourByteTracer) CaptureEnter(op vm.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
// Skip if tracing was interrupted // Skip if tracing was interrupted
@ -115,23 +111,6 @@ func (t *fourByteTracer) CaptureEnter(op vm.OpCode, from common.Address, to comm
t.store(input[0:4], len(input)-4) t.store(input[0:4], len(input)-4)
} }
// CaptureExit is called when EVM exits a scope, even if the scope didn't
// execute any code.
func (t *fourByteTracer) CaptureExit(output []byte, gasUsed uint64, err error) {
}
// CaptureFault implements the EVMLogger interface to trace an execution fault.
func (t *fourByteTracer) CaptureFault(pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, depth int, err error) {
}
// CaptureEnd is called after the call finishes to finalize the tracing.
func (t *fourByteTracer) CaptureEnd(output []byte, gasUsed uint64, _ time.Duration, err error) {
}
func (*fourByteTracer) CaptureTxStart(gasLimit uint64) {}
func (*fourByteTracer) CaptureTxEnd(restGas uint64) {}
// GetResult returns the json-encoded nested list of call traces, and any // GetResult returns the json-encoded nested list of call traces, and any
// error arising from the encoding or forceful termination (via `Stop`). // error arising from the encoding or forceful termination (via `Stop`).
func (t *fourByteTracer) GetResult() (json.RawMessage, error) { func (t *fourByteTracer) GetResult() (json.RawMessage, error) {

View File

@ -99,6 +99,7 @@ type callFrameMarshaling struct {
} }
type callTracer struct { type callTracer struct {
noopTracer
callstack []callFrame callstack []callFrame
config callTracerConfig config callTracerConfig
gasLimit uint64 gasLimit uint64
@ -181,10 +182,6 @@ func (t *callTracer) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, sco
} }
} }
// CaptureFault implements the EVMLogger interface to trace an execution fault.
func (t *callTracer) CaptureFault(pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, depth int, err error) {
}
// CaptureEnter is called when EVM enters a new scope (via call, create or selfdestruct). // CaptureEnter is called when EVM enters a new scope (via call, create or selfdestruct).
func (t *callTracer) CaptureEnter(typ vm.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) { func (t *callTracer) CaptureEnter(typ vm.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
if t.config.OnlyTopCall { if t.config.OnlyTopCall {

View File

@ -55,6 +55,7 @@ type accountMarshaling struct {
} }
type prestateTracer struct { type prestateTracer struct {
noopTracer
env *vm.EVM env *vm.EVM
pre state pre state
post state post state
@ -167,19 +168,6 @@ func (t *prestateTracer) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64,
} }
} }
// CaptureFault implements the EVMLogger interface to trace an execution fault.
func (t *prestateTracer) CaptureFault(pc uint64, op vm.OpCode, gas, cost uint64, _ *vm.ScopeContext, depth int, err error) {
}
// CaptureEnter is called when EVM enters a new scope (via call, create or selfdestruct).
func (t *prestateTracer) CaptureEnter(typ vm.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 *prestateTracer) CaptureExit(output []byte, gasUsed uint64, err error) {
}
func (t *prestateTracer) CaptureTxStart(gasLimit uint64) { func (t *prestateTracer) CaptureTxStart(gasLimit uint64) {
t.gasLimit = gasLimit t.gasLimit = gasLimit
} }