Skip to content

fix(dash-spv): resync on corruption found on startup and in header lookups - #1575

Draft
ZocoLini wants to merge 15 commits into
devfrom
fix/resync-more-storage-corruption
Draft

ZocoLini wants to merge 15 commits into
devfrom
fix/resync-more-storage-corruption

Conversation

@ZocoLini

@ZocoLini ZocoLini commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #1421.

Some storage errors still never reached the sync loop's wipe and resync. Building the sync managers in DashSpvClient::new and DashSpvClient::run could hit a corrupted read and stop the client from starting. BlockHeaderStorage::get_tip, MasternodeListEngine::height_if_known and BlockHeadersManager::handle_inventory turned a failed header read into missing data, so quorum validation, pruning and fork handling acted on it as if it were the chain.

The client now wipes the storage and builds the managers again when that build hits corruption, both on construction and on a run. The three lookups return the StorageError instead, so a corrupted header store reaches the sync loop and is wiped. DashSpvClient::tip_header now returns StorageResult.

`ChainLockManager::new` logged a failed read of the persisted ChainLock and went on without it. It now returns the error, so a corrupted ChainLock fails client construction instead of being dropped silently.
The filters pipeline logged a failed read of the header hashes of a filter batch and went on, so a corrupted header segment never reached the sync loop. It now returns the error. `FiltersManager::new` also returns the errors of its storage reads instead of starting from height 0.
The filters pipeline logged a failed read of the header that ends a filter batch and deferred the batch, so a corrupted header segment never reached the sync loop. It now returns the error.
The ChainLock manager treated a failed read of the header at a ChainLock height as a missing header, and logged a failed write of the best ChainLock. Both errors now reach the sync loop.
The blocks manager logged a failed read of a stored block it had to re-apply and skipped the block, so a corrupted block segment never reached the sync loop. It now returns the error.
The blocks manager read a failed lookup of a needed block as a block not stored yet and downloaded it again, so a corrupted block segment never reached the sync loop. It now returns the error.
The masternodes manager turned every error of a QRInfo the engine could not take into a masternode sync failure, so a corrupted header segment the engine read never reached the sync loop as a storage error. A header storage error now stays one.
The masternodes manager gave up an MnListDiff the engine failed on for any reason, so a corrupted header segment the engine read while validating a tip update never reached the sync loop. A header storage error is now returned.
The masternode list engine left out of the work-block list requests a quorum whose block the header storage could not read, and only logged the failure, so a corrupted header segment never reached the sync loop. The scans for the QRInfo and the tip update now return the error.
Building the sync managers reads persisted state such as the best ChainLock. A corrupted read there stopped `DashSpvClient::new` and `DashSpvClient::run` from starting the client.

Both now go through `open_managers`, which writes the genesis or checkpoint header, builds the managers and on corruption wipes the storage and builds them again. `FiltersManager::new` and `FilterHeadersManager::new` return `StorageResult`, so their corruption reaches the client as `SpvError::Storage`.
Three header reads swallowed a storage error and went on as if the data were missing: `BlockHeaderStorage::get_tip` returned `None`, `MasternodeListEngine::height_if_known` treated the block as unknown, and `BlockHeadersManager::handle_inventory` treated an announced block as new. Quorum validation, pruning and fork handling then acted on a storage failure as if it were the chain.

They now return the `StorageError`, so a corrupted header store reaches the sync loop and is wiped. `DashSpvClient::tip_header` returns `StorageResult`. `BlockHeadersManager::new` treats a store without a tip as corruption, since the client always writes the genesis or checkpoint header first.
@manki-review

manki-review Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

This pull request is a draft, so Manki does not review it automatically. Marking it ready for review starts automatic reviews. Until then, someone with write access to this repository can tick a box below: Review this draft reviews the current commit once, Deeper review does so with more effort, and Review every push reviews it now and again after each push.


Not reviewed yet · head 46f0cdf · draft, not reviewed automatically

  • Deeper review
  • Review this draft
  • Review every push

@coderabbitai

coderabbitai Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

CI does not run on this PR while it is a draft. Someone with write access can start it here:

  • Run CI once on the current commit
  • Run CI on every push, starting now

Marking the PR ready for review also starts CI.

`match_header` returns a failed header read as an error, so `Unknown` only means the header is not stored yet.
Base automatically changed from fix/propagate-storage-corruption to dev December 3, 2026 07:59
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them.

@github-actions github-actions Bot added the merge-conflict The PR conflicts with the target branch. label Dec 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-conflict The PR conflicts with the target branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant