diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index 509ebed6fba..7260f6e7e52 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -1206,6 +1206,22 @@ impl ChannelMonitor { self.inner.lock().unwrap().broadcast_latest_holder_commitment_txn(broadcaster, logger); } + pub(crate) fn broadcast_latest_holder_commitment_txn_if_unspent( + &self, + broadcaster: &B, + logger: &L, + ) where + B::Target: BroadcasterInterface, + L::Target: Logger, + { + let mut locked_inner = self.inner.lock().unwrap(); + if !locked_inner.detected_funding_spend() { + log_info!(logger, "Broadcasting latest holder commitment transaction for channel {}", + log_bytes!(locked_inner.get_funding_txo().0.to_channel_id())); + locked_inner.broadcast_latest_holder_commitment_txn(broadcaster, logger); + } + } + /// Updates a ChannelMonitor on the basis of some new information provided by the Channel /// itself. /// @@ -2275,12 +2291,7 @@ impl ChannelMonitorImpl { // There's no need to broadcast our commitment transaction if we've seen one // confirmed (even with 1 confirmation) as it'll be rejected as // duplicate/conflicting. - let detected_funding_spend = self.funding_spend_confirmed.is_some() || - self.onchain_events_awaiting_threshold_conf.iter().find(|event| match event.event { - OnchainEvent::FundingSpendConfirmation { .. } => true, - _ => false, - }).is_some(); - if detected_funding_spend { + if self.detected_funding_spend() { continue; } self.broadcast_latest_holder_commitment_txn(broadcaster, logger); @@ -2338,6 +2349,15 @@ impl ChannelMonitorImpl { &self.funding_info } + pub fn detected_funding_spend(&self) -> bool { + self.funding_spend_confirmed.is_some() || + self.onchain_events_awaiting_threshold_conf + .iter().find(|event| match event.event { + OnchainEvent::FundingSpendConfirmation { .. } => true, + _ => false, + }).is_some() + } + pub fn get_outputs_to_watch(&self) -> &HashMap> { // If we've detected a counterparty commitment tx on chain, we must include it in the set // of outputs to watch for spends of, otherwise we're likely to lose user funds. Because diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index b2a23c7c1d4..5583736076b 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -7209,8 +7209,10 @@ where for (funding_txo, monitor) in args.channel_monitors.iter_mut() { if !funding_txo_set.contains(funding_txo) { - log_info!(args.logger, "Broadcasting latest holder commitment transaction for closed channel {}", log_bytes!(funding_txo.to_channel_id())); - monitor.broadcast_latest_holder_commitment_txn(&args.tx_broadcaster, &args.logger); + // There's no need to broadcast our commitment transaction if + // we've seen one confirmed (even with 1 confirmation) as it'll + // be rejected as duplicate/conflicting. + monitor.broadcast_latest_holder_commitment_txn_if_unspent(&args.tx_broadcaster, &args.logger); } }