Skip to content

Commit 001c8e9

Browse files
committed
ln: do not maintain fee spike buffer for zero fee commitment channels
1 parent 2c82903 commit 001c8e9

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

lightning/src/ln/channel.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4296,14 +4296,22 @@ where
42964296
funding.get_value_satoshis() * 1000 - pending_value_to_self_msat;
42974297

42984298
if !funding.is_outbound() {
4299-
// `Some(())` is for the fee spike buffer we keep for the remote. This deviates from
4300-
// the spec because the fee spike buffer requirement doesn't exist on the receiver's
4301-
// side, only on the sender's. Note that with anchor outputs we are no longer as
4302-
// sensitive to fee spikes, so we need to account for them.
4299+
// `Some(())` is for the fee spike buffer we keep for the remote if the channel is not
4300+
// zero fee. This deviates from the spec because the fee spike buffer requirement
4301+
// doesn't exist on the receiver's side, only on the sender's. Note that with anchor
4302+
// outputs we are no longer as sensitive to fee spikes, so we need to account for them.
43034303
//
43044304
// A `None` `HTLCCandidate` is used as in this case because we're already accounting for
43054305
// the incoming HTLC as it has been fully committed by both sides.
4306-
let mut remote_fee_cost_incl_stuck_buffer_msat = self.next_remote_commit_tx_fee_msat(funding, None, Some(()));
4306+
let fee_spike_buffer_htlc = if funding.get_channel_type().supports_anchor_zero_fee_commitments() {
4307+
None
4308+
} else {
4309+
Some(())
4310+
};
4311+
4312+
let mut remote_fee_cost_incl_stuck_buffer_msat = self.next_remote_commit_tx_fee_msat(
4313+
funding, None, fee_spike_buffer_htlc,
4314+
);
43074315
if !funding.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
43084316
remote_fee_cost_incl_stuck_buffer_msat *= FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE;
43094317
}
@@ -4845,10 +4853,15 @@ where
48454853
// and the answer will in turn change the amount itself — making it a circular
48464854
// dependency.
48474855
// This complicates the computation around dust-values, up to the one-htlc-value.
4856+
let fee_spike_buffer_htlc = if funding.get_channel_type().supports_anchor_zero_fee_commitments() {
4857+
None
4858+
} else {
4859+
Some(())
4860+
};
48484861
let htlc_above_dust = HTLCCandidate::new(real_htlc_timeout_tx_fee_sat * 1000, HTLCInitiator::LocalOffered);
4849-
let mut max_reserved_commit_tx_fee_msat = context.next_local_commit_tx_fee_msat(&funding, htlc_above_dust, Some(()));
4862+
let mut max_reserved_commit_tx_fee_msat = context.next_local_commit_tx_fee_msat(&funding, htlc_above_dust, fee_spike_buffer_htlc);
48504863
let htlc_dust = HTLCCandidate::new(real_htlc_timeout_tx_fee_sat * 1000 - 1, HTLCInitiator::LocalOffered);
4851-
let mut min_reserved_commit_tx_fee_msat = context.next_local_commit_tx_fee_msat(&funding, htlc_dust, Some(()));
4864+
let mut min_reserved_commit_tx_fee_msat = context.next_local_commit_tx_fee_msat(&funding, htlc_dust, fee_spike_buffer_htlc);
48524865
if !funding.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
48534866
max_reserved_commit_tx_fee_msat *= FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE;
48544867
min_reserved_commit_tx_fee_msat *= FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE;
@@ -4972,6 +4985,7 @@ where
49724985

49734986
if funding.get_channel_type().supports_anchor_zero_fee_commitments() {
49744987
debug_assert_eq!(context.feerate_per_kw, 0);
4988+
debug_assert!(fee_spike_buffer_htlc.is_none());
49754989
return 0;
49764990
}
49774991

@@ -5078,6 +5092,7 @@ where
50785092
) -> u64 {
50795093
if funding.get_channel_type().supports_anchor_zero_fee_commitments() {
50805094
debug_assert_eq!(self.feerate_per_kw, 0);
5095+
debug_assert!(fee_spike_buffer_htlc.is_none());
50815096
return 0
50825097
}
50835098

0 commit comments

Comments
 (0)