Skip to content

Commit 32a31af

Browse files
committed
Rename Channel::pending_monitor_updates to blocked
To differentiate between in-flight pending completion and blocked updates.
1 parent 38740e2 commit 32a31af

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
@@ -859,11 +859,9 @@ pub(super) struct ChannelContext<Signer: ChannelSigner> {
859859
/// [`SignerProvider::derive_channel_signer`].
860860
channel_keys_id: [u8; 32],
861861

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

869867
impl<Signer: ChannelSigner> ChannelContext<Signer> {
@@ -2254,7 +2252,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
22542252
}
22552253

22562254
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 {
2257-
let release_cs_monitor = self.context.pending_monitor_updates.is_empty();
2255+
let release_cs_monitor = self.context.blocked_monitor_updates.is_empty();
22582256
match self.get_update_fulfill_htlc(htlc_id, payment_preimage, logger) {
22592257
UpdateFulfillFetch::NewClaim { mut monitor_update, htlc_value_msat, msg } => {
22602258
// Even if we aren't supposed to let new monitor updates with commitment state
@@ -2269,15 +2267,15 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
22692267
self.context.latest_monitor_update_id = monitor_update.update_id;
22702268
monitor_update.updates.append(&mut additional_update.updates);
22712269
} else {
2272-
let new_mon_id = self.context.pending_monitor_updates.get(0)
2270+
let new_mon_id = self.context.blocked_monitor_updates.get(0)
22732271
.map(|upd| upd.update.update_id).unwrap_or(monitor_update.update_id);
22742272
monitor_update.update_id = new_mon_id;
2275-
for held_update in self.context.pending_monitor_updates.iter_mut() {
2273+
for held_update in self.context.blocked_monitor_updates.iter_mut() {
22762274
held_update.update.update_id += 1;
22772275
}
22782276
if msg.is_some() {
22792277
let update = self.build_commitment_no_status_check(logger);
2280-
self.context.pending_monitor_updates.push(PendingChannelMonitorUpdate {
2278+
self.context.blocked_monitor_updates.push(PendingChannelMonitorUpdate {
22812279
update,
22822280
});
22832281
}
@@ -4398,25 +4396,25 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
43984396

43994397
/// Gets the latest [`ChannelMonitorUpdate`] ID which has been released and is in-flight.
44004398
pub fn get_latest_unblocked_monitor_update_id(&self) -> u64 {
4401-
if self.context.pending_monitor_updates.is_empty() { return self.context.get_latest_monitor_update_id(); }
4402-
self.context.pending_monitor_updates[0].update.update_id - 1
4399+
if self.context.blocked_monitor_updates.is_empty() { return self.context.get_latest_monitor_update_id(); }
4400+
self.context.blocked_monitor_updates[0].update.update_id - 1
44034401
}
44044402

44054403
/// Returns the next blocked monitor update, if one exists, and a bool which indicates a
44064404
/// further blocked monitor update exists after the next.
44074405
pub fn unblock_next_blocked_monitor_update(&mut self) -> Option<(ChannelMonitorUpdate, bool)> {
4408-
if self.context.pending_monitor_updates.is_empty() { return None; }
4409-
Some((self.context.pending_monitor_updates.remove(0).update,
4410-
!self.context.pending_monitor_updates.is_empty()))
4406+
if self.context.blocked_monitor_updates.is_empty() { return None; }
4407+
Some((self.context.blocked_monitor_updates.remove(0).update,
4408+
!self.context.blocked_monitor_updates.is_empty()))
44114409
}
44124410

44134411
/// Pushes a new monitor update into our monitor update queue, returning it if it should be
44144412
/// immediately given to the user for persisting or `None` if it should be held as blocked.
44154413
fn push_ret_blockable_mon_update(&mut self, update: ChannelMonitorUpdate)
44164414
-> Option<ChannelMonitorUpdate> {
4417-
let release_monitor = self.context.pending_monitor_updates.is_empty();
4415+
let release_monitor = self.context.blocked_monitor_updates.is_empty();
44184416
if !release_monitor {
4419-
self.context.pending_monitor_updates.push(PendingChannelMonitorUpdate {
4417+
self.context.blocked_monitor_updates.push(PendingChannelMonitorUpdate {
44204418
update,
44214419
});
44224420
None
@@ -4426,7 +4424,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
44264424
}
44274425

44284426
pub fn blocked_monitor_updates_pending(&self) -> usize {
4429-
self.context.pending_monitor_updates.len()
4427+
self.context.blocked_monitor_updates.len()
44304428
}
44314429

44324430
/// Returns true if the channel is awaiting the persistence of the initial ChannelMonitor.
@@ -5571,7 +5569,7 @@ impl<Signer: WriteableEcdsaChannelSigner> OutboundV1Channel<Signer> {
55715569
channel_type,
55725570
channel_keys_id,
55735571

5574-
pending_monitor_updates: Vec::new(),
5572+
blocked_monitor_updates: Vec::new(),
55755573
}
55765574
})
55775575
}
@@ -6201,7 +6199,7 @@ impl<Signer: WriteableEcdsaChannelSigner> InboundV1Channel<Signer> {
62016199
channel_type,
62026200
channel_keys_id,
62036201

6204-
pending_monitor_updates: Vec::new(),
6202+
blocked_monitor_updates: Vec::new(),
62056203
}
62066204
};
62076205

@@ -6767,7 +6765,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
67676765
(28, holder_max_accepted_htlcs, option),
67686766
(29, self.context.temporary_channel_id, option),
67696767
(31, channel_pending_event_emitted, option),
6770-
(33, self.context.pending_monitor_updates, vec_type),
6768+
(33, self.context.blocked_monitor_updates, vec_type),
67716769
});
67726770

67736771
Ok(())
@@ -7044,7 +7042,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
70447042
let mut temporary_channel_id: Option<[u8; 32]> = None;
70457043
let mut holder_max_accepted_htlcs: Option<u16> = None;
70467044

7047-
let mut pending_monitor_updates = Some(Vec::new());
7045+
let mut blocked_monitor_updates = Some(Vec::new());
70487046

70497047
read_tlv_fields!(reader, {
70507048
(0, announcement_sigs, option),
@@ -7068,7 +7066,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
70687066
(28, holder_max_accepted_htlcs, option),
70697067
(29, temporary_channel_id, option),
70707068
(31, channel_pending_event_emitted, option),
7071-
(33, pending_monitor_updates, vec_type),
7069+
(33, blocked_monitor_updates, vec_type),
70727070
});
70737071

70747072
let (channel_keys_id, holder_signer) = if let Some(channel_keys_id) = channel_keys_id {
@@ -7240,7 +7238,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
72407238
channel_type: channel_type.unwrap(),
72417239
channel_keys_id,
72427240

7243-
pending_monitor_updates: pending_monitor_updates.unwrap(),
7241+
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
72447242
}
72457243
})
72467244
}

0 commit comments

Comments
 (0)