Repository navigation
op-reth: default the pending block timestamp to the chain's block time - #24078
Conversation
156f0e4 to
21f0157
Compare
bdbc4cc to
2722d62
Compare
e5d0e51 to
a0ee5fb
Compare
a0ee5fb to
9ad226a
Compare
There was a problem hiding this comment.
The description mentions the alternative of a block-time field in the chain spec, filled from the superchain registry. I think the data below makes that worth the chainspec change, and the change is smaller than it sounds, because op-reth already embeds the value. I compared the 2 s fallback with the registry, and for some chains it's wrong in both directions.
Where alloy-chains is wrong. I checked OpPendingEnvBuilder::new against block_time for all 58 chains in the superchain-registry checkout. alloy-chains 0.2.34 names 19 of them, and all 19 hints match. The other 39 get the 2 s fallback, which is wrong for 6:
| Chain | Registry block_time |
This PR | pending is dated |
|---|---|---|---|
| settlus (mainnet, sepolia), giwa (sepolia), sepolia-devnet-5 | 1 s | 2 s | one block too far ahead |
| swan (mainnet) | 5 s | 2 s | 3 s before the real next block |
| cyber (sepolia) | 10 s | 2 s | 8 s before the real next block |
The last two are the reverse of the bug this PR fixes: near a fork, pending calls run under the old rules while the real next block already has the new ones. A chain started from a genesis file, such as a 1 s devnet, gets 2 s as well. On the main pending paths a client can't correct it: eth_call, eth_estimateGas and the tracing calls build their environment with None overrides and apply the request's blockOverrides only afterwards (call.rs:923-925 in the fork), and the pool-built pending block takes no input at all.
op-reth already has the exact value. chainspec/build.rs puts each registry TOML into res/superchain-configs.tar in full, so the embedded configs/mainnet/swan.json has "block_time": 5. ChainMetadata is stripped down to chain_id, hardforks and optimism, so the value is dropped when it's parsed. Reading it there and exposing it on OpChainSpec would make the pending timestamp exact for every registry chain, without depending on alloy-chains to list a chain or on a dependency bump after a chain joins the registry.
A setting for the rest. Chains outside the registry still need a source. A --rollup.block-time flag would fit with the existing RollupArgs (--rollup.sequencer, --rollup.compute-pending-block, …). The order I'd suggest:
--rollup.block-time, if set;- the registry's
block_time, for a registry chain; - the alloy-chains hint;
- 2 s, with a startup warning that pending timestamps may be off.
The registry value being the default means most operators never set the flag, so it rarely gets the chance to disagree with op-node's rollup.json.
Pending-state RPCs (eth_call, eth_estimateGas, eth_createAccessList, debug_traceCall and trace_call at `pending`, plus eth_callBundle at `pending` and mev_simBundle without a time override) derive the pending block from their parent header with BuildPendingEnv, which dates it 12 s, Ethereum's slot time, after its parent. On a 2 s OP chain that runs them up to 10 s ahead: from about five blocks before a hardfork they execute under the next fork's OpSpecId, and a pending block built on that environment is the fork's activation block, which admits no user transactions. OpEthApiBuilder now installs OpPendingEnvBuilder as the EthApi's PendingEnvBuilder. When a request sets no `time` override, it sets one of the parent's timestamp plus the chain's block time and leaves the rest to BuildPendingEnv, so the mirrored build_pending_env stays unchanged. The block time comes from alloy-chains' average_blocktime_hint for the chain id, rounded up to whole seconds as upstream's eth_simulateV1 does, with a 2 s fallback for chains without a hint. A block time field in the chain spec, from the superchain registry, would be exact for every chain instead. eth_simulateV1 is unaffected: it sets every block's time override before this builder runs (with upstream's 12 s fallback for chains without a hint), and since #28431 build_pending_env honours it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…gistry The pending block's block time now comes from --rollup.block-time if set, else the superchain registry's block_time for the resolved chain ID, else the alloy-chains hint, else 2 s with a warning. The 2 s fallback is wrong for registry chains with 1 s, 5 s and 10 s blocks; on the slower ones the pending block sat before the real next block. Devstack passes the flag from the rollup config. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9ad226a to
6b84621
Compare
|
🤖 Opus 5.5 says: Done in 6b84621, with the precedence you suggested:
Devstack also passes the flag from the rollup config, so devnets with 1 s blocks get the right pending timestamp. The branch is rebased onto develop. |
rust/op-reth/crates/node/src/args.rs: #24078 on develop and this branch each added a test after `test_proofs_storage_version_accepts_only_v2`. Both tests are kept.
Pending-state RPCs date the pending block 12 s, Ethereum's slot time, after its parent. On a 2 s OP chain that runs them up to 10 s ahead. From about five blocks before a hardfork,
eth_call,eth_estimateGas,eth_createAccessList,debug_traceCallandtrace_callatpendingexecute under the next fork's rules. The block they simulate is then that fork's activation block, which admits no user transactions. Away from forks,block.timestampatpendingis 10 s later than in the real next block.eth_callBundleatpendingandmev_simBundlewithout a time override are affected the same way.The pending block is now one block time after its parent.
OpPendingEnvBuildersupplies atimeoverride when the request sets none, and leaves the mirroredbuild_pending_envunchanged.Block time source, first match wins:
--rollup.block-timeflag, for chains outside the registry, such as test chains not yet added.block_time, looked up by the resolved chain ID, like--testing.sdm-fixed-policy's registry check. op-reth already embeds it;ChainMetadatanow keeps it. The op-reth binary resolves this step, since only it builds with the registry; other binaries built onOpNodecallsuperchain_block_timethemselves.eth_simulateV1does.Without the registry value, 2 s would be wrong for some registry chains: settlus (mainnet and sepolia), giwa-sepolia and sepolia-devnet-5 (1 s), swan (5 s) and cyber-sepolia (10 s). On the last two the pending block would sit before the real next block, so near a fork pending calls would run under the old rules.
Devstack now passes
--rollup.block-timefrom the rollup config, since devnet chains are in neither source.eth_simulateV1passes its per-block overrides through the same builder, so its spec now follows each simulated block's time. Its default spacing between simulated blocks is still upstream's: the alloy-chains hint, else 12 s.Known gap: no test builds
OpEthApito check that the builder is wired in; the tests cover the builder (including a configured block time beating the hint) and the registry lookup.Closes #22685
🤖 Co-created with Claude Opus 5.5