Skip to content

feat(key-wallet)!: dismissed transactions stay out until settled - #1518

Draft
PastaPastaPasta wants to merge 7 commits into
devfrom
feat/dismissed-transactions
Draft

PastaPastaPasta wants to merge 7 commits into
devfrom
feat/dismissed-transactions

Conversation

@PastaPastaPasta

@PastaPastaPasta PastaPastaPasta commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

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 Default for TransactionCheckResult.

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.

  • 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, since 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, and recursively the spends held only through it, unless the wallet dismissed the spend in its own right. A spend of more than 16 dismissed transactions is held until it settles itself.
  • A released spend is still remembered, so its own verified lock has it fetched again.

key-wallet-manager and dash-spv: a dismissal applies across the wallets of a manager.

  • 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, so a wallet's own spend of a payment another wallet abandoned still counts.
  • A block clears the dismissal of each transaction in it, in every wallet, matched or not.
  • A validated InstantSend lock for a txid a wallet dismissed or holds back has it requested again, however long ago it was seen. The mempool manager now receives the validated flag of InstantLockReceived and 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.
  • The mempool manager keeps a locked transaction that spends a dismissed transaction, or a remembered spend of one, while it matters: when it matched no wallet, or when a wallet took it in while another wallet dismissed what it spends. It keeps at most 1,000, for up to 24 hours. It passes each one 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. Without this, the wallet that abandoned the parent would offer change that a verified spend already took.

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:

  • The rebroadcast timer no longer resends a tracked broadcast that a wallet dismissed, whether abandoned, swept as beaten, or held back as a spend of one. The entry stays tracked, so a late lock or confirmation still reports the outcome.
  • A validated InstantSend lock now reaches the wallet when its transaction is first seen in a block. That covers a lock that came before the block, which used to be dropped as pending when the block confirmed the tx, and one that comes after it. truncate_above then keeps the transaction as unconfirmed with its inputs spent after a short fork (Found-021: TransactionRecord::update_context silently drops InstantLock on InBlock/InChainLockedBlock promotion #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 emits TransactionsSwept.

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 real WalletManager:
    • the replay brings back neither a beaten nor an abandoned payment, and doesn't hand a new wallet a payment another wallet abandoned while a third still holds it;
    • an unvalidated lock doesn't fetch a dismissed transaction again, nor bring it back when a peer sends it;
    • a spend seen with an unvalidated lock is held back, then fetched again and kept once the lock is validated;
    • a held spend of a dismissed payment takes its lock once the lock is validated;
    • an unlocked spend of a swept parent and a parent another wallet holds reaches no wallet;
    • a spend of a payment one wallet abandoned reaches the wallet that holds that payment;
    • an abandoned spend settled by a lock is fetched again and credited;
    • a wallet registered after an abandon gets the payment only once a lock or block settles it;
    • spends of an abandoned payment come back once it settles, and don't push out the abandon;
    • a locked spend fetched before its abandoned parent comes back is credited once the parent returns by its lock, by a lock while held, or in a block;
    • an abandoned spend stays out when its parent settles;
    • a locked spend that pays another wallet keeps the abandoned change spent;
    • a block mining a dismissed transaction ends the dismissal in every wallet;
    • a wallet restored in the same session is passed a held locked spend of its change again.
  • Fail-first: turning off the wallet's check, the manager and mempool hooks, the spend gate, the lock-validation checks, or the recheck after an eviction, fails these tests.
  • wallet_view_tests.rs, rebroadcast and locks:
    • an abandoned and a swept broadcast are not resent, and a kept one is;
    • a payment first seen in a block keeps its validated lock across a short fork, whether the lock came before or after the block; an unvalidated lock doesn't keep it;
    • a lock for an unconfirmed record the mempool doesn't hold waits for the transaction;
    • a lock for a transaction no wallet holds isn't recorded.
  • Fail-first: dropping the dismissed filter, the confirm-time pass, the after-block pass, the confirmed-txid gate, or the holds_transaction checks fails exactly these tests.
  • cargo fmt --all --check, contrib/run_clippy.py, cargo doc with -D warnings, and the CI wallet and spv groups pass.

🤖 Generated with Claude Code

PastaPastaPasta and others added 5 commits November 24, 2026 23:13
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]>
@coderabbitai

coderabbitai Bot commented Nov 25, 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 changed the title feat(key-wallet)!: an abandoned or swept transaction stays out until a lock or block settles it feat(key-wallet)!: dismissed transactions stay out until settled Nov 25, 2026
@PastaPastaPasta

PastaPastaPasta commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Pre-review record for head 51c7c82a140120345b2953e22117c6a300c9b2bc, the last of the three commits after #1516's head 4684f18057.

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 c6d41f9cf9. Verdict on the fourth read: approved with suggestions. This head adds three of those suggestions.

Fixed after the first two reads:

  • An unvalidated lock had a dismissed transaction requested again. Only a validated lock does now, and the mempool manager records validated with each pending lock.
  • Abandons, sweeps and held spends are capped separately, so sweeps, which anyone can cause, can't push out the user's abandons. A dismissal pushed out releases the spends it held back.
  • An unlocked spend of a dismissed transaction reached the other wallets if any one of its parents was held. Now each dismissed parent must be held by some wallet.
  • A transaction the wallet already records is not held back as a spend, and a held spend is evicted before its parents are rechecked.

Fixed after the third read:

  • A lock not yet validated still reached the wallet with its transaction. A forged one could bring a dismissed transaction back. A genuine one that hadn't been validated yet let a spend of a dismissed parent skip the hold-back, and the spend was lost once the lock was validated. Such a lock is now withheld from a transaction that is dismissed or spends one: when it arrives, when it is replayed, and when it is already held.
  • An expiry test went back 24 hours on Instant, which panics on a Windows runner that has been up for less time. It now uses a short timeout.

Fixed after the fourth read:

  • A lock not yet validated no longer replaces a validated one for a held transaction.
  • Two doc comments that the change made untrue were corrected.
  • A test now covers a held spend that receives its lock once the lock is validated.

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 wallet and spv groups pass.

Left as is, listed in the description:


🤖 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

❌ Patch coverage is 95.62706% with 53 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.81%. Comparing base (6e15db8) to head (af62a25).
⚠️ Report is 43 commits behind head on dev.

Files with missing lines Patch % Lines
key-wallet-manager/src/wallet_interface.rs 0.00% 15 Missing ⚠️
...allet/managed_wallet_info/wallet_info_interface.rs 40.90% 13 Missing ⚠️
key-wallet-manager/src/process_block.rs 60.00% 12 Missing ⚠️
dash-spv/src/sync/mempool/manager.rs 98.24% 8 Missing ⚠️
key-wallet-manager/src/lib.rs 71.42% 2 Missing ⚠️
...wallet/src/wallet/managed_wallet_info/dismissed.rs 99.10% 2 Missing ⚠️
key-wallet/src/wallet/managed_wallet_info/mod.rs 66.66% 1 Missing ⚠️
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     
Flag Coverage Δ
core 83.42% <89.86%> (+0.03%) ⬆️
rpc 83.42% <89.86%> (+0.03%) ⬆️
spv 95.31% <98.95%> (+0.33%) ⬆️
wallet 83.42% <89.86%> (+0.03%) ⬆️
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/sync_manager.rs 99.67% <100.00%> (+0.14%) ⬆️
key-wallet-manager/src/accessors.rs 63.03% <100.00%> (+0.45%) ⬆️
...wallet/src/transaction_checking/account_checker.rs 66.92% <100.00%> (-0.44%) ⬇️
...-wallet/src/transaction_checking/wallet_checker.rs 98.72% <100.00%> (+0.04%) ⬆️
...y-wallet/src/wallet/managed_wallet_info/helpers.rs 75.76% <100.00%> (+0.94%) ⬆️
key-wallet/src/wallet/managed_wallet_info/mod.rs 78.27% <66.66%> (-0.12%) ⬇️
key-wallet-manager/src/lib.rs 73.23% <71.42%> (-0.04%) ⬇️
... and 5 more

... and 14 files with indirect coverage changes

PastaPastaPasta added a commit that referenced this pull request Nov 25, 2026
…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]>
PastaPastaPasta and others added 2 commits November 27, 2026 20:05
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]>
@manki-review

manki-review Bot commented Nov 27, 2026

Copy link
Copy Markdown

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 af62a25 · draft, not reviewed automatically

  • Deeper review
  • Review this draft
  • Review every push

@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