Skip to content

Commit d450e0f

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 4c342bd commit d450e0f

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5001,24 +5001,29 @@ where
50015001
if peer_state_mutex_opt.is_none() { return }
50025002
peer_state_lock = peer_state_mutex_opt.unwrap().lock().unwrap();
50035003
let peer_state = &mut *peer_state_lock;
5004-
let mut channel = {
5005-
match peer_state.channel_by_id.entry(funding_txo.to_channel_id()){
5006-
hash_map::Entry::Occupied(chan) => chan,
5007-
hash_map::Entry::Vacant(_) => return,
5008-
}
5009-
};
5004+
let channel =
5005+
if let Some(chan) = peer_state.channel_by_id.get_mut(&funding_txo.to_channel_id()) {
5006+
chan
5007+
} else {
5008+
let update_actions = peer_state.monitor_update_blocked_actions
5009+
.remove(&funding_txo.to_channel_id()).unwrap_or(Vec::new());
5010+
mem::drop(peer_state_lock);
5011+
mem::drop(per_peer_state);
5012+
self.handle_monitor_update_completion_actions(update_actions);
5013+
return;
5014+
};
50105015
let remaining_in_flight =
50115016
if let Some(pending) = peer_state.in_flight_monitor_updates.get_mut(funding_txo) {
50125017
pending.retain(|upd| upd.update_id > highest_applied_update_id);
50135018
pending.len()
50145019
} else { 0 };
50155020
log_trace!(self.logger, "ChannelMonitor updated to {}. Current highest is {}. {} pending in-flight updates.",
5016-
highest_applied_update_id, channel.get().context.get_latest_monitor_update_id(),
5021+
highest_applied_update_id, channel.context.get_latest_monitor_update_id(),
50175022
remaining_in_flight);
5018-
if !channel.get().is_awaiting_monitor_update() || channel.get().context.get_latest_monitor_update_id() != highest_applied_update_id {
5023+
if !channel.is_awaiting_monitor_update() || channel.context.get_latest_monitor_update_id() != highest_applied_update_id {
50195024
return;
50205025
}
5021-
handle_monitor_update_completion!(self, peer_state_lock, peer_state, per_peer_state, channel.get_mut());
5026+
handle_monitor_update_completion!(self, peer_state_lock, peer_state, per_peer_state, channel);
50225027
}
50235028

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

0 commit comments

Comments
 (0)