Skip to content

Commit 28af6c7

Browse files
committed
Don't rebroadcast closing TX upon restart
While we don't rebroadcast the latest holder commitment transactions in `ChannelMonitor::update_monitor()` anymore if we had previously seen a closing tx on-chain, we still do so upon restarting / deserlization of `ChannelManager` With this change, we now also refrain from rebroadcasting upon restarting.
1 parent c59150a commit 28af6c7

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,11 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
12361236
self.inner.lock().unwrap().get_funding_txo().clone()
12371237
}
12381238

1239+
/// Gets whether we've seen a confirmed transaction spending the funding output.
1240+
pub(crate) fn detected_funding_spend(&self) -> bool {
1241+
self.inner.lock().unwrap().detected_funding_spend()
1242+
}
1243+
12391244
/// Gets a list of txids, with their output scripts (in the order they appear in the
12401245
/// transaction), which we must learn about spends of via block_connected().
12411246
pub fn get_outputs_to_watch(&self) -> Vec<(Txid, Vec<(u32, Script)>)> {
@@ -2275,12 +2280,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
22752280
// There's no need to broadcast our commitment transaction if we've seen one
22762281
// confirmed (even with 1 confirmation) as it'll be rejected as
22772282
// duplicate/conflicting.
2278-
let detected_funding_spend = self.funding_spend_confirmed.is_some() ||
2279-
self.onchain_events_awaiting_threshold_conf.iter().find(|event| match event.event {
2280-
OnchainEvent::FundingSpendConfirmation { .. } => true,
2281-
_ => false,
2282-
}).is_some();
2283-
if detected_funding_spend {
2283+
if self.detected_funding_spend() {
22842284
continue;
22852285
}
22862286
self.broadcast_latest_holder_commitment_txn(broadcaster, logger);
@@ -2338,6 +2338,15 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
23382338
&self.funding_info
23392339
}
23402340

2341+
pub fn detected_funding_spend(&self) -> bool {
2342+
self.funding_spend_confirmed.is_some() ||
2343+
self.onchain_events_awaiting_threshold_conf
2344+
.iter().find(|event| match event.event {
2345+
OnchainEvent::FundingSpendConfirmation { .. } => true,
2346+
_ => false,
2347+
}).is_some()
2348+
}
2349+
23412350
pub fn get_outputs_to_watch(&self) -> &HashMap<Txid, Vec<(u32, Script)>> {
23422351
// If we've detected a counterparty commitment tx on chain, we must include it in the set
23432352
// of outputs to watch for spends of, otherwise we're likely to lose user funds. Because

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7208,7 +7208,10 @@ where
72087208
}
72097209

72107210
for (funding_txo, monitor) in args.channel_monitors.iter_mut() {
7211-
if !funding_txo_set.contains(funding_txo) {
7211+
// There's no need to broadcast our commitment transaction if we've seen one
7212+
// confirmed (even with 1 confirmation) as it'll be rejected as
7213+
// duplicate/conflicting.
7214+
if !funding_txo_set.contains(funding_txo) && !monitor.detected_funding_spend() {
72127215
log_info!(args.logger, "Broadcasting latest holder commitment transaction for closed channel {}", log_bytes!(funding_txo.to_channel_id()));
72137216
monitor.broadcast_latest_holder_commitment_txn(&args.tx_broadcaster, &args.logger);
72147217
}

0 commit comments

Comments
 (0)