Skip to content

Commit 507fb6d

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 0af83b8 commit 507fb6d

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
@@ -5062,6 +5062,11 @@ where
50625062
let context = self;
50635063
assert!(funding.is_outbound());
50645064

5065+
if funding.get_channel_type().supports_anchor_zero_fee_commitments() {
5066+
debug_assert_eq!(context.feerate_per_kw, 0);
5067+
return 0;
5068+
}
5069+
50655070
let (htlc_success_tx_fee_sat, htlc_timeout_tx_fee_sat) = second_stage_tx_fees_sat(
50665071
funding.get_channel_type(), context.feerate_per_kw,
50675072
);
@@ -5163,11 +5168,16 @@ where
51635168
fn next_remote_commit_tx_fee_msat(
51645169
&self, funding: &FundingScope, htlc: Option<HTLCCandidate>, fee_spike_buffer_htlc: Option<()>,
51655170
) -> u64 {
5166-
debug_assert!(htlc.is_some() || fee_spike_buffer_htlc.is_some(), "At least one of the options must be set");
5167-
51685171
let context = self;
51695172
assert!(!funding.is_outbound());
51705173

5174+
if funding.get_channel_type().supports_anchor_zero_fee_commitments() {
5175+
debug_assert_eq!(context.feerate_per_kw, 0);
5176+
return 0
5177+
}
5178+
5179+
debug_assert!(htlc.is_some() || fee_spike_buffer_htlc.is_some(), "At least one of the options must be set");
5180+
51715181
let (htlc_success_tx_fee_sat, htlc_timeout_tx_fee_sat) = second_stage_tx_fees_sat(
51725182
funding.get_channel_type(), context.feerate_per_kw,
51735183
);
@@ -7969,6 +7979,12 @@ where
79697979
// unable to increase the fee, we don't try to force-close directly here.
79707980
return Ok(());
79717981
}
7982+
7983+
if self.funding.get_channel_type().supports_anchor_zero_fee_commitments() {
7984+
debug_assert_eq!(self.context.feerate_per_kw, 0);
7985+
return Ok(());
7986+
}
7987+
79727988
if self.context.feerate_per_kw < min_feerate {
79737989
log_info!(logger,
79747990
"Closing channel as feerate of {} is below required {} (the minimum required rate over the past day)",

0 commit comments

Comments
 (0)