Skip to content

Commit e5aadb7

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 f9c64f6 commit e5aadb7

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
@@ -5067,6 +5067,11 @@ where
50675067
let context = self;
50685068
assert!(funding.is_outbound());
50695069

5070+
if funding.get_channel_type().supports_anchor_zero_fee_commitments() {
5071+
debug_assert_eq!(context.feerate_per_kw, 0);
5072+
return 0;
5073+
}
5074+
50705075
let (htlc_success_tx_fee_sat, htlc_timeout_tx_fee_sat) = second_stage_tx_fees_sat(
50715076
funding.get_channel_type(), context.feerate_per_kw,
50725077
);
@@ -5168,11 +5173,16 @@ where
51685173
fn next_remote_commit_tx_fee_msat(
51695174
&self, funding: &FundingScope, htlc: Option<HTLCCandidate>, fee_spike_buffer_htlc: Option<()>,
51705175
) -> u64 {
5171-
debug_assert!(htlc.is_some() || fee_spike_buffer_htlc.is_some(), "At least one of the options must be set");
5172-
51735176
let context = self;
51745177
assert!(!funding.is_outbound());
51755178

5179+
if funding.get_channel_type().supports_anchor_zero_fee_commitments() {
5180+
debug_assert_eq!(context.feerate_per_kw, 0);
5181+
return 0
5182+
}
5183+
5184+
debug_assert!(htlc.is_some() || fee_spike_buffer_htlc.is_some(), "At least one of the options must be set");
5185+
51765186
let (htlc_success_tx_fee_sat, htlc_timeout_tx_fee_sat) = second_stage_tx_fees_sat(
51775187
funding.get_channel_type(), context.feerate_per_kw,
51785188
);
@@ -7974,6 +7984,12 @@ where
79747984
// unable to increase the fee, we don't try to force-close directly here.
79757985
return Ok(());
79767986
}
7987+
7988+
if self.funding.get_channel_type().supports_anchor_zero_fee_commitments() {
7989+
debug_assert_eq!(self.context.feerate_per_kw, 0);
7990+
return Ok(());
7991+
}
7992+
79777993
if self.context.feerate_per_kw < min_feerate {
79787994
log_info!(logger,
79797995
"Closing channel as feerate of {} is below required {} (the minimum required rate over the past day)",

0 commit comments

Comments
 (0)