Skip to content

composite.Store uses routers#3420

Open
cody-littley wants to merge 73 commits into
mainfrom
cjl/composite-uses-routers-2
Open

composite.Store uses routers#3420
cody-littley wants to merge 73 commits into
mainfrom
cjl/composite-uses-routers-2

Conversation

@cody-littley
Copy link
Copy Markdown
Contributor

@cody-littley cody-littley commented May 11, 2026

Describe your changes and provide context

Integrates migration.Router with composite.Store implementation.

Testing performed to validate your change

Unit tests. More unit tests to follow in the next PR.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 13, 2026

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

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedMay 19, 2026, 3:44 PM

@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

❌ Patch coverage is 72.16495% with 108 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.43%. Comparing base (adf03c1) to head (c895b39).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
sei-db/state_db/sc/composite/store.go 71.58% 44 Missing and 33 partials ⚠️
sei-db/state_db/sc/flatkv/store_meta.go 63.93% 13 Missing and 9 partials ⚠️
sei-cosmos/storev2/rootmulti/store.go 20.00% 2 Missing and 2 partials ⚠️
sei-db/config/write_mode.go 57.14% 3 Missing ⚠️
sei-db/config/sc_config.go 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3420      +/-   ##
==========================================
+ Coverage   59.24%   59.43%   +0.19%     
==========================================
  Files        2126     2116      -10     
  Lines      175715   174723     -992     
==========================================
- Hits       104097   103849     -248     
+ Misses      62538    61841     -697     
+ Partials     9080     9033      -47     
Flag Coverage Δ
sei-chain-pr 69.03% <72.16%> (?)
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/seidb.go 76.81% <ø> (+4.81%) ⬆️
evmrpc/config/config.go 70.43% <ø> (ø)
sei-cosmos/server/config/config.go 94.53% <100.00%> (+0.12%) ⬆️
sei-db/common/keys/store_keys.go 100.00% <100.00%> (ø)
sei-db/state_db/sc/memiavl/store.go 92.59% <100.00%> (-0.06%) ⬇️
sei-db/state_db/sc/migration/migration_manager.go 96.51% <100.00%> (+1.03%) ⬆️
sei-db/state_db/sc/migration/router_builder.go 56.29% <100.00%> (+3.97%) ⬆️
sei-db/config/sc_config.go 87.50% <50.00%> (-12.50%) ⬇️
sei-db/config/write_mode.go 82.35% <57.14%> (-17.65%) ⬇️
sei-cosmos/storev2/rootmulti/store.go 64.30% <20.00%> (-0.50%) ⬇️
... and 2 more

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

@cody-littley cody-littley marked this pull request as ready for review May 18, 2026 16:27
@cursor
Copy link
Copy Markdown

cursor Bot commented May 18, 2026

PR Summary

High Risk
High risk because it refactors core state-commit storage routing (memiavl/FlatKV), changes config semantics/defaults, and adjusts integration test coverage; mistakes could corrupt state, change AppHash, or break replay/state-sync.

Overview
Composite SC now uses migration.Router for all key-path operations. CompositeCommitStore was reworked to manage optional memIAVL/flatKV backends, build/cancel routers on LoadVersion (including read-only handles and Copy() snapshots), and delegate ApplyChangeSets, reads/proofs/iterators, and GetChildStoreByName to router-backed store views. Construction/initialization now return errors, enforce allowed store names, add flatkv version seeding on mode transitions, and improve close/reconcile behavior.

SC configuration model is simplified and expanded. Removes SC read-mode and enable-lattice-hash flags/types, introduces new WriteMode set (migration phases + test_only_dual_write) with new default memiavl_only, adds keys-to-migrate-per-block, and validates/parses sc-write-mode early in server config. Related tests, TOML templates, and benchmarks are updated accordingly.

Integration/ops scripts pivot to “FlatKV from genesis” testing. CI FlatKV integration job now boots with GIGA_STORAGE=true and sc-write-mode=test_only_dual_write, removes the offline memiavl→FlatKV import script and related assumptions, and relaxes digest/state-sync scripts that previously required lattice-hash flags; crash/state-sync recovery scripts are adjusted to handle the missing legacy import marker file.

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

Comment thread sei-db/state_db/sc/composite/store.go

// GetChildStoreByName returns the underlying child store by module name.
// This only applies to cosmos committer.
func (cs *CompositeCommitStore) GetChildStoreByName(name string) types.CommitKVStore {
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.

GetChildStoreByName func won't return nil anymore, we should update store.go

tree := snap.GetChildStoreByName(k.Name())
if tree == nil {
return nil, fmt.Errorf("snapshot missing child store %q", k.Name())
}

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.

You make a good point, but I think the better behavior here would be to panic if we encounter an unsupported store. If a caller instantiates a bad store type and we allow the behavior, they will get an error during a later operation no matter what we do here. So it's best to raise the problem early.

This method now panics if the requested store name is not supported.

@blindchaser
Copy link
Copy Markdown
Contributor

should we update

func (r *RouterCommitKVStore) RootHash() []byte { return make([]byte, rootHashSize) } in router_kvstore.go` now?

@blindchaser
Copy link
Copy Markdown
Contributor

comments cleanup: we have many comments still using DualWrite / SplitWrite / SplitRead / CosmosOnly wording.

Comment thread sei-db/state_db/sc/composite/store.go Outdated
// memiavl.ApplyUpgrades rejects duplicate names rather than skipping
// them, so we guard with a presence check. Read-only handles inherit
// the tree from the on-disk state.
if cs.memIAVL != nil && cs.config.WriteMode.IsMigrationMode() &&
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.

the readOnly mode in composite/store.go(200-217) assumes the migration tree already exists and it doesn't ApplyUpgrades the migration tree like the writable branch does. Between a write-mode switch into a migration mode and the first Commit(), the tree only lives in memiavl's working state. any concurrent read-only LoadVersion fails with store not found: migration from buildMemIAVLReader

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.

I was able to simplify this code significantly. We don't actually need to store migration metadata in memIAVL, we can just store all the data in flatKV. With this change, the bug you point out is no longer possible.

@cody-littley
Copy link
Copy Markdown
Contributor Author

@blindchaser

should we update
func (r *RouterCommitKVStore) RootHash() []byte { return make([]byte, rootHashSize) } in router_kvstore.go` now?

I've intentionally implemented this as a do nothing method. We never call it in production, and it's a method I plan to delete soon.

The core reason why I hesitate to actually implement this method is because the flatKV implementation would be quite nontrivial.

@cody-littley
Copy link
Copy Markdown
Contributor Author

@blindchaser

comments cleanup: we have many comments still using DualWrite / SplitWrite / SplitRead / CosmosOnly wording.

I did a pass and updated a bunch of comments.

Comment thread sei-db/state_db/sc/composite/store.go
Copy link
Copy Markdown

@cursor cursor Bot left a comment

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 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 c895b39. Configure here.

_, err := cs.flatkvCommitter.LoadVersion(targetVersion, false)
if err != nil {
return nil, fmt.Errorf("failed to load FlatKV version: %w", err)
return ro, nil
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Read-only LoadVersion leaks backend handles on router failure

Medium Severity

In the read-only LoadVersion path, if ro.buildRouter() fails, both the freshly-opened memIAVLCommitter and flatKVStore handles are leaked. They were obtained from LoadVersion calls on the backends but the ro composite is never returned to the caller nor closed before returning the error. Repeated failures would accumulate open file descriptors until exhaustion.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c895b39. Configure here.

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.

2 participants