Skip to content

eth: default Block param to latest on state methods — implementation + conformance tests (builds on #812) - #814

Merged
fjl merged 1 commit into
ethereum:mainfrom
MysticRyuujin:feat/state-block-default-latest
Jun 29, 2026
Merged

fjl merged 1 commit into
ethereum:mainfrom
MysticRyuujin:feat/state-block-default-latest

Conversation

@MysticRyuujin

@MysticRyuujin MysticRyuujin commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Builds on #812 by @manusw7 and carries it through to a tested, client-verified state:

  1. Spec (src/eth/state.yaml): mark the Block parameter required: false with description: "default: 'latest'" on the six state-reading methods (eth_getBalance, eth_getStorageAt, eth_getStorageValues, eth_getTransactionCount, eth_getCode, eth_getProof) — identical to @manusw7's proposal in Default Block param to 'latest' on eth_* state methods #812.
  2. Conformance tests (tools/testgen/generators.go): add a *-default-block case to each method that omits the Block parameter and asserts default-to-latest behavior.
  3. Fixtures (tests/**/*.io): generated via make fill against a go-ethereum build that implements the behavior.

This addresses the two open items in #812's checklist: a go-ethereum implementation, and hive-enforceable conformance tests for the default-to-latest behavior.

Credit

The proposal, rationale, and spec change originate with @manusw7 in #812. This PR exists to implement and test it across clients — full credit to @manusw7 for the standards work.

Validation

  • make build regenerates openrpc.json with Block required: false on all six methods.
  • ./tools/speccheck -v passes. Negative-tested: flipping a method back to required: true makes speccheck reject the omitted-block fixture (missing required parameter), confirming the spec change is load-bearing.
  • The six fixtures replay green in hive rpc-compat against a go-ethereum build with the implementation.

Cross-client status

  • go-ethereum: implemented; passes all six. (PR linked below.)
  • Nethermind: defaults to latest for five of six already; eth_getStorageValues required a one-method fix (its block param was non-nullable). (PR linked below.)

Related

CI note (expected red until go-ethereum merges)

The Test job's make fill step is expected to fail for this PR, and that is
structural — not a defect:

  • make fill regenerates fixtures by building the geth pinned in tools/go.mod.
  • The new *-default-block fixtures require a geth that defaults an omitted block
    to latest — i.e. the accompanying go-ethereum PR (internal/ethapi: default block parameter to latest on state methods go-ethereum#35100),
    which isn't merged yet. Upstream-pinned geth still errors on the omitted block,
    so make fill can't reproduce the committed fixtures and the "no untracked /
    changed files" gate fails.
  • make test (speccheck) and make lint pass; the fixtures were generated with a
    local geth carrying the change and validate against the updated spec.

This resolves once go-ethereum#35100 merges and this PR's tools/go.mod is bumped
to that commit. (A replace to a personal fork would make CI green but isn't
mergeable, so it's intentionally not committed.) This is the two-PR ordering
#812 anticipated.

Mark the Block parameter required:false (default 'latest') on the six
state-reading methods: eth_getBalance, eth_getStorageAt,
eth_getStorageValues, eth_getTransactionCount, eth_getCode and
eth_getProof. Add rpctestgen cases and fixtures that omit the block
parameter and assert default-to-latest behavior.
@MysticRyuujin
MysticRyuujin force-pushed the feat/state-block-default-latest branch from 92c7257 to b14c23c Compare June 29, 2026 15:22
@MysticRyuujin MysticRyuujin reopened this Jun 29, 2026
@fjl
fjl merged commit ff44b23 into ethereum:main Jun 29, 2026
5 checks passed
@MysticRyuujin
MysticRyuujin deleted the feat/state-block-default-latest branch July 29, 2026 19:30
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