Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't rebroadcast redundant closing TX upon restart #2001

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions lightning/src/chain/channelmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,22 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
self.inner.lock().unwrap().broadcast_latest_holder_commitment_txn(broadcaster, logger);
}

pub(crate) fn broadcast_latest_holder_commitment_txn_if_unspent<B: Deref, L: Deref>(
&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.
///
Expand Down Expand Up @@ -2275,12 +2291,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
// 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);
Expand Down Expand Up @@ -2338,6 +2349,15 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
&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<Txid, Vec<(u32, Script)>> {
// 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
Expand Down
6 changes: 4 additions & 2 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down