From 9e50007a8e9a61540b230cb043b21e572c53daad Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Tue, 15 Aug 2023 11:15:47 +0200 Subject: [PATCH] f Rebroadcast every block --- src/sweep.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/sweep.rs b/src/sweep.rs index 14ab7c135..7745f861d 100644 --- a/src/sweep.rs +++ b/src/sweep.rs @@ -13,6 +13,7 @@ use lightning::util::ser::Writeable; use bitcoin::secp256k1::Secp256k1; use bitcoin::{BlockHash, BlockHeader, LockTime, PackedLockTime, Transaction, Txid}; +use std::collections::HashSet; use std::ops::Deref; use std::sync::{Arc, Mutex}; @@ -267,18 +268,14 @@ where let mut locked_outputs = self.outputs.lock().unwrap(); - // Rebroadcast all outputs that didn't get confirmed by now. + // Regenerate spending tx and fee bump all outputs that didn't get confirmed by now. for output_info in locked_outputs.iter_mut().filter(|o| o.confirmed_in_block.is_none()) { - let should_broadcast = if let Some(bcast_height) = output_info.broadcast_height { - height >= bcast_height + num_blocks_from_conf_target(ConfirmationTarget::Background) - } else { - true - }; - if should_broadcast { + let bcast_height = output_info.broadcast_height.unwrap_or(0); + if height >= bcast_height + num_blocks_from_conf_target(ConfirmationTarget::Background) + { let output_descriptors = vec![output_info.descriptor.clone()]; match self.get_spending_tx(&output_descriptors, height) { Ok(Some(spending_tx)) => { - self.wallet.broadcast_transactions(&[&spending_tx]); if let Some(filter) = self.chain_source.as_ref() { if let Some(tx_out) = spending_tx.output.first() { filter.register_tx(&spending_tx.txid(), &tx_out.script_pubkey); @@ -333,6 +330,13 @@ where } true }); + + // Rebroadcast all pending spending txs + let mut txs = locked_outputs + .iter() + .filter_map(|o| o.spending_tx.as_ref()) + .collect::>(); + self.wallet.broadcast_transactions(&txs.drain().collect::>()); } fn get_relevant_txids(&self) -> Vec<(Txid, Option)> {