Skip to content

Refactor StateStore for better readability and Giga support#2984

Merged
yzang2019 merged 19 commits intomainfrom
yzang/refactor-giga-ss
Feb 27, 2026
Merged

Refactor StateStore for better readability and Giga support#2984
yzang2019 merged 19 commits intomainfrom
yzang/refactor-giga-ss

Conversation

@yzang2019
Copy link
Contributor

@yzang2019 yzang2019 commented Feb 26, 2026

Describe your changes and provide context

This PR mainly add RocksDB support for SS and refactor for better readability and code structure:

  • Add New MvccDB interface for DB engine to unify pebbledb mvcc and rocksdb mvcc
  • StateStore interface unchanged and now extends MvccDB
  • Add a new CosmosStateStore: Thin wrapper around a single DB that implements StateStore.
  • EVMStateStore refactored: Sub-DBs typed as types.MvccDB (was types.StateStore)
  • CompositeStateStore simplified (ss/composite/store.go): Both cosmosStore and evmStore fields are now types.StateStore
  • not found errors moved to common/errors
  • RawImport and migrationKey interface removed
  • SS Migrator removed
  • db init static function removed, replaced by resolveBackend function
  • Fixed recoverFromWAL logic

New structure:
image

Testing performed to validate your change

@github-actions
Copy link

github-actions bot commented Feb 26, 2026

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

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedFeb 27, 2026, 9:51 PM

@codecov
Copy link

codecov bot commented Feb 26, 2026

Codecov Report

❌ Patch coverage is 66.54135% with 89 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.34%. Comparing base (1c50d43) to head (787a9e9).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
sei-db/state_db/ss/evm/store.go 62.30% 39 Missing and 10 partials ⚠️
sei-db/state_db/ss/composite/store.go 57.14% 18 Missing and 6 partials ⚠️
sei-db/state_db/ss/cosmos/store.go 73.33% 8 Missing ⚠️
sei-cosmos/storev2/rootmulti/store.go 25.00% 3 Missing ⚠️
sei-db/state_db/ss/backend/backend_rocksdb_stub.go 0.00% 2 Missing ⚠️
sei-db/state_db/ss/backend/resolve.go 66.66% 2 Missing ⚠️
sei-db/state_db/sc/flatkv/store_meta.go 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2984      +/-   ##
==========================================
+ Coverage   58.13%   58.34%   +0.20%     
==========================================
  Files        2113     2121       +8     
  Lines      174071   174931     +860     
==========================================
+ Hits       101204   102062     +858     
- Misses      63812    63818       +6     
+ Partials     9055     9051       -4     
Flag Coverage Δ
sei-chain-pr 54.58% <66.54%> (?)
sei-db 70.41% <ø> (+0.90%) ⬆️

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

Files with missing lines Coverage Δ
app/app.go 71.60% <ø> (ø)
app/seidb.go 68.83% <ø> (ø)
cmd/seid/cmd/root.go 0.00% <ø> (ø)
evmrpc/server.go 91.54% <ø> (ø)
evmrpc/watermark_manager.go 74.46% <ø> (ø)
sei-cosmos/storev2/state/store.go 18.42% <100.00%> (ø)
sei-db/common/errors/errors.go 100.00% <100.00%> (ø)
sei-db/config/ss_config.go 100.00% <100.00%> (ø)
sei-db/db_engine/pebbledb/batch.go 100.00% <100.00%> (ø)
sei-db/db_engine/pebbledb/db.go 93.50% <100.00%> (ø)
... and 32 more
🚀 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.

Comment on lines +115 to +119
for _, db := range s.subDBs {
if err := db.SetLatestVersion(version); err != nil {
return err
}
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
Comment on lines +125 to +129
for _, db := range s.subDBs {
if v := db.GetEarliestVersion(); minVersion < 0 || v < minVersion {
minVersion = v
}
if err := db.ApplyBatch(pairs, version); err != nil {
return fmt.Errorf("failed to apply batch for %s: %w", StoreTypeName(storeType), err)
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
Comment on lines +184 to +186
for storeType, pairs := range grouped {
return s.applyToSubDB(storeType, version, pairs, async)
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
Comment on lines +194 to +199
go func(st EVMStoreType, p []*iavl.KVPair) {
defer wg.Done()
if err := db.ApplyBatch(pairs, version); err != nil {
if err := s.applyToSubDB(st, version, p, async); err != nil {
errCh <- err
}
}(db, pairs)
}(storeType, pairs)

Check notice

Code scanning / CodeQL

Spawning a Go routine Note

Spawning a Go routine may be a possible source of non-determinism
* main:
  Harden `TestStateLock_NoPOL` against proposal/timeout race (#2980)
"evmVersion", evmVersion,
"changelogPath", changelogPath,
)
if err := ReplayWAL(logger, changelogPath, evmVersion, -1, func(entry proto.ChangelogEntry) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious, we do 2 separate replayWAls one for evmstore and cosmosStore. Wondering if we could just do 1 and do both inside each?

Not blocking, just curious

Copy link
Contributor Author

@yzang2019 yzang2019 Feb 27, 2026

Choose a reason for hiding this comment

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

It is definitely doable, I feel separating them is cleaner in the code and easier to remove later on, but the side effect is that it would require double read the WAL for some entries. Given that SS shouldn't fall behind too much (limited by buffer size), I think this should be fine to start with?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea definitely fine to start with, could we just add a TODO to reconsider in future @yzang2019 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

)

// Start migration if --migrate flag is set
if cast.ToBool(appOpts.Get("migrate-iavl")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

it looks --migrate-iavl still changes runtime behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah pretty sure no one is using that, it's for archive migration

* main:
  ERC20 simulation benchmark (#2979)
  feat(flatkv): add snapshot, WAL catchup, and rollback support (#2972)
@yzang2019 yzang2019 merged commit 1c2910c into main Feb 27, 2026
48 of 50 checks passed
@yzang2019 yzang2019 deleted the yzang/refactor-giga-ss branch February 27, 2026 22:21
yzang2019 added a commit that referenced this pull request Feb 27, 2026
This PR mainly add RocksDB support for SS and refactor for better
readability and code structure:
- Add New MvccDB interface for DB engine to unify pebbledb mvcc and
rocksdb mvcc
- StateStore interface unchanged and now extends MvccDB
- Add a new CosmosStateStore: Thin wrapper around a single DB that
implements StateStore.
- EVMStateStore refactored: Sub-DBs typed as types.MvccDB (was
types.StateStore)
- CompositeStateStore simplified (ss/composite/store.go): Both
cosmosStore and evmStore fields are now types.StateStore
- not found errors moved to common/errors
- RawImport and migrationKey interface removed
- SS Migrator removed
- db init static function removed, replaced by resolveBackend function
- Fixed recoverFromWAL logic

New structure:
<img width="2816" height="1536" alt="image"
src="https://github.com/user-attachments/assets/ec5ac9d1-b56f-4ea3-94fb-d7ad7a0f0afd"
/>
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