Skip to content

key-wallet: restored spends cannot follow a fork of their block (restore observed spends with height) #1435

Open

Description

@Claudius-Maginificent

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_outpoints gives the coin a claim. That claim is released only by sweep_conflicts or abandon_transaction removing its claimant, and a claim of None is 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:

Detailed discussion

🤖 Co-authored by Claudius the Magnificent AI Agent

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions