Repository navigation
Description
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.
rust-dashcore/key-wallet/src/transaction_checking/account_checker.rs
Lines 754 to 758 in c0111ef
| .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.
rust-dashcore/key-wallet/src/managed_account/managed_core_funds_account.rs
Lines 361 to 365 in c0111ef
| 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…
rust-dashcore/key-wallet/src/managed_account/managed_core_funds_account.rs
Lines 538 to 542 in c0111ef
| } | |
| // 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.
rust-dashcore/key-wallet/src/managed_account/managed_core_funds_account.rs
Lines 542 to 546 in c0111ef
| 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