Skip to content

rpc/jsonrpc: default omitted block to latest on state methods#21586

Open
MysticRyuujin wants to merge 2 commits into
erigontech:mainfrom
MysticRyuujin:fix/default-block-latest-state-methods
Open

rpc/jsonrpc: default omitted block to latest on state methods#21586
MysticRyuujin wants to merge 2 commits into
erigontech:mainfrom
MysticRyuujin:fix/default-block-latest-state-methods

Conversation

@MysticRyuujin
Copy link
Copy Markdown
Contributor

@MysticRyuujin MysticRyuujin commented Jun 2, 2026

Summary

Make the Block parameter optional (defaulting to latest when omitted) on the six state-reading methods:

  • eth_getBalance
  • eth_getCode
  • eth_getStorageAt
  • eth_getTransactionCount
  • eth_getProof
  • eth_getStorageValues

Each took a value-type rpc.BlockNumberOrHash, so omitting the block parameter failed with -32602 missing value for required argument N — Erigon's rpc package (like go-ethereum's) only permits omitting a trailing argument when it is a pointer. This changes the six handlers (and the EthAPI interface) to *rpc.BlockNumberOrHash and defaults nil to latest via a small orLatest helper, reusing the existing latestNumOrHash var. eth_call already 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 Block parameter required: false (default latest) on these methods. Full credit for the proposal and rationale to @manusw7.

Testing

  • go vet ./rpc/jsonrpc/ passes (handlers + updated tests compile).
  • Verified against the hive rpc-compat simulator 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_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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 EthAPI methods (and implementations) from rpc.BlockNumberOrHash to *rpc.BlockNumberOrHash so the trailing argument can be omitted by JSON-RPC callers.
  • Add an orLatest helper to default nil block selectors to latest.
  • 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 thread rpc/jsonrpc/eth_call.go
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 {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants