Skip to content

Commit ccf3ef5

Browse files
carlaKCTheBlueMatt
andcommitted
ln: return early and assert in fee calculation and checks
When we have zero fee commitments, we don't need to calculate our fee rate or check that it isn't stale because it is always zero. Co-authored-by: Matt Corallo <[email protected]>
1 parent 2a9b187 commit ccf3ef5

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

lightning/src/ln/channel.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5049,6 +5049,11 @@ where
50495049
let context = self;
50505050
assert!(funding.is_outbound());
50515051

5052+
if funding.get_channel_type().supports_anchor_zero_fee_commitments() {
5053+
debug_assert_eq!(context.feerate_per_kw, 0);
5054+
return 0;
5055+
}
5056+
50525057
let (htlc_success_tx_fee_sat, htlc_timeout_tx_fee_sat) = second_stage_tx_fees_sat(
50535058
funding.get_channel_type(), context.feerate_per_kw,
50545059
);
@@ -5150,11 +5155,16 @@ where
51505155
fn next_remote_commit_tx_fee_msat(
51515156
&self, funding: &FundingScope, htlc: Option<HTLCCandidate>, fee_spike_buffer_htlc: Option<()>,
51525157
) -> u64 {
5153-
debug_assert!(htlc.is_some() || fee_spike_buffer_htlc.is_some(), "At least one of the options must be set");
5154-
51555158
let context = self;
51565159
assert!(!funding.is_outbound());
51575160

5161+
if funding.get_channel_type().supports_anchor_zero_fee_commitments() {
5162+
debug_assert_eq!(context.feerate_per_kw, 0);
5163+
return 0
5164+
}
5165+
5166+
debug_assert!(htlc.is_some() || fee_spike_buffer_htlc.is_some(), "At least one of the options must be set");
5167+
51585168
let (htlc_success_tx_fee_sat, htlc_timeout_tx_fee_sat) = second_stage_tx_fees_sat(
51595169
funding.get_channel_type(), context.feerate_per_kw,
51605170
);
@@ -7961,6 +7971,12 @@ where
79617971
// unable to increase the fee, we don't try to force-close directly here.
79627972
return Ok(());
79637973
}
7974+
7975+
if self.funding.get_channel_type().supports_anchor_zero_fee_commitments() {
7976+
debug_assert_eq!(self.context.feerate_per_kw, 0);
7977+
return Ok(());
7978+
}
7979+
79647980
if self.context.feerate_per_kw < min_feerate {
79657981
log_info!(logger,
79667982
"Closing channel as feerate of {} is below required {} (the minimum required rate over the past day)",

0 commit comments

Comments
 (0)