rpc/jsonrpc: default omitted block to latest on state methods#21586
Conversation
eth_getBalance, eth_getCode, eth_getStorageAt, eth_getTransactionCount, eth_getProof and eth_getStorageValues took a value-type rpc.BlockNumberOrHash, so omitting the block parameter failed with -32602 'missing value for required argument N' (the rpc package only permits omitting a trailing pointer argument). Change them to *rpc.BlockNumberOrHash and default nil to latest via a small orLatest helper, matching eth_call and execution-apis (Block required:false, default 'latest'). Update internal callers (mcp, contracts).
Adjust the eth_getStorageAt/getStorageValues/getProof/getBalance test callers to pass *rpc.BlockNumberOrHash after the signature change.
There was a problem hiding this comment.
Pull request overview
This PR updates Erigon’s JSON-RPC state-reading methods to treat the Block parameter as optional (defaulting to latest when omitted), aligning behavior with the Execution APIs spec for eth_getBalance, eth_getCode, eth_getStorageAt, eth_getTransactionCount, eth_getProof, and eth_getStorageValues.
Changes:
- Switch the six affected
EthAPImethods (and implementations) fromrpc.BlockNumberOrHashto*rpc.BlockNumberOrHashso the trailing argument can be omitted by JSON-RPC callers. - Add an
orLatesthelper to defaultnilblock selectors tolatest. - Update internal callers (MCP server + contract backend) and adjust tests to pass pointers.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| rpc/mcp/resources.go | Updates MCP resource handler calls to pass *BlockNumberOrHash (latest). |
| rpc/mcp/mcp.go | Updates MCP tool handlers to pass *BlockNumberOrHash to state methods. |
| rpc/jsonrpc/eth_call.go | Introduces orLatest helper and updates GetProof to accept optional block selector. |
| rpc/jsonrpc/eth_call_test.go | Updates GetProof tests to pass a *BlockNumberOrHash. |
| rpc/jsonrpc/eth_api.go | Changes EthAPI interface signatures for the six methods to use pointers. |
| rpc/jsonrpc/eth_api_test.go | Updates tests for pointer-based signatures; adds bnhPtr helper. |
| rpc/jsonrpc/eth_accounts.go | Updates state-reading method implementations to accept optional block selector and default via orLatest. |
| rpc/jsonrpc/corner_cases_support_test.go | Updates GetBalance test call to pass *BlockNumberOrHash. |
| rpc/contracts/direct_backend.go | Updates internal backend calls (GetCode, GetTransactionCount) to pass *BlockNumberOrHash. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // orLatest resolves an optional block selector, defaulting to the latest block | ||
| // when the caller omitted the parameter (nil). Used by the state-reading methods | ||
| // whose Block parameter is optional per execution-apis (default 'latest'). | ||
| func orLatest(blockNrOrHash *rpc.BlockNumberOrHash) rpc.BlockNumberOrHash { | ||
| if blockNrOrHash != nil { |
Assert that calling each state method with a nil block selector returns the same result as an explicit latest selector, exercising the orLatest(nil) path.
|
Good call — added in c4bef18. |
|
cc @canepat |
Tests for erigontech/erigon#21586: eth_getBalance, eth_getCode, eth_getStorageAt, eth_getTransactionCount, eth_getProof, eth_getStorageValues now accept an omitted block parameter (defaults to latest). Each fixture omits the block param and carries metadata.latest=true so it runs under -L.
Summary
Make the
Blockparameter optional (defaulting tolatestwhen omitted) on the six state-reading methods:eth_getBalanceeth_getCodeeth_getStorageAteth_getTransactionCounteth_getProofeth_getStorageValuesEach took a value-type
rpc.BlockNumberOrHash, so omitting the block parameter failed with-32602 missing value for required argument N— Erigon'srpcpackage (like go-ethereum's) only permits omitting a trailing argument when it is a pointer. This changes the six handlers (and theEthAPIinterface) to*rpc.BlockNumberOrHashand defaultsniltolatestvia a smallorLatesthelper, reusing the existinglatestNumOrHashvar.eth_callalready behaves this way.Internal callers of the interface are updated accordingly (
rpc/contracts/direct_backend.go,rpc/mcp/*) along with the affected tests.Motivation
This aligns Erigon with ethereum/execution-apis#812 by @manusw7, which marks the
Blockparameterrequired: false(defaultlatest) on these methods. Full credit for the proposal and rationale to @manusw7.Testing
go vet ./rpc/jsonrpc/passes (handlers + updated tests compile).hiverpc-compatsimulator with default-block conformance fixtures (block parameter omitted): a locally-built Erigon with this change returns the latest-block values and all six pass (tests=7 failed=0). Before the change, all six failed.Related
eth_getStorageValuesfix: JsonRpc: default omitted block to latest for eth_getStorageValues NethermindEth/nethermind#11883