Skip to content

Commit 9409377

Browse files
committed
Handle monitor completion actions for closed channels
If a channel has been closed, there may still be some `ChannelMonitorUpdate`(s) which are pending completion. These in-flight updates may also be blocking another channel from letting an update fly, e.g. for forwarded payments where the payment preimage will be removed from the downstream channel after the upstream channel has closed. Luckily all the infrastructure to handle this case is already in place - we just need to process the `monitor_update_blocked_actions` for closed channels.
1 parent 2aa66b8 commit 9409377

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4947,24 +4947,30 @@ where
49474947
if peer_state_mutex_opt.is_none() { return }
49484948
peer_state_lock = peer_state_mutex_opt.unwrap().lock().unwrap();
49494949
let peer_state = &mut *peer_state_lock;
4950-
let mut channel = {
4951-
match peer_state.channel_by_id.entry(funding_txo.to_channel_id()){
4952-
hash_map::Entry::Occupied(chan) => chan,
4953-
hash_map::Entry::Vacant(_) => return,
4954-
}
4955-
};
4950+
let channel =
4951+
if let Some(chan) = peer_state.channel_by_id.get_mut(&funding_txo.to_channel_id()) {
4952+
chan
4953+
} else {
4954+
eprintln!("no channel!");
4955+
let update_actions = peer_state.monitor_update_blocked_actions
4956+
.remove(&funding_txo.to_channel_id()).unwrap_or(Vec::new());
4957+
mem::drop(peer_state_lock);
4958+
mem::drop(per_peer_state);
4959+
self.handle_monitor_update_completion_actions(update_actions);
4960+
return;
4961+
};
49564962
let remaining_in_flight =
49574963
if let Some(pending) = peer_state.in_flight_monitor_updates.get_mut(funding_txo) {
49584964
pending.retain(|upd| upd.update_id > highest_applied_update_id);
49594965
pending.len()
49604966
} else { 0 };
49614967
log_trace!(self.logger, "ChannelMonitor updated to {}. Current highest is {}. {} pending in-flight updates.",
4962-
highest_applied_update_id, channel.get().context.get_latest_monitor_update_id(),
4968+
highest_applied_update_id, channel.context.get_latest_monitor_update_id(),
49634969
remaining_in_flight);
4964-
if !channel.get().is_awaiting_monitor_update() || channel.get().context.get_latest_monitor_update_id() != highest_applied_update_id {
4970+
if !channel.is_awaiting_monitor_update() || channel.context.get_latest_monitor_update_id() != highest_applied_update_id {
49654971
return;
49664972
}
4967-
handle_monitor_update_completion!(self, peer_state_lock, peer_state, per_peer_state, channel.get_mut());
4973+
handle_monitor_update_completion!(self, peer_state_lock, peer_state, per_peer_state, channel);
49684974
}
49694975

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

0 commit comments

Comments
 (0)