Skip to content

Seidb restructure#2653

Merged
yzang2019 merged 11 commits intomainfrom
yzang/seidb-restructure
Jan 5, 2026
Merged

Seidb restructure#2653
yzang2019 merged 11 commits intomainfrom
yzang/seidb-restructure

Conversation

@yzang2019
Copy link
Copy Markdown
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
Copy Markdown

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 5, 2026, 4:25 PM

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 2, 2026

Codecov Report

❌ Patch coverage is 5.55556% with 102 lines in your changes missing coverage. Please review.
✅ Project coverage is 43.75%. Comparing base (9fda687) to head (bbb7a84).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
sei-db/db_engine/pebbledb/kv/db.go 0.00% 53 Missing ⚠️
sei-db/db_engine/pebbledb/kv/batch.go 0.00% 45 Missing ⚠️
sei-db/state_db/sc/memiavl/snapshot.go 0.00% 2 Missing ⚠️
sei-cosmos/storev2/rootmulti/store.go 66.66% 1 Missing ⚠️
sei-db/state_db/sc/store.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2653      +/-   ##
==========================================
- Coverage   43.78%   43.75%   -0.03%     
==========================================
  Files        1904     1906       +2     
  Lines      158932   159030      +98     
==========================================
+ Hits        69585    69589       +4     
- Misses      82944    83041      +97     
+ Partials     6403     6400       -3     
Flag Coverage Δ
sei-chain 45.74% <1.94%> (-0.08%) ⬇️
sei-cosmos 38.20% <75.00%> (-0.01%) ⬇️
sei-db 69.06% <100.00%> (ø)
sei-tendermint 47.33% <ø> (+0.05%) ⬆️

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

Files with missing lines Coverage Δ
app/app.go 70.81% <ø> (ø)
app/seidb.go 82.69% <ø> (ø)
app/test_helpers.go 32.82% <ø> (ø)
evmrpc/server.go 91.54% <ø> (ø)
evmrpc/watermark_manager.go 74.46% <ø> (ø)
sei-cosmos/storev2/commitment/store.go 9.37% <100.00%> (ø)
sei-cosmos/storev2/state/store.go 0.00% <ø> (ø)
sei-db/changelog/changelog/changelog.go 53.73% <ø> (ø)
sei-db/changelog/changelog/subscriber.go 0.00% <ø> (ø)
sei-db/changelog/changelog/utils.go 58.20% <ø> (ø)
... and 58 more

... and 16 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i see!

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.

i double checked this issue. the defer executes immediately when OpenDB returns, not when the DB is closed though

}

func getStorePrefix(storeKey string) []byte {
return []byte(fmt.Sprintf("s/k:%s/", storeKey))
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.

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

got it sg

@@ -0,0 +1 @@
package parquet
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.

👍

@@ -0,0 +1 @@
package event
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.

is this for evm logs?

@yzang2019 yzang2019 merged commit d7d72d9 into main Jan 5, 2026
49 of 52 checks passed
@yzang2019 yzang2019 deleted the yzang/seidb-restructure branch January 5, 2026 22:28
philipsu522 pushed a commit that referenced this pull request Jan 6, 2026
## Describe your changes and provide context
Refactor and restructure seidb to prepare for v3. The new structure will
look like this:
<img width="736" height="349" alt="image"
src="https://github.com/user-attachments/assets/de643253-8ffc-4631-9152-ec2a6b5f2676"
/>


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
jewei1997 pushed a commit that referenced this pull request Feb 24, 2026
## Describe your changes and provide context
Refactor and restructure seidb to prepare for v3. The new structure will
look like this:
<img width="736" height="349" alt="image"
src="https://github.com/user-attachments/assets/de643253-8ffc-4631-9152-ec2a6b5f2676"
/>

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
yzang2019 added a commit that referenced this pull request Feb 25, 2026
Refactor and restructure seidb to prepare for v3. The new structure will
look like this:
<img width="736" height="349" alt="image"
src="https://github.com/user-attachments/assets/de643253-8ffc-4631-9152-ec2a6b5f2676"
/>

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
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