Skip to content

A coin held only in claim_guarded_outputs is lost to the spender once it is recorded, so the new unsettled_spends fallback cannot resolve it on re-sight #1404

Open

Description

@manki-review

What goes wrong: Yes, a spender's input can be held in claim_guarded_outputs. When that spender is recorded, update_utxos removes the coin from claim_guarded_outputs and does not put it under unsettled_spends[txid]. When the same transaction is seen again (for example mempool then block), all four lookups miss, so sent is 0. An account whose only link to the transaction is that input then no longer matches it, and a record that does match is rebuilt with an understated sent.

.or_else(|| self.claim_guarded_outputs.get(&input.previous_output))
.or_else(|| {
spent_by_tx?.iter().find(|utxo| utxo.outpoint == input.previous_output)
})
{

How to fix it
Keep a claim-guarded coin under the spender's unsettled_spends entry in a way that a fork dropping the spend does not credit back, for example a separate map keyed by txid and used only for input matching. Alternatively, resolve inputs of an already recorded transaction from the stored record.

Checked in the code
On the flagged line: The lookup chain is utxos, spent_before_funded, claim_guarded_outputs, then unsettled_spends[tx.txid()]. After the first recording none of them holds t…

self.claim_guarded_outputs.insert(outpoint, output); shows a claim-guarded coin lives only in claim_guarded_outputs, not in utxos.

tracing::debug!(outpoint = %outpoint, "Skipping UTXO guarded by a spent-output claim");
self.claim_guarded_outputs.insert(outpoint, output);
return false;
}

The comment says Not kept under the spend, and the code runs self.claim_guarded_outputs.remove(&input.previous_output); without pushing the coin to unset…

}
// Not kept under the spend: a fork dropping it must not credit
// a coin that only a claim kept out of `utxos`.
self.claim_guarded_outputs.remove(&input.previous_output);

Only coins removed from utxos are pushed to unsettled_spends, so a claim-guarded coin never reaches the new fallback.

if let Some(spent) = self.utxos.remove(&input.previous_output) {
tracing::debug!(
outpoint = %input.previous_output,
txid = %tx.txid(),

Found by Manki in #1399 at key-wallet/src/transaction_checking/account_checker.rs:756. See the review.

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