Repository navigation
Description
What goes wrong: Yes, the spender's input can sit in claim_guarded_outputs, and the existing fallback at line 754 resolves it the first time the spender is processed. Recording the spender then removes the entry and does not park it under the spend (managed_core_funds_account.rs:541, comment: "Not kept under the spend"). When the same transaction arrives again (for example mempool then block, with no fork), the new unsettled_spends lookup has nothing for that input, so sent is 0 for it. A spender with a change output is then rebuilt as incoming with the wrong net amount, and one without change drops out of the account.
rust-dashcore/key-wallet/src/transaction_checking/account_checker.rs
Lines 746 to 750 in e360da1
| // Check inputs (sent) - rely on tracked UTXOs to determine spends | |
| if !tx.is_coin_base() { | |
| let spent_by_tx = self.unsettled_spends.get(&tx.txid()); | |
| for input in &tx.input { | |
| if let Some(utxo) = self |
How to fix it
Park claim-guarded inputs under the spender in a store that a fork does not credit back to utxos. Alternatively, resolve a re-seen transaction's inputs from its existing record's input_details. Add a test that delivers the spender of a claim-guarded coin via mempool and then via block.
Checked in the code
On the flagged line: The input fallback chain is utxos, spent_before_funded, claim_guarded_outputs, then spent_by_tx from unsettled_spends.get(&tx.txid()).
self.claim_guarded_outputs.remove(&input.previous_output); with no push into unsettled_spends.
rust-dashcore/key-wallet/src/managed_account/managed_core_funds_account.rs
Lines 540 to 544 in e360da1
| // a coin that only a claim kept out of `utxos`. | |
| self.claim_guarded_outputs.remove(&input.previous_output); | |
| if let Some(spent) = self.utxos.remove(&input.previous_output) { | |
| tracing::debug!( |
And 549: spent_before_funded and utxos entries are moved into unsettled_spends.entry(txid), but claim-guarded entries are not.
rust-dashcore/key-wallet/src/managed_account/managed_core_funds_account.rs
Lines 535 to 539 in e360da1
| // too, so a fork dropping this spend gives it back as well. | |
| if let Some(held) = self.spent_before_funded.remove(&input.previous_output) { | |
| self.unsettled_spends.entry(txid).or_default().push(held); | |
| } | |
| // Not kept under the spend: a fork dropping it must not credit |
keep_recorded_output_for_claim refills the entry only after truncate_above, and it returns early while spent_outpoints still holds the outpoint.
rust-dashcore/key-wallet/src/managed_account/managed_core_funds_account.rs
Lines 726 to 730 in e360da1
| // so the spend is still matched when it is mined again. | |
| for outpoint in spent_claims.keys() { | |
| self.keep_recorded_output_for_claim(outpoint); | |
| } | |
| if !restored.is_empty() { |
key-wallet/src/tests/spent_outpoints_tests.rs:550-590: The claim-then-spender tests deliver the spender once, so the re-delivery case is not covered.key-wallet/src/managed_account/managed_core_funds_account.rs:236-238:pub(crate) fn keep_recorded_output_for_claim(&mut self, outpoint: &OutPoint) {key-wallet/src/managed_account/managed_core_funds_account.rs:325-335:if self.is_outpoint_spent(&outpoint) {key-wallet/src/managed_account/managed_core_funds_account.rs:358-363:if spent_claims.is_some_and(|claims| claims.contains_key(&outpoint))
Double-checked
Manki tried to disprove this by reading the code and could not. Recording the spender removes the claim-guarded coin (line 541) without moving it into unsettled_spends, unlike lines 537 and 549. The claim-refill path return…
Found by Manki in #1399 at key-wallet/src/transaction_checking/account_checker.rs:748. See the review.
Activity