Skip to content

Commit 79a9794

Browse files
committed
Wait for actual funding outpoint spends
The spend helper treated any script history as proof of a spend. The funding transaction itself already creates such a history entry, so the helper normally returned before Electrum indexed the closing transaction. A following reorg could therefore begin while the funding outpoint was still unspent. Wait until the exact transaction output leaves Electrum's unspent set. Co-Authored-By: HAL 9000
1 parent 5ddf270 commit 79a9794

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

tests/common/mod.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -810,15 +810,14 @@ pub(crate) async fn wait_for_outpoint_spend<E: ElectrumApi>(electrs: &E, outpoin
810810
let tx = electrs.transaction_get(&outpoint.txid).unwrap();
811811
let txout_script = tx.output.get(outpoint.vout as usize).unwrap().clone().script_pubkey;
812812

813-
let is_spent = !electrs.script_get_history(&txout_script).unwrap().is_empty();
814-
if is_spent {
815-
return;
816-
}
817-
813+
// Script history already contains the funding transaction itself, so wait until the exact
814+
// funding outpoint leaves the unspent set instead of treating any history as a spend.
818815
exponential_backoff_poll(|| {
819816
electrs.ping().unwrap();
820817

821-
let is_spent = !electrs.script_get_history(&txout_script).unwrap().is_empty();
818+
let is_spent = !electrs.script_list_unspent(&txout_script).unwrap().iter().any(|output| {
819+
output.tx_hash == outpoint.txid && output.tx_pos == outpoint.vout as usize
820+
});
822821
is_spent.then_some(())
823822
})
824823
.await;

0 commit comments

Comments
 (0)