Skip to content

Commit 7ec1631

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 b4ee907 commit 7ec1631

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
@@ -7638,27 +7638,34 @@ where
76387638
if peer_state_mutex_opt.is_none() { return }
76397639
peer_state_lock = peer_state_mutex_opt.unwrap().lock().unwrap();
76407640
let peer_state = &mut *peer_state_lock;
7641+
7642+
let remaining_in_flight =
7643+
if let Some(pending) = peer_state.in_flight_monitor_updates.get_mut(funding_txo) {
7644+
pending.retain(|upd| upd.update_id > highest_applied_update_id);
7645+
pending.len()
7646+
} else { 0 };
7647+
76417648
let channel =
76427649
if let Some(ChannelPhase::Funded(chan)) = peer_state.channel_by_id.get_mut(channel_id) {
76437650
chan
76447651
} else {
7652+
if remaining_in_flight != 0 {
7653+
return;
7654+
}
7655+
76457656
let update_actions = peer_state.monitor_update_blocked_actions
76467657
.remove(channel_id).unwrap_or(Vec::new());
76477658
mem::drop(peer_state_lock);
76487659
mem::drop(per_peer_state);
76497660
self.handle_monitor_update_completion_actions(update_actions);
76507661
return;
76517662
};
7652-
let remaining_in_flight =
7653-
if let Some(pending) = peer_state.in_flight_monitor_updates.get_mut(funding_txo) {
7654-
pending.retain(|upd| upd.update_id > highest_applied_update_id);
7655-
pending.len()
7656-
} else { 0 };
7663+
76577664
let logger = WithChannelContext::from(&self.logger, &channel.context, None);
76587665
log_trace!(logger, "ChannelMonitor updated to {}. Current highest is {}. {} pending in-flight updates.",
76597666
highest_applied_update_id, channel.context.get_latest_monitor_update_id(),
76607667
remaining_in_flight);
7661-
if !channel.is_awaiting_monitor_update() || remaining_in_flight != 0 {
7668+
if remaining_in_flight != 0 || !channel.is_awaiting_monitor_update() {
76627669
return;
76637670
}
76647671
handle_monitor_update_completion!(self, peer_state_lock, peer_state, per_peer_state, channel);

0 commit comments

Comments
 (0)