Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions eth/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1127,12 +1127,22 @@ func (api *API) traceTx(ctx context.Context, tx *types.Transaction, message *cor

// Call Prepare to clear out the statedb access list
statedb.SetTxContext(txctx.TxHash, txctx.TxIndex)

if isSystemTx && tracer.OnSystemTxStart != nil {
tracer.OnSystemTxStart()
}

_, err = core.ApplyTransactionWithEVM(message, api.backend.ChainConfig(), new(core.GasPool).AddGas(message.GasLimit), statedb, vmctx.BlockNumber, txctx.BlockHash, tx, &usedGas, evm)
if err != nil {
return nil, fmt.Errorf("tracing failed: %w", err)
}
if tracer.OnSystemTxFixIntrinsicGas != nil {
tracer.OnSystemTxFixIntrinsicGas(intrinsicGas)
if isSystemTx {
if tracer.OnSystemTxFixIntrinsicGas != nil {
tracer.OnSystemTxFixIntrinsicGas(intrinsicGas)
}
if tracer.OnSystemTxEnd != nil {
tracer.OnSystemTxEnd()
}
}
return tracer.GetResult()
}
Expand Down
25 changes: 20 additions & 5 deletions eth/tracers/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,12 @@ type StructLogger struct {
cfg Config
env *tracing.VMContext

storage map[common.Address]Storage
logs []StructLog
output []byte
err error
usedGas uint64
storage map[common.Address]Storage
logs []StructLog
output []byte
err error
usedGas uint64
systemTxRefundedGas uint64

interrupt atomic.Bool // Atomic flag to signal execution interruption
reason error // Textual reason for the interruption
Expand All @@ -143,6 +144,8 @@ func (l *StructLogger) Hooks() *tracing.Hooks {
OnExit: l.OnExit,
OnOpcode: l.OnOpcode,
OnSystemTxFixIntrinsicGas: l.OnSystemTxFixIntrinsicGas,
OnGasChange: l.OnGasChange,
OnSystemTxEnd: l.OnSystemTxEnd,
}
}

Expand Down Expand Up @@ -296,6 +299,18 @@ func (l *StructLogger) OnSystemTxFixIntrinsicGas(intrinsicGas uint64) {
l.usedGas -= intrinsicGas
}

func (l *StructLogger) OnGasChange(old, new uint64, reason tracing.GasChangeReason) {
if reason == tracing.GasChangeTxRefunds && new >= old {
l.systemTxRefundedGas = new - old
}
}

func (l *StructLogger) OnSystemTxEnd() {
if l.systemTxRefundedGas > 0 {
l.usedGas += l.systemTxRefundedGas
}
}

// StructLogs returns the captured log entries.
func (l *StructLogger) StructLogs() []StructLog { return l.logs }

Expand Down
27 changes: 21 additions & 6 deletions eth/tracers/native/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,13 @@ type callFrameMarshaling struct {
}

type callTracer struct {
callstack []callFrame
config callTracerConfig
gasLimit uint64
depth int
interrupt atomic.Bool // Atomic flag to signal execution interruption
reason error // Textual reason for the interruption
callstack []callFrame
config callTracerConfig
gasLimit uint64
depth int
interrupt atomic.Bool // Atomic flag to signal execution interruption
reason error // Textual reason for the interruption
systemTxRefundedGas uint64
}

type callTracerConfig struct {
Expand All @@ -139,6 +140,8 @@ func newCallTracer(ctx *tracers.Context, cfg json.RawMessage, chainConfig *param
OnExit: t.OnExit,
OnLog: t.OnLog,
OnSystemTxFixIntrinsicGas: t.OnSystemTxFixIntrinsicGas,
OnGasChange: t.OnGasChange,
OnSystemTxEnd: t.OnSystemTxEnd,
},
GetResult: t.GetResult,
Stop: t.Stop,
Expand Down Expand Up @@ -238,6 +241,18 @@ func (t *callTracer) OnSystemTxFixIntrinsicGas(intrinsicGas uint64) {
t.callstack[0].GasUsed -= intrinsicGas
}

func (t *callTracer) OnGasChange(old, new uint64, reason tracing.GasChangeReason) {
if reason == tracing.GasChangeTxRefunds && new >= old {
t.systemTxRefundedGas = new - old
}
}

func (t *callTracer) OnSystemTxEnd() {
if t.systemTxRefundedGas > 0 {
t.callstack[0].GasUsed += t.systemTxRefundedGas
}
}

func (t *callTracer) OnLog(log *types.Log) {
// Only logs need to be captured via opcode processing
if !t.config.WithLog {
Expand Down
10 changes: 10 additions & 0 deletions eth/tracers/native/call_flat.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ func newFlatCallTracer(ctx *tracers.Context, cfg json.RawMessage, chainConfig *p
OnEnter: ft.OnEnter,
OnExit: ft.OnExit,
OnSystemTxFixIntrinsicGas: ft.OnSystemTxFixIntrinsicGas,
OnGasChange: t.OnGasChange,
OnSystemTxEnd: t.OnSystemTxEnd,
},
Stop: ft.Stop,
GetResult: ft.GetResult,
Expand Down Expand Up @@ -223,6 +225,14 @@ func (t *flatCallTracer) OnSystemTxFixIntrinsicGas(intrinsicGas uint64) {
t.tracer.OnSystemTxFixIntrinsicGas(intrinsicGas)
}

func (t *flatCallTracer) OnGasChange(old, new uint64, reason tracing.GasChangeReason) {
t.tracer.OnGasChange(old, new, reason)
}

func (t *flatCallTracer) OnSystemTxEnd() {
t.tracer.OnSystemTxEnd()
}

// GetResult returns an empty json object.
func (t *flatCallTracer) GetResult() (json.RawMessage, error) {
if len(t.tracer.callstack) < 1 {
Expand Down
18 changes: 18 additions & 0 deletions eth/tracers/native/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ func newMuxTracer(ctx *tracers.Context, cfg json.RawMessage, chainConfig *params
OnStorageChange: t.OnStorageChange,
OnLog: t.OnLog,
OnSystemTxFixIntrinsicGas: t.OnSystemTxFixIntrinsicGas,
OnSystemTxStart: t.OnSystemTxStart,
OnSystemTxEnd: t.OnSystemTxEnd,
},
GetResult: t.GetResult,
Stop: t.Stop,
Expand Down Expand Up @@ -181,6 +183,22 @@ func (t *muxTracer) OnSystemTxFixIntrinsicGas(intrinsicGas uint64) {
}
}

func (t *muxTracer) OnSystemTxStart() {
for _, t := range t.tracers {
if t.OnSystemTxStart != nil {
t.OnSystemTxStart()
}
}
}

func (t *muxTracer) OnSystemTxEnd() {
for _, t := range t.tracers {
if t.OnSystemTxEnd != nil {
t.OnSystemTxEnd()
}
}
}

// GetResult returns an empty json object.
func (t *muxTracer) GetResult() (json.RawMessage, error) {
resObject := make(map[string]json.RawMessage)
Expand Down
33 changes: 21 additions & 12 deletions eth/tracers/native/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,21 @@ func newNoopTracer(ctx *tracers.Context, cfg json.RawMessage, chainConfig *param
t := &noopTracer{}
return &tracers.Tracer{
Hooks: &tracing.Hooks{
OnTxStart: t.OnTxStart,
OnTxEnd: t.OnTxEnd,
OnEnter: t.OnEnter,
OnExit: t.OnExit,
OnOpcode: t.OnOpcode,
OnFault: t.OnFault,
OnGasChange: t.OnGasChange,
OnBalanceChange: t.OnBalanceChange,
OnNonceChange: t.OnNonceChange,
OnCodeChange: t.OnCodeChange,
OnStorageChange: t.OnStorageChange,
OnLog: t.OnLog,
OnTxStart: t.OnTxStart,
OnTxEnd: t.OnTxEnd,
OnEnter: t.OnEnter,
OnExit: t.OnExit,
OnOpcode: t.OnOpcode,
OnFault: t.OnFault,
OnGasChange: t.OnGasChange,
OnBalanceChange: t.OnBalanceChange,
OnNonceChange: t.OnNonceChange,
OnCodeChange: t.OnCodeChange,
OnStorageChange: t.OnStorageChange,
OnLog: t.OnLog,
OnSystemTxFixIntrinsicGas: t.OnSystemTxFixIntrinsicGas,
OnSystemTxStart: t.OnSystemTxStart,
OnSystemTxEnd: t.OnSystemTxEnd,
},
GetResult: t.GetResult,
Stop: t.Stop,
Expand Down Expand Up @@ -89,6 +92,12 @@ func (*noopTracer) OnStorageChange(a common.Address, k, prev, new common.Hash) {

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

func (*noopTracer) OnSystemTxFixIntrinsicGas(intrinsicGas uint64) {}

func (*noopTracer) OnSystemTxStart() {}

func (*noopTracer) OnSystemTxEnd() {}

// GetResult returns an empty json object.
func (t *noopTracer) GetResult() (json.RawMessage, error) {
return json.RawMessage(`{}`), nil
Expand Down
Loading