Skip to content

internal/ethapi: default block parameter to latest on state methods - #35100

Merged
s1na merged 3 commits into
ethereum:masterfrom
MysticRyuujin:feat/state-block-default-latest
Jun 3, 2026
Merged

s1na merged 3 commits into
ethereum:masterfrom
MysticRyuujin:feat/state-block-default-latest

Conversation

@MysticRyuujin

@MysticRyuujin MysticRyuujin commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

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

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

Each now takes *rpc.BlockNumberOrHash and resolves a nil (omitted/null) value to latest via a small blockNrOrHashOrLatest helper — mirroring the behavior eth_call already implements. This requires the pointer type because go-ethereum's rpc package only permits omitting a trailing positional argument when its Go type is a pointer; a value type is mandatory and an omitted block currently fails with -32602 missing value for required argument N.

Motivation

This implements the behavior proposed in ethereum/execution-apis#812 by @manusw7, which marks the Block parameter required: false (default latest) on these methods to align them with eth_call, eth_estimateGas, eth_createAccessList, and eth_simulateV1. Full credit for the proposal and rationale goes to @manusw7. That PR notes it was "not expected to merge until client consensus + go-ethereum implementation" — this PR provides that go-ethereum implementation.

Testing

  • New TestStateMethodsDefaultToLatest drives the full JSON-RPC server stack (rpc.DialInProc) and asserts that omitting the block parameter yields the same result as passing "latest" for all six methods.
  • Verified against the hive rpc-compat simulator with new .io fixtures that omit the block parameter: all six pass on this branch.

Related

Make the block parameter optional on eth_getBalance, eth_getCode,
eth_getStorageAt, eth_getTransactionCount, eth_getProof and
eth_getStorageValues. When omitted, it now defaults to the latest block,
matching execution-apis (Block marked required:false, default 'latest')
and the existing behavior of eth_call.
@s1na

s1na commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Overall looks good, just one small improvement for consistency with other methods, change inputBlockNumberFormatter to inputDefaultBlockNumberFormatter on eth_getProof and eth_getStorageValues in web3ext file.

Even without that change the console works fine, sort of by accident, because the JSON serializer produces null for an unprovided argument, and the server accepting null and setting the default latest. But would be nice to also have it more correct at the client side.

…Values

Use inputDefaultBlockNumberFormatter so the console supplies latest when the
block arg is omitted, consistent with the other state methods.
@MysticRyuujin

Copy link
Copy Markdown
Contributor Author

Done in 18e0fd8 — switched eth_getProof and eth_getStorageValues to inputDefaultBlockNumberFormatter in web3ext.go, so the console supplies latest when the block arg is omitted rather than relying on the null-serialization happening to work. Thanks for the review!

@MysticRyuujin
MysticRyuujin marked this pull request as ready for review June 2, 2026 19:12
@s1na s1na added this to the 1.17.4 milestone Jun 3, 2026
Comment thread internal/ethapi/api_test.go Resolved

@s1na s1na left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@MariusVanDerWijden MariusVanDerWijden left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

SGTM

@s1na
s1na merged commit 6b451a4 into ethereum:master Jun 3, 2026
9 checks passed
@MysticRyuujin
MysticRyuujin deleted the feat/state-block-default-latest branch June 3, 2026 13:32
0xjvn pushed a commit to 0xjvn/go-ethereum that referenced this pull request Jun 5, 2026
…thereum#35100)

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

- `eth_getBalance`
- `eth_getCode`
- `eth_getStorageAt`
- `eth_getTransactionCount`
- `eth_getProof`
- `eth_getStorageValues`

This implements the behavior proposed in ethereum/execution-apis#812.

---------

Co-authored-by: Sina M <1591639+s1na@users.noreply.github.com>
gballet pushed a commit to gballet/go-ethereum that referenced this pull request Jun 12, 2026
…thereum#35100)

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

- `eth_getBalance`
- `eth_getCode`
- `eth_getStorageAt`
- `eth_getTransactionCount`
- `eth_getProof`
- `eth_getStorageValues`

This implements the behavior proposed in ethereum/execution-apis#812.

---------

Co-authored-by: Sina M <1591639+s1na@users.noreply.github.com>
AdityaSripal pushed a commit to AdityaSripal/go-ethereum that referenced this pull request Jun 21, 2026
…thereum#35100)

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

- `eth_getBalance`
- `eth_getCode`
- `eth_getStorageAt`
- `eth_getTransactionCount`
- `eth_getProof`
- `eth_getStorageValues`

This implements the behavior proposed in ethereum/execution-apis#812.

---------

Co-authored-by: Sina M <1591639+s1na@users.noreply.github.com>
rjl493456442 pushed a commit that referenced this pull request Aug 28, 2026
`debug_traceCall` requires the block number or hash parameter today.
`TraceCall` takes `rpc.BlockNumberOrHash` by value, so an omitted
parameter returns "missing value for required argument 1".

The pending callTracer spec (ethereum/execution-apis#855) marks the
parameter optional with a default of `latest`, consistent with the
state-method defaults from #35100 (execution-apis #812/#814 lineage).

This changes the argument to `*rpc.BlockNumberOrHash` and defaults to
latest when nil. A regression test calls `debug_traceCall` through the
RPC server with the parameter omitted and compares against an explicit
`latest`. No behavior change when the parameter is supplied.
jimmyc256 pushed a commit to Lambda256/go-ethereum-ralim that referenced this pull request Sep 23, 2026
…35583)

`debug_traceCall` requires the block number or hash parameter today.
`TraceCall` takes `rpc.BlockNumberOrHash` by value, so an omitted
parameter returns "missing value for required argument 1".

The pending callTracer spec (ethereum/execution-apis#855) marks the
parameter optional with a default of `latest`, consistent with the
state-method defaults from ethereum#35100 (execution-apis ethereum#812/ethereum#814 lineage).

This changes the argument to `*rpc.BlockNumberOrHash` and defaults to
latest when nil. A regression test calls `debug_traceCall` through the
RPC server with the parameter omitted and compares against an explicit
`latest`. No behavior change when the parameter is supplied.
MegaRedHand added a commit to suna4/ethrex that referenced this pull request Oct 27, 2026
…aclass#6780)

## Summary

Two related JSON-RPC changes aligning ethrex with
**ethereum/execution-apis#812** by **@manusw7** (Block parameter
optional, default `latest`):

1. **Default an omitted block parameter to `latest`** on the state
methods that previously required it. `eth_getBalance`, `eth_getCode`,
`eth_getStorageAt`, `eth_getTransactionCount`, and `eth_getProof` did a
strict `params.len() != N` check and returned `-32000 "Expected N
params"` when the block was omitted. They now accept the block as
optional and default it to `latest` via a new `impl Default for
BlockIdentifierOrHash` (latest).
2. **Implement `eth_getStorageValues`** (previously `-32601 method not
found`): batches storage-slot reads for multiple accounts at a block,
mirroring `eth_getStorageAt`, with the same optional-block default and a
1024-slot cap. Registered in the `eth` dispatch. Slots follow the spec's
`bytesMax32` (`0x` and at most 64 hex digits, `0x` alone is slot 0). An
invalid slot or an empty request returns `-32602`, and more than 1,024
slots in total returns `-32005`. Every slot is read from the state root
of one resolved block, so a block hash reads that block and a block the
node does not have is an error.

## Motivation

Aligns ethrex with execution-apis#812 (@manusw7) and matches the other
clients implementing the same change. Full credit to @manusw7 for the
proposal.

## Testing

- New parse-layer tests assert each state method resolves an **omitted**
block to `latest`
(`test_state_methods_default_block_to_latest_when_omitted`). The
`eth_getStorageValues` tests cover the slot format, the empty request,
the slot cap, and the handler: values, lowercase keys, zeros for an
absent account, a lookup by hash, and the error for an unknown block.
- Confirmed via the hive `rpc-compat` simulator that the omitted-block
request now produces the **same** response as an explicit `"latest"`
request for every method (previously the omitted form errored).

### Note on hive rpc-compat value fixtures (out of scope)

ethrex does not currently pass the rpc-compat *value* fixtures for these
state methods in the hive default chain — but this is **pre-existing and
unrelated to this change**: a stock ethrex build returns the same
results for an explicit `"latest"` request (e.g. `eth_getBalance(addr,
"latest")` returns `0x0` where other clients return the funded balance),
and `*-blockhash` requests error with "Could not resolve block number".
That points to an ethrex/hive default-chain state-serving issue, which
is out of scope here. This PR makes the omitted-block path behave
identically to the explicit-`latest` path (the spec change), proven by
the unit tests above.

## Related

- Source proposal: ethereum/execution-apis#812 (by @manusw7)
- execution-apis spec + conformance tests: ethereum/execution-apis#814
- go-ethereum: ethereum/go-ethereum#35100
- Nethermind: NethermindEth/nethermind#11883
- Erigon: erigontech/erigon#21586
- Besu: besu-eth/besu#10587

---------

Co-authored-by: ilitteri <ivanlitteri@hotmail.com>
Co-authored-by: Tomás Grüner <47506558+MegaRedHand@users.noreply.github.com>
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