Skip to content

feat(dash-spv): opt-in mempool relay while filters still sync - #1512

Draft
PastaPastaPasta wants to merge 1 commit into
devfrom
feat/mempool-during-sync
Draft

PastaPastaPasta wants to merge 1 commit into
devfrom
feat/mempool-during-sync

Conversation

@PastaPastaPasta

Copy link
Copy Markdown
Member

The mempool manager turns on relay (filterload/filterclear and mempool) only on FiltersSyncComplete, so peers announce no transaction or InstantSend lock until the filter scan reaches the tip. A payment to a fresh wallet that is InstantSend-locked within seconds reaches the wallet only minutes later, when sync ends.

ClientConfig::mempool_during_sync turns relay on for each peer as it connects instead. It is off by default, so nothing changes for existing users. InstantSend locks that arrive before the masternode list can verify them wait in the InstantSend manager as before.

Before filter sync completes, the wallet may not know every address and coin it owns. A payment to an address the scan derives later, or a spend of a coin it hasn't found yet, is judged irrelevant, and peers never announce it again. So when filter sync first completes and the wallet's monitored set has changed, the manager forgets the txids it judged irrelevant and asks every activated peer for its mempool again, reloading the bloom filter first under BloomFilter. If no peer is connected at that point, the txids are still forgotten, so the next peer's mempool brings them back. Until then the bloom filter isn't reloaded on every change the scan makes.

Trade-offs of turning it on:

  • Under BloomFilter, peers get a filter of the addresses known at connect, and the filter is reloaded at completion. A peer that sees both filters can intersect them, which weakens their false-positive cover.
  • A relevant transaction seen during sync is kept as first judged. If it spends a coin the scan hasn't found yet, its direction and net amount can be off until it confirms. If that coin belongs to another account of the wallet, that account's balance reads high until then.
  • Locks reach the InstantSend manager from connect onward, so its queue of locks waiting for the masternode list fills sooner. On dev, a lock dropped from that full queue stays cached and a re-announcement of it is ignored, so its transaction shows unlocked until it confirms. fix(dash-spv): defer unverified InstantLocks #1336 stops caching unverified locks.

Tests: unit tests in sync_manager.rs cover the default (no activation before completion), activation on connect and on reconnect during sync, the re-request after completion, forgetting txids with and without connected peers, no re-request when the wallet is unchanged, and the bloom filter not reloading before completion. Four of them fail with the completion refresh removed. test_mempool_during_sync_detects_a_payment_before_sync_completes runs against dashd on the 40,000-block chain under both strategies. It pays a fresh wallet's first address before the client starts and checks that each client detects the payment before it reports synced; with the option off, it fails. It passed in repeated full dashd_sync runs. cargo fmt --all --check, contrib/run_clippy.py, cargo doc with -D warnings, and the CI spv group pass.

🤖 Generated with Claude Code

The mempool manager turns on relay (`filterload`/`filterclear` and `mempool`) only on `FiltersSyncComplete`, so peers announce no transaction or InstantSend lock until the filter scan reaches the tip. A payment to a fresh wallet, InstantSend-locked within seconds, reaches the wallet only minutes later, when sync ends.

`ClientConfig::mempool_during_sync` (off by default, so nothing changes for existing users) activates each peer as it connects instead. InstantSend locks that arrive before the masternode list can verify them wait in the InstantSend manager as before.

Before filter sync completes the wallet may not know every address and coin it owns, so a payment to an address the scan derives later, or a spend of a coin it has not found yet, is judged irrelevant, and peers never announce it again. When filter sync first completes and the wallet watches something it did not when the mempool was first requested, the manager forgets the txids it found irrelevant and asks every activated peer for its mempool again, reloading the bloom filter first under `BloomFilter`. Until then the bloom filter is not reloaded on every change the scan makes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 24, 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

@PastaPastaPasta

PastaPastaPasta commented Nov 24, 2026 •

Copy link
Copy Markdown
Member Author

Pre-review record for head 602fac26d0e176825b153dcce69dfbc9dc93af64.

An independent automated code review read three versions. The last full read was 9fd1d9ccff; this head adds only the fixes from that read, plus a move of the dashd test to the 40,000-block chain. Verdict: approved with suggestions. With the option off, every new condition reduces to the old code path.

Fixed before this head:

  • The first dashd test passed with the option off. It now checks that each client detects the payment before it reports synced. On the 200-block chain that raced sync under parallel load, so it runs on the 40,000-block chain. With the option off, it fails.
  • When filter sync completed with no peer connected, txids judged irrelevant weren't forgotten. The next peer's announcements were then deduplicated and never fetched. They are now forgotten in that case too.
  • Near the tip, the refresh downloaded the whole mempool a second time. It is skipped when the wallet's monitor hash hasn't changed since the mempool was first requested.
  • Docs: the field doc fits in three lines, the module and struct docs mention the option, and the last_monitor_hash doc says why activating a single peer leaves it unchanged.

Left as is, listed under trade-offs in the description:

  • Under BloomFilter, peers can intersect the connect-time and completion filters.
  • A relevant transaction seen during sync isn't judged again. A spend of another account's coin the scan hasn't found yet can overstate that account until the transaction confirms.
  • On dev, a lock dropped from the full InstantSend queue stays cached until fix(dash-spv): defer unverified InstantLocks #1336.
  • The completion refresh doesn't retry activating a peer whose bloom filter failed to build at connect.

🤖 Posted autonomously by Claude (claude-opus-5-5) on behalf of pasta.

@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.58%. Comparing base (6e15db8) to head (602fac2).
⚠️ Report is 43 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1512      +/-   ##
==========================================
+ Coverage   87.53%   87.58%   +0.04%     
==========================================
  Files         270      270              
  Lines       71309    71537     +228     
==========================================
+ Hits        62421    62653     +232     
+ Misses       8888     8884       -4     
Flag Coverage Δ
core 83.40% <ø> (+0.01%) ⬆️
rpc 83.40% <ø> (+0.01%) ⬆️
spv 95.02% <100.00%> (+0.04%) ⬆️
wallet 83.40% <ø> (+0.01%) ⬆️
Files with missing lines Coverage Δ
dash-spv/src/client/config.rs 82.38% <100.00%> (+0.57%) ⬆️
dash-spv/src/client/config_test.rs 100.00% <100.00%> (ø)
dash-spv/src/client/lifecycle.rs 93.68% <100.00%> (+0.06%) ⬆️
dash-spv/src/sync/mempool/manager.rs 98.14% <100.00%> (+0.03%) ⬆️
dash-spv/src/sync/mempool/sync_manager.rs 99.63% <100.00%> (+0.10%) ⬆️

... and 6 files with indirect coverage changes

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

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