Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle error and revert data in EthEstimateGas and EthCall #12553

Merged
merged 27 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
19bf92e
fix: handle error and revert data in EthEstimateGas and EthCall
virajbhartiya Oct 4, 2024
1f47508
feat: itests
virajbhartiya Oct 4, 2024
6859ee5
feat: Add EthCallError struct and tests
virajbhartiya Oct 7, 2024
61f7fe5
refactor: eth call error
akaladarshi Oct 9, 2024
619b9a5
fix: handle error and revert data in EthCall
virajbhartiya Oct 11, 2024
e53a74d
feat: Refactor EthCall to handle invalid block number
virajbhartiya Oct 11, 2024
6d69cdd
refactor: eth call error to execution reverted error
akaladarshi Oct 11, 2024
5c7bdae
address comments
akaladarshi Oct 15, 2024
d1abde9
small change
akaladarshi Oct 15, 2024
22d418a
update changelog
akaladarshi Oct 15, 2024
273cbcc
update tests
virajbhartiya Oct 15, 2024
529dd97
remove go-jsonrpc
virajbhartiya Oct 15, 2024
d8015cc
add test for ethEstimateGas and addressed changes
virajbhartiya Oct 16, 2024
cc212fe
rename error
virajbhartiya Oct 16, 2024
cad6f2b
fix lint errors
virajbhartiya Oct 16, 2024
7aec77b
refactor: execution reverted error
akaladarshi Oct 16, 2024
a092883
Merge branch 'master' into jsonrpc
akaladarshi Oct 17, 2024
0ba5a70
implement error codec interface
akaladarshi Oct 22, 2024
3206a77
fix ci tests
akaladarshi Oct 22, 2024
6a7b6c1
update go mod
akaladarshi Oct 22, 2024
762d719
address comments
akaladarshi Oct 23, 2024
a88c3fe
small fix
akaladarshi Oct 23, 2024
35519c0
Merge branch 'master' into jsonrpc
akaladarshi Oct 23, 2024
0992e7e
address comments
akaladarshi Oct 24, 2024
2264607
Update go.mod dependencies
virajbhartiya Oct 24, 2024
cd7455e
Update go-jsonrpc version to v0.7.0
virajbhartiya Oct 24, 2024
5ed6352
Merge branch 'master' into jsonrpc
rvagg Oct 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- `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))
- 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))
- Implement new `lotus f3` CLI commands to list F3 participants, dump manifest and check the F3 status. ([filecoin-project/lotus#12617](https://github.com/filecoin-project/lotus/pull/12617))
- 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))

## Bug Fixes
- 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))
Expand Down
64 changes: 57 additions & 7 deletions api/api_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import (
"errors"
"reflect"

"golang.org/x/xerrors"

"github.com/filecoin-project/go-jsonrpc"
)

var invalidExecutionRevertedMsg = xerrors.New("invalid execution reverted error")

const (
EOutOfGas = iota + jsonrpc.FirstUserCode
EActorNotFound
Expand All @@ -17,6 +21,7 @@ const (
EF3ParticipationTooManyInstances
EF3ParticipationTicketStartBeforeExisting
EF3NotReady
EExecutionReverted
)

var (
Expand All @@ -40,13 +45,15 @@ var (
// should back off and try again later.
ErrF3NotReady = errF3NotReady{}

_ error = (*ErrOutOfGas)(nil)
_ error = (*ErrActorNotFound)(nil)
_ error = (*errF3Disabled)(nil)
_ error = (*errF3ParticipationTicketInvalid)(nil)
_ error = (*errF3ParticipationTicketExpired)(nil)
_ error = (*errF3ParticipationIssuerMismatch)(nil)
_ error = (*errF3NotReady)(nil)
_ error = (*ErrOutOfGas)(nil)
_ error = (*ErrActorNotFound)(nil)
_ error = (*errF3Disabled)(nil)
_ error = (*errF3ParticipationTicketInvalid)(nil)
_ error = (*errF3ParticipationTicketExpired)(nil)
_ error = (*errF3ParticipationIssuerMismatch)(nil)
_ error = (*errF3NotReady)(nil)
_ error = (*ErrExecutionReverted)(nil)
_ jsonrpc.RPCErrorCodec = (*ErrExecutionReverted)(nil)
)

func init() {
Expand All @@ -59,6 +66,7 @@ func init() {
RPCErrors.Register(EF3ParticipationTooManyInstances, new(*errF3ParticipationTooManyInstances))
RPCErrors.Register(EF3ParticipationTicketStartBeforeExisting, new(*errF3ParticipationTicketStartBeforeExisting))
RPCErrors.Register(EF3NotReady, new(*errF3NotReady))
RPCErrors.Register(EExecutionReverted, new(*ErrExecutionReverted))
}

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

func (errF3NotReady) Error() string { return "f3 isn't yet ready to participate" }

// ErrExecutionReverted is used to return execution reverted with a reason for a revert in the `data` field.
type ErrExecutionReverted struct {
Message string
Data string
}

// Error returns the error message.
func (e *ErrExecutionReverted) Error() string { return e.Message }

// FromJSONRPCError converts a JSONRPCError to ErrExecutionReverted.
func (e *ErrExecutionReverted) FromJSONRPCError(jerr jsonrpc.JSONRPCError) error {
if jerr.Code != EExecutionReverted || jerr.Message == "" || jerr.Data == nil {
return invalidExecutionRevertedMsg
}

data, ok := jerr.Data.(string)
rvagg marked this conversation as resolved.
Show resolved Hide resolved
if !ok {
return xerrors.Errorf("expected string data in execution reverted error, got %T", jerr.Data)
}

e.Message = jerr.Message
e.Data = data
return nil
}

// ToJSONRPCError converts ErrExecutionReverted to a JSONRPCError.
func (e *ErrExecutionReverted) ToJSONRPCError() (jsonrpc.JSONRPCError, error) {
return jsonrpc.JSONRPCError{
Code: EExecutionReverted,
Message: e.Message,
Data: e.Data,
}, nil
}

// NewErrExecutionReverted creates a new ErrExecutionReverted with the given reason.
func NewErrExecutionReverted(reason string) *ErrExecutionReverted {
return &ErrExecutionReverted{
Message: "execution reverted",
Data: reason,
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ require (
github.com/filecoin-project/go-f3 v0.7.0
github.com/filecoin-project/go-fil-commcid v0.2.0
github.com/filecoin-project/go-hamt-ipld/v3 v3.4.0
github.com/filecoin-project/go-jsonrpc v0.6.0
github.com/filecoin-project/go-jsonrpc v0.7.0
github.com/filecoin-project/go-padreader v0.0.1
github.com/filecoin-project/go-paramfetch v0.0.4
github.com/filecoin-project/go-state-types v0.15.0-rc1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ github.com/filecoin-project/go-hamt-ipld/v3 v3.0.1/go.mod h1:gXpNmr3oQx8l3o7qkGy
github.com/filecoin-project/go-hamt-ipld/v3 v3.1.0/go.mod h1:bxmzgT8tmeVQA1/gvBwFmYdT8SOFUwB3ovSUfG1Ux0g=
github.com/filecoin-project/go-hamt-ipld/v3 v3.4.0 h1:nYs6OPUF8KbZ3E8o9p9HJnQaE8iugjHR5WYVMcicDJc=
github.com/filecoin-project/go-hamt-ipld/v3 v3.4.0/go.mod h1:s0qiHRhFyrgW0SvdQMSJFQxNa4xEIG5XvqCBZUEgcbc=
github.com/filecoin-project/go-jsonrpc v0.6.0 h1:/fFJIAN/k6EgY90m7qbyfY28woMwyseZmh2gVs5sYjY=
github.com/filecoin-project/go-jsonrpc v0.6.0/go.mod h1:/n/niXcS4ZQua6i37LcVbY1TmlJR0UIK9mDFQq2ICek=
github.com/filecoin-project/go-jsonrpc v0.7.0 h1:mqA5pIOlBODx7ascY9cJdBAYonhgbdUOIn2dyYI1YBg=
github.com/filecoin-project/go-jsonrpc v0.7.0/go.mod h1:lAUpS8BSVtKaA8+/CFUMA5dokMiSM7n0ehf8bHOFdpE=
github.com/filecoin-project/go-padreader v0.0.1 h1:8h2tVy5HpoNbr2gBRr+WD6zV6VD6XHig+ynSGJg8ZOs=
github.com/filecoin-project/go-padreader v0.0.1/go.mod h1:VYVPJqwpsfmtoHnAmPx6MUwmrK6HIcDqZJiuZhtmfLQ=
github.com/filecoin-project/go-paramfetch v0.0.4 h1:H+Me8EL8T5+79z/KHYQQcT8NVOzYVqXIi7nhb48tdm8=
Expand Down
Loading