Skip to content

Commit b50354d

Browse files
committed
Check in-flight updates before completing events on closed chans
When we handle a `ChannelMonitorUpdate` completion we always complete everything that was waiting on any updates to the same channel all at once. Thus, we need to skip all updates if there's pending updates besides the one that was just completed. We handled this correctly for open channels, but the shortcut for closed channels ignored any other pending updates entirely. Here we fix this, which is ultimately required for tests which are added in a few commits to pass.
1 parent 4766e99 commit b50354d

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

lightning/src/ln/channelmanager.rs

+23-17
Original file line numberDiff line numberDiff line change
@@ -7675,30 +7675,36 @@ where
76757675
if peer_state_mutex_opt.is_none() { return }
76767676
peer_state_lock = peer_state_mutex_opt.unwrap().lock().unwrap();
76777677
let peer_state = &mut *peer_state_lock;
7678-
let channel =
7679-
if let Some(ChannelPhase::Funded(chan)) = peer_state.channel_by_id.get_mut(channel_id) {
7680-
chan
7681-
} else {
7682-
let update_actions = peer_state.monitor_update_blocked_actions
7683-
.remove(channel_id).unwrap_or(Vec::new());
7684-
mem::drop(peer_state_lock);
7685-
mem::drop(per_peer_state);
7686-
self.handle_monitor_update_completion_actions(update_actions);
7687-
return;
7688-
};
7678+
76897679
let remaining_in_flight =
76907680
if let Some(pending) = peer_state.in_flight_monitor_updates.get_mut(funding_txo) {
76917681
pending.retain(|upd| upd.update_id > highest_applied_update_id);
76927682
pending.len()
76937683
} else { 0 };
7694-
let logger = WithChannelContext::from(&self.logger, &channel.context, None);
7695-
log_trace!(logger, "ChannelMonitor updated to {}. Current highest is {}. {} pending in-flight updates.",
7696-
highest_applied_update_id, channel.context.get_latest_monitor_update_id(),
7697-
remaining_in_flight);
7698-
if !channel.is_awaiting_monitor_update() || remaining_in_flight != 0 {
7684+
7685+
let logger = WithContext::from(&self.logger, Some(counterparty_node_id), Some(*channel_id), None);
7686+
log_trace!(logger, "ChannelMonitor updated to {}. {} pending in-flight updates.",
7687+
highest_applied_update_id, remaining_in_flight);
7688+
7689+
if remaining_in_flight != 0 {
76997690
return;
77007691
}
7701-
handle_monitor_update_completion!(self, peer_state_lock, peer_state, per_peer_state, channel);
7692+
7693+
if let Some(ChannelPhase::Funded(chan)) = peer_state.channel_by_id.get_mut(channel_id) {
7694+
if chan.is_awaiting_monitor_update() {
7695+
log_trace!(logger, "Channel is open and awaiting update, resuming it");
7696+
handle_monitor_update_completion!(self, peer_state_lock, peer_state, per_peer_state, chan);
7697+
} else {
7698+
log_trace!(logger, "Channel is open but not awaiting update");
7699+
}
7700+
} else {
7701+
let update_actions = peer_state.monitor_update_blocked_actions
7702+
.remove(channel_id).unwrap_or(Vec::new());
7703+
log_trace!(logger, "Channel is closed, applying {} post-update actions", update_actions.len());
7704+
mem::drop(peer_state_lock);
7705+
mem::drop(per_peer_state);
7706+
self.handle_monitor_update_completion_actions(update_actions);
7707+
}
77027708
}
77037709

77047710
/// Accepts a request to open a channel after a [`Event::OpenChannelRequest`].

0 commit comments

Comments
 (0)