Skip to content

CompositeStateStore: Add RocksDB backend support #2956

Open
Kbhat1 wants to merge 11 commits intomainfrom
kartik/evm-rocksdb-backend
Open

CompositeStateStore: Add RocksDB backend support #2956
Kbhat1 wants to merge 11 commits intomainfrom
kartik/evm-rocksdb-backend

Conversation

@Kbhat1
Copy link
Contributor

@Kbhat1 Kbhat1 commented Feb 23, 2026

Describe your changes and provide context

  • Adds RocksDB backend support for and change default PebbleDB in the composite state store
  • Introduces EVMDBEngine interface + backend registry so both Cosmos_SS and EVM_SS respect ssConfig.Backend for engine selection
  • NewCompositeStateStore now accepts a pre-created cosmos store from the existing backend registry instead of importing pebbledb/mvcc directly

Testing performed to validate your change

  • Unit tests
  • verifying on node

Introduce an EVMDBEngine interface and backend registry (matching the
existing pattern in ss/pebbledb_init.go and ss/rocksdb_init.go) so that
EVM sub-databases can use either PebbleDB or RocksDB.

New files:
- evm/engine.go: EVMDBEngine interface + RegisterEVMBackend registry
- evm/db_rocksdb.go: RocksDB implementation using user-defined timestamps
  and column families (mirrors the rocksdb/mvcc pattern), includes
  timestamp comparator and backend registration

Modified files:
- evm/db.go: registers PebbleDB EVM backend at init
- evm/store.go: EVMStateStore uses EVMDBEngine interface; NewEVMStateStore
  accepts a backend name parameter
- composite/store.go: NewCompositeStateStore accepts a pre-created cosmos
  store (removing the hardcoded pebbledb/mvcc import) and passes the
  backend name through to NewEVMStateStore
- ss/store.go: NewStateStore uses the backend registry to create the
  cosmos store, then passes it to the composite store

Both Cosmos_SS and EVM_SS now respect ssConfig.Backend for engine selection.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions
Copy link

github-actions bot commented Feb 23, 2026

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

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedFeb 25, 2026, 5:15 PM

@codecov
Copy link

codecov bot commented Feb 23, 2026

Codecov Report

❌ Patch coverage is 73.52941% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.44%. Comparing base (7298da1) to head (5514a00).

Files with missing lines Patch % Lines
sei-db/state_db/ss/evm/store.go 64.28% 3 Missing and 2 partials ⚠️
sei-db/state_db/ss/store.go 42.85% 2 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #2956       +/-   ##
===========================================
+ Coverage   58.10%   63.44%    +5.33%     
===========================================
  Files        2109       12     -2097     
  Lines      173384     1209   -172175     
===========================================
- Hits       100749      767    -99982     
+ Misses      63683      331    -63352     
+ Partials     8952      111     -8841     
Flag Coverage Δ
sei-chain 59.59% <73.52%> (+1.51%) ⬆️
sei-db 69.50% <ø> (ø)

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

Files with missing lines Coverage Δ
sei-db/state_db/ss/composite/store.go 50.00% <100.00%> (+0.30%) ⬆️
sei-db/state_db/ss/evm/db.go 71.23% <100.00%> (+0.38%) ⬆️
sei-db/state_db/ss/evm/engine.go 100.00% <100.00%> (ø)
sei-db/state_db/ss/store.go 35.29% <42.85%> (-1.07%) ⬇️
sei-db/state_db/ss/evm/store.go 57.35% <64.28%> (-1.43%) ⬇️

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

store.asyncChs[storeType] = ch
store.asyncWg.Add(1)
go store.asyncWorker(db, ch)
go store.asyncWorker(storeType, db, ch)

Check notice

Code scanning / CodeQL

Spawning a Go routine Note

Spawning a Go routine may be a possible source of non-determinism
opts.SetCreateIfMissing(true)
opts.SetComparator(createTimestampComparator())
opts.IncreaseParallelism(runtime.NumCPU())
opts.OptimizeLevelStyleCompaction(512 * 1024 * 1024)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will have to tune these opts more

@Kbhat1 Kbhat1 changed the title CompositeStateStore: Add RocksDB backend support for EVM sub-databases CompositeStateStore: Add RocksDB backend support Feb 23, 2026
@Kbhat1 Kbhat1 requested review from blindchaser, jewei1997 and yzang2019 and removed request for blindchaser February 23, 2026 03:48
// EVM stores are opened when ssConfig.EVMEnabled() returns true (derived from WriteMode/ReadMode).
// The same backend (ssConfig.Backend) is used for EVM sub-databases.
func NewCompositeStateStore(
cosmosStore types.StateStore,
Copy link
Contributor

Choose a reason for hiding this comment

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

Having to pass in cosmosStore seems a bit weird to me, why can't we keep the previous interface but just move backend to top level ssconfig?

Copy link
Contributor Author

@Kbhat1 Kbhat1 Feb 25, 2026

Choose a reason for hiding this comment

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

The ss package imports composite, so composite can't import ss back to use the backend registry (would be a circular import). The old code addressed by hardcoding pebbledb/mvcc directly, but now that we support both PebbleDB and RocksDB (with RocksDB behind a build tag), we need the registry-based selection that lives in ss. Passing in the pre-created store is the standard dependency injection pattern to avoid the cycle

Copy link
Contributor

@yzang2019 yzang2019 Feb 25, 2026

Choose a reason for hiding this comment

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

Let me think about whether there's other way to address this, thanks for the explanation!

Copy link
Contributor

@jewei1997 jewei1997 left a comment

Choose a reason for hiding this comment

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

similar comments to Yiren

once those are fixed, lgtm

Kbhat1 and others added 6 commits February 24, 2026 14:17
Apply the same fix from #2971 to the EVM RocksDB backend: assign
ReadOptions to a local, defer Destroy(), and use heap-allocated
timestamp slices so the backing array outlives the stack frame.

Co-authored-by: Cursor <cursoragent@cursor.com>
- Destroy C-allocated Options (defaultOpts, cfOpts) after OpenDbColumnFamilies
- Destroy ColumnFamilyHandle before DB.Close() to prevent C memory leak
- Update latestVersion in Delete to match Set/ApplyBatch and PebbleDB behavior

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
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.

4 participants