Skip to content

Commit d362cb5

Browse files
f Fix configurable in-flight limit percentage
1 parent 50beda1 commit d362cb5

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

lightning/src/ln/channel.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,10 @@ pub const COMMITMENT_TX_WEIGHT_PER_HTLC: u64 = 172;
745745

746746
pub const ANCHOR_OUTPUT_VALUE_SATOSHI: u64 = 330;
747747

748+
/// The percentage of the channel value `holder_max_htlc_value_in_flight_msat` used to be set to,
749+
/// before this was made configurable.
750+
pub const OLD_LDK_MAX_IN_FLIGHT_PERCENT: u8 = 10;
751+
748752
/// Maximum `funding_satoshis` value according to the BOLT #2 specification, if
749753
/// `option_support_large_channel` (aka wumbo channels) is not supported.
750754
/// It's 2^24 - 1.
@@ -5893,13 +5897,16 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
58935897

58945898
// The same logic applies for `holder_selected_channel_reserve_satoshis` values other than
58955899
// the default, and when `holder_max_htlc_value_in_flight_msat` is configured to be set to
5896-
// a different percentage of the channel value then the default value of
5897-
// `ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel`.
5900+
// a different percentage of the channel value then 10%, which older versions of LDK used
5901+
// to set it to before the percentage was made configurable.
58985902
let serialized_holder_selected_reserve =
58995903
if self.holder_selected_channel_reserve_satoshis != Self::get_holder_selected_channel_reserve_satoshis(self.channel_value_satoshis)
59005904
{ Some(self.holder_selected_channel_reserve_satoshis) } else { None };
5905+
5906+
let mut old_max_in_flight_percent_config = UserConfig::default().own_channel_config;
5907+
old_max_in_flight_percent_config.max_inbound_htlc_value_in_flight_percent_of_channel = OLD_LDK_MAX_IN_FLIGHT_PERCENT;
59015908
let serialized_holder_htlc_max_in_flight =
5902-
if self.holder_max_htlc_value_in_flight_msat != Self::get_holder_max_htlc_value_in_flight_msat(self.channel_value_satoshis, &UserConfig::default().own_channel_config)
5909+
if self.holder_max_htlc_value_in_flight_msat != Self::get_holder_max_htlc_value_in_flight_msat(self.channel_value_satoshis, &old_max_in_flight_percent_config)
59035910
{ Some(self.holder_max_htlc_value_in_flight_msat) } else { None };
59045911

59055912
write_tlv_fields!(writer, {

lightning/src/util/config.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,25 @@ pub struct ChannelHandshakeConfig {
4848
/// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
4949
/// by the protocol.
5050
pub our_htlc_minimum_msat: u64,
51-
/// Sets how many the percent of the channel value we will cap the total value of outstanding
52-
/// inbound HTLCs to.
51+
/// Sets the percentage of the channel value we will cap the total value of outstanding inbound
52+
/// HTLCs to.
5353
///
5454
/// This can be set to a value between 1-100, where the value corresponds to the percent of the
5555
/// channel value in whole percentages.
5656
///
57-
/// Note that if configured to another value than the default value 10, any new channels
58-
/// created with the non default value won't be backwards compatible with LDK versions prior
59-
/// to 0.0.100.
57+
/// Note that:
58+
/// * If configured to another value than the default value 10, any new channels
59+
/// created with the non default value will cause versions of LDK prior to 0.0.100 to refuse to
60+
/// read the ChannelManager.
6061
///
61-
/// Note that this caps the total value for inbound HTLCs in-flight only, and there's currently
62-
/// no availability to configure the cap for the total value of outbound HTLCs in-flight.
63-
/// This effects the in-flight HTLC balance, which [`ChannelConfig::cltv_expiry_delta`] is
64-
/// applied to.
62+
/// * This caps the total value for inbound HTLCs in-flight only, and there's currently
63+
/// no way to configure the cap for the total value of outbound HTLCs in-flight.
6564
///
66-
/// This does not cap the total value of the non-HTLC-encumbered balance which
67-
/// [`ChannelHandshakeConfig::our_to_self_delay`] is applied to.
65+
/// * The online requirements for ensuring the safety of HTLC-encumbered funds are
66+
/// different from the non-HTLC-encumbered funds. This makes this an important knob to restrict
67+
/// exposure to loss due to being offline for too long.
68+
/// See [`ChannelHandshakeConfig::our_to_self_delay`] and [`ChannelConfig::cltv_expiry_delta`]
69+
/// for more information.
6870
///
6971
/// Default value: 10.
7072
/// Minimum value: 1, any values less than 1 will be treated as 1 instead.

0 commit comments

Comments
 (0)