Skip to content

Commit 082b7ca

Browse files
feat(api): populate data field for revert error in EthEstimateGas and EthCall (#12553)
Co-authored-by: Aryan Tikarya <[email protected]>
1 parent 703333c commit 082b7ca

File tree

6 files changed

+250
-87
lines changed

6 files changed

+250
-87
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- `lotus-shed indexes inspect-indexes` now performs a comprehensive comparison of the event index data for each message by comparing the AMT root CID from the message receipt with the root of a reconstructed AMT. Previously `inspect-indexes` simply compared event counts, comparing AMT roots confirms all the event data is byte-perfect. ([filecoin-project/lotus#12570](https://github.com/filecoin-project/lotus/pull/12570))
1212
- Expose APIs to list the miner IDs that are currently participating in F3 via node. ([filecoin-project/lotus#12608](https://github.com/filecoin-project/lotus/pull/12608))
1313
- Implement new `lotus f3` CLI commands to list F3 participants, dump manifest, get/list finality certificates and check the F3 status. ([filecoin-project/lotus#12617](https://github.com/filecoin-project/lotus/pull/12617), [filecoin-project/lotus#12627](https://github.com/filecoin-project/lotus/pull/12627))
14+
- Return a `"data"` field on the `"error"` returned from RPC when `eth_call` and `eth_estimateGas` APIs encounter `execution reverted` errors. ([filecoin-project/lotus#12553](https://github.com/filecoin-project/lotus/pull/12553))
1415

1516
## Bug Fixes
1617
- Fix a bug in the `lotus-shed indexes backfill-events` command that may result in either duplicate events being backfilled where there are existing events (such an operation *should* be idempotent) or events erroneously having duplicate `logIndex` values when queried via ETH APIs. ([filecoin-project/lotus#12567](https://github.com/filecoin-project/lotus/pull/12567))

api/api_errors.go

+57-7
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ import (
44
"errors"
55
"reflect"
66

7+
"golang.org/x/xerrors"
8+
79
"github.com/filecoin-project/go-jsonrpc"
810
)
911

12+
var invalidExecutionRevertedMsg = xerrors.New("invalid execution reverted error")
13+
1014
const (
1115
EOutOfGas = iota + jsonrpc.FirstUserCode
1216
EActorNotFound
@@ -17,6 +21,7 @@ const (
1721
EF3ParticipationTooManyInstances
1822
EF3ParticipationTicketStartBeforeExisting
1923
EF3NotReady
24+
EExecutionReverted
2025
)
2126

2227
var (
@@ -40,13 +45,15 @@ var (
4045
// should back off and try again later.
4146
ErrF3NotReady = &errF3NotReady{}
4247

43-
_ error = (*ErrOutOfGas)(nil)
44-
_ error = (*ErrActorNotFound)(nil)
45-
_ error = (*errF3Disabled)(nil)
46-
_ error = (*errF3ParticipationTicketInvalid)(nil)
47-
_ error = (*errF3ParticipationTicketExpired)(nil)
48-
_ error = (*errF3ParticipationIssuerMismatch)(nil)
49-
_ error = (*errF3NotReady)(nil)
48+
_ error = (*ErrOutOfGas)(nil)
49+
_ error = (*ErrActorNotFound)(nil)
50+
_ error = (*errF3Disabled)(nil)
51+
_ error = (*errF3ParticipationTicketInvalid)(nil)
52+
_ error = (*errF3ParticipationTicketExpired)(nil)
53+
_ error = (*errF3ParticipationIssuerMismatch)(nil)
54+
_ error = (*errF3NotReady)(nil)
55+
_ error = (*ErrExecutionReverted)(nil)
56+
_ jsonrpc.RPCErrorCodec = (*ErrExecutionReverted)(nil)
5057
)
5158

5259
func init() {
@@ -59,6 +66,7 @@ func init() {
5966
RPCErrors.Register(EF3ParticipationTooManyInstances, new(*errF3ParticipationTooManyInstances))
6067
RPCErrors.Register(EF3ParticipationTicketStartBeforeExisting, new(*errF3ParticipationTicketStartBeforeExisting))
6168
RPCErrors.Register(EF3NotReady, new(*errF3NotReady))
69+
RPCErrors.Register(EExecutionReverted, new(*ErrExecutionReverted))
6270
}
6371

6472
func ErrorIsIn(err error, errorTypes []error) bool {
@@ -110,3 +118,45 @@ func (errF3ParticipationTicketStartBeforeExisting) Error() string {
110118
type errF3NotReady struct{}
111119

112120
func (errF3NotReady) Error() string { return "f3 isn't yet ready to participate" }
121+
122+
// ErrExecutionReverted is used to return execution reverted with a reason for a revert in the `data` field.
123+
type ErrExecutionReverted struct {
124+
Message string
125+
Data string
126+
}
127+
128+
// Error returns the error message.
129+
func (e *ErrExecutionReverted) Error() string { return e.Message }
130+
131+
// FromJSONRPCError converts a JSONRPCError to ErrExecutionReverted.
132+
func (e *ErrExecutionReverted) FromJSONRPCError(jerr jsonrpc.JSONRPCError) error {
133+
if jerr.Code != EExecutionReverted || jerr.Message == "" || jerr.Data == nil {
134+
return invalidExecutionRevertedMsg
135+
}
136+
137+
data, ok := jerr.Data.(string)
138+
if !ok {
139+
return xerrors.Errorf("expected string data in execution reverted error, got %T", jerr.Data)
140+
}
141+
142+
e.Message = jerr.Message
143+
e.Data = data
144+
return nil
145+
}
146+
147+
// ToJSONRPCError converts ErrExecutionReverted to a JSONRPCError.
148+
func (e *ErrExecutionReverted) ToJSONRPCError() (jsonrpc.JSONRPCError, error) {
149+
return jsonrpc.JSONRPCError{
150+
Code: EExecutionReverted,
151+
Message: e.Message,
152+
Data: e.Data,
153+
}, nil
154+
}
155+
156+
// NewErrExecutionReverted creates a new ErrExecutionReverted with the given reason.
157+
func NewErrExecutionReverted(reason string) *ErrExecutionReverted {
158+
return &ErrExecutionReverted{
159+
Message: "execution reverted",
160+
Data: reason,
161+
}
162+
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ require (
4747
github.com/filecoin-project/go-f3 v0.7.0
4848
github.com/filecoin-project/go-fil-commcid v0.2.0
4949
github.com/filecoin-project/go-hamt-ipld/v3 v3.4.0
50-
github.com/filecoin-project/go-jsonrpc v0.6.0
50+
github.com/filecoin-project/go-jsonrpc v0.7.0
5151
github.com/filecoin-project/go-padreader v0.0.1
5252
github.com/filecoin-project/go-paramfetch v0.0.4
5353
github.com/filecoin-project/go-state-types v0.15.0-rc1

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ github.com/filecoin-project/go-hamt-ipld/v3 v3.0.1/go.mod h1:gXpNmr3oQx8l3o7qkGy
287287
github.com/filecoin-project/go-hamt-ipld/v3 v3.1.0/go.mod h1:bxmzgT8tmeVQA1/gvBwFmYdT8SOFUwB3ovSUfG1Ux0g=
288288
github.com/filecoin-project/go-hamt-ipld/v3 v3.4.0 h1:nYs6OPUF8KbZ3E8o9p9HJnQaE8iugjHR5WYVMcicDJc=
289289
github.com/filecoin-project/go-hamt-ipld/v3 v3.4.0/go.mod h1:s0qiHRhFyrgW0SvdQMSJFQxNa4xEIG5XvqCBZUEgcbc=
290-
github.com/filecoin-project/go-jsonrpc v0.6.0 h1:/fFJIAN/k6EgY90m7qbyfY28woMwyseZmh2gVs5sYjY=
291-
github.com/filecoin-project/go-jsonrpc v0.6.0/go.mod h1:/n/niXcS4ZQua6i37LcVbY1TmlJR0UIK9mDFQq2ICek=
290+
github.com/filecoin-project/go-jsonrpc v0.7.0 h1:mqA5pIOlBODx7ascY9cJdBAYonhgbdUOIn2dyYI1YBg=
291+
github.com/filecoin-project/go-jsonrpc v0.7.0/go.mod h1:lAUpS8BSVtKaA8+/CFUMA5dokMiSM7n0ehf8bHOFdpE=
292292
github.com/filecoin-project/go-padreader v0.0.1 h1:8h2tVy5HpoNbr2gBRr+WD6zV6VD6XHig+ynSGJg8ZOs=
293293
github.com/filecoin-project/go-padreader v0.0.1/go.mod h1:VYVPJqwpsfmtoHnAmPx6MUwmrK6HIcDqZJiuZhtmfLQ=
294294
github.com/filecoin-project/go-paramfetch v0.0.4 h1:H+Me8EL8T5+79z/KHYQQcT8NVOzYVqXIi7nhb48tdm8=

0 commit comments

Comments
 (0)