Skip to content

feat(key-wallet-manager)!: report dismissal changes for persistence - #1522

Draft
PastaPastaPasta wants to merge 10 commits into
devfrom
feat/dismissal-changes
Draft

PastaPastaPasta wants to merge 10 commits into
devfrom
feat/dismissal-changes

Conversation

@PastaPastaPasta

@PastaPastaPasta PastaPastaPasta commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

A wallet holds the transactions it dropped as dead (swept losers, abandoned payments) in memory only. After a restart, a peer that delivers one of them again unlocked has it counted again. This PR lets a host persist those dismissals and hand them back on load.

This builds on #1520 and contains the commits of #1512, #1516, #1518, #1519 and #1520; only the last commit is new here.

  • DismissalChange in key-wallet records each change to the wallet's own dismissals, in order:

    • Dismissed(txid): a locked or mined conflict beat it;
    • Abandoned(txid): the user abandoned it;
    • Forgotten(txid): it was locked or mined, or pushed out at capacity.

    Abandons and sweeps keep separate caps, as in feat(key-wallet)!: dismissed transactions stay out until settled #1518, and a persister mirrors each set with the same cap. So joining either set is a change even when the other holds the transaction, and a push-out from one set while the other still holds it is no change, since the persister's set pushes it out too. Held-back spends are not recorded: a delivery after a restart holds them back again.

  • ManagedWalletInfo::restore_dismissed(abandoned, swept) takes back what a persister kept, each kind in the order first reported, under the same caps.

  • WalletEvent::DismissalsChanged { wallet_id, changes }. WalletManager sends the changes not yet taken right ahead of the wallet's next event, so a persister stores them in the same write as their cause.

    • A sweep's Dismissed waits for its TransactionsSwept.
    • abandon_transaction sends its changes itself, since no other event reports an abandon.
    • In apply_chain_lock, each sweep's changes go with its own TransactionsSwept.
  • A sweep no event reports drops its dismissals. That covers a lock-only sweep in process_instant_send_lock, and check_transaction_in_all_wallets. The loser's record stays stored then, and the next load sweeps it again, so nothing waits forever.

  • WalletInfoInterface gains take_dismissal_changes, dismissal_pending and drop_unreported_dismissals, all defaulted. A wrapper type that delegates to ManagedWalletInfo must forward all three together.

Breaking: WalletEvent gains a variant (it is not #[non_exhaustive]), and the private emit_event takes &mut self.

Limits:

  • Order across kinds is not in the stream. A persister keeps the order each txid was first reported in.
  • Changes accumulate until taken when ManagedWalletInfo is used without WalletManager.

Tests:

  • dismissed.rs:
    • changes are kept in order until taken;
    • each set a transaction joins is a change, and a push-out from one set while the other holds it is not;
    • a sweep of an abandoned transaction is Dismissed, and its push-out from the sweeps while abandoned is no change;
    • a transaction in both sets is forgotten once pushed out of the second, and a restore doesn't forget one its swept list keeps;
    • a store applying the changes in order, set by set with the same caps, holds the same sets over a long mixed run;
    • a push-out at capacity is forgotten, also by a restore;
    • only a sweep's dismissal waits for its report.
  • event_tests.rs:
    • the dismissal goes right ahead of its sweep, from a block and from an InstantSend-locked mempool winner;
    • a lock-only sweep sends no dismissal and holds back no later change;
    • an abandon is sent at once and forgotten ahead of the block that mines it.
  • Fail-first: without the event, the drop after a lock-only sweep, the Abandoned kind, the sweep of an abandoned transaction, a push-out from one set while the other holds it, deciding a restore's push-outs before both lists are back, or the abandon's own send, these tests fail.
  • 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 8 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]>
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]>
A plain block can't overturn an InstantSend-locked record, so a locked record that a block transaction conflicts with stays until a ChainLock covers that block. Nothing then swept it: the ChainLock applied, but the conflicting transaction was no longer at hand. And a wallet the block wasn't fetched for, because the block holds none of its scripts, never saw the conflict at all. Its locked or pending record kept the coins it spends marked spent, and its change stayed offered.

- A block transaction that spends an input of an unconfirmed record in a wallet the block wasn't fetched for sweeps that wallet by the same rule. Nothing of the transaction is recorded there. Each wallet's unconfirmed spends are collected once per block.
- A block transaction that conflicts with another transaction's unconfirmed record, swept with a context that isn't ChainLocked, is kept until a ChainLock covers its block; then every wallet sweeps with it. At most 1,000 are kept, the lowest block going first. A reorg below its block drops it, after every wallet's truncation.
- Behind a ChainLocked winner the sweep also follows a loser's InstantSend-locked descendants: nothing built on a transaction a ChainLock beat can exist. A record whose txid the wallet holds a lock for counts as locked, also after a fork reset its context.
- A transaction a ChainLocked conflict overturned in any wallet is remembered for the session, at most 1,000, and refused when it arrives again, locked or not. So is every other unconfirmed spend a kept conflict beat, once its ChainLock lands, even if a plain block already swept it. Only its own txid is refused.
- `WalletManager` reports and clears the conflicts it keeps, for a reset of the chain data.

Both sets are in memory: a restart between a block and its ChainLock loses what was kept, and the locked record then stays. Each cap can be filled by someone who gets many conflicting transactions mined, which pushes out the oldest entries.

`WalletInfoInterface` gains `unconfirmed_spent_outpoints` and `sweep_conflicts_only`, both defaulted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A wallet holds the transactions it dropped as dead only in memory. After a restart, a peer that delivers one of them again has it counted again.

- key-wallet records each change to the wallet's own dismissals as a `DismissalChange`:
  - a swept loser is `Dismissed`;
  - an abandon is `Abandoned`;
  - a transaction locked, mined or pushed out at capacity is `Forgotten`;
  - one pushed out of the abandons while still swept is `Dismissed` again, since each kind keeps its own cap.
- `restore_dismissed` takes back a persisted set, each kind oldest first.
- `WalletManager` sends the changes not yet taken as `WalletEvent::DismissalsChanged`, right ahead of the wallet's next event, so a persister stores them in the same write as their cause.
  - A sweep's dismissal waits for its `TransactionsSwept`.
  - `abandon_transaction` sends its changes itself.
- A sweep that no event reports drops its dismissals. That covers a lock-only sweep and `check_transaction_in_all_wallets`. The loser's record stays stored, and the next load sweeps it again.

`WalletEvent` gains a variant, and `emit_event` takes `&mut self`.

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

manki-review Bot commented Nov 25, 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 c1e3ac2 · draft, not reviewed automatically

  • Deeper review
  • Review this draft
  • Review every push

@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 commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Pre-review record for head b5698ba08926477af10c45c9dd22829b7f79e45d, the last commit after #1520's head 521fd64418.

An independent automated code review read this PR at c02e13131a. Verdict: approved with suggestions. It traced every transition of the two capped sets against what a persister derives from the change stream, kind included, and every path that sweeps: block, unfetched-wallet sweep, mempool, chain lock and lock-only. It found no corrupted stored state and no path in normal SPV operation that blocks the changes for good.

Fixed in this head:

  • An abandon's change used to wait for the wallet's next event, so a crash in between lost it. abandon_transaction now sends it at once.
  • check_transaction_in_all_wallets sweeps but sends no event, which left a sweep's change pending and held back every later one. It now drops what its sweeps dismissed.
  • In apply_chain_lock, each TransactionsSwept used to carry the dismissals of every sweep the lock made. Each now carries only its own.
  • The lock-only test now also shows that nothing is held back afterwards.
  • New tests: a block sweep sends its dismissal right ahead of TransactionsSwept, and a swept transaction pushed out while abandoned is no change.
  • The kind test builds its state with live calls.
  • settled no longer relies on a non-short-circuit |.
  • The pending flag is a named struct field.
  • The trait methods don't duplicate public inherent methods.
  • The docs say when the event is sent and what restore_dismissed takes back.

Left as is, listed in the description:

  • a transaction both swept and abandoned is stored as abandoned only;
  • order across kinds is not in the stream;
  • changes accumulate until taken when ManagedWalletInfo is used without WalletManager;
  • a wrapper type must forward the three new trait methods together.

Fail-first: five branches each turn off one part, and each fails the new tests. The parts are the event, the drop after a lock-only sweep, the Abandoned kind, the kind change on a push-out, and the abandon's own send.

Gate on this head: fmt, clippy, doc, and the CI wallet and spv groups pass.

Update for head c1e3ac24e33fdff6bbe22af420cfdba9e9603186 (two commits after b5698ba089): a persister now mirrors the abandoned and swept sets one by one, with the same caps. A sweep of an abandoned transaction is Dismissed. A push-out from one set while the other still holds the transaction is no change.

An independent automated code review read fcdfeb3fb4. Verdict: approved with suggestions. Fixed in c1e3ac24e3:

  • The restore_dismissed doc described one kind per txid. It now says a txid may be in both lists.
  • A restore judged a push-out from the abandoned list before the swept list was back, so it could forget a transaction that list kept. Both lists now go in first.
  • The pushed_out doc said spends were always released. Restored "if it is no longer dismissed".
  • New tests: a transaction in both sets is forgotten once pushed out of the second; a restore keeps one its swept list holds; a store applying the changes in order, with the same caps, holds the same sets over a long mixed run.

Fail-first on c1e3ac24e3: the old sweep condition, the old push-out rule, and the old restore order each fail the new tests. Gate on this head: fmt, clippy, doc, and the CI wallet and spv groups pass.


🤖 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 94.24939% with 95 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.79%. Comparing base (6e15db8) to head (c1e3ac2).
⚠️ Report is 18 commits behind head on dev.

Files with missing lines Patch % Lines
...allet/managed_wallet_info/wallet_info_interface.rs 57.14% 30 Missing ⚠️
key-wallet-manager/src/process_block.rs 78.18% 24 Missing ⚠️
key-wallet-manager/src/wallet_interface.rs 0.00% 15 Missing ⚠️
key-wallet/src/wallet/managed_wallet_info/mod.rs 20.00% 8 Missing ⚠️
dash-spv/src/sync/mempool/manager.rs 98.27% 7 Missing ⚠️
key-wallet-manager/src/lib.rs 93.85% 7 Missing ⚠️
key-wallet-manager/src/events.rs 33.33% 2 Missing ⚠️
...wallet/src/wallet/managed_wallet_info/dismissed.rs 99.50% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1522      +/-   ##
==========================================
+ Coverage   87.53%   87.79%   +0.25%     
==========================================
  Files         270      271       +1     
  Lines       71309    73276    +1967     
==========================================
+ Hits        62421    64329    +1908     
- Misses       8888     8947      +59     
Flag Coverage Δ
core 83.58% <90.57%> (+0.19%) ⬆️
rpc 83.58% <90.57%> (+0.19%) ⬆️
spv 95.18% <99.02%> (+0.19%) ⬆️
wallet 83.58% <90.57%> (+0.19%) ⬆️
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/filters/manager.rs 97.93% <ø> (ø)
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%) ⬆️
.../src/managed_account/managed_core_funds_account.rs 89.82% <100.00%> (+0.05%) ⬆️
...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 78.27% <100.00%> (+3.45%) ⬆️
... and 8 more

... and 11 files with indirect coverage changes

PastaPastaPasta added a commit that referenced this pull request Nov 25, 2026
…persistence

The events.rs imports combine #1507's BlockInfo with #1522's DismissalChange.
PastaPastaPasta added a commit to dashpay/platform that referenced this pull request Nov 25, 2026
The pin adds rust-dashcore's DismissalsChanged wallet event (dashpay/rust-dashcore#1522) and the pending-spend authorization check (dashpay/rust-dashcore#1523). Platform's matches over wallet events treat DismissalsChanged as an event that carries no records, spends, balance or payment evidence, and the changeset adapter stores nothing for it yet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
PastaPastaPasta and others added 2 commits November 25, 2026 11:22
A persister mirroring the abandoned and swept sets could not keep them in step: a sweep of a transaction the user had abandoned recorded no change, and an abandon pushed out at capacity while the transaction was still swept was reported as Dismissed. A sweep now records Dismissed whenever the transaction joins the swept set, and a push-out from one set records nothing while the other set still holds the transaction, since a persister with the same caps pushes it out too. Forgotten still means the transaction left both sets.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…h-out

A restore replayed the abandoned list first and decided on each push-out before the swept list was back, so a transaction the swept list kept was reported forgotten. Both lists now go in before any push-out is judged. The restore_dismissed doc now says a txid may be in both lists, and a test applies the changes to a store with the same caps and checks it holds the same sets.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
PastaPastaPasta added a commit that referenced this pull request Nov 25, 2026
PastaPastaPasta added a commit to dashpay/platform that referenced this pull request Nov 25, 2026
Takes rust-dashcore's pending-spend authorization (dashpay/rust-dashcore#1523 at 8d7f9b22ca): a pending spend of a held coin is ignored unless it may carry the owner's authorization. Test fixtures sign their pending spends again with key_wallet::test_utils::sign_owned_inputs. The pin also carries the per-set dismissal reports of dashpay/rust-dashcore#1522.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the merge-conflict The PR conflicts with the target branch. label Nov 27, 2026
@github-actions

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