Skip to content

Commit caf0ea1

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 <git@bluematt.me>
1 parent 5a04a84 commit caf0ea1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lightning/src/ln/channel.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4966,6 +4966,11 @@ where
49664966
let context = &self;
49674967
assert!(funding.is_outbound());
49684968

4969+
if funding.get_channel_type().supports_anchor_zero_fee_commitments() {
4970+
debug_assert_eq!(context.feerate_per_kw, 0);
4971+
return 0;
4972+
}
4973+
49694974
let (htlc_success_tx_fee_sat, htlc_timeout_tx_fee_sat) = second_stage_tx_fees_sat(
49704975
funding.get_channel_type(), context.feerate_per_kw,
49714976
);
@@ -5067,6 +5072,11 @@ where
50675072
fn next_remote_commit_tx_fee_msat(
50685073
&self, funding: &FundingScope, htlc: Option<HTLCCandidate>, fee_spike_buffer_htlc: Option<()>,
50695074
) -> u64 {
5075+
if funding.get_channel_type().supports_anchor_zero_fee_commitments() {
5076+
debug_assert_eq!(self.feerate_per_kw, 0);
5077+
return 0
5078+
}
5079+
50705080
debug_assert!(htlc.is_some() || fee_spike_buffer_htlc.is_some(), "At least one of the options must be set");
50715081

50725082
let context = &self;
@@ -7414,6 +7424,12 @@ where
74147424
// unable to increase the fee, we don't try to force-close directly here.
74157425
return Ok(());
74167426
}
7427+
7428+
if self.funding.get_channel_type().supports_anchor_zero_fee_commitments() {
7429+
debug_assert_eq!(self.context.feerate_per_kw, 0);
7430+
return Ok(());
7431+
}
7432+
74177433
if self.context.feerate_per_kw < min_feerate {
74187434
log_info!(logger,
74197435
"Closing channel as feerate of {} is below required {} (the minimum required rate over the past day)",

0 commit comments

Comments
 (0)