Skip to content

test(dash-spv): corrupt every storage part in the resync tests - #1503

Merged
xdustinface merged 2 commits into
devfrom
test/storage-corruption-resync
Nov 24, 2026
Merged

xdustinface merged 2 commits into
devfrom
test/storage-corruption-resync

Conversation

@ZocoLini

@ZocoLini ZocoLini commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

The dashd tests corrupted one storage file at a time: block headers on restart and filters at runtime.

This PR turns both tests into test cases over the corrupted file. The restart test corrupts block headers, filter headers, filters and blocks, and restarts with a fresh wallet, so the client downloads the wiped files again and the wallet syncs back to its balance. The runtime test corrupts block headers, filters and blocks while the client runs, and rescans the funded wallet so the client reads the corrupted file. Masternodes and the ChainLock are not covered, since the regtest chain stores neither.

PR Hygiene · 34fa90b

  • Bots — coderabbitai ✓
  • Self-review — post /self-reviewed
  • Build failed
  • Approvals
    • dash-spv (dash-spv/tests/dashd_sync/tests_restart.rs) — approved by xdustinface

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

Summary by CodeRabbit

  • Tests
    • Expanded checks for sync recovery after stored data is corrupted, including scenarios where the client is stopped or running. Tests verify that synchronization completes and affected data is restored.

The restart and runtime corruption tests now take the corrupted file as a test case, so each part of the storage can get its own case. The restart case moves out of `test_sync_restart_consistency`, and the runtime test rescans the funded wallet instead of an empty one, so it also checks the balance the client syncs back to.
The restart test corrupts block headers, filter headers, filters and blocks, and restarts with a fresh wallet, so the client downloads the wiped files again and the wallet syncs back to its balance. The runtime test corrupts block headers, filters and blocks.
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The restart tests now cover corruption in block headers, filter headers, filters, and blocks. They verify recovery after restarting a stopped client and after triggering a rescan in a running client.

Changes: Storage corruption recovery tests

Layer / File(s) Summary
Stopped-client corruption recovery
dash-spv/tests/dashd_sync/tests_restart.rs
Parameterized tests corrupt four storage file types while the client is stopped. After restart with a fresh wallet, the tests check sync completion and verify that the original file bytes are restored. The prior corruption check in test_sync_restart_consistency was removed.
Running-client corruption recovery
dash-spv/tests/dashd_sync/tests_restart.rs
Parameterized tests corrupt block headers, filters, or blocks while the client is running. The tests recreate the existing wallet to trigger a rescan, then check sync completion and verify that the original file bytes are restored.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Possibly related PRs

  • dashpay/rust-dashcore#1325: Changes peer departure announcements during shutdown, which relates to the restart consistency test's stop-time peer assertions.
  • dashpay/rust-dashcore#1327: Changes NetworkEvent::PeersUpdated, which the restart consistency test's peer tracker reads.

Suggested reviewers: xdustinface

Merge Risk: Minimal · up to 34fa9

This PR extends the storage-corruption resync tests to cover each storage file and does not alter runtime behavior. No concrete merge-blocking problem was found. The runtime cases were not run, so a CI run of the dashd integration tests would confirm them.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title says the PR corrupts every storage part in the resync tests. The raw summary shows the change adds parameterized corruption tests for each storage file: block headers, filter headers, filter…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title says the PR corrupts every storage part in the resync tests. The raw summary shows the change adds parameterized corruption tests for each storage file: block headers, filter headers, filters, and blocks, in both the stopped-client and running-client tests. The objectives confirm this scope. The title is specific and describes the main change. It omits the restart-with-fresh-wallet and rescan details, which is acceptable.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • Commit to this branch
  • Create a new PR
  • 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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 6e15db8 and 34fa90b.

Files selected for processing: 1

  • dash-spv/tests/dashd_sync/tests_restart.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@ZocoLini
ZocoLini marked this pull request as ready for review November 24, 2026 17:48
@ZocoLini
ZocoLini requested a review from xdustinface November 24, 2026 17:48
@manki-review

manki-review Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

✅ Review complete in 4m 49s

Planner (8s)
    test · 107 lines · 1 agents
    judge effort: low

Review (internal · solo): 1 finding
    ✅ Claude Opus 5.5 · medium: 1 finding (1m 14s)
    ✅ Related checks and claim checks: 10 of 10 done (1m 23s)
    ✅ Second reads: 1 of 1 done (28s)

Judge (1m 11s)
    graded 1 finding: 1 kept · 0 dropped
    refuter: 1 checked · 1 unsettled
    verdict reader: read the diff (21s)

Posted: 0 findings
    not finished checking: 1 possible problem

Review metadata

Config:

  • Models: reviewer=claude-opus-5-5, judge=claude-opus-5-5
  • Triage: trivial=false, subtle=false, paired=false (planner)
  • Team: Claude Opus 5.5 · medium
  • Memory: enabled (central)

Account limits:

  • Claude subscription: weekly 34% (resets 2026-12-01 05:00 UTC)
  • ChatGPT subscription: weekly 27% (resets 2026-11-25 01:21 UTC)

Judge decisions:

  • Not finished: "Runtime corruption of a cached segment may never be read, so the block headers and blocks cases could time out" (warning): "warning, unproven. get_segment_mut returns a cached segment without touching disk (dash-spv/src/storage/segments.rs:196), and only a cache miss calls Segment::load (segments.rs:218). On a small regtest chain, segment 0 of headers or blocks may stay cached, so the corruption written by corrupt would never be read. The new cases would then fail at the Corruption not detected timeout. Whether segment 0 is evicted before the rescan cannot be settled from the code shown.
    Refutation unsettled: A cached segment is served from memory (segments.rs:196-203), and only a cache miss reads the file again through Segment::load (segments.rs:218). It is still open whether segment 0 of block_headers or blocks is still cached when the rescan runs, because that depends on the height of the regtest chain and on which segments were read before. I did not check either, and the test was not run. Rule checked: A SegmentCache returns a segment it already holds in memory without reading its file again, so a change to the file on disk is seen only after that segment has been evicted and reloaded.
  • Premise "During the rescan in test_runtime_corruption_resyncs, segment 0 of block_headers or blocks is still in the SegmentCache of the running client, so no read of segment_000000.dat from disk happens and SyncEvent::StorageCorrupted is never emitted" unsettled. The cache serves hits from memory and holds at most MAX_ACTIVE_SEGMENTS segments, evicting the one used longest ago. I did not establish the TestChain::Full height or which segments the client reads before the rescan, so I cannot tell whether segment 0 is still cached when the rescan reads it.
    Pair refutation unsettled: If segment 0 is still cached, the rescan can use its unchanged in-memory data and leave the test waiting for a StorageCorrupted event until the timeout. The blocks handler also treats a failed cached-block lookup as a reason to redownload, rather than propagating the storage error. Rule checked: A cache hit bypasses disk validation, so changing a backing file does not invalidate the cached segment.
  • Premise "During the rescan in test_runtime_corruption_resyncs, segment 0 of block_headers or blocks is still in the SegmentCache of the running client, so no read of segment_000000.dat from disk happens and SyncEvent::StorageCorrupted is never emitted" unsettled. Full selects the regtest-40000 fixture, not a sub-20,000-block fixture, but the actual tip is queried at startup and full blocks are stored only when fetched, so the fixture name alone does not establish whether segment 0 is resident when the rescan reads it."

Timing:

  • Parse: 6.8s
  • Review agents: 211.6s
  • Judge: 70.6s
  • Total: 289.0s

Last reviewed 34fa90b · head 34fa90b · up to date

  • Pause automatic reviews
  • Review again
  • Deeper review

@github-actions

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Nov 24, 2026

@manki-review manki-review 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.

✅ Approved.

What this does: Tests that the SPV client wipes and syncs again when a storage file is corrupted now cover each storage type (block headers, filter headers, filters, blocks). They cover both corruption while the client is stopped and corruption while it runs.


What to test

The review model wrote these steps. Check what a step runs before you follow it.

Setup: Load the regtest dashd environment with eval $(python3 contrib/setup-dashd.py) or use just dash-spv::test.

  1. Run just dash-spv::test test_restart_corruption_resyncs. Expect four cases to pass: block headers, filter headers, filters and blocks.
  2. Run just dash-spv::test test_runtime_corruption_resyncs. Expect three cases to pass, each emitting a StorageCorrupted event before the resync finishes.
  3. Run just dash-spv::test test_sync_restart_consistency. Expect it to pass without the corruption step, including the boundary-block mining check when mining is supported.
  4. Run a single case with DASHD_TEST_LOG=1 and --nocapture. Expect the log to show the corrupted segment being wiped and downloaded again.

Checked and left out: 1 finding

Not finished checking · 1 possible problem

The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.

About this review
  • Reviewed 34fa90b, round 1
  • 107 changed lines read in 4m 49s
  • Found by claude-opus-5-5, judged by claude-opus-5-5
  • Tokens: 1.9M in (1.5M from cache) · 29k out · about $2.66 at API prices
  • Runner: self-hosted · started after 16s · peak memory 2.9 GiB of 30.0 GiB
  • How Manki reviews

@github-actions

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Nov 24, 2026
@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.51%. Comparing base (6e15db8) to head (34fa90b).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1503      +/-   ##
==========================================
- Coverage   87.53%   87.51%   -0.03%     
==========================================
  Files         270      270              
  Lines       71309    71309              
==========================================
- Hits        62421    62405      -16     
- Misses       8888     8904      +16     
Flag Coverage Δ
core 83.38% <ø> (-0.01%) ⬇️
rpc 83.38% <ø> (-0.01%) ⬇️
spv 94.93% <ø> (-0.06%) ⬇️
wallet 83.38% <ø> (-0.01%) ⬇️
see 11 files with indirect coverage changes

@xdustinface
xdustinface merged commit f402a28 into dev Nov 24, 2026
45 of 47 checks passed
@xdustinface
xdustinface deleted the test/storage-corruption-resync branch November 24, 2026 22:23
manki-review Bot added a commit to manki-review/review-memory that referenced this pull request Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-self-review Waiting for the author to post /self-reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants