Skip to content

Commit cd76e97

Browse files
committed
Rename Channel::pending_monitor_updates to blocked
To differentiate between in-flight pending completion and blocked updates.
1 parent 30d4593 commit cd76e97

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

lightning/src/ln/channel.rs

+21-23
Original file line numberDiff line numberDiff line change
@@ -862,11 +862,9 @@ pub(super) struct ChannelContext<Signer: ChannelSigner> {
862862
/// [`SignerProvider::derive_channel_signer`].
863863
channel_keys_id: [u8; 32],
864864

865-
/// When we generate [`ChannelMonitorUpdate`]s to persist, they may not be persisted immediately.
866-
/// If we then persist the [`channelmanager::ChannelManager`] and crash before the persistence
867-
/// completes we still need to be able to complete the persistence. Thus, we have to keep a
868-
/// copy of the [`ChannelMonitorUpdate`] here until it is complete.
869-
pending_monitor_updates: Vec<PendingChannelMonitorUpdate>,
865+
/// If we can't release a [`ChannelMonitorUpdate`] until some external action completes, we
866+
/// store it here and only release it to [`ChannelManager`] once it asks for it.
867+
blocked_monitor_updates: Vec<PendingChannelMonitorUpdate>,
870868
}
871869

872870
impl<Signer: ChannelSigner> ChannelContext<Signer> {
@@ -2257,7 +2255,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
22572255
}
22582256

22592257
pub fn get_update_fulfill_htlc_and_commit<L: Deref>(&mut self, htlc_id: u64, payment_preimage: PaymentPreimage, logger: &L) -> UpdateFulfillCommitFetch where L::Target: Logger {
2260-
let release_cs_monitor = self.context.pending_monitor_updates.is_empty();
2258+
let release_cs_monitor = self.context.blocked_monitor_updates.is_empty();
22612259
match self.get_update_fulfill_htlc(htlc_id, payment_preimage, logger) {
22622260
UpdateFulfillFetch::NewClaim { mut monitor_update, htlc_value_msat, msg } => {
22632261
// Even if we aren't supposed to let new monitor updates with commitment state
@@ -2272,16 +2270,16 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
22722270
self.context.latest_monitor_update_id = monitor_update.update_id;
22732271
monitor_update.updates.append(&mut additional_update.updates);
22742272
} else {
2275-
let new_mon_id = self.context.pending_monitor_updates.get(0)
2273+
let new_mon_id = self.context.blocked_monitor_updates.get(0)
22762274
.map(|upd| upd.update.update_id).unwrap_or(monitor_update.update_id);
22772275
monitor_update.update_id = new_mon_id;
2278-
for held_update in self.context.pending_monitor_updates.iter_mut() {
2276+
for held_update in self.context.blocked_monitor_updates.iter_mut() {
22792277
held_update.update.update_id += 1;
22802278
}
22812279
if msg.is_some() {
22822280
debug_assert!(false, "If there is a pending blocked monitor we should have MonitorUpdateInProgress set");
22832281
let update = self.build_commitment_no_status_check(logger);
2284-
self.context.pending_monitor_updates.push(PendingChannelMonitorUpdate {
2282+
self.context.blocked_monitor_updates.push(PendingChannelMonitorUpdate {
22852283
update,
22862284
});
22872285
}
@@ -4406,25 +4404,25 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
44064404

44074405
/// Gets the latest [`ChannelMonitorUpdate`] ID which has been released and is in-flight.
44084406
pub fn get_latest_unblocked_monitor_update_id(&self) -> u64 {
4409-
if self.context.pending_monitor_updates.is_empty() { return self.context.get_latest_monitor_update_id(); }
4410-
self.context.pending_monitor_updates[0].update.update_id - 1
4407+
if self.context.blocked_monitor_updates.is_empty() { return self.context.get_latest_monitor_update_id(); }
4408+
self.context.blocked_monitor_updates[0].update.update_id - 1
44114409
}
44124410

44134411
/// Returns the next blocked monitor update, if one exists, and a bool which indicates a
44144412
/// further blocked monitor update exists after the next.
44154413
pub fn unblock_next_blocked_monitor_update(&mut self) -> Option<(ChannelMonitorUpdate, bool)> {
4416-
if self.context.pending_monitor_updates.is_empty() { return None; }
4417-
Some((self.context.pending_monitor_updates.remove(0).update,
4418-
!self.context.pending_monitor_updates.is_empty()))
4414+
if self.context.blocked_monitor_updates.is_empty() { return None; }
4415+
Some((self.context.blocked_monitor_updates.remove(0).update,
4416+
!self.context.blocked_monitor_updates.is_empty()))
44194417
}
44204418

44214419
/// Pushes a new monitor update into our monitor update queue, returning it if it should be
44224420
/// immediately given to the user for persisting or `None` if it should be held as blocked.
44234421
fn push_ret_blockable_mon_update(&mut self, update: ChannelMonitorUpdate)
44244422
-> Option<ChannelMonitorUpdate> {
4425-
let release_monitor = self.context.pending_monitor_updates.is_empty();
4423+
let release_monitor = self.context.blocked_monitor_updates.is_empty();
44264424
if !release_monitor {
4427-
self.context.pending_monitor_updates.push(PendingChannelMonitorUpdate {
4425+
self.context.blocked_monitor_updates.push(PendingChannelMonitorUpdate {
44284426
update,
44294427
});
44304428
None
@@ -4434,7 +4432,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
44344432
}
44354433

44364434
pub fn blocked_monitor_updates_pending(&self) -> usize {
4437-
self.context.pending_monitor_updates.len()
4435+
self.context.blocked_monitor_updates.len()
44384436
}
44394437

44404438
/// Returns true if the channel is awaiting the persistence of the initial ChannelMonitor.
@@ -5590,7 +5588,7 @@ impl<Signer: WriteableEcdsaChannelSigner> OutboundV1Channel<Signer> {
55905588
channel_type,
55915589
channel_keys_id,
55925590

5593-
pending_monitor_updates: Vec::new(),
5591+
blocked_monitor_updates: Vec::new(),
55945592
}
55955593
})
55965594
}
@@ -6220,7 +6218,7 @@ impl<Signer: WriteableEcdsaChannelSigner> InboundV1Channel<Signer> {
62206218
channel_type,
62216219
channel_keys_id,
62226220

6223-
pending_monitor_updates: Vec::new(),
6221+
blocked_monitor_updates: Vec::new(),
62246222
}
62256223
};
62266224

@@ -6806,7 +6804,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
68066804
(28, holder_max_accepted_htlcs, option),
68076805
(29, self.context.temporary_channel_id, option),
68086806
(31, channel_pending_event_emitted, option),
6809-
(33, self.context.pending_monitor_updates, vec_type),
6807+
(33, self.context.blocked_monitor_updates, vec_type),
68106808
(35, pending_outbound_skimmed_fees, optional_vec),
68116809
(37, holding_cell_skimmed_fees, optional_vec),
68126810
});
@@ -7087,7 +7085,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
70877085
let mut temporary_channel_id: Option<[u8; 32]> = None;
70887086
let mut holder_max_accepted_htlcs: Option<u16> = None;
70897087

7090-
let mut pending_monitor_updates = Some(Vec::new());
7088+
let mut blocked_monitor_updates = Some(Vec::new());
70917089

70927090
let mut pending_outbound_skimmed_fees_opt: Option<Vec<Option<u64>>> = None;
70937091
let mut holding_cell_skimmed_fees_opt: Option<Vec<Option<u64>>> = None;
@@ -7114,7 +7112,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
71147112
(28, holder_max_accepted_htlcs, option),
71157113
(29, temporary_channel_id, option),
71167114
(31, channel_pending_event_emitted, option),
7117-
(33, pending_monitor_updates, vec_type),
7115+
(33, blocked_monitor_updates, vec_type),
71187116
(35, pending_outbound_skimmed_fees_opt, optional_vec),
71197117
(37, holding_cell_skimmed_fees_opt, optional_vec),
71207118
});
@@ -7307,7 +7305,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
73077305
channel_type: channel_type.unwrap(),
73087306
channel_keys_id,
73097307

7310-
pending_monitor_updates: pending_monitor_updates.unwrap(),
7308+
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
73117309
}
73127310
})
73137311
}

0 commit comments

Comments
 (0)