Skip to content

Commit 50b1401

Browse files
author
Antoine Riard
committed
-f Constify HTLC buffer
1 parent 0c07fc6 commit 50b1401

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

lightning/src/ln/channel.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,18 @@ pub const FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE: u64 = 2;
355355
#[cfg(not(fuzzing))]
356356
const FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE: u64 = 2;
357357

358+
359+
/// In case of a concurrent update_add_htlc proposed by our counterparty, we might
360+
/// not have enough balance value remaining to cover the onchain cost of this new
361+
/// HTLC weight. If this happens, our counterparty fails the reception of our
362+
/// commitment_signed including this new HTLC due to infringement on the channel
363+
/// reserve.
364+
/// To prevent this case, we compute our outbound update_fee with an HTLC buffer of
365+
/// size 2. However, if the number of concurrent update_add_htlc is higher, this still
366+
/// leads to a channel force-close. Ultimately, this is an issue coming from the
367+
/// design of LN state machines, allowing asynchronous updates.
368+
const CONCURRENT_INBOUND_HTLC_FEE_BUFFER: u32 = 2;
369+
358370
// TODO: We should refactor this to be an Inbound/OutboundChannel until initial setup handshaking
359371
// has been completed, and then turn into a Channel to get compiler-time enforcement of things like
360372
// calling channel_id() before we're set up or things like get_outbound_funding_signed on an
@@ -2974,16 +2986,7 @@ impl<Signer: Sign> Channel<Signer> {
29742986
// Before proposing a feerate update, check that we can actually afford the new fee.
29752987
let inbound_stats = self.get_inbound_pending_htlc_stats(Some(feerate_per_kw));
29762988
let outbound_stats = self.get_outbound_pending_htlc_stats(Some(feerate_per_kw));
2977-
// In case of a concurrent update_add_htlc proposed by our counterparty, we might
2978-
// not have enough balance value remaining to cover the onchain cost of this new
2979-
// HTLC weight. If this happens, our counterparty fails the reception of our
2980-
// commitment_signed including this new HTLC due to infringement on the channel
2981-
// reserve.
2982-
// To prevent this case, we compute our outbound update_fee with an HTLC buffer of
2983-
// size 2. However, if the number of concurrent update_add_htlc is higher, this still
2984-
// leads to a channel force-close. Ultimately, this is an issue coming from the
2985-
// design of LN state machines, allowing asynchronous updates.
2986-
let total_fee_sat = Channel::<Signer>::commit_tx_fee_sat(feerate_per_kw, (inbound_stats.pending_htlcs + /* HTLC feerate buffer */ 2 + outbound_stats.pending_htlcs) as usize);
2989+
let total_fee_sat = Channel::<Signer>::commit_tx_fee_sat(feerate_per_kw, (inbound_stats.pending_htlcs + CONCURRENT_INBOUND_HTLC_FEE_BUFFER + outbound_stats.pending_htlcs) as usize);
29872990
let keys = if let Ok(keys) = self.build_holder_transaction_keys(self.cur_holder_commitment_transaction_number) { keys } else { return None; };
29882991
let holder_balance_msat = self.build_commitment_transaction(self.cur_holder_commitment_transaction_number, &keys, true, true, logger).4;
29892992
if holder_balance_msat * 1000 < total_fee_sat + self.counterparty_selected_channel_reserve_satoshis.unwrap() {

0 commit comments

Comments
 (0)