eth/tracers: avoid panic if nil-receipt passed to OnTxEnd

This commit is contained in:
Martin Holst Swende 2024-08-20 12:42:23 +02:00
parent 710c3f32ac
commit 3917452e20
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
3 changed files with 9 additions and 3 deletions

View file

@ -275,7 +275,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)