Skip to content

Composite State Store Part 2: EVM database implementation#2755

Merged
Kbhat1 merged 10 commits intomainfrom
feature/evm-ss-database
Feb 5, 2026
Merged

Composite State Store Part 2: EVM database implementation#2755
Kbhat1 merged 10 commits intomainfrom
feature/evm-ss-database

Conversation

@Kbhat1
Copy link
Contributor

@Kbhat1 Kbhat1 commented Jan 23, 2026

Describe your changes and provide context

  • EVMDatabase: Single PebbleDB with DefaultComparer for each EVM data type
  • EVMStateStore: Manages multiple EVMDatabase instances (nonce, code, codehash, codesize, storage)
  • Versioned key encoding with big-endian version suffix
  • ApplyBatch and ApplyChangesetParallel for efficient concurrent writes
  • Uses commonevm.ParseMemIAVLEVMKey directly for key routing

Testing performed to validate your change

  • Unit tests

@Kbhat1 Kbhat1 changed the title Composite State Store part 2: EVM database implementation Composite State Store Part 2: EVM database implementation Jan 23, 2026
@github-actions
Copy link

github-actions bot commented Jan 23, 2026

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

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedFeb 5, 2026, 4:51 PM

@codecov
Copy link

codecov bot commented Jan 23, 2026

Codecov Report

❌ Patch coverage is 55.86420% with 143 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.60%. Comparing base (c50da24) to head (e18a444).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
sei-db/state_db/ss/evm/store.go 27.61% 67 Missing and 9 partials ⚠️
sei-db/state_db/ss/evm/db.go 69.40% 39 Missing and 28 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2755      +/-   ##
==========================================
+ Coverage   46.89%   56.60%   +9.70%     
==========================================
  Files        1965     2033      +68     
  Lines      160600   166253    +5653     
==========================================
+ Hits        75312    94105   +18793     
+ Misses      78760    63877   -14883     
- Partials     6528     8271    +1743     
Flag Coverage Δ
sei-chain 41.49% <55.86%> (+0.03%) ⬆️
sei-cosmos 48.13% <ø> (ø)
sei-db 68.72% <ø> (ø)
sei-tendermint 58.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/ss/evm/db.go 69.40% <69.40%> (ø)
sei-db/state_db/ss/evm/store.go 27.61% <27.61%> (ø)

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

Comment on lines +367 to +368
for keyStr, value := range keyValues {
if value != nil { // Skip tombstones
keys = append(keys, []byte(keyStr))
values = append(values, value)
}
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
@Kbhat1 Kbhat1 force-pushed the feature/evm-ss-router-config branch from ac83d2f to 0935d03 Compare January 23, 2026 22:08
@Kbhat1 Kbhat1 force-pushed the feature/evm-ss-database branch from 7271005 to 7ef1b00 Compare January 23, 2026 22:08
@Kbhat1 Kbhat1 force-pushed the feature/evm-ss-database branch from 7ef1b00 to 906d2ed Compare January 27, 2026 19:34
Comment on lines +75 to +83
for storeType, pairs := range changes {
db := s.databases[storeType]
if db == nil {
continue
}
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 +101 to +114
for storeType, pairs := range changes {
db := s.databases[storeType]
if db == nil {
continue
}

wg.Add(1)
go func(db *EVMDatabase, pairs []*iavl.KVPair) {
defer wg.Done()
if err := db.ApplyBatch(pairs, version); err != nil {
errCh <- err
}
}(db, pairs)
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
Comment on lines +129 to +133
for _, db := range s.databases {
if v := db.GetLatestVersion(); v > maxVersion {
maxVersion = v
}
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
Comment on lines +139 to +143
for _, db := range s.databases {
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 +150 to +155
for _, db := range s.databases {
v := db.GetEarliestVersion()
if minVersion < 0 || v < minVersion {
minVersion = v
}
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
Comment on lines +164 to +168
for _, db := range s.databases {
if err := db.SetEarliestVersion(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 +185 to +208
for _, db := range s.databases {
if err := db.Close(); err != nil {
lastErr = err
}
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
Comment on lines +108 to +113
go func(db *EVMDatabase, pairs []*iavl.KVPair) {
defer wg.Done()
if err := db.ApplyBatch(pairs, version); err != nil {
errCh <- err
}
}(db, pairs)

Check notice

Code scanning / CodeQL

Spawning a Go routine Note

Spawning a Go routine may be a possible source of non-determinism
@Kbhat1 Kbhat1 force-pushed the feature/evm-ss-database branch from 906d2ed to 851b64c Compare January 28, 2026 02:35
Comment on lines +181 to +189
for _, db := range s.databases {
wg.Add(1)
go func(db *EVMDatabase) {
defer wg.Done()
if err := db.Prune(version); err != nil {
errCh <- err
}
}(db)
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
Comment on lines +183 to +188
go func(db *EVMDatabase) {
defer wg.Done()
if err := db.Prune(version); err != nil {
errCh <- err
}
}(db)

Check notice

Code scanning / CodeQL

Spawning a Go routine Note

Spawning a Go routine may be a possible source of non-determinism
Copy link
Contributor

@yzang2019 yzang2019 left a comment

Choose a reason for hiding this comment

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

Please also address all lint issues

@Kbhat1 Kbhat1 force-pushed the feature/evm-ss-database branch from 851b64c to 3801df9 Compare January 29, 2026 17:53
"encoding/binary"
"fmt"
"path/filepath"
"runtime"

Check notice

Code scanning / CodeQL

Sensitive package import Note

Certain system packages contain functions which may be a possible source of non-determinism
@Kbhat1 Kbhat1 requested a review from yzang2019 January 30, 2026 04:47
Base automatically changed from feature/evm-ss-router-config to main February 2, 2026 18:20
Adds configuration and type definitions for EVM state stores:
- EVMStateStoreConfig in config/config.go for enabling EVM SS
- EVMStoreType alias to EVMKeyKind from common/evm
- AllEVMStoreTypes() for iteration over store types
- StoreTypeName() for DB directory naming

Also renames common/evm/memiavl_keys.go to keys.go and
ParseMemIAVLEVMKey to ParseEVMKey for broader applicability.
Adds the core EVM state store components:

db.go - EVMDatabase (single PebbleDB for a specific EVM data type):
- Uses DefaultComparer (lexicographic byte ordering)
- Versioned key encoding with big-endian version suffix
- ApplyBatch for efficient batch writes
- EVMIterator for version-aware iteration (for state dumps/full scans)

store.go - EVMStateStore (manages multiple EVMDatabase instances):
- Manages databases for nonce, code, codehash, codesize, storage
- ApplyChangesetParallel for concurrent writes to multiple DBs
- Uses commonevm.ParseEVMKey directly for key routing
- Use runtime.NumCPU() for MaxConcurrentCompactions
- Remove sync writes for version metadata (improves performance)
- Parallelize EVMStateStore.Prune across all databases
- Fix errcheck: properly handle Close() error returns with _ = or defer func
- Fix gosec G115: add nolint comments for safe int64/uint64 conversions
- Fix staticcheck S1009: remove redundant nil checks before len()
- Use atomic.Int64 for latestVersion/earliestVersion to fix race condition
- Add github.com/cockroachdb/pebble v1.1.2 as direct dependency (was indirect)
- All lint fixes from previous commit included
@Kbhat1 Kbhat1 force-pushed the feature/evm-ss-database branch from 40f2a73 to 7c8c4b4 Compare February 3, 2026 21:52
Metadata keys (latest_version, earliest_version) are stored without
a version suffix, unlike data keys. The iterator was incorrectly
decoding all keys first, which stripped 8 bytes from metadata key
names, causing the skip check to fail.

Now checks raw iterator key against metadata key names before
calling decodeKey, matching the pattern used in Prune().
@Kbhat1 Kbhat1 enabled auto-merge (squash) February 5, 2026 17:03
@Kbhat1 Kbhat1 merged commit 7e01541 into main Feb 5, 2026
43 checks passed
@Kbhat1 Kbhat1 deleted the feature/evm-ss-database branch February 5, 2026 17:05
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