Skip to content

Commit

Permalink
f - Always pass FundingScope
Browse files Browse the repository at this point in the history
  • Loading branch information
jkczyz committed Feb 19, 2025
1 parent 04abb58 commit 15f1c21
Showing 1 changed file with 10 additions and 40 deletions.
50 changes: 10 additions & 40 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3868,17 +3868,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
}

let htlc_above_dust = HTLCCandidate::new(real_dust_limit_timeout_sat * 1000, HTLCInitiator::LocalOffered);
let mut max_reserved_commit_tx_fee_msat = context.next_local_commit_tx_fee_msat(
#[cfg(any(test, fuzzing))]
&funding,
htlc_above_dust, Some(()),
);
let mut max_reserved_commit_tx_fee_msat = context.next_local_commit_tx_fee_msat(&funding, htlc_above_dust, Some(()));
let htlc_dust = HTLCCandidate::new(real_dust_limit_timeout_sat * 1000 - 1, HTLCInitiator::LocalOffered);
let mut min_reserved_commit_tx_fee_msat = context.next_local_commit_tx_fee_msat(
#[cfg(any(test, fuzzing))]
&funding,
htlc_dust, Some(()),
);
let mut min_reserved_commit_tx_fee_msat = context.next_local_commit_tx_fee_msat(&funding, htlc_dust, Some(()));
if !context.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
max_reserved_commit_tx_fee_msat *= FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE;
min_reserved_commit_tx_fee_msat *= FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE;
Expand Down Expand Up @@ -3907,11 +3899,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
}

let htlc_above_dust = HTLCCandidate::new(real_dust_limit_success_sat * 1000, HTLCInitiator::LocalOffered);
let max_reserved_commit_tx_fee_msat = context.next_remote_commit_tx_fee_msat(
#[cfg(any(test, fuzzing))]
&funding,
Some(htlc_above_dust), None,
);
let max_reserved_commit_tx_fee_msat = context.next_remote_commit_tx_fee_msat(&funding, Some(htlc_above_dust), None);

let holder_selected_chan_reserve_msat = funding.holder_selected_channel_reserve_satoshis * 1000;
let remote_balance_msat = (funding.channel_value_satoshis * 1000 - funding.value_to_self_msat)
Expand Down Expand Up @@ -4009,10 +3997,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
///
/// Dust HTLCs are excluded.
fn next_local_commit_tx_fee_msat(
&self,
#[cfg(any(test, fuzzing))]
funding: &FundingScope,
htlc: HTLCCandidate, fee_spike_buffer_htlc: Option<()>,
&self, _funding: &FundingScope, htlc: HTLCCandidate, fee_spike_buffer_htlc: Option<()>,
) -> u64 {
let context = &self;
assert!(context.is_outbound());
Expand Down Expand Up @@ -4102,7 +4087,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
},
feerate: context.feerate_per_kw,
};
*funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = Some(commitment_tx_info);
*_funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = Some(commitment_tx_info);
}
res
}
Expand All @@ -4118,10 +4103,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
///
/// Dust HTLCs are excluded.
fn next_remote_commit_tx_fee_msat(
&self,
#[cfg(any(test, fuzzing))]
funding: &FundingScope,
htlc: Option<HTLCCandidate>, fee_spike_buffer_htlc: Option<()>,
&self, _funding: &FundingScope, htlc: Option<HTLCCandidate>, fee_spike_buffer_htlc: Option<()>,
) -> u64 {
debug_assert!(htlc.is_some() || fee_spike_buffer_htlc.is_some(), "At least one of the options must be set");

Expand Down Expand Up @@ -4201,7 +4183,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
},
feerate: context.feerate_per_kw,
};
*funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap() = Some(commitment_tx_info);
*_funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap() = Some(commitment_tx_info);
}
res
}
Expand Down Expand Up @@ -5221,11 +5203,7 @@ impl<SP: Deref> FundedChannel<SP> where
{
let remote_commit_tx_fee_msat = if self.context.is_outbound() { 0 } else {
let htlc_candidate = HTLCCandidate::new(msg.amount_msat, HTLCInitiator::RemoteOffered);
self.context.next_remote_commit_tx_fee_msat(
#[cfg(any(test, fuzzing))]
&self.funding,
Some(htlc_candidate), None, // Don't include the extra fee spike buffer HTLC in calculations
)
self.context.next_remote_commit_tx_fee_msat(&self.funding, Some(htlc_candidate), None) // Don't include the extra fee spike buffer HTLC in calculations
};
let anchor_outputs_value_msat = if !self.context.is_outbound() && self.context.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
ANCHOR_OUTPUT_VALUE_SATOSHI * 2 * 1000
Expand All @@ -5248,11 +5226,7 @@ impl<SP: Deref> FundedChannel<SP> where
if self.context.is_outbound() {
// Check that they won't violate our local required channel reserve by adding this HTLC.
let htlc_candidate = HTLCCandidate::new(msg.amount_msat, HTLCInitiator::RemoteOffered);
let local_commit_tx_fee_msat = self.context.next_local_commit_tx_fee_msat(
#[cfg(any(test, fuzzing))]
&self.funding,
htlc_candidate, None,
);
let local_commit_tx_fee_msat = self.context.next_local_commit_tx_fee_msat(&self.funding, htlc_candidate, None);
if self.funding.value_to_self_msat < self.funding.counterparty_selected_channel_reserve_satoshis.unwrap() * 1000 + local_commit_tx_fee_msat + anchor_outputs_value_msat {
return Err(ChannelError::close("Cannot accept HTLC that would put our balance under counterparty-announced channel reserve value".to_owned()));
}
Expand Down Expand Up @@ -7441,11 +7415,7 @@ impl<SP: Deref> FundedChannel<SP> where
//
// A `None` `HTLCCandidate` is used as in this case because we're already accounting for
// the incoming HTLC as it has been fully committed by both sides.
let mut remote_fee_cost_incl_stuck_buffer_msat = self.context.next_remote_commit_tx_fee_msat(
#[cfg(any(test, fuzzing))]
&self.funding,
None, Some(()),
);
let mut remote_fee_cost_incl_stuck_buffer_msat = self.context.next_remote_commit_tx_fee_msat(&self.funding, None, Some(()));
if !self.context.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
remote_fee_cost_incl_stuck_buffer_msat *= FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE;
}
Expand Down

0 comments on commit 15f1c21

Please sign in to comment.