Skip to content

Commit 940313b

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 ab51917 commit 940313b

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
@@ -7675,27 +7675,34 @@ 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+
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 };
7684+
76787685
let channel =
76797686
if let Some(ChannelPhase::Funded(chan)) = peer_state.channel_by_id.get_mut(channel_id) {
76807687
chan
76817688
} else {
7689+
if remaining_in_flight != 0 {
7690+
return;
7691+
}
7692+
76827693
let update_actions = peer_state.monitor_update_blocked_actions
76837694
.remove(channel_id).unwrap_or(Vec::new());
76847695
mem::drop(peer_state_lock);
76857696
mem::drop(per_peer_state);
76867697
self.handle_monitor_update_completion_actions(update_actions);
76877698
return;
76887699
};
7689-
let remaining_in_flight =
7690-
if let Some(pending) = peer_state.in_flight_monitor_updates.get_mut(funding_txo) {
7691-
pending.retain(|upd| upd.update_id > highest_applied_update_id);
7692-
pending.len()
7693-
} else { 0 };
7700+
76947701
let logger = WithChannelContext::from(&self.logger, &channel.context, None);
76957702
log_trace!(logger, "ChannelMonitor updated to {}. Current highest is {}. {} pending in-flight updates.",
76967703
highest_applied_update_id, channel.context.get_latest_monitor_update_id(),
76977704
remaining_in_flight);
7698-
if !channel.is_awaiting_monitor_update() || remaining_in_flight != 0 {
7705+
if remaining_in_flight != 0 || !channel.is_awaiting_monitor_update() {
76997706
return;
77007707
}
77017708
handle_monitor_update_completion!(self, peer_state_lock, peer_state, per_peer_state, channel);

0 commit comments

Comments
 (0)