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 23 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 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))
rvagg marked this conversation as resolved.
Show resolved Hide resolved

## 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
95 changes: 79 additions & 16 deletions api/api_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,27 @@ import (
"errors"
"reflect"

"golang.org/x/xerrors"

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

var invalidExecutionRevertedWithDataMsg = xerrors.New("invalid execution reverted with data error")

// Default messages for errors.
const (
rvagg marked this conversation as resolved.
Show resolved Hide resolved
executionRevertedDefaultMsg = "execution reverted"
outOfGasDefaultMsg = "call ran out of gas"
actorNotFoundDefaultMsg = "actor not found"
f3DisabledDefaultMsg = "f3 is disabled"
ticketInvalidDefaultMsg = "ticket is not valid"
ticketExpiredDefaultMsg = "ticket has expired"
ticketIssuerMismatchDefaultMsg = "issuer does not match current node"
tooManyInstancesDefaultMsg = "requested instance count too high"
ticketStartBeforeExistingDefaultMsg = "ticket starts before existing lease"
f3NotReadyDefaultMsg = "f3 isn't yet ready to participate"
)

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

var (
Expand All @@ -40,13 +59,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 = (*ErrExecutionRevertedWithData)(nil)
_ jsonrpc.RPCErrorCodec = (*ErrExecutionRevertedWithData)(nil)
)

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

func ErrorIsIn(err error, errorTypes []error) bool {
Expand All @@ -74,39 +96,80 @@ func ErrorIsIn(err error, errorTypes []error) bool {
// ErrOutOfGas signals that a call failed due to insufficient gas.
type ErrOutOfGas struct{}

func (ErrOutOfGas) Error() string { return "call ran out of gas" }
func (ErrOutOfGas) Error() string { return outOfGasDefaultMsg }

// ErrActorNotFound signals that the actor is not found.
type ErrActorNotFound struct{}

func (ErrActorNotFound) Error() string { return "actor not found" }
func (ErrActorNotFound) Error() string { return actorNotFoundDefaultMsg }

type errF3Disabled struct{}

func (errF3Disabled) Error() string { return "f3 is disabled" }
func (errF3Disabled) Error() string { return f3DisabledDefaultMsg }

type errF3ParticipationTicketInvalid struct{}

func (errF3ParticipationTicketInvalid) Error() string { return "ticket is not valid" }
func (errF3ParticipationTicketInvalid) Error() string { return ticketInvalidDefaultMsg }

type errF3ParticipationTicketExpired struct{}

func (errF3ParticipationTicketExpired) Error() string { return "ticket has expired" }
func (errF3ParticipationTicketExpired) Error() string { return ticketExpiredDefaultMsg }

type errF3ParticipationIssuerMismatch struct{}

func (errF3ParticipationIssuerMismatch) Error() string { return "issuer does not match current node" }
func (errF3ParticipationIssuerMismatch) Error() string { return ticketIssuerMismatchDefaultMsg }

type errF3ParticipationTooManyInstances struct{}

func (errF3ParticipationTooManyInstances) Error() string { return "requested instance count too high" }
func (errF3ParticipationTooManyInstances) Error() string { return tooManyInstancesDefaultMsg }

type errF3ParticipationTicketStartBeforeExisting struct{}

func (errF3ParticipationTicketStartBeforeExisting) Error() string {
return "ticket starts before existing lease"
return ticketStartBeforeExistingDefaultMsg
}

type errF3NotReady struct{}

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

type ErrExecutionRevertedWithData struct {
rvagg marked this conversation as resolved.
Show resolved Hide resolved
Message string
Data string
}

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

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

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 ErrExecutionRevertedWithData to a JSONRPCError.
func (e *ErrExecutionRevertedWithData) ToJSONRPCError() (jsonrpc.JSONRPCError, error) {
return jsonrpc.JSONRPCError{
Code: EExecutionRevertedWithData,
Message: e.Message,
Data: e.Data,
}, nil
}

// NewErrExecutionRevertedWithData creates a new ErrExecutionRevertedWithData.
func NewErrExecutionRevertedWithData(data string) *ErrExecutionRevertedWithData {
return &ErrExecutionRevertedWithData{
Message: executionRevertedDefaultMsg,
Data: data,
}
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ replace github.com/filecoin-project/test-vectors => ./extern/test-vectors // pro

replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi // provided via a git submodule

replace github.com/filecoin-project/go-jsonrpc => github.com/virajbhartiya/go-jsonrpc v0.0.0-20241023032238-90c8605569be
rvagg marked this conversation as resolved.
Show resolved Hide resolved

require (
contrib.go.opencensus.io/exporter/prometheus v0.4.2
github.com/BurntSushi/toml v1.3.2
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,6 @@ 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-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 Expand Up @@ -1281,6 +1279,8 @@ github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8W
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU=
github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM=
github.com/virajbhartiya/go-jsonrpc v0.0.0-20241023032238-90c8605569be h1:ObhGJfaDM6Hzq8UtvCqXmUcfhAqUAA5iRfrIzRmmKJk=
github.com/virajbhartiya/go-jsonrpc v0.0.0-20241023032238-90c8605569be/go.mod h1:lAUpS8BSVtKaA8+/CFUMA5dokMiSM7n0ehf8bHOFdpE=
github.com/warpfork/go-testmark v0.12.1 h1:rMgCpJfwy1sJ50x0M0NgyphxYYPMOODIJHhsXyEHU0s=
github.com/warpfork/go-testmark v0.12.1/go.mod h1:kHwy7wfvGSPh1rQJYKayD4AbtNaeyZdcGi9tNJTaa5Y=
github.com/warpfork/go-wish v0.0.0-20180510122957-5ad1f5abf436/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw=
Expand Down
Loading