Skip to content

Commit ff1f492

Browse files
authored
eth/tracers: remove revertReasonTracer, add revert reason to callTracer (#25508)
* eth/tracers: add revertReason to callTracer * update callframe gen json * add revertal to calltrace test
1 parent c2918c2 commit ff1f492

File tree

5 files changed

+58
-149
lines changed

5 files changed

+58
-149
lines changed

eth/tracers/internal/tracetest/calltrace_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,17 @@ type callContext struct {
104104

105105
// callTrace is the result of a callTracer run.
106106
type callTrace struct {
107-
Type string `json:"type"`
108-
From common.Address `json:"from"`
109-
To common.Address `json:"to"`
110-
Input hexutil.Bytes `json:"input"`
111-
Output hexutil.Bytes `json:"output"`
112-
Gas *hexutil.Uint64 `json:"gas,omitempty"`
113-
GasUsed *hexutil.Uint64 `json:"gasUsed,omitempty"`
114-
Value *hexutil.Big `json:"value,omitempty"`
115-
Error string `json:"error,omitempty"`
116-
Calls []callTrace `json:"calls,omitempty"`
107+
Type string `json:"type"`
108+
From common.Address `json:"from"`
109+
To common.Address `json:"to"`
110+
Input hexutil.Bytes `json:"input"`
111+
Output hexutil.Bytes `json:"output"`
112+
Gas *hexutil.Uint64 `json:"gas,omitempty"`
113+
GasUsed *hexutil.Uint64 `json:"gasUsed,omitempty"`
114+
Value *hexutil.Big `json:"value,omitempty"`
115+
Error string `json:"error,omitempty"`
116+
Revertal string `json:"revertReason,omitempty"`
117+
Calls []callTrace `json:"calls,omitempty"`
117118
}
118119

119120
// callTracerTest defines a single test to check the call tracer against.

eth/tracers/internal/tracetest/testdata/call_tracer/revert_reason.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"to": "0xf58833cf0c791881b494eb79d461e08a1f043f52",
6060
"type": "CALL",
6161
"value": "0x0",
62-
"output": "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001e53656c662d64656c65676174696f6e20697320646973616c6c6f7765642e0000"
62+
"output": "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001e53656c662d64656c65676174696f6e20697320646973616c6c6f7765642e0000",
63+
"revertReason": "Self-delegation is disallowed."
6364
}
6465
}

eth/tracers/native/call.go

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"sync/atomic"
2424
"time"
2525

26+
"github.com/ethereum/go-ethereum/accounts/abi"
2627
"github.com/ethereum/go-ethereum/common"
2728
"github.com/ethereum/go-ethereum/common/hexutil"
2829
"github.com/ethereum/go-ethereum/core/vm"
@@ -36,15 +37,16 @@ func init() {
3637
}
3738

3839
type callFrame struct {
39-
Type vm.OpCode `json:"-"`
40-
From common.Address `json:"from"`
41-
Gas uint64 `json:"gas"`
42-
GasUsed uint64 `json:"gasUsed"`
43-
To common.Address `json:"to,omitempty" rlp:"optional"`
44-
Input []byte `json:"input" rlp:"optional"`
45-
Output []byte `json:"output,omitempty" rlp:"optional"`
46-
Error string `json:"error,omitempty" rlp:"optional"`
47-
Calls []callFrame `json:"calls,omitempty" rlp:"optional"`
40+
Type vm.OpCode `json:"-"`
41+
From common.Address `json:"from"`
42+
Gas uint64 `json:"gas"`
43+
GasUsed uint64 `json:"gasUsed"`
44+
To common.Address `json:"to,omitempty" rlp:"optional"`
45+
Input []byte `json:"input" rlp:"optional"`
46+
Output []byte `json:"output,omitempty" rlp:"optional"`
47+
Error string `json:"error,omitempty" rlp:"optional"`
48+
Revertal string `json:"revertReason,omitempty"`
49+
Calls []callFrame `json:"calls,omitempty" rlp:"optional"`
4850
// Placed at end on purpose. The RLP will be decoded to 0 instead of
4951
// nil if there are non-empty elements after in the struct.
5052
Value *big.Int `json:"value,omitempty" rlp:"optional"`
@@ -109,13 +111,20 @@ func (t *callTracer) CaptureStart(env *vm.EVM, from common.Address, to common.Ad
109111
func (t *callTracer) CaptureEnd(output []byte, gasUsed uint64, _ time.Duration, err error) {
110112
t.callstack[0].GasUsed = gasUsed
111113
output = common.CopyBytes(output)
112-
if err != nil {
113-
t.callstack[0].Error = err.Error()
114-
if err.Error() == "execution reverted" && len(output) > 0 {
115-
t.callstack[0].Output = output
116-
}
117-
} else {
114+
if err == nil {
118115
t.callstack[0].Output = output
116+
return
117+
}
118+
t.callstack[0].Error = err.Error()
119+
if !errors.Is(err, vm.ErrExecutionReverted) || len(output) == 0 {
120+
return
121+
}
122+
t.callstack[0].Output = output
123+
if len(output) < 4 {
124+
return
125+
}
126+
if unpacked, err := abi.UnpackRevert(output); err == nil {
127+
t.callstack[0].Revertal = unpacked
119128
}
120129
}
121130

eth/tracers/native/gen_callframe_json.go

Lines changed: 21 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eth/tracers/native/revertreason.go

Lines changed: 0 additions & 108 deletions
This file was deleted.

0 commit comments

Comments
 (0)