Skip to content

Commit

Permalink
f Rebroadcast every block
Browse files Browse the repository at this point in the history
  • Loading branch information
tnull committed Aug 15, 2023
1 parent d465be7 commit 9e50007
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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::<HashSet<&Transaction>>();
self.wallet.broadcast_transactions(&txs.drain().collect::<Vec<_>>());
}

fn get_relevant_txids(&self) -> Vec<(Txid, Option<BlockHash>)> {
Expand Down

0 comments on commit 9e50007

Please sign in to comment.