Skip to content

Re-derive the composite write mode on rollback - #4477

Merged
masih merged 3 commits into
mainfrom
masih/1791300466-composite-rollback-write-mode
Oct 6, 2026
Merged

masih merged 3 commits into
mainfrom
masih/1791300466-composite-rollback-write-mode

Conversation

@masih

@masih masih commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

CompositeCommitStore.Rollback rewinds both backends and resets the commit-info latches, but it keeps the write mode and router that were derived at the pre-rollback height. When an Auto store is rolled back across a migration seam, the in-process store therefore disagrees with what a restart derives from the same disk state. Two cases show this: rolling back below bank completion from a store that derived FlatKVOnly, and rolling back to the height before activation after the EVM migration finished. The commit info that seid rollback reports is wrong in both. In the bank case, blocks committed afterwards in the same process also route writes as if the migration had completed. The on-disk state is correct, and the next start derives the right mode.

The resolve-mode-then-build-router step that LoadLatest runs is now a named step, adoptPersistedWriteMode. Rollback calls it after the latch resets, so a rolled-back store matches a restarted one. Pinned modes are unaffected because resolving a pinned mode is a copy. The new tests roll back across both seams and check that the reported commit info is canonical. They also recommit the rolled-back blocks and require the forward-run commit info at every height, in the same process and after a restart. The bank test also fails if only the mode is re-derived and the router is left stale.

No change to the AppHash.

Rollback rewound both backends and reset the commit-info latches but kept the write mode and router derived at the pre-rollback height. Rolling back across a migration seam therefore reported the wrong commit info and would route later writes as if the seam were still crossed. Rollback now re-derives the mode and rebuilds the router from the rolled-back metadata, the same step LoadLatest runs.
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

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

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedOct 6, 2026, 5:56 PM

@codecov

codecov Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.91%. Comparing base (36941db) to head (befd438).

Files with missing lines Patch % Lines
sei-db/state_db/sc/composite/store.go 66.66% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #4477   +/-   ##
=======================================
  Coverage   56.90%   56.91%           
=======================================
  Files        2130     2130           
  Lines      167552   167555    +3     
=======================================
+ Hits        95353    95361    +8     
+ Misses      72194    72189    -5     
  Partials        5        5           
Flag Coverage Δ
sei-chain 55.10% <ø> (+<0.01%) ⬆️
sei-db 75.17% <ø> (ø)
sei-db-state-db 78.90% <66.66%> (-0.03%) ⬇️

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

Files with missing lines Coverage Δ
sei-db/state_db/sc/composite/store.go 79.97% <66.66%> (-0.06%) ⬇️

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

@masih
masih marked this pull request as ready for review October 6, 2026 16:27
@cursor

cursor Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches offline rollback and Auto write-mode routing for consensus commit info; behavior change is intentional and test-covered, with no AppHash algorithm change.

Overview
Rollback now re-derives write mode and router after rewinding backends, so an in-process CompositeCommitStore matches what a fresh LoadLatest would build from the same on-disk metadata.

The resolve-mode-then-build-router sequence used on load is factored into adoptPersistedWriteMode, which LoadLatest and Rollback both call. Rollback still clears the lattice/memiavl commit-info latches; it now also re-adopts persisted mode and rebuilds the router before refreshLastCommitInfo, fixing wrong LastCommitInfo/routing when Auto rolls back across bank completion (from FlatKVOnly) or before EVM activation (from post-migration modes).

Tests add walkToMigrateBank and block-recording helpers, refactor the existing bank-completion rollback test, and add integration cases that assert canonical commit info, derived mode, flatkv closure where expected, and byte-identical replay—same process and after restart.

Reviewed by Cursor Bugbot for commit befd438. 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.

Rollback now re-derives the Auto write mode and rebuilds the router from the rolled-back metadata, using the same adoptPersistedWriteMode step that LoadLatest uses, so a store rolled back in process matches one rebuilt by a restart. Pinned modes still resolve as a plain copy, the latches are still reset before refreshLastCommitInfo, and both new tests replay the blocks they roll back over against recorded commit info, so I found nothing that blocks; the codex reading (no findings) agrees with this and added nothing to check, and the tree was the PR merge ref, but no Go toolchain was available, so the tests were not run.

seidroid review · decision approve · session 0187fc1992ef4863a492b4b7c15b54b5 · turn resp_claude_8f1507289ff538c4fc0fa0578ecdf6e8 · item 38bf6a7eaeda598bb4dc58100b17780d

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

@masih masih added the backport release/v6.7 Backport to release v6.7 label Oct 6, 2026
@masih

masih commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator Author

The second part of improvements to follow in a separate PR; I will link up the PRs on GH for visibility; thanks all for speedy reviews 🍻

@masih
masih added this pull request to the merge queue Oct 6, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 6, 2026
…osite-rollback-write-mode

# Conflicts:
#	sei-db/state_db/sc/composite/store_migration_test.go
@masih
masih enabled auto-merge October 6, 2026 17:57
@masih
masih added this pull request to the merge queue Oct 6, 2026
Merged via the queue into main with commit 6278fe9 Oct 6, 2026
57 checks passed
@masih
masih deleted the masih/1791300466-composite-rollback-write-mode branch October 6, 2026 18:26
@seidroid

seidroid Bot commented Oct 6, 2026

Copy link
Copy Markdown

Created backport PR for release/v6.7:

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin backport-4477-to-release/v6.7
git worktree add --checkout .worktree/backport-4477-to-release/v6.7 backport-4477-to-release/v6.7
cd .worktree/backport-4477-to-release/v6.7
git reset --hard HEAD^
git cherry-pick -x 6278fe9b1295a861c2eb7c7dac683845e762d0a2
git push --force-with-lease

devin-ai-integration Bot pushed a commit that referenced this pull request Oct 6, 2026
`CompositeCommitStore.Rollback` rewinds both backends and resets the
commit-info latches, but it keeps the write mode and router that were
derived at the pre-rollback height. When an Auto store is rolled back
across a migration seam, the in-process store therefore disagrees with
what a restart derives from the same disk state. Two cases show this:
rolling back below bank completion from a store that derived
`FlatKVOnly`, and rolling back to the height before activation after the
EVM migration finished. The commit info that `seid rollback` reports is
wrong in both. In the bank case, blocks committed afterwards in the same
process also route writes as if the migration had completed. The on-disk
state is correct, and the next start derives the right mode.

The resolve-mode-then-build-router step that `LoadLatest` runs is now a
named step, `adoptPersistedWriteMode`. `Rollback` calls it after the
latch resets, so a rolled-back store matches a restarted one. Pinned
modes are unaffected because resolving a pinned mode is a copy. The new
tests roll back across both seams and check that the reported commit
info is canonical. They also recommit the rolled-back blocks and require
the forward-run commit info at every height, in the same process and
after a restart. The bank test also fails if only the mode is re-derived
and the router is left stale.

No change to the AppHash.

(cherry picked from commit 6278fe9)
masih added a commit that referenced this pull request Oct 7, 2026
…ck (#4486)

Backport of #4477 to `release/v6.7`.

Co-authored-by: Masih H. Derkani <m@derkani.org>
revofusion pushed a commit to revofusion/sei-chain that referenced this pull request Oct 7, 2026
…-protocol#4484)

A store pinned to a steady-state write mode (`evm_migrated`,
`all_migrated_but_bank` or `flatkv_only`) copies the configured mode
without looking at the migration state persisted in flatkv. When that
state says a migration is still in flight, for example after `Rollback`
to a height below a migration's completion, the pinned router and commit
info no longer match the data. A `flatkv_only` pin never opens memiavl,
so its commit info drops memiavl's stores. An `evm_migrated` pin stops
running the in-flight migration, so the next block diverges. Either way
it persists across restarts for as long as the pin stays.

`resolveCurrentWriteMode`, which `LoadLatest` and, since sei-protocol#4477,
`Rollback` both go through, now calls
`requirePinnedModeMatchesMigration`. It derives the persisted mode and
refuses the pin unless the two match or the persisted mode is
`MemiavlOnly`, which is what a store whose history began in flatkv
derives. The error tells the operator to re-enable auto mode, and
reopening in Auto reconciles memiavl down to the rolled-back height.

This builds on sei-protocol#4477 and is based on its branch, so the diff here shows
only this change. It touches the same fields as sei-protocol#4475, so whichever
lands second needs a small rebase. There is no AppHash change for
supported configurations: the genesis-pinned `flatkv_only` localnode and
CI clusters carry no migration metadata and are unaffected. New
composite tests cover the rollback refusal and recovery in Auto, the
in-flight refusal for each steady-state pin, and a genesis-pinned store,
and the composite, migration and rootmulti packages pass under `-race`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants