Skip to content

feat(evmonly): serve staking's bonded set as the validator set - #4741

Open
codchen wants to merge 70 commits into
mainfrom
claude/giga-evmonly-get-validators
Open

codchen wants to merge 70 commits into
mainfrom
claude/giga-evmonly-get-validators

Conversation

@codchen

@codchen codchen commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Autobahn derives epoch E+2's committee from app.GetValidators(), read once epoch E's last road has executed, and keeps that committee in its own epoch state. The evm-only app returned a fixed list built from the autobahn config file. This serves staking's current bonded set instead.

  • GetValidators serves staking's bonded set as the last EndBlock stored it, and the configured validators until staking has bonded one. A stored set that does not add up is logged and returns no validators: autobahn then fails to stage the next committee, so the node stops at the epoch boundary rather than serving a committee the state doesn't back.
  • staking.BondedValidators returns lastValidators with each member's operator, ed25519 consensus key and power. A set longer than any MaxValidators allows, or a member with no validator record, is an error.
  • Executor.ReadLatest reads state holding every finalized block through the in-flight block's overlay, so GetValidators, which autobahn also calls before every block, never waits on a commit. It refuses once a commit is known to have failed.
  • evmonly.ReadOnlyState wraps a committed store view as a custom precompile State. A write is dropped and fails the state, as under a static call, and nothing is charged.
  • Header.ClosingEpoch: the autobahn executor marks each epoch's last block, from the epoch package's arithmetic over the genesis initial height (epoch.ClosingEpoch), and the evm-only app carries it to the end blockers' BlockContext. The app never repeats the epoch length.
  • Epoch snapshot, for rewards: on that block, staking's EndBlock copies the bonded set, with each member's consensus key, into epochValidators[epoch] and keeps the latest three, since the committee serving epoch E is the set at the end of epoch E−2. staking.EpochValidators reads the latest. Nothing outside tests reads it until rewards land. A member removed since keeps its key, and a bonded member with no validator record fails the snapshot, leaving the previous one in place. The rationale doc has a section on it.

runPushAppHashes reads GetValidators() at the app tip, which can be past the epoch's last block, so the set it stages is that block's only while no later block has changed it. The comment at the call site says so, with the TODO to ask the app for the set as of that block.

Staking isn't registered in the node yet (evmOnlyCustomPrecompiles builds only gov's registry), so a running node still serves the configured validators. Registering it, and writing its params and genesis validators from the autobahn config, is the next step. The consensus keys staking stores have to be the autobahn validator keys for the committee to carry over.

Test plan

  • go test -race ./giga/evmonly/precompiles/staking/
    • BondedValidators moves at any EndBlock, not at a delegation, is empty before staking bonds a set, and fails on a member with no validator or a set longer than MaxValidators allows.
    • The snapshot moves only when an epoch closes, the latest three are kept, a member removed after the snapshot keeps its key, and a set that does not add up is not snapshotted. The layout is pinned against solc 0.8.30.
  • go test -race ./giga/evmonly/: ReadLatest serves a block whose commit is held open, and refuses after a failed commit whether or not anything waited on it.
  • go test ./sei-tendermint/internal/autobahn/epoch/: ClosingEpoch marks each epoch's last road.
  • go test -race ./giga/evmonly/... ./sei-tendermint/internal/evmonlyapp/... ./sei-tendermint/internal/proxy/... ./sei-tendermint/internal/autobahn/... ./sei-tendermint/internal/p2p/...
    • The app serves the configured validators until staking bonds a set, and staking's set from the block that bonded it, with no epoch closed.
    • A corrupt bonded set returns no validators, as does a failed commit once it is reported.
    • End blockers see ClosingEpoch on the block that closes an epoch and on no other.
    • The existing configured-validators test passes unchanged.
  • make fmtcheck

Stack

#4726 to #4730 have merged; this PR is based on main.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

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

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedNov 17, 2026, 5:20 AM

@codecov

codecov Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.48819% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.65%. Comparing base (06ad847) to head (24acfa7).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
giga/evmonly/giga_store.go 83.33% 4 Missing ⚠️
sei-tendermint/internal/evmonlyapp/validators.go 89.65% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4741      +/-   ##
==========================================
+ Coverage   61.58%   61.65%   +0.07%     
==========================================
  Files        2078     2082       +4     
  Lines      161897   162154     +257     
==========================================
+ Hits        99711    99983     +272     
+ Misses      62181    62166      -15     
  Partials        5        5              
Flag Coverage Δ
sei-chain 59.86% <94.48%> (+0.04%) ⬆️
sei-db 75.17% <ø> (ø)
sei-db-state-db 81.60% <ø> (+0.03%) ⬆️

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

Files with missing lines Coverage Δ
giga/evmonly/custom_precompile.go 86.39% <100.00%> (+1.46%) ⬆️
giga/evmonly/end_block.go 94.59% <100.00%> (+0.07%) ⬆️
giga/evmonly/precompiles/staking/bonded_set.go 100.00% <100.00%> (ø)
giga/evmonly/precompiles/staking/endblock.go 93.38% <100.00%> (+1.38%) ⬆️
giga/evmonly/precompiles/staking/layout.go 100.00% <ø> (ø)
giga/evmonly/precompiles/staking/storage.go 97.89% <100.00%> (+1.01%) ⬆️
giga/evmonly/types.go 90.00% <ø> (ø)
sei-tendermint/internal/autobahn/epoch/registry.go 98.48% <100.00%> (-0.05%) ⬇️
...endermint/internal/autobahn/execution/execution.go 89.28% <100.00%> (+0.12%) ⬆️
sei-tendermint/internal/evmonlyapp/app.go 88.34% <100.00%> (+0.04%) ⬆️
... and 4 more

... and 24 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.

func (a *evmOnlyApplication) bondedValidators() ([]abci.ValidatorUpdate, error) {
view := a.openSettledView()
defer view.Close()
bonded, err := staking.BondedValidators(evmonly.ReadOnlyState(view))

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.

Hmm, we don't have unjail right now, so if you are jailed, you won't be in next Committee no matter how much stake you have?

@philipsu522 is that the semantics we want?

@cursor

cursor Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

PR Summary

High Risk
Changes consensus validator sourcing, epoch-boundary behavior, and read paths over pipelined commits—errors can halt committee staging or serve wrong validator sets.

Overview
Validator set from staking. The evm-only app’s GetValidators now returns staking’s lastValidators (with ed25519 keys and power) from the latest executed state, falling back to genesis-configured validators until staking bonds a set. Reads use new Executor.ReadLatest and ReadOnlyState so Autobahn never waits on an in-flight commit; corrupt bonded data or a failed commit returns no validators so committees are not staged on bad state.

Epoch closing signal. Autobahn sets Header.ClosingEpoch on each epoch’s last road (epoch.ClosingEpoch), and the EVM executor passes it through BlockContext.ClosingEpoch to EndBlock hooks.

Per-epoch bonded snapshots. On epoch-close blocks, staking EndBlock copies the bonded set (including consensus keys) into new storage epochValidators[epoch], keeps the latest three, and exposes EpochValidators for future rewards. Storage layout, harness, and design docs are updated accordingly.

Caveat. runPushAppHashes still calls GetValidators() at the app tip (not block n); a TODO notes fixing that when the set changes between epoch end and push.

Reviewed by Cursor Bugbot for commit 24acfa7. Bugbot is set up for automated code reviews on this repo. Configure here.

seidroid[bot]
seidroid Bot previously requested changes Nov 9, 2026

@seidroid seidroid Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This makes the evm-only app serve staking's committed bonded set from GetValidators, which autobahn uses to stage each epoch's committee, and falls back to the configured validators until staking bonds a set. It needs changes because a failed background commit can put a committee from a stale height into the persisted epoch registry. I dropped codex's empty-set finding: applyBondedSet returns errNoBondedPower instead of storing an empty set over a populated one.

Blocking

1 finding on the changed lines, as inline comments.

seidroid review · decision request_changes · session 9f43c20da24e4b8eb5cb28b8b94a8845 · turn resp_claude_6b2045c7f435da4baf8f129e501b6caa · item 6c6ba7ca8dae5b349e03d6b90a935e93

Findings: 1 blocking | 0 non-blocking | 1 posted inline

seidroid[bot]
seidroid Bot previously requested changes Nov 9, 2026

@seidroid seidroid Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The PR diff is unchanged since my last review: only the base merge moved, and the open blocker on validators.go:32 still holds. I dropped codex's empty-set claim again, because applyBondedSet returns errNoBondedPower instead of writing an empty set over a populated one, so a committed set never goes from populated to empty.

Blocking

1 finding on the changed lines, as inline comments.

seidroid review · decision request_changes · session 9f43c20da24e4b8eb5cb28b8b94a8845 · turn resp_claude_cb6ccd70350525ba82c4dc12a4898162 · item 0c67f369c8505178b53065eb8accb4ac

Findings: 1 blocking | 0 non-blocking | 1 posted inline

@seidroid seidroid Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since my last review, bondedValidators calls AwaitCommits itself and returns no validators when a commit has failed; that failure is sticky, so a committee from before the failed block can no longer be staged, and the new failed-commit test covers it. I dropped codex's empty-set claim again, because applyBondedSet returns errNoBondedPower instead of storing an empty set over a populated one, and nothing else blocks.

seidroid review · decision approve · session 9f43c20da24e4b8eb5cb28b8b94a8845 · turn resp_claude_f7343b64209c5760fdf7d51f6ac4489e · item 838acbf8916d59c9ba38468a2a01c38c

Findings: 0 blocking | 0 non-blocking | 0 posted inline

@seidroid
seidroid Bot dismissed stale reviews from themself November 9, 2026 04:03

Superseded: the latest review found nothing blocking in this change.

shemnon and others added 15 commits November 12, 2026 11:59
Draft storage layouts for the EVM-only staking, distribution and slashing
precompiles, and the rationale behind them, taken from ffd15bb, which is not
merged on its own.

- staking-design-rationale.md: the proposal, built from three principles
  (Solidity slot layout, V2 structures for migration, rewards undesigned)
- StakingStorage, DistributionStorage, SlashingStorage: draft layouts
- Sets.sol: dependency-free AddressSet/UintSet with EnumerableSet's layout
… reads

- Drop the consensus address: validators are keyed by operator in staking,
  distribution and slashing. 0x22 is keyed by the ed25519 key, for the
  duplicate-key check and key lookups; slashing's 0x03 relation is dropped.
- Drop the enumeration sets read only by queries (0x37, unbonding and
  redelegations by delegator) or by entry slashing (0x33, 0x35).
- Keep redelegation entries in the redelegation queue, with a per-triple
  count for maxEntries.
- Store the bonded set as one ValidatorPower array instead of a mapping
  and a set.
- Update the rationale doc to match, including which queue entries the
  FIFO clamp delays.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A mapping value grows at its end and needs no reserved slots. A struct
inside another, a top-level struct with variables after it, and an array
element cannot grow at their end; say what each can do instead, and add
an open question on validatorSlashEvents, the one array of structs kept
for good.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Validator is a mapping value, so it grows at its end and needs no
__gap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…alues and sets in the growth rule

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Only queries walk signing infos, so the slashing layout keeps no enumeration of
them, as the rule for enumerations says.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Add a Staking struct to ParamsStorage at slot 16: unbondingTime,
  maxValidators, maxEntries, maxVotingPowerRatio and
  maxVotingPowerEnforcementThreshold.
- ReadStaking, HasStaking and WriteStaking, which writes them once at
  genesis; later changes go through gov.
- Bound them so a change cannot wedge staking: unbonding time within the
  period bounds, 1..100 bonded validators (an autobahn committee's limit),
  at least one entry, and a ratio in (0, 1].
- Regenerate the harness and layout testdata, and keep the gov
  param-change test to gov's own keys.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Add the staking precompile's storage layer over StakingStorage.sol: the
  slot layout, typed accessors for validators, delegations, unbonding and
  redelegation records and the three queues, the power index, and the
  1e18 fixed-point share math.
- Add solstorage AddressAt/SetAddressAt for packed addresses, and rename
  ValidatorQueueEntry.completionHeight to unbondingHeight.
- Tests check the layout against solc's, read state a compiled harness
  wrote, and compare the share math with sdk.Dec.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Validator no longer reserves a __gap, so it takes 15 slots and
deleteValidator zeroes those. The layout testdata is regenerated; the
harness bytecode never writes the gap and is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Add the staking precompile at 0x1005 over its storage: delegate
  (payable), redelegate and undelegate, by address and in whole usei.
  V2's string forms and authz methods keep their selectors and revert
  naming the replacement.
- Port x/staking's share math, minSelfDelegation jailing, Sei's max
  voting power ratio, the maxEntries limits, transitive redelegation
  refusal, and the bonded/not-bonded escrow moves.
- EndBlock applies the bonded set from the sorted power index, then
  completes the validator, unbonding and redelegation queues under a
  per-queue budget. Each step runs under a snapshot; a failure is
  reverted and reported as degraded.
- Add Hooks at StakingHooks' points, and genesis SetParams and
  AddGenesisValidator.

Not yet registered in evmonlyapp.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An operator whose self-delegation falls below its minimum keeps its validator
in the power index, where x/staking jails it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Runs each delegate, undelegate, redelegate and EndBlock on the precompile
and on x/staking's keeper side by side, and requires the same outcome, the
same hooks and the same state after every step. Covers the delegation rules
and the validator lifecycle in scenarios, plus seeded random operations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
codchen and others added 7 commits November 16, 2026 11:55
…nly-get-validators

Main now hands consensus its validators as proxy.ValidatorUpdate, keyed by
autobahn's PublicKey, and NewEVMOnlyApplication takes a genesis alloc.
GetValidators serves staking's bonded set in those types.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
V2's staking precompile serves a validator's delegations to contracts, and a
set of them cannot be filled after launch, since a mapping's keys cannot be
listed from its slots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

codchen and others added 8 commits November 16, 2026 12:09
setDelegation and removeDelegation keep delegationsByValidator in step with
delegationsByDelegator, so a validator's delegations can be listed without a
migration. The harness and layout testdata are rebuilt with solc 0.8.30.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…king-precompile

requireInvariants also checks that each validator's delegators are exactly
the accounts delegating to it, so every delegate, undelegate and redelegate
test covers the new index.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…light

Autobahn calls GetValidators before every block, so awaiting the previous
block's commit there held execution behind it. Executor.ReadLatest reads the
store through the in-flight block's overlay instead, and refuses once a commit
is known to have failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The executor sets Header.ClosingEpoch on each epoch's last block, from the
epoch package's arithmetic over the genesis initial height, and the EVM-only
app carries it to the end blockers' BlockContext.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
EndBlock copies lastValidators into epochValidators on an epoch's last block
and keeps the latest three, and GetValidators serves the latest snapshot, so
every node hands consensus the same set for an epoch's committee.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codchen
codchen requested a review from pompon0 as a code owner November 16, 2026 04:49
codchen and others added 8 commits November 16, 2026 22:38
…torage-layer

# Conflicts:
#	docs/giga-storage/StakingStorage.sol
Taking the last shares out of an unbonded validator removes it before
the redelegation's completion is decided, so the move waits a full
unbonding period, as x/staking's BeginRedelegation does. The Redelegate
event and redelegate's doc now say so, and a test pins it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…es with V2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4715836. Configure here.

A snapshotted validator can leave the bonded set, finish unbonding with
no shares and be removed before its snapshot is retired, so reading its
key from the live record left GetValidators with no committee. The
snapshot now copies each member's key when it is taken, while every
member is bonded, and is read on its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Base automatically changed from claude/giga-staking-parity-tests to main November 16, 2026 16:32
codchen and others added 2 commits November 17, 2026 00:35
…et-validators

# Conflicts:
#	giga/evmonly/precompiles/staking/endblock.go
#	giga/evmonly/precompiles/staking/helpers_test.go
#	giga/evmonly/precompiles/staking/layout.go
#	giga/evmonly/precompiles/staking/layout_test.go
#	giga/evmonly/precompiles/staking/storage.go
#	giga/evmonly/precompiles/staking/testdata/StakingStorageHarness.bin-runtime
#	giga/evmonly/precompiles/staking/testdata/StakingStorageHarness.sol
#	giga/evmonly/precompiles/staking/testdata/staking_storage_layout.json
Autobahn keeps the committee it derives in its own epoch state, so what it
needs from the app is the bonded set as it stands. GetValidators reads
staking's lastValidators through BondedValidators again, and the epoch
snapshot stays for rewards, built from the same read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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