Skip to content

Commit 7c21491

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 be71d37 commit 7c21491

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
}
@@ -2699,7 +2699,7 @@ impl<SP: Deref> Channel<SP> where
26992699
where L::Target: Logger {
27002700
// Assert that we'll add the HTLC claim to the holding cell in `get_update_fulfill_htlc`
27012701
// (see equivalent if condition there).
2702-
assert!(self.context.channel_state.should_force_holding_cell());
2702+
assert!(!self.context.channel_state.can_generate_new_commitment());
27032703
let mon_update_id = self.context.latest_monitor_update_id; // Forget the ChannelMonitor update
27042704
let fulfill_resp = self.get_update_fulfill_htlc(htlc_id_arg, payment_preimage_arg, logger);
27052705
self.context.latest_monitor_update_id = mon_update_id;
@@ -2768,7 +2768,7 @@ impl<SP: Deref> Channel<SP> where
27682768
}],
27692769
};
27702770

2771-
if self.context.channel_state.should_force_holding_cell() {
2771+
if !self.context.channel_state.can_generate_new_commitment() {
27722772
// Note that this condition is the same as the assertion in
27732773
// `claim_htlc_while_disconnected_dropping_mon_update` and must match exactly -
27742774
// `claim_htlc_while_disconnected_dropping_mon_update` would not work correctly if we
@@ -2942,7 +2942,7 @@ impl<SP: Deref> Channel<SP> where
29422942
return Ok(None);
29432943
}
29442944

2945-
if self.context.channel_state.should_force_holding_cell() {
2945+
if !self.context.channel_state.can_generate_new_commitment() {
29462946
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!");
29472947
force_holding_cell = true;
29482948
}
@@ -3544,7 +3544,7 @@ impl<SP: Deref> Channel<SP> where
35443544
) -> (Option<ChannelMonitorUpdate>, Vec<(HTLCSource, PaymentHash)>)
35453545
where F::Target: FeeEstimator, L::Target: Logger
35463546
{
3547-
if matches!(self.context.channel_state, ChannelState::ChannelReady(_)) && !self.context.channel_state.should_force_holding_cell() {
3547+
if matches!(self.context.channel_state, ChannelState::ChannelReady(_)) && self.context.channel_state.can_generate_new_commitment() {
35483548
self.free_holding_cell_htlcs(fee_estimator, logger)
35493549
} else { (None, Vec::new()) }
35503550
}
@@ -5821,7 +5821,7 @@ impl<SP: Deref> Channel<SP> where
58215821
return Err(ChannelError::Ignore("Cannot send an HTLC while disconnected from channel counterparty".to_owned()));
58225822
}
58235823

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

0 commit comments

Comments
 (0)