Repository navigation
fix(key-wallet): credit again a swept loser's coins only it spent - #1519
PastaPastaPasta wants to merge 6 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]>
An empty result is now `TransactionCheckResult::default()`, for the checks that return early with nothing found. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A conflict sweep removes a loser that a locked or mined transaction beat, and an abandon removes a transaction the user gave up on, but nothing remembers either. Peers still hold them in their mempools, so a peer, or the mempool manager's replay, delivers them again as new arrivals, and the wallet credits them again. The wallet now keeps the txids it dropped this way, in memory, with abandons and sweeps capped separately so that sweeps, which anyone can cause with a locked double-spend, can't push out the user's abandons. Delivered again unconfirmed and unlocked, such a transaction is ignored, and so is a spend of one of its outputs. Mined or InstantSend-locked, it is real after all and applies as before. Spends of a dismissed transaction are held back in a third bounded set, because anyone can send them. A dismissal pushed out at capacity releases the spends it held back. A spend is held only while a transaction it spends is dismissed: a lock or block settling that transaction releases it, recursively, unless the wallet dismissed the spend in its own right. A released spend is still remembered so that its own lock has it fetched again. A spend of more than 16 dismissed transactions is held until it settles itself. A transaction the wallet already records is not held back. `WalletInfoInterface` gains `is_dismissed`, `refetch_on_lock`, `dismiss_spend` and `undismiss`, all defaulted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A transaction one wallet dismissed could still reach the others. The mempool replay passed it to a wallet registered later, a lock for it that arrived after its seen entry expired was ignored, and a locked spend fetched before its abandoned parent came back matched no wallet and was dropped, so the wallet kept offering change it held a verified spend of. - `WalletManager::process_mempool_transaction` ignores an unlocked transaction any wallet dismissed. An unlocked spend of one is held back in each wallet that dismissed what it spends, and reaches the other wallets only if each dismissed transaction it spends is held by some wallet. - A block clears the dismissal of each transaction it contains in every wallet, matched or not. - A validated lock for a txid a wallet dismissed, or held back as a spend, has it requested again. An unvalidated lock doesn't, so a peer can't use one to make the client request arbitrary transactions. The mempool manager now receives the `validated` flag of `InstantLockReceived` and records it with each pending and held lock. Only a validated lock keeps a spend or replays kept spends, and an unvalidated one is not passed to the wallet with a transaction that a wallet dismissed or that spends one, so it can't settle the dismissal. - The mempool manager keeps a locked transaction that matched no wallet but spends a dismissed transaction or a remembered spend of one, and one a wallet took in while another wallet dismissed what it spends, at most 1,000 for up to 24 hours. It passes it to the wallet again with its lock when a transaction it spends comes back: fetched with its lock, locked while held, or confirmed in a block. `WalletInterface` gains `is_dismissed`, `refetch_on_lock` and `spends_dismissed_elsewhere`, all defaulted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A conflict sweep removes a loser that a locked or mined transaction beat and frees the inputs only the loser spent, but the coins themselves were dropped when the loser took them. The wallet showed less than it held until a rescan delivered their funding again. The sweep now credits each freed coin again, with the confirmation and lock its funding transaction has now, but only while an account still holds the transaction that funded it: a fork or the same sweep may have removed it, and then the coin never existed. Outputs of transactions the sweep removed are left out of the released set. A credited coin is a watched outpoint again, so the monitor hash changes and a Bloom filter is rebuilt. 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 PR at
Fail-first: three branches each turn off the credit, the funding check, or the refreshed flags, and each fails the new tests. Gate on this head: fmt, clippy, doc, and the CI Left as is, listed in the description: the known gap with another device's spend of an abandoned coin, which a test pins. 🤖 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 #1519 +/- ##
==========================================
+ Coverage 87.53% 87.64% +0.10%
==========================================
Files 270 271 +1
Lines 71309 72489 +1180
==========================================
+ Hits 62421 63531 +1110
- Misses 8888 8958 +70
|
…ture Merges fix/pending-spend-authorization at 920f103 (built on #1416 at f134961). Conflict resolutions: - key-wallet-manager events.rs and process_block.rs: R9's wording for the drop trigger combined with #1507's `winner_block` field; R9's event test reads `winner_block: None`. - key-wallet helpers.rs: #1518/#1519's dismissal and give-back helpers and R9's authorization helpers are kept side by side; imports are merged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them. |
A conflict sweep removes a loser that a locked or mined transaction beat, and frees the inputs only the loser spent. But the coins themselves were dropped when the loser took them, so the wallet showed less than it held until a rescan delivered their funding again. A user whose payment lost a double-spend race saw the coins it didn't share with the winner disappear.
This builds on #1518 (dismissed transactions) and contains its commits and theirs; only the last commit is new here.
monitor_hashchanges and a Bloom filter is rebuilt.Known gap, pinned by a test: when another device on the same recovery phrase spends a coin that an abandoned payment also spent, and that payment then comes back locked and loses to a ChainLocked winner, the coin is reported as released although the other device's spend takes it. It isn't credited, since the loser took it as no coin, and the other spend settles it once mined.
Tests:
loser_sweep_credit_tests.rs:wallet_checker.rs: a swept loser's extra input is credited again, and counted once when its funding is delivered again.wallet_view_tests.rs: a ChainLocked conflict beating a locked spend gives back the change of a payment the wallet had abandoned.cargo fmt --all --check,contrib/run_clippy.py,cargo docwith-D warnings, and the CIwalletandspvgroups pass.🤖 Generated with Claude Code