Skip to content

Commit 39f2834

Browse files
committed
f fly/unflown -> release/blocked
1 parent cc2a169 commit 39f2834

File tree

1 file changed

+52
-53
lines changed

1 file changed

+52
-53
lines changed

lightning/src/ln/channel.rs

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -481,13 +481,12 @@ pub(crate) const EXPIRE_PREV_CONFIG_TICKS: usize = 5;
481481

482482
struct PendingChannelMonitorUpdate {
483483
update: ChannelMonitorUpdate,
484-
/// In some cases we need to delay letting the [`ChannelMonitorUpdate`] fly until after an
485-
/// `Event` is processed by the user. This bool indicates the [`ChannelMonitorUpdate`] has
486-
/// flown and we're waiting to hear back, otherwise the update is waiting on some external
487-
/// event and the [`ChannelManager`] will update us when we're ready.
484+
/// In some cases we need to delay letting the [`ChannelMonitorUpdate`] go until after an
485+
/// `Event` is processed by the user. This bool indicates the [`ChannelMonitorUpdate`] is
486+
/// blocked on some externl event and the [`ChannelManager`] will update us when we're ready.
488487
///
489488
/// [`ChannelManager`]: super::channelmanager::ChannelManager
490-
flown: bool,
489+
blocked: bool,
491490
}
492491

493492
// TODO: We should refactor this to be an Inbound/OutboundChannel until initial setup handshaking
@@ -1988,48 +1987,48 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
19881987
}
19891988

19901989
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 {
1991-
let fly_cs_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);
1990+
let release_cs_monitor = self.pending_monitor_updates.iter().all(|upd| !upd.blocked);
19921991
match self.get_update_fulfill_htlc(htlc_id, payment_preimage, logger) {
19931992
UpdateFulfillFetch::NewClaim { mut monitor_update, htlc_value_msat, msg } => {
19941993
// Even if we aren't supposed to let new monitor updates with commitment state
1995-
// updates fly, we still need to push the preimage ChannelMonitorUpdateStep no
1994+
// updates run, we still need to push the preimage ChannelMonitorUpdateStep no
19961995
// matter what. Sadly, to push a new monitor update which flies before others
19971996
// already queued, we have to insert it into the pending queue and update the
19981997
// update_ids of all the following monitors.
1999-
let flown_monitor_pos = if fly_cs_monitor && msg.is_some() {
1998+
let unblocked_monitor_pos = if release_cs_monitor && msg.is_some() {
20001999
// build_commitment_no_status_check may bump latest_monitor_id but we want them to be
20012000
// strictly increasing by one, so decrement it here.
20022001
let mut additional_update = self.build_commitment_no_status_check(logger);
20032002
self.latest_monitor_update_id = monitor_update.update_id;
20042003
monitor_update.updates.append(&mut additional_update.updates);
20052004
self.pending_monitor_updates.push(PendingChannelMonitorUpdate {
2006-
update: monitor_update, flown: true,
2005+
update: monitor_update, blocked: false,
20072006
});
20082007
self.pending_monitor_updates.len() - 1
20092008
} else {
2010-
let insert_pos = self.pending_monitor_updates.iter().position(|upd| !upd.flown)
2009+
let insert_pos = self.pending_monitor_updates.iter().position(|upd| upd.blocked)
20112010
.unwrap_or(self.pending_monitor_updates.len());
20122011
let new_mon_id = self.pending_monitor_updates.get(insert_pos)
20132012
.map(|upd| upd.update.update_id).unwrap_or(monitor_update.update_id);
20142013
monitor_update.update_id = new_mon_id;
20152014
self.pending_monitor_updates.insert(insert_pos, PendingChannelMonitorUpdate {
2016-
update: monitor_update, flown: true,
2015+
update: monitor_update, blocked: false,
20172016
});
20182017
for held_update in self.pending_monitor_updates.iter_mut().skip(insert_pos + 1) {
20192018
held_update.update.update_id += 1;
20202019
}
20212020
if msg.is_some() {
2022-
debug_assert!(false, "If there is a pending unflown monitor we should have MonitorUpdateInProgress set");
2021+
debug_assert!(false, "If there is a pending blocked monitor we should have MonitorUpdateInProgress set");
20232022
let update = self.build_commitment_no_status_check(logger);
20242023
self.pending_monitor_updates.push(PendingChannelMonitorUpdate {
2025-
update, flown: false,
2024+
update, blocked: true,
20262025
});
20272026
}
20282027
insert_pos
20292028
};
20302029
self.monitor_updating_paused(false, msg.is_some(), false, Vec::new(), Vec::new(), Vec::new());
20312030
UpdateFulfillCommitFetch::NewClaim {
2032-
monitor_update: &self.pending_monitor_updates.get(flown_monitor_pos)
2031+
monitor_update: &self.pending_monitor_updates.get(unblocked_monitor_pos)
20332032
.expect("We just pushed the monitor update").update,
20342033
htlc_value_msat,
20352034
}
@@ -3277,11 +3276,11 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
32773276
}
32783277
log_debug!(logger, "Received valid commitment_signed from peer in channel {}, updated HTLC state but awaiting a monitor update resolution to reply.",
32793278
log_bytes!(self.channel_id));
3280-
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);
3279+
let release_monitor = self.pending_monitor_updates.iter().all(|upd| !upd.blocked);
32813280
self.pending_monitor_updates.push(PendingChannelMonitorUpdate {
3282-
update: monitor_update, flown: fly_monitor
3281+
update: monitor_update, blocked: !release_monitor
32833282
});
3284-
return Ok(if fly_monitor { self.pending_monitor_updates.last().map(|upd| &upd.update) } else { None });
3283+
return Ok(if release_monitor { self.pending_monitor_updates.last().map(|upd| &upd.update) } else { None });
32853284
}
32863285

32873286
let need_commitment_signed = if need_commitment && (self.channel_state & (ChannelState::AwaitingRemoteRevoke as u32)) == 0 {
@@ -3298,12 +3297,12 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
32983297

32993298
log_debug!(logger, "Received valid commitment_signed from peer in channel {}, updating HTLC state and responding with{} a revoke_and_ack.",
33003299
log_bytes!(self.channel_id()), if need_commitment_signed { " our own commitment_signed and" } else { "" });
3301-
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);
3300+
let release_monitor = self.pending_monitor_updates.iter().all(|upd| !upd.blocked);
33023301
self.pending_monitor_updates.push(PendingChannelMonitorUpdate {
3303-
update: monitor_update, flown: fly_monitor,
3302+
update: monitor_update, blocked: !release_monitor,
33043303
});
33053304
self.monitor_updating_paused(true, need_commitment_signed, false, Vec::new(), Vec::new(), Vec::new());
3306-
return Ok(if fly_monitor { self.pending_monitor_updates.last().map(|upd| &upd.update) } else { None });
3305+
return Ok(if release_monitor { self.pending_monitor_updates.last().map(|upd| &upd.update) } else { None });
33073306
}
33083307

33093308
/// Public version of the below, checking relevant preconditions first.
@@ -3418,11 +3417,11 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
34183417
update_add_htlcs.len(), update_fulfill_htlcs.len(), update_fail_htlcs.len());
34193418

34203419
self.monitor_updating_paused(false, true, false, Vec::new(), Vec::new(), Vec::new());
3421-
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);
3420+
let release_monitor = self.pending_monitor_updates.iter().all(|upd| !upd.blocked);
34223421
self.pending_monitor_updates.push(PendingChannelMonitorUpdate {
3423-
update: monitor_update, flown: fly_monitor,
3422+
update: monitor_update, blocked: !release_monitor,
34243423
});
3425-
(if fly_monitor { self.pending_monitor_updates.last().map(|upd| &upd.update) } else { None },
3424+
(if release_monitor { self.pending_monitor_updates.last().map(|upd| &upd.update) } else { None },
34263425
htlcs_to_fail)
34273426
} else {
34283427
(None, Vec::new())
@@ -3631,12 +3630,12 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
36313630
self.monitor_pending_failures.append(&mut revoked_htlcs);
36323631
self.monitor_pending_finalized_fulfills.append(&mut finalized_claimed_htlcs);
36333632
log_debug!(logger, "Received a valid revoke_and_ack for channel {} but awaiting a monitor update resolution to reply.", log_bytes!(self.channel_id()));
3634-
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);
3633+
let release_monitor = self.pending_monitor_updates.iter().all(|upd| !upd.blocked);
36353634
self.pending_monitor_updates.push(PendingChannelMonitorUpdate {
3636-
update: monitor_update, flown: fly_monitor,
3635+
update: monitor_update, blocked: !release_monitor,
36373636
});
36383637
return Ok((Vec::new(),
3639-
if fly_monitor { self.pending_monitor_updates.last().map(|upd| &upd.update) } else { None }));
3638+
if release_monitor { self.pending_monitor_updates.last().map(|upd| &upd.update) } else { None }));
36403639
}
36413640

36423641
match self.free_holding_cell_htlcs(logger) {
@@ -3648,12 +3647,12 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
36483647
monitor_update.updates.append(&mut additional_update.updates);
36493648

36503649
self.monitor_updating_paused(false, true, false, to_forward_infos, revoked_htlcs, finalized_claimed_htlcs);
3651-
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);
3650+
let release_monitor = self.pending_monitor_updates.iter().all(|upd| !upd.blocked);
36523651
self.pending_monitor_updates.push(PendingChannelMonitorUpdate {
3653-
update: monitor_update, flown: fly_monitor,
3652+
update: monitor_update, blocked: !release_monitor,
36543653
});
36553654
Ok((htlcs_to_fail,
3656-
if fly_monitor { self.pending_monitor_updates.last().map(|upd| &upd.update) } else { None }))
3655+
if release_monitor { self.pending_monitor_updates.last().map(|upd| &upd.update) } else { None }))
36573656
},
36583657
(None, htlcs_to_fail) => {
36593658
if require_commitment {
@@ -3667,21 +3666,21 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
36673666
log_debug!(logger, "Received a valid revoke_and_ack for channel {}. Responding with a commitment update with {} HTLCs failed.",
36683667
log_bytes!(self.channel_id()), update_fail_htlcs.len() + update_fail_malformed_htlcs.len());
36693668
self.monitor_updating_paused(false, true, false, to_forward_infos, revoked_htlcs, finalized_claimed_htlcs);
3670-
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);
3669+
let release_monitor = self.pending_monitor_updates.iter().all(|upd| !upd.blocked);
36713670
self.pending_monitor_updates.push(PendingChannelMonitorUpdate {
3672-
update: monitor_update, flown: fly_monitor,
3671+
update: monitor_update, blocked: !release_monitor,
36733672
});
36743673
Ok((htlcs_to_fail,
3675-
if fly_monitor { self.pending_monitor_updates.last().map(|upd| &upd.update) } else { None }))
3674+
if release_monitor { self.pending_monitor_updates.last().map(|upd| &upd.update) } else { None }))
36763675
} else {
36773676
log_debug!(logger, "Received a valid revoke_and_ack for channel {} with no reply necessary.", log_bytes!(self.channel_id()));
36783677
self.monitor_updating_paused(false, false, false, to_forward_infos, revoked_htlcs, finalized_claimed_htlcs);
3679-
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);
3678+
let release_monitor = self.pending_monitor_updates.iter().all(|upd| !upd.blocked);
36803679
self.pending_monitor_updates.push(PendingChannelMonitorUpdate {
3681-
update: monitor_update, flown: fly_monitor,
3680+
update: monitor_update, blocked: !release_monitor,
36823681
});
36833682
Ok((htlcs_to_fail,
3684-
if fly_monitor { self.pending_monitor_updates.last().map(|upd| &upd.update) } else { None }))
3683+
if release_monitor { self.pending_monitor_updates.last().map(|upd| &upd.update) } else { None }))
36853684
}
36863685
}
36873686
}
@@ -3870,11 +3869,11 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
38703869
{
38713870
assert_eq!(self.channel_state & ChannelState::MonitorUpdateInProgress as u32, ChannelState::MonitorUpdateInProgress as u32);
38723871
self.channel_state &= !(ChannelState::MonitorUpdateInProgress as u32);
3873-
let mut found_unflown = false;
3872+
let mut found_blocked = false;
38743873
self.pending_monitor_updates.retain(|upd| {
3875-
if found_unflown { debug_assert!(!upd.flown, "No mons may fly after one is paused"); }
3876-
if !upd.flown { found_unflown = true; }
3877-
!upd.flown
3874+
if found_blocked { debug_assert!(upd.blocked, "No mons may be unblocked after a blocked one"); }
3875+
if upd.blocked { found_blocked = true; }
3876+
upd.blocked
38783877
});
38793878

38803879
// If we're past (or at) the FundingSent stage on an outbound channel, try to
@@ -4418,11 +4417,11 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
44184417
}],
44194418
};
44204419
self.monitor_updating_paused(false, false, false, Vec::new(), Vec::new(), Vec::new());
4421-
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);
4420+
let release_monitor = self.pending_monitor_updates.iter().all(|upd| !upd.blocked);
44224421
self.pending_monitor_updates.push(PendingChannelMonitorUpdate {
4423-
update: monitor_update, flown: fly_monitor,
4422+
update: monitor_update, blocked: !release_monitor,
44244423
});
4425-
if fly_monitor { self.pending_monitor_updates.last().map(|upd| &upd.update) } else { None }
4424+
if release_monitor { self.pending_monitor_updates.last().map(|upd| &upd.update) } else { None }
44264425
} else { None };
44274426
let shutdown = if send_shutdown {
44284427
Some(msgs::Shutdown {
@@ -4994,12 +4993,12 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
49944993
(self.channel_state & ChannelState::MonitorUpdateInProgress as u32) != 0
49954994
}
49964995

4997-
/// Returns the next unflown monitor update, if one exists, and a bool which indicates a
4998-
/// further unflown monitor update exists after the next.
4999-
pub fn fly_next_unflown_monitor_update(&mut self) -> Option<(&ChannelMonitorUpdate, bool)> {
4996+
/// Returns the next blocked monitor update, if one exists, and a bool which indicates a
4997+
/// further blocked monitor update exists after the next.
4998+
pub fn unblock_next_blocked_monitor_update(&mut self) -> Option<(&ChannelMonitorUpdate, bool)> {
50004999
for i in 0..self.pending_monitor_updates.len() {
5001-
if !self.pending_monitor_updates[i].flown {
5002-
self.pending_monitor_updates[i].flown = true;
5000+
if self.pending_monitor_updates[i].blocked {
5001+
self.pending_monitor_updates[i].blocked = false;
50035002
return Some((&self.pending_monitor_updates[i].update,
50045003
self.pending_monitor_updates.len() > i + 1));
50055004
}
@@ -6061,11 +6060,11 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
60616060
let monitor_update = self.build_commitment_no_status_check(logger);
60626061
self.monitor_updating_paused(false, true, false, Vec::new(), Vec::new(), Vec::new());
60636062

6064-
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);
6063+
let release_monitor = self.pending_monitor_updates.iter().all(|upd| !upd.blocked);
60656064
self.pending_monitor_updates.push(PendingChannelMonitorUpdate {
6066-
update: monitor_update, flown: fly_monitor,
6065+
update: monitor_update, blocked: !release_monitor,
60676066
});
6068-
Ok(if fly_monitor { self.pending_monitor_updates.last().map(|upd| &upd.update) } else { None })
6067+
Ok(if release_monitor { self.pending_monitor_updates.last().map(|upd| &upd.update) } else { None })
60696068
},
60706069
None => Ok(None)
60716070
}
@@ -6154,11 +6153,11 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
61546153
}],
61556154
};
61566155
self.monitor_updating_paused(false, false, false, Vec::new(), Vec::new(), Vec::new());
6157-
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);
6156+
let release_monitor = self.pending_monitor_updates.iter().all(|upd| !upd.blocked);
61586157
self.pending_monitor_updates.push(PendingChannelMonitorUpdate {
6159-
update: monitor_update, flown: fly_monitor,
6158+
update: monitor_update, blocked: !release_monitor,
61606159
});
6161-
if fly_monitor { self.pending_monitor_updates.last().map(|upd| &upd.update) } else { None }
6160+
if release_monitor { self.pending_monitor_updates.last().map(|upd| &upd.update) } else { None }
61626161
} else { None };
61636162
let shutdown = msgs::Shutdown {
61646163
channel_id: self.channel_id,

0 commit comments

Comments
 (0)