Skip to content

Backport release/v6.7: fix(rootmulti): return errors instead of panics for malformed snapshot streams - #4435

Closed
blindchaser wants to merge 1 commit into
release/v6.7from
backport-4368-to-release/v6.7
Closed

blindchaser wants to merge 1 commit into
release/v6.7from
backport-4368-to-release/v6.7

Conversation

@blindchaser

Copy link
Copy Markdown
Contributor

Backport of #4368 to release/v6.7.

Made with Cursor

…t streams (#4368)

## Summary

Snapshot restore now returns an error, not a panic, for three kinds of
malformed stream, and for a failed state-store import. `Restore` runs on
the snapshot manager's goroutine, so a panic there stopped the node.
With an error, the restore fails and state sync stops cleanly with the
cause in the log. A failed restore also publishes nothing: no memIAVL
snapshot, no flatkv import, and no state-store versions. Retrying with
another snapshot needs a separate change.

- `sei-cosmos/storev2/rootmulti/store.go`: `restore` rejects a node that
is not inside a named store section. Before, such a node reached
memIAVL's `MultiTreeImporter` with no tree importer open. The
state-store import now runs through `stateStoreImport`. Its error fails
the restore, not the process, and `restore` waits for the import to
return before it returns. `finishSCImport` publishes the SC import only
when the restore succeeded, and aborts it otherwise. The state store's
earliest and latest versions are set only on success.
- `sei-db/state_db/sc/types/types.go`: `Importer` gains `Abort`, which
discards an import without publishing it.
- `sei-db/state_db/sc/memiavl/import.go`: the tree importer rejects a
branch node that does not have two pending children. `TreeImporter.Add`
stops queueing nodes after the import has stopped, and `Close` returns
the import's error. `MultiTreeImporter.Abort` removes the temp directory
without publishing a snapshot or moving `current`, and a failed `Close`
removes it too.
- `sei-db/state_db/sc/composite/importer.go`: when the cosmos import
fails, `Close` aborts the flatkv import rather than publishing it.
`Abort` aborts both.

Honest snapshots do not change, so there is no consensus or state
impact. Checks on which stores a snapshot contains are not in scope.

## Test plan

- `sei-cosmos/storev2/rootmulti/restore_test.go`: under `memiavl_only`
and `test_dual_write`, these streams fail the restore with an error and
do not panic: a node before any store item, a node after an unnamed
store item, and a branch node before its leaves. A state-store import
that fails early, or after it reads the full stream, also fails the
restore. A failed restore leaves memIAVL's snapshots and `current` as
they were, and leaves the state-store versions unset. A successful
restore publishes the snapshot and sets the versions.
- `sei-db/state_db/sc/composite/importer_test.go`: `Close` publishes
flatkv only after the cosmos import succeeds, and `Abort` aborts both.
- `sei-db/state_db/sc/memiavl/import_test.go`: a branch node before its
leaves fails the import, and `Add` returns after the import has stopped,
also when the node channel is full.

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
(cherry picked from commit 7b415b7)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-02T19:58:27.238373Z 0a582ac PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

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

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedOct 2, 2026, 7:54 PM

@seidroid seidroid Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I found nothing that needs changing in this backport of #4368. Malformed snapshot streams now fail restore with an error instead of a panic. A failed restore no longer publishes a memIAVL or flatkv snapshot and no longer records the state store's version height. Tests cover each of these cases. Every Importer implementation in the tree gets the new Abort method.

Findings: 0 blocking | 0 non-blocking | 0 posted inline

Blockers

  • None at the file/PR level.

Non-blocking

  • None at the file/PR level.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0a582ac787

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +87 to +88
if si.flatkvImporter != nil {
return si.flatkvImporter.Close()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Abort memIAVL when the flatKV import has failed

With the state store disabled and a dual-backend snapshot, a malformed flatKV node (for example, an empty physical value) is recorded as an error by KVImporter.AddNode but is only reported by Close. This ordering publishes the memIAVL snapshot first and then returns the flatKV error, so Restore fails after advancing memIAVL's current; worse, a valid retry at the same height will adopt that existing partial snapshot and discard its newly imported memIAVL data. The flatKV failure must be observed before publishing memIAVL, or both backends must remain staged until both are known to be valid.

Useful? React with 👍 / 👎.

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.

address this in #4412

@codecov

codecov Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.14634% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.81%. Comparing base (b9b9f14) to head (0a582ac).

Files with missing lines Patch % Lines
sei-db/state_db/sc/memiavl/import.go 61.53% 9 Missing and 1 partial ⚠️
sei-cosmos/storev2/rootmulti/store.go 93.33% 2 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff                @@
##           release/v6.7    #4435      +/-   ##
================================================
- Coverage         61.49%   60.81%   -0.69%     
================================================
  Files              2168     2093      -75     
  Lines            189616   181806    -7810     
================================================
- Hits             116607   110566    -6041     
+ Misses            62232    61106    -1126     
+ Partials          10777    10134     -643     
Flag Coverage Δ
sei-chain-pr 70.03% <93.33%> (?)
sei-db 69.80% <ø> (ø)
sei-db-state-db ?
sei-db-state-db-pr 76.11% <72.97%> (?)

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 93.33% <100.00%> (+1.66%) ⬆️
sei-cosmos/storev2/rootmulti/store.go 71.46% <93.33%> (+1.79%) ⬆️
sei-db/state_db/sc/memiavl/import.go 66.34% <61.53%> (-2.77%) ⬇️

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

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.

1 participant