Skip to content

Conversation

@yzang2019
Copy link
Contributor

@yzang2019 yzang2019 commented Jan 2, 2026

Describe your changes and provide context

Refactor and restructure seidb to prepare for v3. The new structure will look like this:
image

This PR made changes of:

  1. Move files around to different folder names
  2. Update all dependency references based on the new structure
  3. Add new placeholders for future preparation
  4. Add a new basic pebbledb implementation

Testing performed to validate your change

@github-actions
Copy link

github-actions bot commented Jan 2, 2026

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

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedJan 2, 2026, 4:34 PM

@codecov
Copy link

codecov bot commented Jan 2, 2026

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 42.00%. Comparing base (884e779) to head (98c663c).

Files with missing lines Patch % Lines
sei-cosmos/storev2/rootmulti/store.go 66.66% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2653      +/-   ##
==========================================
- Coverage   42.01%   42.00%   -0.02%     
==========================================
  Files        1018     1018              
  Lines       84809    84809              
==========================================
- Hits        35636    35624      -12     
- Misses      45834    45843       +9     
- Partials     3339     3342       +3     
Flag Coverage Δ
sei-cosmos 38.20% <75.00%> (ø)
sei-db 69.06% <100.00%> (ø)
sei-tendermint 47.32% <ø> (-0.04%) ⬇️

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

Files with missing lines Coverage Δ
sei-cosmos/storev2/commitment/store.go 9.37% <100.00%> (ø)
sei-cosmos/storev2/state/store.go 0.00% <ø> (ø)
sei-db/db_engine/rocksdb/mvcc/batch.go 92.30% <ø> (ø)
sei-db/db_engine/rocksdb/mvcc/comparator.go 100.00% <ø> (ø)
sei-db/db_engine/rocksdb/mvcc/db.go 58.63% <100.00%> (ø)
sei-db/db_engine/rocksdb/mvcc/iterator.go 85.55% <ø> (ø)
sei-db/db_engine/rocksdb/mvcc/opts.go 63.07% <ø> (ø)
sei-cosmos/storev2/rootmulti/store.go 32.30% <66.66%> (ø)

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

}

// Get returns value by key.
func (db *Database) Get(key []byte) ([]byte, error) {
Copy link
Contributor

@blindchaser blindchaser Jan 2, 2026

Choose a reason for hiding this comment

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

from ai: Pebble Get() returns a value that is only valid until the returned closer is closed.
value is returned while closer.Close() is also called, which means the caller may observe invalid / corrupted data? We should copy value before closing the closer. we can do:

func (db *Database) Get(key []byte) ([]byte, error) {
    value, closer, err := db.storage.Get(key)
    if err != nil {
        if errors.Is(err, pebble.ErrNotFound) {
            return nil, nil
        }
        return nil, errors.WithStack(err)
    }
    defer closer.Close()

    out := append([]byte(nil), value...) // copy
    return out, nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's interesting, I think this is copied from v3 and we didn't really see this issue at all in v3. Will still fix it though

// OpenDB opens an existing or create a new database.
func OpenDB(dbPath string) *Database {
cache := pebble.NewCache(1024 * 1024 * 512)
defer cache.Unref()
Copy link
Contributor

Choose a reason for hiding this comment

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

defer cache.Unref() will run when OpenDB() returns, potentially releasing the cache while the DB is still using it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have to keep the defer cache.Unref() - it's the correct pattern recommended by PebbleDB. The idea is to keep reference counting down to 0 when closing the DB.

Copy link
Contributor

Choose a reason for hiding this comment

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

i see!

}

func getStorePrefix(storeKey string) []byte {
return []byte(fmt.Sprintf("s/k:%s/", storeKey))
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick perf improve:


func getStorePrefix(storeKey string) []byte {
    // "s/k:" + storeKey + "/"
    b := make([]byte, 0, len("s/k:/")+len(storeKey))
    b = append(b, "s/k:"...)
    b = append(b, storeKey...)
    b = append(b, '/' )
    return b
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice!


GetProof(key []byte) *ics23.CommitmentProof

io.Closer
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems ModuleStore inherits io.Closer, but commitment.NewStore wraps it and never calls Close. Is ModuleStore.Close a no-op? or we should also have it in commitment.Store and call close() on rootmulti

Copy link
Contributor Author

@yzang2019 yzang2019 Jan 2, 2026

Choose a reason for hiding this comment

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

It's called by CMS I think? But this piece of code need more refactory in the future, I would not really touch it in this PR yet

Copy link
Contributor

Choose a reason for hiding this comment

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

got it sg

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