rpc/jsonrpc: default omitted block to latest on state methods#21586
Open
MysticRyuujin wants to merge 2 commits into
Open
rpc/jsonrpc: default omitted block to latest on state methods#21586MysticRyuujin wants to merge 2 commits into
MysticRyuujin wants to merge 2 commits into
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.
This was referenced Jun 2, 2026
Merged
Merged
Contributor
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.
Comment on lines
+59
to
+63
| // 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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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