bitcoin: don't assign incorrect spend_txid on conflict tx confirmation

This commit is contained in:
Antoine Poinsot 2023-11-16 15:55:17 +01:00
parent 20ab30924f
commit bc25addf34
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304
2 changed files with 16 additions and 7 deletions

View File

@ -261,8 +261,18 @@ impl BitcoinInterface for d::BitcoinD {
// spender for this coin with it and mark it as confirmed.
for txid in &res.conflicting_txs {
if let Some(tx) = tx_getter.get_transaction(txid) {
// FIXME: if a conflict was mined we should somehow wipe the spend_txid of this
// coin.
if let Some(block) = tx.block {
spent.push((*op, *txid, block))
// Being part of our watchonly wallet isn't enough, as it could be a
// conflicting transaction which spends a different set of coins. Make sure
// it does actually spend this coin.
for txin in tx.tx.input {
if &txin.previous_output == op {
spent.push((*op, *txid, block));
break;
}
}
}
}
}

View File

@ -480,7 +480,7 @@ def test_spend_replacement(lianad, bitcoind):
== first_txid
)
# Even once the RBF gets merged, the first coin's spend txid isn't updated.
# Even once the RBF gets mined, the first coin's spend txid isn't updated.
bitcoind.generate_block(1, wait_for_mempool=third_txid)
wait_for(
lambda: all(
@ -488,8 +488,7 @@ def test_spend_replacement(lianad, bitcoind):
for c in lianad.rpc.listcoins([], second_outpoints)["coins"]
)
)
# FIXME: the code is incorrectly assigning the third txid to the first coin.
# assert (
# lianad.rpc.listcoins([], [first_outpoints[0]])["coins"][0]["spend_info"]["txid"]
# == first_txid
# )
assert (
lianad.rpc.listcoins([], [first_outpoints[0]])["coins"][0]["spend_info"]["txid"]
== first_txid
)