diff --git a/src/bitcoin/mod.rs b/src/bitcoin/mod.rs index ed2143b9..0cf345e4 100644 --- a/src/bitcoin/mod.rs +++ b/src/bitcoin/mod.rs @@ -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; + } + } } } } diff --git a/tests/test_chain.py b/tests/test_chain.py index 1f79945d..5ae84ea2 100644 --- a/tests/test_chain.py +++ b/tests/test_chain.py @@ -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 + )