Skip to content

Commit 7100cb8

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 f5a8caa commit 7100cb8

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7665,27 +7665,34 @@ where
76657665
if peer_state_mutex_opt.is_none() { return }
76667666
peer_state_lock = peer_state_mutex_opt.unwrap().lock().unwrap();
76677667
let peer_state = &mut *peer_state_lock;
7668+
7669+
let remaining_in_flight =
7670+
if let Some(pending) = peer_state.in_flight_monitor_updates.get_mut(funding_txo) {
7671+
pending.retain(|upd| upd.update_id > highest_applied_update_id);
7672+
pending.len()
7673+
} else { 0 };
7674+
76687675
let channel =
76697676
if let Some(ChannelPhase::Funded(chan)) = peer_state.channel_by_id.get_mut(channel_id) {
76707677
chan
76717678
} else {
7679+
if remaining_in_flight != 0 {
7680+
return;
7681+
}
7682+
76727683
let update_actions = peer_state.monitor_update_blocked_actions
76737684
.remove(channel_id).unwrap_or(Vec::new());
76747685
mem::drop(peer_state_lock);
76757686
mem::drop(per_peer_state);
76767687
self.handle_monitor_update_completion_actions(update_actions);
76777688
return;
76787689
};
7679-
let remaining_in_flight =
7680-
if let Some(pending) = peer_state.in_flight_monitor_updates.get_mut(funding_txo) {
7681-
pending.retain(|upd| upd.update_id > highest_applied_update_id);
7682-
pending.len()
7683-
} else { 0 };
7690+
76847691
let logger = WithChannelContext::from(&self.logger, &channel.context, None);
76857692
log_trace!(logger, "ChannelMonitor updated to {}. Current highest is {}. {} pending in-flight updates.",
76867693
highest_applied_update_id, channel.context.get_latest_monitor_update_id(),
76877694
remaining_in_flight);
7688-
if !channel.is_awaiting_monitor_update() || remaining_in_flight != 0 {
7695+
if remaining_in_flight != 0 || !channel.is_awaiting_monitor_update() {
76897696
return;
76907697
}
76917698
handle_monitor_update_completion!(self, peer_state_lock, peer_state, per_peer_state, channel);

0 commit comments

Comments
 (0)