@@ -355,6 +355,18 @@ pub const FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE: u64 = 2;
355
355
#[ cfg( not( fuzzing) ) ]
356
356
const FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE : u64 = 2 ;
357
357
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
+
358
370
// TODO: We should refactor this to be an Inbound/OutboundChannel until initial setup handshaking
359
371
// has been completed, and then turn into a Channel to get compiler-time enforcement of things like
360
372
// 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> {
2974
2986
// Before proposing a feerate update, check that we can actually afford the new fee.
2975
2987
let inbound_stats = self . get_inbound_pending_htlc_stats ( Some ( feerate_per_kw) ) ;
2976
2988
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 ) ;
2987
2990
let keys = if let Ok ( keys) = self . build_holder_transaction_keys ( self . cur_holder_commitment_transaction_number ) { keys } else { return None ; } ;
2988
2991
let holder_balance_msat = self . build_commitment_transaction ( self . cur_holder_commitment_transaction_number , & keys, true , true , logger) . 4 ;
2989
2992
if holder_balance_msat * 1000 < total_fee_sat + self . counterparty_selected_channel_reserve_satoshis . unwrap ( ) {
0 commit comments