eth/tracers: avoid panic in state test runner #30332 (#1485)

Make tracers more robust by handling `nil` receipt as input.
Also pass in a receipt with gas used in the state test runner.
Closes https://github.com/ethereum/go-ethereum/issues/30117.

---------

Co-authored-by: Martin HS <martin@swende.se>
Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
This commit is contained in:
Daniel Liu 2025-09-13 10:50:10 +08:00 committed by GitHub
parent 1597be6879
commit f5e76ea6df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 3 deletions

View file

@ -274,7 +274,9 @@ func (t *jsTracer) OnTxEnd(receipt *types.Receipt, err error) {
}
return
}
t.ctx["gasUsed"] = t.vm.ToValue(receipt.GasUsed)
if receipt != nil {
t.ctx["gasUsed"] = t.vm.ToValue(receipt.GasUsed)
}
}
// onStart implements the Tracer interface to initialize the tracing operation.

View file

@ -268,7 +268,9 @@ func (l *StructLogger) OnTxEnd(receipt *types.Receipt, err error) {
}
return
}
l.usedGas = receipt.GasUsed
if receipt != nil {
l.usedGas = receipt.GasUsed
}
}
// StructLogs returns the captured log entries.

View file

@ -225,7 +225,9 @@ func (t *callTracer) OnTxEnd(receipt *types.Receipt, err error) {
if err != nil {
return
}
t.callstack[0].GasUsed = receipt.GasUsed
if receipt != nil {
t.callstack[0].GasUsed = receipt.GasUsed
}
if t.config.WithLog {
// Logs are not emitted when the call fails
clearFailedLogs(&t.callstack[0], false)