Skip to content

Refactor/drop committed range sweep - #1016

Draft
ZocoLini wants to merge 2 commits into
devfrom
refactor/drop-committed-range-sweep
Draft

ZocoLini wants to merge 2 commits into
devfrom
refactor/drop-committed-range-sweep

Conversation

@ZocoLini

Copy link
Copy Markdown
Collaborator

Needs fix/reapply-spend-funded-late

Drops de final sweep, syncs goes from 21–27 min → 6–9 min, gives up the #846 case. This can be done now, because all (known) bugs that were losing funds are solved and it doesn't discover anything new

@coderabbitai

coderabbitai Bot commented Sep 12, 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

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

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Sep 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.69421% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.17%. Comparing base (ed0df9d) to head (5156e07).

Files with missing lines Patch % Lines
dash-spv/src/sync/blocks/manager.rs 94.66% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1016      +/-   ##
==========================================
- Coverage   77.20%   77.17%   -0.04%     
==========================================
  Files         329      329              
  Lines       83862    83684     -178     
==========================================
- Hits        64747    64582     -165     
+ Misses      19115    19102      -13     
Flag Coverage Δ
core 78.24% <ø> (ø)
ffi 50.95% <ø> (+<0.01%) ⬆️
rpc 20.00% <ø> (ø)
spv 92.01% <95.12%> (-0.06%) ⬇️
wallet 79.84% <100.00%> (+0.05%) ⬆️
Files with missing lines Coverage Δ
dash-spv/src/sync/filters/batch.rs 97.56% <ø> (-0.32%) ⬇️
dash-spv/src/sync/filters/block_match_tracker.rs 99.35% <ø> (-0.02%) ⬇️
dash-spv/src/sync/filters/manager.rs 97.83% <100.00%> (+0.02%) ⬆️
dash-spv/src/sync/filters/sync_manager.rs 100.00% <ø> (ø)
key-wallet-manager/src/process_block.rs 93.47% <100.00%> (+0.31%) ⬆️
key-wallet-manager/src/wallet_interface.rs 9.37% <ø> (ø)
...allet/managed_wallet_info/wallet_info_interface.rs 81.60% <100.00%> (+0.90%) ⬆️
dash-spv/src/sync/blocks/manager.rs 96.02% <94.66%> (-0.77%) ⬇️

... and 6 files with indirect coverage changes

ZocoLini and others added 2 commits September 16, 2026 08:33
Two mainnet restores of the same wallet ended at the same balance with 7112
and 7111 wallet records. Replaying each run's logged block applications
offline, against the blocks it stored, reproduced both results exactly, with
no divergence from the logs. The missing record was e66553f3…8c9e at height
2 185 057: it pays change to the BIP44 account and spends a CoinJoin coin
funded at 2 182 877.

When the spend is applied before its funding, the CoinJoin account cannot
recognise it. The funding then parks the coin in `spent_before_funded` (#1001),
and that only attributes the spend if its block is delivered again. In one
run it was (funding at step 1494, spend at 1516); in the other it was not
(spend at 1608, funding at 1627, no redelivery), so the result depended on
delivery order.

`WalletInfoInterface::unrecorded_spend_heights` reports, for a transaction,
the heights of the blocks that spent its outputs before it arrived and that
the owning account has not recorded yet. `process_block_for_wallets` returns
them per wallet in `BlockProcessingResult::reapply_heights`, only heights
above the block being applied, so re-applying cannot loop. `BlocksManager`
re-applies those blocks from block storage straight away; every downloaded
block is stored on arrival. Re-applications emit no `SyncEvent::BlockProcessed`
and so never touch a batch's pending-block accounting.

Offline, both orderings now end with identical per-account records (7112),
with about 105 blocks re-applied from disk per restore.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017DruChNTWXwJoWPartZwCf
…scripts rescan

The #846 sweep re-tested every late-derived script against the whole stored
filter history, from the wallet's birth height. On a mainnet restore of the
bench wallet that was one 63 s walk over 200 000..tip matching 41 687 blocks,
overwhelmingly compact-filter false positives, then about 17.7 min downloading
and applying them, out of a 21–27 min sync.

The notification-driven path (`collect_new_scripts`,
`FiltersBatch::collected_scripts`, the current-and-later batch rescan at
commit) duplicated `reconcile_untested_scripts`, which asks the wallet what it
watches, a superset of any `new_scripts`, and re-tests whatever the batch never
matched. `rescan_complete` was set immediately before the batch left
`active_batches`, so it was never read as true.

Trade-off: the #846 case, a CoinJoin output paying an index derived only after
its batch committed, is no longer recovered. Its repro,
`coinjoin_gap_limit_stall_across_committed_batch`, fails without the sweep and
is removed with it, as is the sweep-cost test. The bench wallet does not hit
that case.

Validated on top of the spend re-application fix: 5 consecutive mainnet
restores at 100 Mbit / 100 ms, then 100/50 Mbit x 100/500 ms, all ending at
7112 records, 14 114 383 sat and 13 389 addresses, in 6.0–17.2 min.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017DruChNTWXwJoWPartZwCf
@ZocoLini
ZocoLini force-pushed the refactor/drop-committed-range-sweep branch from 63bd002 to 5156e07 Compare September 16, 2026 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant