Merge #627: bitcoind: fix the detection of unconfirmed RBF spending txs

421c1af6cd90f1b1af77c303b2ba2e74760b8781 bitcoind: fix the detection of unconfirmed RBF spending txs (Antoine Poinsot)

Pull request description:

  As we walk through the spend transactions in the wallet, we may return the txid of the transaction that was replaced instead of the new one.

  Note: this fixes the `test_conflicting_unconfirmed_spend_txs` flakiness, which exposed this bug.

ACKs for top commit:
  darosior:
    ACK 421c1af6cd90f1b1af77c303b2ba2e74760b8781 -- tested it locally by running the `test_conflicting_unconfirmed_spend_txs` functional test around a thousand times.

Tree-SHA512: 8bb4a198934ae66a13d123c79cef2c9718d57a4ee8f9dbcc3e38257e54a758b1c63cdccfe90092d0bdabcdc3a488d6de82369e11130f6699aceeee9082075488
This commit is contained in:
Antoine Poinsot 2023-08-22 17:00:34 +02:00
commit 031dd45df1
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304

View File

@ -916,9 +916,25 @@ impl BitcoinD {
let input_outpoint = bitcoin::OutPoint { txid, vout };
if spent_outpoint == &input_outpoint {
return bitcoin::Txid::from_str(spending_txid)
.map(Some)
.expect("Must be a valid txid");
let spending_txid =
bitcoin::Txid::from_str(spending_txid).expect("Must be a valid txid");
// If the spending transaction is unconfirmed, there may more than one of them.
// Make sure to not return one that RBF'd.
let confs = gettx_res
.get("confirmations")
.and_then(Json::as_i64)
.expect("A valid number of confirmations must always be present.");
let conflicts = gettx_res
.get("walletconflicts")
.and_then(Json::as_array)
.expect("A valid list of wallet conflicts must always be present.");
if confs == 0 && !conflicts.is_empty() && !self.is_in_mempool(&spending_txid) {
log::debug!("Noticed '{}' as spending '{}', but is unconfirmed with conflicts and is not in mempool anymore. Discarding it.", &spending_txid, &spent_outpoint);
break;
}
return Some(spending_txid);
}
}
}