eth/tracers: avoid panic in state test runner (#30332)
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: Sina Mahmoodi <itz.s1na@gmail.com>
This commit is contained in:
parent
733fcbbc65
commit
30824faf90
|
@ -275,8 +275,10 @@ func (t *jsTracer) OnTxEnd(receipt *types.Receipt, err error) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if receipt != nil {
|
||||||
t.ctx["gasUsed"] = t.vm.ToValue(receipt.GasUsed)
|
t.ctx["gasUsed"] = t.vm.ToValue(receipt.GasUsed)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// onStart implements the Tracer interface to initialize the tracing operation.
|
// onStart implements the Tracer interface to initialize the tracing operation.
|
||||||
func (t *jsTracer) onStart(from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) {
|
func (t *jsTracer) onStart(from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) {
|
||||||
|
|
|
@ -268,8 +268,10 @@ func (l *StructLogger) OnTxEnd(receipt *types.Receipt, err error) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if receipt != nil {
|
||||||
l.usedGas = receipt.GasUsed
|
l.usedGas = receipt.GasUsed
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// StructLogs returns the captured log entries.
|
// StructLogs returns the captured log entries.
|
||||||
func (l *StructLogger) StructLogs() []StructLog { return l.logs }
|
func (l *StructLogger) StructLogs() []StructLog { return l.logs }
|
||||||
|
|
|
@ -225,7 +225,9 @@ func (t *callTracer) OnTxEnd(receipt *types.Receipt, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if receipt != nil {
|
||||||
t.callstack[0].GasUsed = receipt.GasUsed
|
t.callstack[0].GasUsed = receipt.GasUsed
|
||||||
|
}
|
||||||
if t.config.WithLog {
|
if t.config.WithLog {
|
||||||
// Logs are not emitted when the call fails
|
// Logs are not emitted when the call fails
|
||||||
clearFailedLogs(&t.callstack[0], false)
|
clearFailedLogs(&t.callstack[0], false)
|
||||||
|
|
|
@ -297,19 +297,17 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh
|
||||||
|
|
||||||
if tracer := vmconfig.Tracer; tracer != nil && tracer.OnTxStart != nil {
|
if tracer := vmconfig.Tracer; tracer != nil && tracer.OnTxStart != nil {
|
||||||
tracer.OnTxStart(evm.GetVMContext(), nil, msg.From)
|
tracer.OnTxStart(evm.GetVMContext(), nil, msg.From)
|
||||||
if evm.Config.Tracer.OnTxEnd != nil {
|
|
||||||
defer func() {
|
|
||||||
evm.Config.Tracer.OnTxEnd(nil, err)
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Execute the message.
|
// Execute the message.
|
||||||
snapshot := st.StateDB.Snapshot()
|
snapshot := st.StateDB.Snapshot()
|
||||||
gaspool := new(core.GasPool)
|
gaspool := new(core.GasPool)
|
||||||
gaspool.AddGas(block.GasLimit())
|
gaspool.AddGas(block.GasLimit())
|
||||||
_, err = core.ApplyMessage(evm, msg, gaspool)
|
vmRet, err := core.ApplyMessage(evm, msg, gaspool)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
st.StateDB.RevertToSnapshot(snapshot)
|
st.StateDB.RevertToSnapshot(snapshot)
|
||||||
|
if tracer := evm.Config.Tracer; tracer != nil && tracer.OnTxEnd != nil {
|
||||||
|
evm.Config.Tracer.OnTxEnd(nil, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Add 0-value mining reward. This only makes a difference in the cases
|
// Add 0-value mining reward. This only makes a difference in the cases
|
||||||
// where
|
// where
|
||||||
|
@ -320,6 +318,10 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh
|
||||||
|
|
||||||
// Commit state mutations into database.
|
// Commit state mutations into database.
|
||||||
root, _ = st.StateDB.Commit(block.NumberU64(), config.IsEIP158(block.Number()))
|
root, _ = st.StateDB.Commit(block.NumberU64(), config.IsEIP158(block.Number()))
|
||||||
|
if tracer := evm.Config.Tracer; tracer != nil && tracer.OnTxEnd != nil {
|
||||||
|
receipt := &types.Receipt{GasUsed: vmRet.UsedGas}
|
||||||
|
tracer.OnTxEnd(receipt, nil)
|
||||||
|
}
|
||||||
return st, root, err
|
return st, root, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue