Skip to content

Eth APIs should (mostly?) return nil when block or transaction not found #13043

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

Open
rvagg opened this issue Apr 17, 2025 · 0 comments
Open

Eth APIs should (mostly?) return nil when block or transaction not found #13043

rvagg opened this issue Apr 17, 2025 · 0 comments

Comments

@rvagg
Copy link
Member

rvagg commented Apr 17, 2025

Related to #12999, but there's more. I've done a partial fix in #13026 where I'm deciding not to fully fix this but to defer it to a separate issue because the breakage is a bit large.

go-ethereum seems to mostly be happy returning nil whenever you ask for something that doesn't exist. In fact, the pattern it uses a lot in internal/ethapi/api.go is: if thing != nil && err == nil { return thing } return nil, err. That means two things for us:

  1. Ignoring errors where it's a "not found" type of error (ipld.IsNotFound but also cases where the block number is beyond the heaviest epoch).
  2. Changing many of our return types to pointers so we can return nil

Some of the empty types we return are pretty large and when they go through JSON encoding they end up looking like they might be a thing you requested, just with values zeroed. Such as EthBlock.

These are the current APIs that can't return nil that may need to. Investigation is needed into exactly which APIs (more than just these) should return nil but the place to start is all of the transaction and block lookup APIs (mainly in transaction.go).

EthGetBlockTransactionCountByNumber(ctx context.Context, blkNum string) (ethtypes.EthUint64, error)
EthGetBlockTransactionCountByHash(ctx context.Context, blkHash ethtypes.EthHash) (ethtypes.EthUint64, error)
EthGetBlockByHash(ctx context.Context, blkHash ethtypes.EthHash, fullTxInfo bool) (ethtypes.EthBlock, error)
EthGetBlockByNumber(ctx context.Context, blkNum string, fullTxInfo bool) (ethtypes.EthBlock, error)
EthGetTransactionCount(ctx context.Context, sender ethtypes.EthAddress, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthUint64, error)
EthGetBalance(ctx context.Context, address ethtypes.EthAddress, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthBigInt, error)
EthFeeHistory(ctx context.Context, p jsonrpc.RawParams) (ethtypes.EthFeeHistory, error)
EthEstimateGas(ctx context.Context, p jsonrpc.RawParams) (ethtypes.EthUint64, error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 📌 Triage
Development

No branches or pull requests

1 participant