Skip to content

Add snapshot import for Giga Live State#2970

Merged
yzang2019 merged 12 commits intomainfrom
yzang/STO-372
Feb 24, 2026
Merged

Add snapshot import for Giga Live State#2970
yzang2019 merged 12 commits intomainfrom
yzang/STO-372

Conversation

@yzang2019
Copy link
Contributor

Describe your changes and provide context

This PR add feature to import snapshot

  • Add feature for FlatKV import from snapshot
  • Make go benchmark able to load from local snapshot

Testing performed to validate your change

* main:
  fix: use correct EVM storage key prefix in benchmark key generation (#2966)
  Harden staking precompile test against CI flakiness (#2967)
  Don't sync flatKV DBs when committing  (#2964)
  Fix flaky `TestStateLock_POLSafety1` (#2962)
* main:
  go bench read + write receipts/logs for parquet vs pebble (#2794)
  [giga] clear up cache after Write (#2827)
@github-actions
Copy link

github-actions bot commented Feb 24, 2026

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

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedFeb 24, 2026, 9:06 PM


var (
totalKeys int64
startTime = time.Now()

Check warning

Code scanning / CodeQL

Calling the system time Warning

Calling the system time may be a possible source of non-determinism
Comment on lines +286 to +302
go func() {
defer close(chunks)
for i := 0; ; i++ {
path := filepath.Join(chunksDir, strconv.Itoa(i))
f, err := os.Open(filepath.Clean(path))
if err != nil {
if os.IsNotExist(err) {
return
}
pr, pw := io.Pipe()
_ = pw.CloseWithError(fmt.Errorf("open chunk %d: %w", i, err))
chunks <- pr
return
}
chunks <- f
}
}()

Check notice

Code scanning / CodeQL

Spawning a Go routine Note

Spawning a Go routine may be a possible source of non-determinism
if totalKeys%1_000_000 == 0 {
elapsed := time.Since(startTime).Seconds()
fmt.Printf("[Snapshot] keys=%d, keys/sec=%.0f, elapsed=%.2fs\n",
totalKeys, float64(totalKeys)/elapsed, elapsed)

Check notice

Code scanning / CodeQL

Floating point arithmetic Note

Floating point arithmetic operations are not associative and a possible source of non-determinism

elapsed := time.Since(startTime).Seconds()
fmt.Printf("[Snapshot] Import Done: keys=%d, keys/sec=%.0f, elapsed=%.2fs\n",
totalKeys, float64(totalKeys)/elapsed, elapsed)

Check notice

Code scanning / CodeQL

Floating point arithmetic Note

Floating point arithmetic operations are not associative and a possible source of non-determinism
Copy link
Contributor

Choose a reason for hiding this comment

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

It's funny, I have almost this exact change set in my branch where I'm working on the crypto transfer simulation. 😅

importer.AddNode(node)
if node.Height == 0 {
totalKeys++
if totalKeys%1_000_000 == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should number of keys before a snapshot be configurable?

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 usually want to finish loading all keys in a snapshot so that we can do hash verification, but I'm open to that feature in a future PR

Comment on lines 59 to 62
func (s *CommitStore) Exporter(version int64) (types.Exporter, error) {
// TODO: Implement exporter
return nil, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit, should this panic or return something like fmt.Errof("not implemented")?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, will do that instead

type SnapshotImporter struct {
cosmosImporter types.Importer
evmImporter types.Importer
currentModule string
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 currentModule is declared but not set anywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch!

Changeset: iavl.ChangeSet{Pairs: imp.batch},
}}
if err := imp.store.ApplyChangeSets(cs); err != nil {
imp.err = fmt.Errorf("import apply changesets: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

how about adding some logs here like

imp.store.log.Error("import flush failed, remaining nodes will be dropped", "err", imp.err)

so we can see error log output with context. otherwise we only see errors when Close()

return
}
if err := imp.store.commitBatches(imp.version); err != nil {
imp.err = fmt.Errorf("import commit batches: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

@yzang2019 yzang2019 merged commit 37f1b8d into main Feb 24, 2026
35 checks passed
@yzang2019 yzang2019 deleted the yzang/STO-372 branch February 24, 2026 22:10
@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

❌ Patch coverage is 1.31579% with 75 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.22%. Comparing base (aa8885f) to head (c993029).
⚠️ Report is 1 commits behind head on main.

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

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #2970       +/-   ##
===========================================
+ Coverage   58.15%   61.22%    +3.07%     
===========================================
  Files        2107       16     -2091     
  Lines      173323     1354   -171969     
===========================================
- Hits       100794      829    -99965     
+ Misses      63580      403    -63177     
+ Partials     8949      122     -8827     
Flag Coverage Δ
sei-chain 56.83% <1.31%> (-1.29%) ⬇️
sei-db 69.50% <ø> (ø)

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/config.go 100.00% <100.00%> (ø)
sei-db/state_db/sc/flatkv/iterator.go 38.01% <ø> (-1.99%) ⬇️
sei-db/state_db/sc/flatkv/store_write.go 70.96% <ø> (+2.92%) ⬆️
sei-db/state_db/sc/flatkv/store.go 64.03% <0.00%> (-1.15%) ⬇️
sei-db/state_db/sc/flatkv/store_lifecycle.go 48.38% <0.00%> (-6.46%) ⬇️
sei-db/state_db/sc/composite/store.go 49.15% <0.00%> (-3.10%) ⬇️
sei-db/state_db/sc/composite/importer.go 0.00% <0.00%> (ø)
sei-db/state_db/sc/flatkv/importer.go 0.00% <0.00%> (ø)

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

yzang2019 added a commit that referenced this pull request Feb 25, 2026
This PR add feature to import snapshot
- Add feature for FlatKV import from snapshot
- Make go benchmark able to load from local snapshot
yzang2019 added a commit that referenced this pull request Feb 27, 2026
* main: (66 commits)
  feat(flatkv): include legacyDB in ApplyChangeSets, LtHash, and read path (#2978)
  Deflake mempool tests with Eventually-based block waits (#2983)
  Demote noisy gasless classification log to debug level (#2982)
  Harden `TestStateLock_NoPOL` against proposal/timeout race (#2980)
  added a config parameter to limit outbound p2p connections. (#2974)
  merged unconditional and persistent peers status (#2977)
  Fix race between file pruning and in-flight parquet queries (#2975)
  fix(giga): don't migrate balance on failed txs (#2961)
  Fix hanging upgrade tests by adding timeouts to wait_for_height (#2976)
  Add snapshot import for Giga Live State (#2970)
  Fix Rocksdb MVCC read timestamp lifetime for iterators (#2971)
  Reduce exposed tendermint RPC endpoint (#2968)
  Deflake `TestStateLock_NoPOL` by widening propose timeout in test (#2969)
  go bench read + write receipts/logs for parquet vs pebble (#2794)
  [giga] clear up cache after Write (#2827)
  fix: use correct EVM storage key prefix in benchmark key generation (#2966)
  Harden staking precompile test against CI flakiness (#2967)
  Don't sync flatKV DBs when committing  (#2964)
  Fix flaky `TestStateLock_POLSafety1` (#2962)
  Add metrics for historical proof success/failure rate (#2958)
  ...
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