Skip to content

Commit

Permalink
bitcoind: fix the detection of unconfirmed RBF spending txs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
darosior committed Aug 22, 2023
1 parent 032bb26 commit e722480
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/bitcoin/d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit e722480

Please sign in to comment.