From 9c3ad28fa854ffa43eff9a367028920ec3d8f294 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 20 Jun 2023 23:27:55 +0000 Subject: [PATCH] Rename `Channel::pending_monitor_updates` to `blocked` To differentiate between in-flight pending completion and blocked updates. --- lightning/src/ln/channel.rs | 44 ++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 4745ac80e..69a69e7a1 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -862,11 +862,9 @@ pub(super) struct ChannelContext { /// [`SignerProvider::derive_channel_signer`]. channel_keys_id: [u8; 32], - /// When we generate [`ChannelMonitorUpdate`]s to persist, they may not be persisted immediately. - /// If we then persist the [`channelmanager::ChannelManager`] and crash before the persistence - /// completes we still need to be able to complete the persistence. Thus, we have to keep a - /// copy of the [`ChannelMonitorUpdate`] here until it is complete. - pending_monitor_updates: Vec, + /// If we can't release a [`ChannelMonitorUpdate`] until some external action completes, we + /// store it here and only release it to the `ChannelManager` once it asks for it. + blocked_monitor_updates: Vec, } impl ChannelContext { @@ -2257,7 +2255,7 @@ impl Channel { } pub fn get_update_fulfill_htlc_and_commit(&mut self, htlc_id: u64, payment_preimage: PaymentPreimage, logger: &L) -> UpdateFulfillCommitFetch where L::Target: Logger { - let release_cs_monitor = self.context.pending_monitor_updates.is_empty(); + let release_cs_monitor = self.context.blocked_monitor_updates.is_empty(); match self.get_update_fulfill_htlc(htlc_id, payment_preimage, logger) { UpdateFulfillFetch::NewClaim { mut monitor_update, htlc_value_msat, msg } => { // Even if we aren't supposed to let new monitor updates with commitment state @@ -2272,16 +2270,16 @@ impl Channel { self.context.latest_monitor_update_id = monitor_update.update_id; monitor_update.updates.append(&mut additional_update.updates); } else { - let new_mon_id = self.context.pending_monitor_updates.get(0) + let new_mon_id = self.context.blocked_monitor_updates.get(0) .map(|upd| upd.update.update_id).unwrap_or(monitor_update.update_id); monitor_update.update_id = new_mon_id; - for held_update in self.context.pending_monitor_updates.iter_mut() { + for held_update in self.context.blocked_monitor_updates.iter_mut() { held_update.update.update_id += 1; } if msg.is_some() { debug_assert!(false, "If there is a pending blocked monitor we should have MonitorUpdateInProgress set"); let update = self.build_commitment_no_status_check(logger); - self.context.pending_monitor_updates.push(PendingChannelMonitorUpdate { + self.context.blocked_monitor_updates.push(PendingChannelMonitorUpdate { update, }); } @@ -4406,25 +4404,25 @@ impl Channel { /// Gets the latest [`ChannelMonitorUpdate`] ID which has been released and is in-flight. pub fn get_latest_unblocked_monitor_update_id(&self) -> u64 { - if self.context.pending_monitor_updates.is_empty() { return self.context.get_latest_monitor_update_id(); } - self.context.pending_monitor_updates[0].update.update_id - 1 + if self.context.blocked_monitor_updates.is_empty() { return self.context.get_latest_monitor_update_id(); } + self.context.blocked_monitor_updates[0].update.update_id - 1 } /// Returns the next blocked monitor update, if one exists, and a bool which indicates a /// further blocked monitor update exists after the next. pub fn unblock_next_blocked_monitor_update(&mut self) -> Option<(ChannelMonitorUpdate, bool)> { - if self.context.pending_monitor_updates.is_empty() { return None; } - Some((self.context.pending_monitor_updates.remove(0).update, - !self.context.pending_monitor_updates.is_empty())) + if self.context.blocked_monitor_updates.is_empty() { return None; } + Some((self.context.blocked_monitor_updates.remove(0).update, + !self.context.blocked_monitor_updates.is_empty())) } /// Pushes a new monitor update into our monitor update queue, returning it if it should be /// immediately given to the user for persisting or `None` if it should be held as blocked. fn push_ret_blockable_mon_update(&mut self, update: ChannelMonitorUpdate) -> Option { - let release_monitor = self.context.pending_monitor_updates.is_empty(); + let release_monitor = self.context.blocked_monitor_updates.is_empty(); if !release_monitor { - self.context.pending_monitor_updates.push(PendingChannelMonitorUpdate { + self.context.blocked_monitor_updates.push(PendingChannelMonitorUpdate { update, }); None @@ -4434,7 +4432,7 @@ impl Channel { } pub fn blocked_monitor_updates_pending(&self) -> usize { - self.context.pending_monitor_updates.len() + self.context.blocked_monitor_updates.len() } /// Returns true if the channel is awaiting the persistence of the initial ChannelMonitor. @@ -5590,7 +5588,7 @@ impl OutboundV1Channel { channel_type, channel_keys_id, - pending_monitor_updates: Vec::new(), + blocked_monitor_updates: Vec::new(), } }) } @@ -6220,7 +6218,7 @@ impl InboundV1Channel { channel_type, channel_keys_id, - pending_monitor_updates: Vec::new(), + blocked_monitor_updates: Vec::new(), } }; @@ -6806,7 +6804,7 @@ impl Writeable for Channel { (28, holder_max_accepted_htlcs, option), (29, self.context.temporary_channel_id, option), (31, channel_pending_event_emitted, option), - (33, self.context.pending_monitor_updates, vec_type), + (33, self.context.blocked_monitor_updates, vec_type), (35, pending_outbound_skimmed_fees, optional_vec), (37, holding_cell_skimmed_fees, optional_vec), }); @@ -7087,7 +7085,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch let mut temporary_channel_id: Option<[u8; 32]> = None; let mut holder_max_accepted_htlcs: Option = None; - let mut pending_monitor_updates = Some(Vec::new()); + let mut blocked_monitor_updates = Some(Vec::new()); let mut pending_outbound_skimmed_fees_opt: Option>> = None; let mut holding_cell_skimmed_fees_opt: Option>> = None; @@ -7114,7 +7112,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch (28, holder_max_accepted_htlcs, option), (29, temporary_channel_id, option), (31, channel_pending_event_emitted, option), - (33, pending_monitor_updates, vec_type), + (33, blocked_monitor_updates, vec_type), (35, pending_outbound_skimmed_fees_opt, optional_vec), (37, holding_cell_skimmed_fees_opt, optional_vec), }); @@ -7307,7 +7305,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch channel_type: channel_type.unwrap(), channel_keys_id, - pending_monitor_updates: pending_monitor_updates.unwrap(), + blocked_monitor_updates: blocked_monitor_updates.unwrap(), } }) } -- 2.39.5