Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 48 additions & 16 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2834,7 +2834,7 @@ impl FundingScope {

// New reserve values are based on the new channel value and are v2-specific
let counterparty_selected_channel_reserve_satoshis =
Some(get_v2_channel_reserve_satoshis(post_channel_value, MIN_CHAN_DUST_LIMIT_SATOSHIS));
get_v2_channel_reserve_satoshis(post_channel_value, MIN_CHAN_DUST_LIMIT_SATOSHIS);
let holder_selected_channel_reserve_satoshis = get_v2_channel_reserve_satoshis(
post_channel_value,
context.counterparty_dust_limit_satoshis,
Expand All @@ -2844,23 +2844,39 @@ impl FundingScope {
channel_transaction_parameters: post_channel_transaction_parameters,
value_to_self_msat: post_value_to_self_msat,
funding_transaction: None,
counterparty_selected_channel_reserve_satoshis,
counterparty_selected_channel_reserve_satoshis: Some(
counterparty_selected_channel_reserve_satoshis,
),
holder_selected_channel_reserve_satoshis,
#[cfg(debug_assertions)]
holder_prev_commitment_tx_balance: {
let prev = *prev_funding.holder_prev_commitment_tx_balance.lock().unwrap();
Mutex::new((
prev.0.saturating_add_signed(our_funding_contribution.to_sat() * 1000),
prev.1.saturating_add_signed(their_funding_contribution.to_sat() * 1000),
))
let new_holder_balance_msat =
prev.0.saturating_add_signed(our_funding_contribution.to_sat() * 1000);
let new_counterparty_balance_msat =
prev.1.saturating_add_signed(their_funding_contribution.to_sat() * 1000);
if new_holder_balance_msat < counterparty_selected_channel_reserve_satoshis {
assert_eq!(new_holder_balance_msat, prev.0);
}
if new_counterparty_balance_msat < holder_selected_channel_reserve_satoshis {
assert_eq!(new_counterparty_balance_msat, prev.1);
}
Mutex::new((new_holder_balance_msat, new_counterparty_balance_msat))
},
#[cfg(debug_assertions)]
counterparty_prev_commitment_tx_balance: {
let prev = *prev_funding.counterparty_prev_commitment_tx_balance.lock().unwrap();
Mutex::new((
prev.0.saturating_add_signed(our_funding_contribution.to_sat() * 1000),
prev.1.saturating_add_signed(their_funding_contribution.to_sat() * 1000),
))
let new_holder_balance_msat =
prev.0.saturating_add_signed(our_funding_contribution.to_sat() * 1000);
let new_counterparty_balance_msat =
prev.1.saturating_add_signed(their_funding_contribution.to_sat() * 1000);
if new_holder_balance_msat < counterparty_selected_channel_reserve_satoshis {
assert_eq!(new_holder_balance_msat, prev.0);
}
if new_counterparty_balance_msat < holder_selected_channel_reserve_satoshis {
assert_eq!(new_counterparty_balance_msat, prev.1);
}
Mutex::new((new_holder_balance_msat, new_counterparty_balance_msat))
},
#[cfg(any(test, fuzzing))]
next_local_fee: Mutex::new(PredictedNextFee::default()),
Expand Down Expand Up @@ -5942,7 +5958,9 @@ impl<SP: SignerProvider> ChannelContext<SP> {
max_reserved_commit_tx_fee_msat as i64;
if capacity_minus_commitment_fee_msat < (real_dust_limit_timeout_sat as i64) * 1000 {
let one_htlc_difference_msat = max_reserved_commit_tx_fee_msat - min_reserved_commit_tx_fee_msat;
debug_assert!(one_htlc_difference_msat != 0);
if !funding.get_channel_type().supports_anchor_zero_fee_commitments() {
debug_assert!(one_htlc_difference_msat != 0);
}
capacity_minus_commitment_fee_msat += one_htlc_difference_msat as i64;
capacity_minus_commitment_fee_msat = cmp::min(real_dust_limit_timeout_sat as i64 * 1000 - 1, capacity_minus_commitment_fee_msat);
available_capacity_msat = cmp::max(0, cmp::min(capacity_minus_commitment_fee_msat, available_capacity_msat as i64)) as u64;
Expand Down Expand Up @@ -12702,20 +12720,34 @@ where
&self, funding: &FundingScope,
) -> Result<(Amount, Amount), String> {
let include_counterparty_unknown_htlcs = true;
// Make sure that that the funder of the channel can pay the transaction fees for an additional
// nondust HTLC on the channel.
let addl_nondust_htlc_count = 1;
// We are not interested in dust exposure
let dust_exposure_limiting_feerate = None;

let addl_nondust_htlc_count =
if funding.get_channel_type().supports_anchor_zero_fee_commitments() {
0
} else {
// Require the channel opener to reserve enough funds to pay the fees for an
// additional non-dust HTLC in the channel.
1
};

let feerate_per_kw = if !funding.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
// Similar to HTLC additions, require the funder to have enough funds reserved for
// fees such that the feerate can jump without rendering the channel useless.
self.context.feerate_per_kw * FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE as u32
} else {
self.context.feerate_per_kw
};

let local_commitment_stats = self
.context
.get_next_local_commitment_stats(
funding,
None, // htlc_candidate
include_counterparty_unknown_htlcs,
addl_nondust_htlc_count,
self.context.feerate_per_kw,
feerate_per_kw,
dust_exposure_limiting_feerate,
)
.map_err(|()| "Balance after HTLCs and anchors exhausted on local commitment")?;
Expand All @@ -12731,7 +12763,7 @@ where
None, // htlc_candidate
include_counterparty_unknown_htlcs,
addl_nondust_htlc_count,
self.context.feerate_per_kw,
feerate_per_kw,
dust_exposure_limiting_feerate,
)
.map_err(|()| "Balance after HTLCs and anchors exhausted on remote commitment")?;
Expand Down
Loading
Loading