Skip to content

Commit fa58176

Browse files
authored
eth/tracers: fix json logger for evm blocktest (#29795)
1 parent 0d4cdb3 commit fa58176

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

eth/tracers/api.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,9 +804,13 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
804804
// Execute the transaction and flush any traces to disk
805805
vmenv := vm.NewEVM(vmctx, txContext, statedb, chainConfig, vmConf)
806806
statedb.SetTxContext(tx.Hash(), i)
807-
vmConf.Tracer.OnTxStart(vmenv.GetVMContext(), tx, msg.From)
807+
if vmConf.Tracer.OnTxStart != nil {
808+
vmConf.Tracer.OnTxStart(vmenv.GetVMContext(), tx, msg.From)
809+
}
808810
vmRet, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.GasLimit))
809-
vmConf.Tracer.OnTxEnd(&types.Receipt{GasUsed: vmRet.UsedGas}, err)
811+
if vmConf.Tracer.OnTxEnd != nil {
812+
vmConf.Tracer.OnTxEnd(&types.Receipt{GasUsed: vmRet.UsedGas}, err)
813+
}
810814
if writer != nil {
811815
writer.Flush()
812816
}

eth/tracers/logger/logger_json.go

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type jsonLogger struct {
5858
encoder *json.Encoder
5959
cfg *Config
6060
env *tracing.VMContext
61+
hooks *tracing.Hooks
6162
}
6263

6364
// NewJSONLogger creates a new EVM tracer that prints execution steps as JSON objects
@@ -67,12 +68,14 @@ func NewJSONLogger(cfg *Config, writer io.Writer) *tracing.Hooks {
6768
if l.cfg == nil {
6869
l.cfg = &Config{}
6970
}
70-
return &tracing.Hooks{
71-
OnTxStart: l.OnTxStart,
72-
OnExit: l.OnExit,
73-
OnOpcode: l.OnOpcode,
74-
OnFault: l.OnFault,
71+
l.hooks = &tracing.Hooks{
72+
OnTxStart: l.OnTxStart,
73+
OnSystemCallStart: l.onSystemCallStart,
74+
OnExit: l.OnEnd,
75+
OnOpcode: l.OnOpcode,
76+
OnFault: l.OnFault,
7577
}
78+
return l.hooks
7679
}
7780

7881
// NewJSONLoggerWithCallFrames creates a new EVM tracer that prints execution steps as JSON objects
@@ -82,13 +85,15 @@ func NewJSONLoggerWithCallFrames(cfg *Config, writer io.Writer) *tracing.Hooks {
8285
if l.cfg == nil {
8386
l.cfg = &Config{}
8487
}
85-
return &tracing.Hooks{
86-
OnTxStart: l.OnTxStart,
87-
OnEnter: l.OnEnter,
88-
OnExit: l.OnExit,
89-
OnOpcode: l.OnOpcode,
90-
OnFault: l.OnFault,
88+
l.hooks = &tracing.Hooks{
89+
OnTxStart: l.OnTxStart,
90+
OnSystemCallStart: l.onSystemCallStart,
91+
OnEnter: l.OnEnter,
92+
OnExit: l.OnExit,
93+
OnOpcode: l.OnOpcode,
94+
OnFault: l.OnFault,
9195
}
96+
return l.hooks
9297
}
9398

9499
func (l *jsonLogger) OnFault(pc uint64, op byte, gas uint64, cost uint64, scope tracing.OpContext, depth int, err error) {
@@ -122,6 +127,16 @@ func (l *jsonLogger) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracin
122127
l.encoder.Encode(log)
123128
}
124129

130+
func (l *jsonLogger) onSystemCallStart() {
131+
// Process no events while in system call.
132+
hooks := *l.hooks
133+
*l.hooks = tracing.Hooks{
134+
OnSystemCallEnd: func() {
135+
*l.hooks = hooks
136+
},
137+
}
138+
}
139+
125140
// OnEnter is not enabled by default.
126141
func (l *jsonLogger) OnEnter(depth int, typ byte, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
127142
frame := callFrame{

0 commit comments

Comments
 (0)