Skip to content

Commit 03c1795

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 0101507 commit 03c1795

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

lightning/src/ln/channelmanager.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -7656,27 +7656,34 @@ where
76567656
if peer_state_mutex_opt.is_none() { return }
76577657
peer_state_lock = peer_state_mutex_opt.unwrap().lock().unwrap();
76587658
let peer_state = &mut *peer_state_lock;
7659+
7660+
let remaining_in_flight =
7661+
if let Some(pending) = peer_state.in_flight_monitor_updates.get_mut(funding_txo) {
7662+
pending.retain(|upd| upd.update_id > highest_applied_update_id);
7663+
pending.len()
7664+
} else { 0 };
7665+
76597666
let channel =
76607667
if let Some(ChannelPhase::Funded(chan)) = peer_state.channel_by_id.get_mut(channel_id) {
76617668
chan
76627669
} else {
7670+
if remaining_in_flight != 0 {
7671+
return;
7672+
}
7673+
76637674
let update_actions = peer_state.monitor_update_blocked_actions
76647675
.remove(channel_id).unwrap_or(Vec::new());
76657676
mem::drop(peer_state_lock);
76667677
mem::drop(per_peer_state);
76677678
self.handle_monitor_update_completion_actions(update_actions);
76687679
return;
76697680
};
7670-
let remaining_in_flight =
7671-
if let Some(pending) = peer_state.in_flight_monitor_updates.get_mut(funding_txo) {
7672-
pending.retain(|upd| upd.update_id > highest_applied_update_id);
7673-
pending.len()
7674-
} else { 0 };
7681+
76757682
let logger = WithChannelContext::from(&self.logger, &channel.context, None);
76767683
log_trace!(logger, "ChannelMonitor updated to {}. Current highest is {}. {} pending in-flight updates.",
76777684
highest_applied_update_id, channel.context.get_latest_monitor_update_id(),
76787685
remaining_in_flight);
7679-
if !channel.is_awaiting_monitor_update() || remaining_in_flight != 0 {
7686+
if remaining_in_flight != 0 || !channel.is_awaiting_monitor_update() {
76807687
return;
76817688
}
76827689
handle_monitor_update_completion!(self, peer_state_lock, peer_state, per_peer_state, channel);

0 commit comments

Comments
 (0)