Skip to content

fix(flatkv): fix state sync panic on nil DB handles during snapshot restore#3003

Merged
blindchaser merged 3 commits intomainfrom
yiren/flatkv-fix-importer
Mar 2, 2026
Merged

fix(flatkv): fix state sync panic on nil DB handles during snapshot restore#3003
blindchaser merged 3 commits intomainfrom
yiren/flatkv-fix-importer

Conversation

@blindchaser
Copy link
Contributor

@blindchaser blindchaser commented Mar 2, 2026

Issue:

rootmulti.Restore closes the SC store before calling Importer(), leaving all DB handles nil. The old code created a KVImporter against the closed store, which panicked in commitGlobalMetadata() on the nil metadataDB.

A second bug in composite.SnapshotImporter.AddModule() never set currentModule, so the EVM importer received zero nodes — masking the nil-DB crash until Close() reached commitGlobalMetadata().

Fixes:

  • Reopen the store in Importer() when isClosed() is true
  • Set currentModule in composite SnapshotImporter.AddModule()
  • Move flatkv data dir under data/ to align with evm_ss convention
  • Add isClosed() helper to avoid spreading the nil-check assumption

Describe your changes and provide context

Testing performed to validate your change

…estore

rootmulti.Restore closes the SC store before calling Importer(), leaving
all DB handles nil. The old code created a KVImporter against the closed
store, which panicked in commitGlobalMetadata() on the nil metadataDB.

A second bug in composite.SnapshotImporter.AddModule() never set
currentModule, so the EVM importer received zero nodes — masking the
nil-DB crash until Close() reached commitGlobalMetadata().

Fixes:
- Reopen the store in Importer() when isClosed() is true
- Set currentModule in composite SnapshotImporter.AddModule()
- Move flatkv data dir under data/ to align with evm_ss convention
- Add isClosed() helper to avoid spreading the nil-check assumption
@blindchaser blindchaser changed the title fix(flatkv): fix state sync panic on nil DB handles during snapshot r… fix(flatkv): fix state sync panic on nil DB handles during snapshot restore Mar 2, 2026
@github-actions
Copy link

github-actions bot commented Mar 2, 2026

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

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedMar 2, 2026, 10:57 PM

@codecov
Copy link

codecov bot commented Mar 2, 2026

Codecov Report

❌ Patch coverage is 25.00000% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.30%. Comparing base (555d520) to head (ee520dd).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
sei-db/state_db/sc/flatkv/store.go 50.00% 3 Missing ⚠️
sei-db/state_db/sc/flatkv/store_lifecycle.go 0.00% 3 Missing ⚠️
sei-db/state_db/sc/composite/store.go 0.00% 2 Missing ⚠️
sei-db/state_db/sc/composite/importer.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3003      +/-   ##
==========================================
- Coverage   58.30%   58.30%   -0.01%     
==========================================
  Files        2108     2108              
  Lines      173672   173680       +8     
==========================================
  Hits       101262   101262              
- Misses      63390    63398       +8     
  Partials     9020     9020              
Flag Coverage Δ
sei-chain-pr 59.53% <25.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/flatkv/importer.go 0.00% <ø> (ø)
sei-db/state_db/sc/composite/importer.go 0.00% <0.00%> (ø)
sei-db/state_db/sc/composite/store.go 48.73% <0.00%> (-0.42%) ⬇️
sei-db/state_db/sc/flatkv/store.go 58.76% <50.00%> (-0.93%) ⬇️
sei-db/state_db/sc/flatkv/store_lifecycle.go 48.88% <0.00%> (-3.50%) ⬇️
🚀 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.

@blindchaser blindchaser requested a review from yzang2019 March 2, 2026 22:04

func (s *CommitStore) flatkvDir() string {
return filepath.Join(s.homeDir, flatkvRootDir)
return filepath.Join(s.homeDir, "data", flatkvRootDir)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should do the appending to the dir when we initialize FlatKV in CompositeSC layer instead of changing the function here. We probably don't wanna change the test as well, just use whatever is passed in should be good ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thx updated

)

// isClosed reports whether the store's DB handles have been released.
func (s *CommitStore) isClosed() bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we add an atomic bool just to make sure this is thread safe in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

closed flag alone is probably not sufficient since other store fields are still unsynchronized. I’d avoid that for now and revisit when/if we decide to make CommitStore concurrent-safe.

@blindchaser blindchaser enabled auto-merge (squash) March 2, 2026 22:56
@blindchaser blindchaser merged commit 778ced7 into main Mar 2, 2026
35 checks passed
@blindchaser blindchaser deleted the yiren/flatkv-fix-importer branch March 2, 2026 23:11
yzang2019 pushed a commit that referenced this pull request Mar 19, 2026
…estore (#3003)

Issue:

rootmulti.Restore closes the SC store before calling Importer(), leaving
all DB handles nil. The old code created a KVImporter against the closed
store, which panicked in commitGlobalMetadata() on the nil metadataDB.

A second bug in composite.SnapshotImporter.AddModule() never set
currentModule, so the EVM importer received zero nodes — masking the
nil-DB crash until Close() reached commitGlobalMetadata().

Fixes:
- Reopen the store in Importer() when isClosed() is true
- Set currentModule in composite SnapshotImporter.AddModule()
- Move flatkv data dir under data/ to align with evm_ss convention
- Add isClosed() helper to avoid spreading the nil-check assumption

## Describe your changes and provide context

## Testing performed to validate your change
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