Skip to content

docs(giga-storage): keep only the staking structures an on-chain path reads - #4726

Open
codchen wants to merge 9 commits into
mainfrom
claude/giga-staking-docs-simplify
Open

codchen wants to merge 9 commits into
mainfrom
claude/giga-staking-docs-simplify

Conversation

@codchen

@codchen codchen commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds the staking, distribution and slashing storage proposal from ffd15bb, which is not merged on its own, and simplifies it to the structures an on-chain path reads. Docs only, plus one comment in gov's electorate.go.

The first commit is the proposal as Danno Ferrin wrote it; the commits after it make the changes below.

  • Validators are keyed by their 0x operator address in staking, distribution and slashing, so the consensus-address indexes are gone. 0x22 is keyed by the ed25519 key, for the duplicate-key check and for resolving a key consensus names.
  • Indexes that only queries or entry slashing read are dropped: 0x33, 0x35, and unbonding delegations and redelegations by delegator.
  • 0x37 is kept as delegationsByValidator, a set of each validator's delegators. V2's staking precompile serves it to contracts as validatorDelegations, and a set cannot be filled after launch.
  • Redelegation entries live in the redelegation queue, with a count per (delegator, src, dst) for maxEntries.
  • The bonded set is one ValidatorPower[] instead of a mapping and a set.
  • The rationale doc is updated to match, including which queue entries the FIFO clamp delays.
  • Validator drops its __gap and takes 15 slots: a mapping value grows at its end, so it needs no reserved slots.
  • The rationale's Layouts only grow rule says how each kind of state can change after launch: a top-level value is replaced by a new variable; a mapping value grows at its end, and one that is not a struct can become a struct that starts with the old value; an array element or a top-level struct with variables after it grows only into room of its own; a struct inside another does not grow; and an enumeration set can be added later only where its members can be found another way. A delete clears every slot the record has used.
  • ValidatorSlashEvent gets a uint256[8] __gap, since validatorSlashEvents is kept for good.

Stack

Replaces #4713. Each PR's base is the one above it; review and merge from the top.

  1. docs(giga-storage): keep only the staking structures an on-chain path reads #4726 docs(giga-storage): keep only the staking structures an on-chain path reads ← this PR
  2. feat(params): add the staking subspace #4727 feat(params): add the staking subspace
  3. feat(staking): read and write the staking precompile's storage #4728 feat(staking): read and write the staking precompile's storage
  4. feat(staking): delegate, redelegate and undelegate in a giga evmonly precompile #4729 feat(staking): delegate, redelegate and undelegate in a giga evmonly precompile
  5. test(staking): check delegations and EndBlock against x/staking #4730 test(staking): check delegations and EndBlock against x/staking

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Nov 4, 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 16, 2026, 4:06 AM

@cursor

cursor Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Documentation and a comment-only change in gov; no runtime behavior or migration code.

Overview
Adds documentation-only proposals for giga staking, distribution, and slashing precompile storage under docs/giga-storage/, as Solidity layout specs (StakingStorage.sol, DistributionStorage.sol, SlashingStorage.sol, Sets.sol) plus a long design rationale.

The layouts are trimmed to state that on-chain paths actually read: validators keyed by operator address (consensus-address indexes removed except validatorsByConsensusPubkey on ed25519); query/slashing-only prefix indexes dropped; redelegation data modeled via the redelegation queue and entry counters; bonded set as lastValidators (ValidatorPower[]) instead of a separate mapping/set; Validator without __gap; ValidatorSlashEvent with __gap for append-only arrays.

Updates a gov TODO in electorate.go to reference lastValidators instead of bondedValidatorSet when describing a future Electorate backed by staking storage.

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

@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.

Docs-only change that trims the giga staking, distribution and slashing storage proposal to the structures an on-chain path reads, keys validators by operator, and moves redelegation entries into the queue. The slot arithmetic checks out (delegations at slot 7, Validator at 15 slots, ValidatorPower in one slot) and nothing blocks; codex's reading found nothing, which agrees on blockers, and I added two small notes of my own on consistency.

Non-blocking

1 finding on the changed lines, as inline comments.

1 nit, not posted on the code
  • docs/giga-storage/staking-design-rationale.md:116 — "lastValidators holds at most 100" hard-codes what is really the governance param maxValidators, which this doc cites by name elsewhere (e.g. the gov bonded-set section).

seidroid review · decision approve · session 3fc622a813e64131ba020b173b848d11 · turn resp_claude_844c6b5607de47300dd446bcec06b634 · item b644107725d75583a1373502f44e976a

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

Comment thread docs/giga-storage/SlashingStorage.sol Resolved
@codchen
codchen force-pushed the claude/giga-staking-docs-simplify branch from 90fa425 to 717798f Compare November 12, 2026 04:08
@codchen
codchen requested a review from pompon0 as a code owner November 12, 2026 04:08
@codchen
codchen changed the base branch from shemnon/giga-staking-storage-proposal to main November 12, 2026 04:08
@cursor

cursor Bot commented Nov 12, 2026

Copy link
Copy Markdown

This PR is too large for Bugbot to review. It changes 60,519 lines and 3,888,374 characters. Split the change into smaller pull requests to get a review.

@manav2401 manav2401 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 but have a small question.

v2 exposes delegationsByValidator to contracts on-chain which lists all delegations of a validator. While this is dropped here, I don't think we can add this later. Are we okay with this?

shemnon and others added 8 commits November 16, 2026 11:46
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>
@codchen
codchen force-pushed the claude/giga-staking-docs-simplify branch from 717798f to 01eba02 Compare November 16, 2026 03:48
@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.40%. Comparing base (18af010) to head (0ca730f).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4726      +/-   ##
==========================================
- Coverage   61.41%   61.40%   -0.01%     
==========================================
  Files        2066     2066              
  Lines      160953   160953              
==========================================
- Hits        98849    98841       -8     
- Misses      62099    62107       +8     
  Partials        5        5              
Flag Coverage Δ
sei-chain 59.60% <ø> (-0.01%) ⬇️
sei-db 75.17% <ø> (ø)
sei-db-state-db 81.58% <ø> (-0.02%) ⬇️

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

Files with missing lines Coverage Δ
giga/evmonly/precompiles/gov/electorate.go 92.85% <ø> (ø)

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

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>

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