Skip to content

Commit

Permalink
eth/tracer: add onSystemTxEnd hook for system tx.
Browse files Browse the repository at this point in the history
  • Loading branch information
zlacfzy committed Nov 25, 2024
1 parent af11fdf commit 84adc43
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 33 deletions.
5 changes: 2 additions & 3 deletions core/tracing/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ type (
// beacon block root.
OnSystemCallEndHook = func()

// TODO(Nathan,Eric): refine this func
OnCaptureSystemTxEndHook = func(uint64)
OnSystemTxEndHook = func(uint64)

/*
- State events -
Expand Down Expand Up @@ -192,7 +191,7 @@ type Hooks struct {
OnSystemCallStart OnSystemCallStartHook
OnSystemCallEnd OnSystemCallEndHook

CaptureSystemTxEnd OnCaptureSystemTxEndHook
OnSystemTxEnd OnSystemTxEndHook

// State events
OnBalanceChange BalanceChangeHook
Expand Down
4 changes: 2 additions & 2 deletions eth/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1198,8 +1198,8 @@ func (api *API) traceTx(ctx context.Context, tx *types.Transaction, message *cor
if err != nil {
return nil, fmt.Errorf("tracing failed: %w", err)
}
if tracer.CaptureSystemTxEnd != nil {
tracer.CaptureSystemTxEnd(intrinsicGas)
if tracer.OnSystemTxEnd != nil {
tracer.OnSystemTxEnd(intrinsicGas)
}
return tracer.GetResult()
}
Expand Down
2 changes: 0 additions & 2 deletions eth/tracers/js/goja.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,6 @@ func newJsTracer(code string, ctx *tracers.Context, cfg json.RawMessage) (*trace
}, nil
}

func (t *jsTracer) CaptureSystemTxEnd(intrinsicGas uint64) {}

// OnTxStart implements the Tracer interface and is invoked at the beginning of
// transaction processing.
func (t *jsTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
Expand Down
2 changes: 0 additions & 2 deletions eth/tracers/logger/access_list_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ func (a *AccessListTracer) OnOpcode(pc uint64, opcode byte, gas, cost uint64, sc
}
}

func (*AccessListTracer) CaptureSystemTxEnd(intrinsicGas uint64) {}

// AccessList returns the current accesslist maintained by the tracer.
func (a *AccessListTracer) AccessList() types.AccessList {
return a.list.accessList()
Expand Down
13 changes: 6 additions & 7 deletions eth/tracers/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ func NewStructLogger(cfg *Config) *StructLogger {

func (l *StructLogger) Hooks() *tracing.Hooks {
return &tracing.Hooks{
OnTxStart: l.OnTxStart,
OnTxEnd: l.OnTxEnd,
OnExit: l.OnExit,
OnOpcode: l.OnOpcode,
OnTxStart: l.OnTxStart,
OnTxEnd: l.OnTxEnd,
OnExit: l.OnExit,
OnOpcode: l.OnOpcode,
OnSystemTxEnd: l.OnSystemTxEnd,
}
}

Expand Down Expand Up @@ -273,7 +274,7 @@ func (l *StructLogger) OnTxEnd(receipt *types.Receipt, err error) {
}
}

func (l *StructLogger) CaptureSystemTxEnd(intrinsicGas uint64) {
func (l *StructLogger) OnSystemTxEnd(intrinsicGas uint64) {
l.usedGas -= intrinsicGas
}

Expand Down Expand Up @@ -416,8 +417,6 @@ func (t *mdLogger) OnFault(pc uint64, op byte, gas, cost uint64, scope tracing.O
fmt.Fprintf(t.out, "\nError: at pc=%d, op=%v: %v\n", pc, op, err)
}

func (*mdLogger) CaptureSystemTxEnd(intrinsicGas uint64) {}

// ExecutionResult groups all structured logs emitted by the EVM
// while replaying a transaction in debug mode as well as transaction
// execution status, the amount of gas used and the return value
Expand Down
2 changes: 0 additions & 2 deletions eth/tracers/logger/logger_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,3 @@ func (l *jsonLogger) OnExit(depth int, output []byte, gasUsed uint64, err error,
func (l *jsonLogger) OnTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) {
l.env = env
}

func (l *jsonLogger) CaptureSystemTxEnd(intrinsicGas uint64) {}
2 changes: 0 additions & 2 deletions eth/tracers/native/4byte.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ func (t *fourByteTracer) OnEnter(depth int, opcode byte, from common.Address, to
t.store(input[0:4], len(input)-4)
}

func (*fourByteTracer) CaptureSystemTxEnd(intrinsicGas uint64) {}

// GetResult returns the json-encoded nested list of call traces, and any
// error arising from the encoding or forceful termination (via `Stop`).
func (t *fourByteTracer) GetResult() (json.RawMessage, error) {
Expand Down
13 changes: 7 additions & 6 deletions eth/tracers/native/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,12 @@ func newCallTracer(ctx *tracers.Context, cfg json.RawMessage) (*tracers.Tracer,
}
return &tracers.Tracer{
Hooks: &tracing.Hooks{
OnTxStart: t.OnTxStart,
OnTxEnd: t.OnTxEnd,
OnEnter: t.OnEnter,
OnExit: t.OnExit,
OnLog: t.OnLog,
OnTxStart: t.OnTxStart,
OnTxEnd: t.OnTxEnd,
OnEnter: t.OnEnter,
OnExit: t.OnExit,
OnLog: t.OnLog,
OnSystemTxEnd: t.OnSystemTxEnd,
},
GetResult: t.GetResult,
Stop: t.Stop,
Expand Down Expand Up @@ -234,7 +235,7 @@ func (t *callTracer) OnTxEnd(receipt *types.Receipt, err error) {
}
}

func (t *callTracer) CaptureSystemTxEnd(intrinsicGas uint64) {
func (t *callTracer) OnSystemTxEnd(intrinsicGas uint64) {
t.callstack[0].GasUsed -= intrinsicGas
}

Expand Down
4 changes: 2 additions & 2 deletions eth/tracers/native/call_flat.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ func (t *flatCallTracer) OnTxEnd(receipt *types.Receipt, err error) {
t.tracer.OnTxEnd(receipt, err)
}

func (t *flatCallTracer) CaptureSystemTxEnd(intrinsicGas uint64) {
t.tracer.CaptureSystemTxEnd(intrinsicGas)
func (t *flatCallTracer) OnSystemTxEnd(intrinsicGas uint64) {
t.tracer.OnSystemTxEnd(intrinsicGas)
}

// GetResult returns an empty json object.
Expand Down
5 changes: 3 additions & 2 deletions eth/tracers/native/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func newMuxTracer(ctx *tracers.Context, cfg json.RawMessage) (*tracers.Tracer, e
OnCodeChange: t.OnCodeChange,
OnStorageChange: t.OnStorageChange,
OnLog: t.OnLog,
OnSystemTxEnd: t.OnSystemTxEnd,
},
GetResult: t.GetResult,
Stop: t.Stop,
Expand Down Expand Up @@ -173,9 +174,9 @@ func (t *muxTracer) OnLog(log *types.Log) {
}
}

func (t *muxTracer) CaptureSystemTxEnd(intrinsicGas uint64) {
func (t *muxTracer) OnSystemTxEnd(intrinsicGas uint64) {
for _, t := range t.tracers {
t.CaptureSystemTxEnd(intrinsicGas)
t.OnSystemTxEnd(intrinsicGas)
}
}

Expand Down
3 changes: 2 additions & 1 deletion eth/tracers/native/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func newNoopTracer(ctx *tracers.Context, _ json.RawMessage) (*tracers.Tracer, er
OnCodeChange: t.OnCodeChange,
OnStorageChange: t.OnStorageChange,
OnLog: t.OnLog,
OnSystemTxEnd: t.OnSystemTxEnd,
},
GetResult: t.GetResult,
Stop: t.Stop,
Expand Down Expand Up @@ -88,7 +89,7 @@ func (*noopTracer) OnStorageChange(a common.Address, k, prev, new common.Hash) {

func (*noopTracer) OnLog(log *types.Log) {}

func (*noopTracer) CaptureSystemTxEnd(intrinsicGas uint64) {}
func (*noopTracer) OnSystemTxEnd(intrinsicGas uint64) {}

// GetResult returns an empty json object.
func (t *noopTracer) GetResult() (json.RawMessage, error) {
Expand Down
2 changes: 0 additions & 2 deletions eth/tracers/native/prestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,6 @@ func (t *prestateTracer) processDiffState() {
}
}

func (t *prestateTracer) CaptureSystemTxEnd(intrinsicGas uint64) {}

// lookupAccount fetches details of an account and adds it to the prestate
// if it doesn't exist there.
func (t *prestateTracer) lookupAccount(addr common.Address) {
Expand Down

0 comments on commit 84adc43

Please sign in to comment.