Skip to content

Add exporter for FlatKV and CompositeSC#3064

Open
yzang2019 wants to merge 5 commits intomainfrom
yzang/add-flatkv-export
Open

Add exporter for FlatKV and CompositeSC#3064
yzang2019 wants to merge 5 commits intomainfrom
yzang/add-flatkv-export

Conversation

@yzang2019
Copy link
Contributor

@yzang2019 yzang2019 commented Mar 13, 2026

Describe your changes and provide context

This PR is adding exporter used by state sync to export live state into snapshot files.

Composite Exporter (composite/exporter.go): Orchestrates the export stream from both the Cosmos (memiavl) and FlatKV backends. All Cosmos modules are exported first, then FlatKV EVM data is appended as a distinct module named "evm_flatkv". The FlatKV phase is only included when WriteMode == SplitWrite or DualWrite.

Composite Importer routing (composite/importer.go): Updated to route the "evm_flatkv" module exclusively to the FlatKV importer, and all other modules exclusively to the Cosmos importer. Previously, EVM data was duplicated to both importers based on the "evm" module name.

FlatKV Importer snapshot fix (flatkv/importer.go): The importer now writes a snapshot after import completes. Import bypasses the WAL and writes directly to PebbleDB in the working directory. Without a snapshot, the next LoadVersion would re-clone the working directory from the pre-import snapshot (e.g. snapshot-0), destroying all imported data.

Testing performed to validate your change

@github-actions
Copy link

github-actions bot commented Mar 13, 2026

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

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedMar 13, 2026, 1:55 AM

@codecov
Copy link

codecov bot commented Mar 13, 2026

Codecov Report

❌ Patch coverage is 74.00000% with 52 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.38%. Comparing base (9029c60) to head (873f066).

Files with missing lines Patch % Lines
sei-db/state_db/sc/flatkv/exporter.go 76.98% 22 Missing and 7 partials ⚠️
sei-db/state_db/sc/composite/exporter.go 80.95% 5 Missing and 3 partials ⚠️
sei-db/state_db/sc/composite/store.go 41.66% 5 Missing and 2 partials ⚠️
sei-db/state_db/sc/flatkv/store_lifecycle.go 50.00% 3 Missing and 2 partials ⚠️
sei-db/state_db/sc/flatkv/importer.go 0.00% 1 Missing and 1 partial ⚠️
sei-db/state_db/sc/composite/importer.go 87.50% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3064      +/-   ##
==========================================
+ Coverage   58.32%   58.38%   +0.05%     
==========================================
  Files        2076     2078       +2     
  Lines      171478   171673     +195     
==========================================
+ Hits       100020   100231     +211     
+ Misses      62549    62506      -43     
- Partials     8909     8936      +27     
Flag Coverage Δ
sei-chain-pr 69.47% <74.00%> (?)
sei-db 70.41% <ø> (ø)

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

Files with missing lines Coverage Δ
sei-db/state_db/sc/composite/importer.go 92.59% <87.50%> (+92.59%) ⬆️
sei-db/state_db/sc/flatkv/importer.go 48.83% <0.00%> (+48.83%) ⬆️
sei-db/state_db/sc/flatkv/store_lifecycle.go 61.97% <50.00%> (+5.52%) ⬆️
sei-db/state_db/sc/composite/store.go 61.87% <41.66%> (+13.03%) ⬆️
sei-db/state_db/sc/composite/exporter.go 80.95% <80.95%> (ø)
sei-db/state_db/sc/flatkv/exporter.go 76.98% <76.98%> (ø)

... and 1 file 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.

* main:
  feat(flatkv): add comprehensive writing test coverage and centralize account-field semantics (#3057)
  Fix flaky test caused by async WAL writes (#3063)
"github.com/sei-protocol/sei-chain/sei-db/common/evm"
"github.com/sei-protocol/sei-chain/sei-db/common/metrics"
"github.com/sei-protocol/sei-chain/sei-db/config"
flatkvpkg "github.com/sei-protocol/sei-chain/sei-db/state_db/sc/flatkv"
Copy link
Contributor

Choose a reason for hiding this comment

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

flatkv pkg is imported twice

if err != nil {
return nil, fmt.Errorf("open iterator for db %d: %w", e.currentDB, err)
}
if iter == nil || !iter.First() {
Copy link
Contributor

Choose a reason for hiding this comment

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

if iter.First() fails because of an iterator/IO error rather than because the DB is empty, we should also handle the iter.Error()?

Copy link
Contributor

@cody-littley cody-littley left a comment

Choose a reason for hiding this comment

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

Would be interested in learning about the import/export lifecycle, and how it's currently working with cosmos. Perhaps a good topic for a white boarding session at the onsite?

}, nil
}

func (s *SnapshotExporter) Next() (interface{}, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Short godoc explaining the methods in struct would be helpful. Purpose of these methods wasn't immediately obvious based on function names and context.

pendingNodes []*types.SnapshotNode
}

func NewKVExporter(store *CommitStore, version int64) *KVExporter {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this sort of export happen on validators on mainnet? If so, would it make sense to have throttles to prevent an export from impacting the handling of regular traffic? Do we currently throttle export from memIAVL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Export only happens on RPC nodes, validator doesn't export at all

@yzang2019 yzang2019 requested a review from Kbhat1 March 13, 2026 19:57
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