Repository navigation
Description
TL;DR: A wallet restored from stored history cannot give back a coin when a chain fork removes the transaction that spent it, if the wallet has no record of how the coin was funded.
User story
As a developer of a wallet built on key-wallet that restores spent coins from its own storage, I want a restored spend in a block that is not final yet to follow the chain: released when a fork drops its block, permanent once that block is final, so that the balance stays right across forks without the coin ever being counted twice.
Scenario
Base flow
A host stores which coins its wallet already spent and restores them at load with ManagedWalletInfo::restore_spent_outpoints. One restored coin was spent by a transaction in a block above the last ChainLock, and the host has no stored record of the transaction that funded the coin.
Actual behavior
restore_spent_outpointsgives the coin a claim. That claim is released only bysweep_conflictsorabandon_transactionremoving its claimant, and a claim ofNoneis never released.- If a fork drops the spending block and the spend never confirms again, the coin stays spent in the wallet, and the balance under-reports.
- The host cannot use the observed-spend set instead.
observed_spent_outpoints(bug: out-of-order block processing causes SPV wallet to miss UTXO spends #649) has a read accessor but no way to restore entries, and its entries are pruned below the ChainLock. A host-seeded entry would therefore lose its guard at finality, and a later delivery of the funding would credit the coin again.
Expected behavior
An API, for example ManagedWalletInfo::restore_observed_spends(&[(OutPoint, Txid, CoreBlockHeight)]), restores a spend together with the height of the block that holds it:
- while that height is above the ChainLock, a fork that drops the block releases the coin, through the same path dash-spv: build a reorg/disconnect pipeline so key-wallet can retract non-chainlocked observed-spent entries #854 builds for observed spends;
- once a ChainLock covers that height, the entry becomes a permanent claim instead of being pruned, so a late funding delivery is never credited.
Detailed discussion
- Consumer: fix(platform-wallet)!: replay recorded transaction history on load for every persister platform#5220 restores stored history on load (
rs-platform-wallet/src/manager/history_repair.rs,TODO(restore-observed-spends)). When the funding transaction and the spend are both in the replayed history, the account records the spend itself and a fork releases it. When the funding is missing, the platform keeps a plain claim, because dropping the claim would let the funding be credited again after finality. That is the known limitation this API would close. - Pinned at
6f206d48, the public surface isrestore_spent_outpoints(claims that survive ChainLock pruning, released only by sweep or abandon) and the read-onlyobserved_spent_outpoints(). - Related: dash-spv: build a reorg/disconnect pipeline so key-wallet can retract non-chainlocked observed-spent entries #854 (reorg/disconnect pipeline that retracts non-chain-locked observed spends) and Proposal: Persist versioned wallet snapshots as the SPV source of truth #1196 (versioned wallet snapshots). If Proposal: Persist versioned wallet snapshots as the SPV source of truth #1196 lands, restoring this state may come from the snapshot instead of a new API; this issue then reduces to making sure the snapshot keeps the spend's height and finality.
🤖 Co-authored by Claudius the Magnificent AI Agent
Activity