Repository navigation
feat(key-wallet)!: dismissed transactions stay out until settled - #1518
PastaPastaPasta wants to merge 7 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]>
|
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 four times. The first three reads required changes. The fourth read covered the fixes made after the third, at Fixed after the first two reads:
Fixed after the third read:
Fixed after the fourth read:
Fail-first: five branches each turn off one part of the fix, and each fails the new tests. The parts are the wallet's check, the manager and mempool hooks, the spend gate, the lock-validation checks, and the recheck after an eviction. Gate on this head: fmt, clippy, doc, and the CI Left as is, listed in the description:
🤖 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 #1518 +/- ##
==========================================
+ Coverage 87.53% 87.81% +0.27%
==========================================
Files 270 271 +1
Lines 71309 73316 +2007
==========================================
+ Hits 62421 64383 +1962
- Misses 8888 8933 +45
|
…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]>
The rebroadcast timer kept resending our own broadcasts every 10 minutes for up to a day after the wallet abandoned them or swept them as beaten by a locked or mined conflict. Peers were handed again bytes the wallet treats as dead. `rebroadcast_if_due` now skips any tracked broadcast that a wallet reports as dismissed. The entry stays tracked, so a late lock or confirmation still reports the outcome, and resends pick up again if the dismissal ends. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…first seen in a block A validated InstantSend lock that arrived before its transaction was kept as pending, and a block confirming the transaction dropped it without telling the wallet. A lock that arrived after the block was kept the same way. Either way the wallet never recorded the lock, so a short fork dropping a block without a ChainLock also dropped the locked transaction and gave its inputs back as spendable. - On `BlockProcessed`, a validated pending lock for a confirmed txid is passed to the wallet through `process_instant_send_lock` before the pending entry is removed. - A validated lock that comes after a block confirmed its txid, for a transaction the mempool doesn't hold, is passed the same way. The manager remembers the txids blocks confirmed, pruned with the mempool. A lock for a transaction a wallet holds only unconfirmed still waits for the transaction: passed lock-only it would sweep conflicts without `TransactionsSwept`. Only validated locks are passed, and only for a transaction `holds_transaction` reports, so a peer can't use locks to grow the wallet's lock set. `truncate_above` then keeps the transaction as unconfirmed with its inputs spent. Refs #763. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
This pull request is a draft, so Manki does not review it automatically. Marking it ready for review starts automatic reviews. Until then, someone with write access to this repository can tick a box below: Review this draft reviews the current commit once, Deeper review does so with more effort, and Review every push reviews it now and again after each push. Not reviewed yet · head
|
|
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 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 replay when the wallets change, delivers them again as new arrivals and the wallet credits them again. The same goes for a spend of one of their outputs. A user who abandons a stuck payment sees it come back with its change. A wallet registered later is credited a payment another wallet dropped as dead.
This builds on #1512 and #1516, and contains their commits. The last three commits are new here; the first of them only derives
DefaultforTransactionCheckResult.key-wallet: the wallet keeps the txids it dropped as dead, in memory, with abandons and sweeps capped separately. Anyone can cause a sweep with a locked double-spend, so sweeps can't push out the user's abandons.
key-wallet-manager and dash-spv: a dismissal applies across the wallets of a manager.
WalletManager::process_mempool_transactionignores 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, so a wallet's own spend of a payment another wallet abandoned still counts.validatedflag ofInstantLockReceivedand records it with each pending and held lock. An unvalidated lock doesn't trigger this, nor keep a spend or pass kept spends again, so a peer can't use one to make the client request arbitrary transactions.New trait methods, all defaulted, so other implementations are unaffected:
WalletInfoInterface:is_dismissed,refetch_on_lock,dismiss_spend,undismiss.WalletInterface:is_dismissed,refetch_on_lock,spends_dismissed_elsewhere.Dismissals are in memory only, like
instant_send_locks. After a restart, a host that persists abandons must abandon again.On
dev, the mempool manager still receives locks that are not validated yet, for example before quorum data is known. Such a lock is not passed to the wallet with a transaction a wallet dismissed, or with a spend of one, whether the transaction arrives, is replayed or is already held: the transaction is treated as unlocked until the lock is validated, and then fetched again. Other transactions still get unvalidated locks as before; #1336 stops dash-spv from emitting them. #1336 stops dash-spv from emitting unvalidated locks at all, which closes it.dash-spv, two more fixes on the same paths:
truncate_abovethen keeps the transaction as unconfirmed with its inputs spent after a short fork (Found-021:TransactionRecord::update_contextsilently dropsInstantLockonInBlock/InChainLockedBlockpromotion #763). This applies only to transactions a wallet holds, and only to txids a block confirmed. A lock for a record a wallet holds only unconfirmed still waits for the transaction, so the full check emitsTransactionsSwept.Not in this PR: crediting again the other coins of a swept loser that only the loser spent. That comes in a follow-up.
Tests:
dismissed.rs: abandons are capped oldest first; a spend whose only held parent it pushes out is not held; sweeps don't push out an abandon; spends don't push out own dismissals; a dismissal pushed out releases its held spends; settling releases spends recursively but not an explicit abandon; a spend of many dismissed transactions is pinned until it settles.wallet_checker.rs: a loser a locked winner swept isn't credited when delivered again, nor a spend of it; an abandoned transaction delivered again counts only once mined.manager.rs: kept locked spends are capped oldest first and expire with the mempool timeout.wallet_view_tests.rs, against a realWalletManager:wallet_view_tests.rs, rebroadcast and locks:holds_transactionchecks fails exactly these tests.cargo fmt --all --check,contrib/run_clippy.py,cargo docwith-D warnings, and the CIwalletandspvgroups pass.🤖 Generated with Claude Code