Skip to content

Commit 178c9ee

Browse files
committed
Rename should_force_holding_cell to can_generate_new_commitment
This better reflects the intent behind the callsites of the method.
1 parent a657244 commit 178c9ee

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

lightning/src/ln/channel.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -525,14 +525,14 @@ impl ChannelState {
525525
}
526526
}
527527

528-
fn should_force_holding_cell(&self) -> bool {
528+
fn can_generate_new_commitment(&self) -> bool {
529529
match self {
530530
ChannelState::ChannelReady(flags) =>
531-
flags.is_set(ChannelReadyFlags::AWAITING_REMOTE_REVOKE) ||
532-
flags.is_set(FundedStateFlags::MONITOR_UPDATE_IN_PROGRESS.into()) ||
533-
flags.is_set(FundedStateFlags::PEER_DISCONNECTED.into()),
531+
!flags.is_set(ChannelReadyFlags::AWAITING_REMOTE_REVOKE) &&
532+
!flags.is_set(FundedStateFlags::MONITOR_UPDATE_IN_PROGRESS.into()) &&
533+
!flags.is_set(FundedStateFlags::PEER_DISCONNECTED.into()),
534534
_ => {
535-
debug_assert!(false, "The holding cell is only valid within ChannelReady");
535+
debug_assert!(false, "Can only generate new commitment within ChannelReady");
536536
false
537537
},
538538
}
@@ -2709,7 +2709,7 @@ impl<SP: Deref> Channel<SP> where
27092709
where L::Target: Logger {
27102710
// Assert that we'll add the HTLC claim to the holding cell in `get_update_fulfill_htlc`
27112711
// (see equivalent if condition there).
2712-
assert!(self.context.channel_state.should_force_holding_cell());
2712+
assert!(!self.context.channel_state.can_generate_new_commitment());
27132713
let mon_update_id = self.context.latest_monitor_update_id; // Forget the ChannelMonitor update
27142714
let fulfill_resp = self.get_update_fulfill_htlc(htlc_id_arg, payment_preimage_arg, logger);
27152715
self.context.latest_monitor_update_id = mon_update_id;
@@ -2779,7 +2779,7 @@ impl<SP: Deref> Channel<SP> where
27792779
}],
27802780
};
27812781

2782-
if self.context.channel_state.should_force_holding_cell() {
2782+
if !self.context.channel_state.can_generate_new_commitment() {
27832783
// Note that this condition is the same as the assertion in
27842784
// `claim_htlc_while_disconnected_dropping_mon_update` and must match exactly -
27852785
// `claim_htlc_while_disconnected_dropping_mon_update` would not work correctly if we
@@ -2953,7 +2953,7 @@ impl<SP: Deref> Channel<SP> where
29532953
return Ok(None);
29542954
}
29552955

2956-
if self.context.channel_state.should_force_holding_cell() {
2956+
if !self.context.channel_state.can_generate_new_commitment() {
29572957
debug_assert!(force_holding_cell, "!force_holding_cell is only called when emptying the holding cell, so we shouldn't end up back in it!");
29582958
force_holding_cell = true;
29592959
}
@@ -3570,7 +3570,7 @@ impl<SP: Deref> Channel<SP> where
35703570
) -> (Option<ChannelMonitorUpdate>, Vec<(HTLCSource, PaymentHash)>)
35713571
where F::Target: FeeEstimator, L::Target: Logger
35723572
{
3573-
if matches!(self.context.channel_state, ChannelState::ChannelReady(_)) && !self.context.channel_state.should_force_holding_cell() {
3573+
if matches!(self.context.channel_state, ChannelState::ChannelReady(_)) && self.context.channel_state.can_generate_new_commitment() {
35743574
self.free_holding_cell_htlcs(fee_estimator, logger)
35753575
} else { (None, Vec::new()) }
35763576
}
@@ -5857,7 +5857,7 @@ impl<SP: Deref> Channel<SP> where
58575857
return Err(ChannelError::Ignore("Cannot send an HTLC while disconnected from channel counterparty".to_owned()));
58585858
}
58595859

5860-
let need_holding_cell = self.context.channel_state.should_force_holding_cell();
5860+
let need_holding_cell = !self.context.channel_state.can_generate_new_commitment();
58615861
log_debug!(logger, "Pushing new outbound HTLC with hash {} for {} msat {}",
58625862
payment_hash, amount_msat,
58635863
if force_holding_cell { "into holding cell" }

0 commit comments

Comments
 (0)