Repository navigation
fix(dash-spv): look at the mempool again when the wallets change - #1516
PastaPastaPasta wants to merge 2 commits into
Conversation
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]>
The mempool manager decides once whether a transaction concerns the wallets. Three cases stayed wrong until the transaction confirmed: - A transaction one wallet matched that spends a coin another wallet's scan had not found yet was held, and never shown to that wallet. - A wallet registered after filter sync completed never saw payments already in the mempool, because with `FetchAll` nothing was requested again. - A lock that arrived before a transaction that then matched no wallet was dropped, and the InstantSend manager does not announce it again. When the mempool is looked at again (the first filter sync completion with `mempool_during_sync`, a wallet registered, and again once its scan reaches the tip), every held transaction is now passed to the wallet again with its lock, in batches that release the wallet between them. Then the txids found irrelevant are forgotten and every activated peer is asked for its mempool again. A wallet that already has a transaction changes nothing, and a held transaction no wallet holds any more, such as one swept because a conflicting spend settled, is dropped instead of replayed. A lock whose transaction matched nothing is kept for the retry, and a full pending-lock map drops its oldest entry, preferring one whose transaction was already found irrelevant, instead of the new lock. `WalletInterface` gains `wallet_set_revision` (default 0), which `WalletManager` bumps whenever a wallet is added or removed, so a wallet removed and restored in the same session counts too, and `holds_transaction` (default true). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
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. |
|
Pre-review record for head An independent automated code review read this commit twice: in full at Fixed after the first read (verdict then: requires changes):
Fixed after the second read:
After the fixes, the pending-lock tuple became a small private Fail-first: three branches that each remove part of the fix fail the new mempool unit tests, and the dashd test fails without the fix. Left as is, listed under limits in the description: no refresh when an account is added to an existing wallet, held-child replay ordering, the refresh staying armed while a wallet is stuck behind, a dropped loser re-fetched from a lagging peer, and unverified locks on 🤖 Posted autonomously by Claude (claude-opus-5-5) on behalf of pasta. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## dev #1516 +/- ##
==========================================
+ Coverage 87.53% 87.59% +0.05%
==========================================
Files 270 270
Lines 71309 71845 +536
==========================================
+ Hits 62421 62933 +512
- Misses 8888 8912 +24
|
|
This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them. |
The mempool manager decides only once whether a transaction concerns the wallets, so three cases stay wrong until the transaction confirms:
FetchAllnothing is requested again, and peers don't announce a transaction twice.This builds on #1512 (
mempool_during_sync) and contains its commit; only the last commit is new here.The mempool is now looked at again at three points: the first filter sync completion with
mempool_during_syncon, a tick on which the set of wallets has changed, and once the scan of a wallet that was new, or behind at the first completion, reaches the tip. Each time:BloomFilterthe filter is reloaded first. The monitor-hash shortcut is skipped on these refreshes, because a new wallet's scan can finish without changing the hash.A lock whose transaction matched nothing goes back to the pending map, marked as such, where the retry finds it. When that map is full, the oldest marked lock goes first, then the oldest of the rest, never the new lock.
WalletInterfacegains two defaulted methods:wallet_set_revision()defaults to 0, which means "never changes".WalletManagerbumps it whenever a wallet is added or removed, so a wallet removed and restored from the same recovery phrase in one session is looked at again.holds_transaction(txid)defaults to true.WalletManagerchecks whether any account of any wallet records the txid.Limits, left as follow-ups:
wallet_set_revision, so it doesn't trigger a refresh.synced_height()is the minimum over wallets, so a wallet stuck behind keeps the after-scan refresh armed. A removed wallet also triggers one refresh. UnderFetchAll, each refresh downloads the peers' mempools again, twice per registered wallet.devthe mempool manager still gets unverified locks; fix(dash-spv): defer unverified InstantLocks #1336 stops that.holds_transactionasks whether any wallet records the txid. If the only wallet that matched a held transaction is removed, the transaction is dropped, even if another wallet's scan would later find a coin it spends.Tests:
manager.rsandsync_manager.rscover:wallet_view_tests.rsdrives a realWalletManager:test_wallet_registered_after_sync_detects_a_payment_already_in_the_mempoolruns against dashd under both strategies. It pays a wallet that isn't registered yet, waits, then registers the wallet and checks that both clients detect the payment. Without the fix it fails.cargo fmt --all --check,contrib/run_clippy.pyandcargo docwith-D warningspass, as do the CIwalletandspvgroups.🤖 Generated with Claude Code