Skip to content

Producer MaxGas from genesis (autobahn); ConsensusParams on RPC ctx (CON-257)#3341

Merged
wen-coding merged 6 commits into
mainfrom
wen/producer_support_for_autobahn
May 1, 2026
Merged

Producer MaxGas from genesis (autobahn); ConsensusParams on RPC ctx (CON-257)#3341
wen-coding merged 6 commits into
mainfrom
wen/producer_support_for_autobahn

Conversation

@wen-coding

@wen-coding wen-coding commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Two independent fixes on the path from genesis.consensus_params.block.max_gas to its consumers.

Fix 1 — Autobahn producer sources MaxGasPerBlock from genesis

Autobahn-only. Producer.MaxGasPerBlock was populated from autobahn.json's max_gas_per_block, while the EVM runtime and CometBFT's reaping read from genDoc.ConsensusParams.Block.MaxGas — two configurable sources for the same chain rule. buildGigaConfig now sources from genesis (validated > 0), matching CometBFT. The autobahn.json field is removed.

Fix 2 — RPCContextProvider populates ConsensusParams

Both engines. app.GetCheckCtx() and CreateQueryContext build ctxs without WithConsensusParams — only the tx-execution path (getContextForTx) does. So every RPC ctx had ctx.ConsensusParams() == nil, masked under the old block.go (which read blockRes.ConsensusParamUpdates) and worked around in info.go with a fallback cascade. After 2593ceb28 switched EncodeTmBlock to ctx.ConsensusParams(), eth_getBlockByNumber.gasLimit returns 0.

RPCContextProvider now calls WithConsensusParams(app.GetConsensusParams(ctx)) on both branches. eth_getBlockByNumber.gasLimit matches the GASLIMIT opcode bit-exactly. The info.go cascade can be cleaned up in a follow-up.

Test plan

  • go test ./sei-tendermint/node/ — incl. new TestBuildGigaConfig_GenesisMaxGas (nil / zero / negative)
  • go test ./app/ — incl. new TestRPCContextProviderPopulatesConsensusParams (verified to fail without Fix 2)
  • go test ./evmrpc/... — all 4 packages
  • make autobahn-integration-test — 5/5 subtests, full cluster boot/teardown
  • gofmt -s -l . clean, go vet clean

🤖 Generated with Claude Code

wen-coding and others added 3 commits April 29, 2026 09:48
…esults

eth_getBlockByNumber's gasLimit field was sourced from
blockRes.ConsensusParamUpdates.Block.MaxGas. Two problems with that:

- Under CometBFT, ConsensusParamUpdates is only populated when the app
  proposes a consensus-param update — most blocks have it nil. The code
  path nil-derefs in that case (or relies on Sei's per-block synthesis
  in app.go's getFinalizeBlockResponse, which always populates it but
  with whatever endBlockResp returned, not strictly the active params).

- Under Autobahn, /block_results is synthesized in sei-tendermint's
  GigaRouter path with whatever the autobahn config's MaxGasPerBlock
  is. That can drift from the genesis ConsensusParams.Block.MaxGas the
  EVM runtime actually uses for the GASLIMIT opcode (x/evm/keeper/keeper.go
  BlockContext.GasLimit reads ctx.ConsensusParams().Block.MaxGas).

Switch to ctx.ConsensusParams().Block.MaxGas — the same source the EVM
uses internally — so eth_getBlockByNumber.gasLimit and the GASLIMIT
opcode return the same number under both consensus engines. Adds nil
guards so the path is safe if ConsensusParams hasn't been populated
yet (very early init).

Unblocks hardhat tests:
  - Should return correct gas limit via GASLIMIT opcode
  - Should access gas limit directly via inline assembly
  - Should access gas limit correctly within a state-changing transaction

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The Autobahn producer's mempool reaping budget (Producer.MaxGasPerBlock,
used by ReapMaxBytesMaxGas via MaxGasWanted/MaxGasEstimated) was sourced
from autobahn.json's max_gas_per_block field. The chain's gas-limit
consensus rule lives in genesis (consensus_params.block.max_gas), which
is the same number x/evm reads via ctx.ConsensusParams().Block.MaxGas
for the GASLIMIT opcode.

Two independently configurable sources for the same physical rule could
silently drift — a leader sized to one limit while verifiers (and the
EVM) enforced the other. Source the producer from genesis so there's
one canonical value, and drop the autobahn.json field entirely.

Validate that genesis ConsensusParams.Block.MaxGas > 0 at node startup
and fail fast if it isn't.

The autobahn-integration-test cluster boots cleanly and all 5 subtests
(BlockProduction / BankTransfer / LivenessUnderMaxFaults /
HaltsBeyondMaxFaults / Recovery) pass with the new path.

Non-app-hash-breaking: producer reaping affects which txs the leader
proposes, not block validity. Verifiers re-check against genesis
(unchanged), so any working deployment already had the two sources
matching — at most this removes a way to silently misconfigure.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
evmrpc handlers that read ctx.ConsensusParams() — EncodeTmBlock's
gasLimit (eth_getBlockByNumber), InfoAPI.CalculateGasUsedRatio,
x/evm BlockContext.GasLimit when reached via debug_trace*, etc. —
were getting nil and falling through to zero or hardcoded 10M defaults.

Reason: app.GetCheckCtx() returns app.checkState.ctx, which
setCheckState builds without WithConsensusParams; CreateQueryContext
likewise omits it. Only the tx-execution path (getContextForTx in
sei-cosmos baseapp) sets it. So every RPC ctx returned by
RPCContextProvider lacked the params even though the param store had
them.

Populate it in both branches of RPCContextProvider via
WithConsensusParams(app.GetConsensusParams(ctx)). The existing
case-by-case workarounds (e.g. the cascade in evmrpc/info.go's
CalculateGasUsedRatio) become redundant; they can be cleaned up
separately.

Cost: ~7 in-memory paramStore reads per RPC ctx (already paid on
every tx via getContextForTx, well-trodden). Negligible against the
JSON serialization cost of a typical handler.

Adds TestRPCContextProviderPopulatesConsensusParams covering the
latest-height and historical-height branches; verified to fail
without the fix.

Also updates evmrpc/tests/regression_test.go: the captured trace
ground truths were recorded under specific block consensus_params
(visible in mock_data/.../*.json -> consensus_param_updates).
Previously the test happened to match because the fallback to
DefaultBlockGasLimit (10M) coincidentally equaled the captured
mainnet block's max_gas. With this fix, ctx now carries the test
fixture's DefaultConsensusParams (100M), so traces drift unless we
honor the captured per-block params. Add withCapturedConsensusParams
that reads them from the already-loaded mockedBlockResultsResults
and applies them to the ctx — making the regression replay faithful
to mainnet conditions, not coincidentally equal to a default fallback.

Non-app-hash-breaking: RPCContextProvider is query-only; no
state-transition path uses it.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Apr 29, 2026

Copy link
Copy Markdown

The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedApr 30, 2026, 5:23 PM

@github-actions

Copy link
Copy Markdown

The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedApr 29, 2026, 9:21 PM

@wen-coding wen-coding changed the title Source block-gas-limit from a single canonical place (genesis ConsensusParams) Producer MaxGas from genesis (autobahn); ConsensusParams on RPC ctx Apr 29, 2026
@wen-coding wen-coding changed the title Producer MaxGas from genesis (autobahn); ConsensusParams on RPC ctx Producer MaxGas from genesis (autobahn); ConsensusParams on RPC ctx (CON-257) Apr 29, 2026
@codecov

codecov Bot commented Apr 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.16%. Comparing base (08689b2) to head (47c426c).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3341      +/-   ##
==========================================
- Coverage   59.21%   59.16%   -0.05%     
==========================================
  Files        2097     2097              
  Lines      172509   172451      -58     
==========================================
- Hits       102152   102032     -120     
- Misses      61501    61558      +57     
- Partials     8856     8861       +5     
Flag Coverage Δ
sei-chain-pr 61.16% <100.00%> (?)
sei-db 70.41% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
app/app.go 69.55% <100.00%> (+0.05%) ⬆️
evmrpc/block.go 82.26% <100.00%> (+0.10%) ⬆️
...int/cmd/tendermint/commands/gen_autobahn_config.go 18.51% <ø> (+0.33%) ⬆️
sei-tendermint/config/autobahn.go 28.57% <ø> (-8.93%) ⬇️
sei-tendermint/node/setup.go 69.57% <100.00%> (+0.29%) ⬆️

... and 40 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread sei-tendermint/node/setup_test.go Outdated
genDoc := &types.GenesisDoc{ChainID: "test-chain", InitialHeight: 1}
genDoc := &types.GenesisDoc{
ChainID: "test-chain",
InitialHeight: 1,

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.

while at it, can we make InitialHeight nontrivial? Or will it break tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed, I don't think it matters here

Comment thread sei-tendermint/node/setup_test.go Outdated
genDoc.ConsensusParams = nil
_, err := buildGigaConfig(cfgFile, nodeKey, valKey, txMempool, genDoc)
assert.Error(t, err)
assert.Contains(t, err.Error(), "max_gas")

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.

pls, no error parsing, use errors.Is instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

wen-coding and others added 3 commits April 30, 2026 09:20
Reviewer feedback on #3341: replace substring-matching error text
(`assert.Contains(err.Error(), "max_gas")`) with a typed sentinel.

Define ErrGenesisMaxGasInvalid and wrap via fmt.Errorf("...: %w", ...)
so callers can `errors.Is(err, ErrGenesisMaxGasInvalid)`. Tests now
use assert.ErrorIs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Reviewer feedback on #3341: the test fixture used InitialHeight: 1.
Bump to 100 (with a comment) so any future code in buildGigaConfig
that implicitly assumes the genesis is at height 1 fails the test
instead of accidentally working.

buildGigaConfig itself only reads genDoc.ConsensusParams and
genDoc.ChainID — InitialHeight flows untouched into result.GenDoc,
so the existing equality assertion still holds.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@wen-coding wen-coding requested review from arajasek and codchen April 30, 2026 18:27
@wen-coding wen-coding added this pull request to the merge queue May 1, 2026
Merged via the queue into main with commit 6620fb6 May 1, 2026
38 checks passed
@wen-coding wen-coding deleted the wen/producer_support_for_autobahn branch May 1, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants