Skip to content

Commit 570db8b

Browse files
authored
Merge pull request #2265 from wpaulino/channel-force-closed-update-err
Prevent ChannelForceClosed monitor update error after detecting spend
2 parents 818dbdf + 1aeb821 commit 570db8b

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,8 +2339,16 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
23392339
F::Target: FeeEstimator,
23402340
L::Target: Logger,
23412341
{
2342-
log_info!(logger, "Applying update to monitor {}, bringing update_id from {} to {} with {} changes.",
2343-
log_funding_info!(self), self.latest_update_id, updates.update_id, updates.updates.len());
2342+
if self.latest_update_id == CLOSED_CHANNEL_UPDATE_ID && updates.update_id == CLOSED_CHANNEL_UPDATE_ID {
2343+
log_info!(logger, "Applying post-force-closed update to monitor {} with {} change(s).",
2344+
log_funding_info!(self), updates.updates.len());
2345+
} else if updates.update_id == CLOSED_CHANNEL_UPDATE_ID {
2346+
log_info!(logger, "Applying force close update to monitor {} with {} change(s).",
2347+
log_funding_info!(self), updates.updates.len());
2348+
} else {
2349+
log_info!(logger, "Applying update to monitor {}, bringing update_id from {} to {} with {} change(s).",
2350+
log_funding_info!(self), self.latest_update_id, updates.update_id, updates.updates.len());
2351+
}
23442352
// ChannelMonitor updates may be applied after force close if we receive a preimage for a
23452353
// broadcasted commitment transaction HTLC output that we'd like to claim on-chain. If this
23462354
// is the case, we no longer have guaranteed access to the monitor's update ID, so we use a
@@ -2407,6 +2415,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
24072415
_ => false,
24082416
}).is_some();
24092417
if detected_funding_spend {
2418+
log_trace!(logger, "Avoiding commitment broadcast, already detected confirmed spend onchain");
24102419
continue;
24112420
}
24122421
self.broadcast_latest_holder_commitment_txn(broadcaster, logger);
@@ -2457,7 +2466,9 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
24572466

24582467
self.latest_update_id = updates.update_id;
24592468

2460-
if ret.is_ok() && self.funding_spend_seen {
2469+
// Refuse updates after we've detected a spend onchain, but only if we haven't processed a
2470+
// force closed monitor update yet.
2471+
if ret.is_ok() && self.funding_spend_seen && self.latest_update_id != CLOSED_CHANNEL_UPDATE_ID {
24612472
log_error!(logger, "Refusing Channel Monitor Update as counterparty attempted to update commitment after funding was spent");
24622473
Err(())
24632474
} else { ret }

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7756,6 +7756,8 @@ where
77567756

77577757
for (funding_txo, _) in args.channel_monitors.iter() {
77587758
if !funding_txo_set.contains(funding_txo) {
7759+
log_info!(args.logger, "Queueing monitor update to ensure missing channel {} is force closed",
7760+
log_bytes!(funding_txo.to_channel_id()));
77597761
let monitor_update = ChannelMonitorUpdate {
77607762
update_id: CLOSED_CHANNEL_UPDATE_ID,
77617763
updates: vec![ChannelMonitorUpdateStep::ChannelForceClosed { should_broadcast: true }],

0 commit comments

Comments
 (0)