Repository navigation
Description
TL;DR: Since #1326, a funds account keeps a FinalizedSummary (owned outputs and input_details) for each record
that ChainLock finality evicts, but only inside the crate. A consumer that needs to know "was this coin of mine spent
by a transaction no reorg can undo?" still cannot ask key-wallet, and has to rebuild the answer by watching records
before they are evicted.
Who needs it
dashpay/platform's rs-platform-wallet reconciles a host app's TXO store against the engine (dashpay/platform#5796).
A stored coin is marked spent only when its spender is ChainLocked, because a write based on a spender a fork could
drop would retire a live coin for good. To know that, it keeps its own finalized_spends set, filled by intercepting
the wallet before key-wallet evicts:
- in
apply_chain_lock, the owned inputs of every in-block record at or below the lock height, before delegating; - in
check_core_transaction, the owned inputs of new and updated records whose own context is ChainLocked,
including records handed back by late-input attribution; - a compile-time
cfg!(not(feature = "keep-finalized-transactions"))standing in for "key-wallet evicts". That is
wrong if another crate enableskey-wallet/keep-finalized-transactionsdirectly, through Cargo feature
unification.
This ties platform-wallet to key-wallet's promotion and eviction paths, the record slices it returns, and its
late-input attribution. A missed path leaves a coin Unknown (safe, but never repaired); a misread one could mark a
live coin spent.
What key-wallet has today (dev 451c6cc)
ManagedCoreKeysAccount::drop_finalized_transactionstoresFinalizedSummary::of(&record)in
finalized_summarieswhen a record is evicted;FinalizedSummarykeepsinput_details. Both arepub(crate).- The summary's outputs are updated later (
adopt_finalized_outputs, a rescan that finds more owned outputs). I
found no path that adds an input to a summary when the coin it spent is funded late, so a spender finalized
before its funding arrives would still be missing that input. is_outpoint_spenton the funds account ispub(crate), per account, and does not say whether the spender is
final.- With
keep-finalized-transactionson, records stay and there are no summaries; nothing public tells a consumer
which mode the crate was compiled in.
Ask
- A public, finality-aware query on the wallet (or each funds account), for example
finalized_spender_of(&OutPoint) -> Option<Txid>, answered from retained records in the
keep-finalized-transactionsbuild and fromfinalized_summariesotherwise, so the answer doesn't depend on the
feature. - Keep it complete on every path that finalizes a spend: ChainLock promotion, a transaction first seen in a
ChainLocked block, and funding that arrives after its spender was finalized (add the input to the summary).
With that, platform-wallet drops finalized_spends, both interceptions and the feature constant.
Related
#1303: re-delivery reaches only accounts that are still relevant, so an account whose only part in a transaction was
the coin it spent keeps its record in Mempool after the transaction is mined or ChainLocked. #1303 shows it for an
asset lock with no change. By the same root cause an ordinary payment whose change goes to another account of the
same wallet should leave the paying account's record unpromoted too (not tested). The query above has to answer for
that account's coins whether or not #1303 is fixed first.
Raised by thepastaclaw on dashpay/platform#5796 (packages/rs-platform-wallet/src/wallet/platform_wallet_traits.rs,
lines 296 and 319).
Activity