feat(consensus): migrate epoch_state to state trie post-fork (SIP-6, PR 4/N)#758
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis PR extends the blockchain state trie to persist epoch consensus state. Three new trie-encoding functions were added to serialize epoch snapshots into an 80-byte format (6 big-endian u64 scalars plus a 32-byte validator-set hash commitment). The block update logic was modified to capture epoch fields from the EpochManager and write the serialized snapshot to the trie during designated fork-height checkpoints, ensuring epoch state is reflected in committed state roots alongside existing per-account and per-validator fields. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
PR 4/N — the last off-trie consensus state piece migration. Closes the 4-class Bug A drift surface (
pending_rewardsin #756 + liveness/jail/total_mintedin #757 + this PR'sepoch_state).Pre-fork (`STATE_IN_TRIE_HEIGHT == u64::MAX` default) = bit-identical chain history. Post-fork the current epoch's commitment-relevant fields ride along into state_root.
What this PR commits to the trie
Single fixed key (`epoch_state_key`), 80-byte fixed-layout value:
`history` (past epoch records) intentionally NOT committed — diagnostic only, never consumed by consensus.
What changes
Self-review (per
feedback_smoke_test_and_code_review_every_change)Activation hazard (same as PR #756, #757)
First post-fork block writes the current epoch's snapshot. If accumulators / validator_set have already drifted across validators (the bug class this PR closes), state_root will diverge at the activation block. Mitigation via operator-set canonical override env vars at activation time, modelled on `STATE_ROOT_V2_TREASURY_BALANCE`. Out of scope here.
Closes the migration arc
After this PR merges, all 4 off-trie consensus state pieces flow through state_root post-fork:
Remaining work:
Summary by CodeRabbit