From 51f11a9e2f51945c7ec1f59a9acfd43d2f3977d3 Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Wed, 12 Oct 2022 17:24:27 +0200 Subject: [PATCH] looper: cleanup the check for spending coins' confirmation --- src/bitcoin/poller/looper.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/bitcoin/poller/looper.rs b/src/bitcoin/poller/looper.rs index 26c151e0..5afd7e85 100644 --- a/src/bitcoin/poller/looper.rs +++ b/src/bitcoin/poller/looper.rs @@ -88,14 +88,16 @@ fn update_coins( .collect(); let spending = bit.spending_coins(&to_be_spent); - // We need to confirm coins that are currently spending and which transactions are now in a - // block. - let mut spending_coins: Vec<(bitcoin::OutPoint, bitcoin::Txid)> = db_conn + // Mark coins in a spending state whose Spend transaction was confirmed as such. Note we + // need to take into account the freshly marked as spending coins as well, as their spend + // may have been confirmed within the previous tip and the current one, and we may not poll + // this chunk of the chain anymore. + let spending_coins: Vec<(bitcoin::OutPoint, bitcoin::Txid)> = db_conn .list_spending_coins() .values() .map(|coin| (coin.outpoint, coin.spend_txid.expect("Coin is spending"))) + .chain(spending.iter().cloned()) .collect(); - spending_coins.extend(&spending); let spent = bit.spent_coins(spending_coins.as_slice()); UpdatedCoins {