@@ -4102,6 +4102,7 @@ impl<SP: SignerProvider> ChannelContext<SP> {
41024102 ),
41034103 holder_max_htlc_value_in_flight_msat: get_holder_max_htlc_value_in_flight_msat(
41044104 channel_value_satoshis,
4105+ announce_for_forwarding,
41054106 &config.channel_handshake_config,
41064107 ),
41074108 counterparty_htlc_minimum_msat: open_channel_fields.htlc_minimum_msat,
@@ -4405,6 +4406,7 @@ impl<SP: SignerProvider> ChannelContext<SP> {
44054406 // receive `accept_channel2`.
44064407 holder_max_htlc_value_in_flight_msat: get_holder_max_htlc_value_in_flight_msat(
44074408 channel_value_satoshis,
4409+ config.channel_handshake_config.announce_for_forwarding,
44084410 &config.channel_handshake_config,
44094411 ),
44104412 counterparty_htlc_minimum_msat: 0,
@@ -6678,24 +6680,41 @@ impl<SP: SignerProvider> ChannelContext<SP> {
66786680
66796681/// Returns the value to use for `holder_max_htlc_value_in_flight_msat` as a percentage of the
66806682/// `channel_value_satoshis` in msat, set through
6681- /// [`ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel`]
6683+ /// [`ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage`]
6684+ /// or [`ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage`]
6685+ /// depending on the value of [`ChannelHandshakeConfig::announce_for_forwarding`].
66826686///
66836687/// The effective percentage is lower bounded by 1% and upper bounded by 100%.
66846688///
6685- /// [`ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel`]: crate::util::config::ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel
6689+ /// [`ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage`]: crate::util::config::ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage
6690+ /// [`ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage`]: crate::util::config::ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage
6691+ /// [`ChannelHandshakeConfig::announce_for_forwarding`]: crate::util::config::ChannelHandshakeConfig::announce_for_forwarding
66866692fn get_holder_max_htlc_value_in_flight_msat(
6687- channel_value_satoshis: u64, config: &ChannelHandshakeConfig,
6693+ channel_value_satoshis: u64, is_announced_channel: bool, config: &ChannelHandshakeConfig,
66886694) -> u64 {
6689- let configured_percent = if config.max_inbound_htlc_value_in_flight_percent_of_channel < 1 {
6695+ let config_setting = if is_announced_channel {
6696+ config.announced_channel_max_inbound_htlc_value_in_flight_percentage
6697+ } else {
6698+ config.unannounced_channel_max_inbound_htlc_value_in_flight_percentage
6699+ };
6700+ let configured_percent = if config_setting < 1 {
66906701 1
6691- } else if config.max_inbound_htlc_value_in_flight_percent_of_channel > 100 {
6702+ } else if config_setting > 100 {
66926703 100
66936704 } else {
6694- config.max_inbound_htlc_value_in_flight_percent_of_channel as u64
6705+ config_setting as u64
66956706 };
66966707 channel_value_satoshis * 10 * configured_percent
66976708}
66986709
6710+ /// This is for legacy reasons, present for forward-compatibility.
6711+ /// LDK versions older than 0.0.104 don't know how read/handle values other than the legacy
6712+ /// percentage from storage. Hence, we use this function to not persist legacy values of
6713+ /// `holder_max_htlc_value_in_flight_msat` for channels into storage.
6714+ fn get_legacy_default_holder_max_htlc_value_in_flight_msat(channel_value_satoshis: u64) -> u64 {
6715+ channel_value_satoshis * 10 * MAX_IN_FLIGHT_PERCENT_LEGACY as u64
6716+ }
6717+
66996718/// Returns a minimum channel reserve value the remote needs to maintain,
67006719/// required by us according to the configured or default
67016720/// [`ChannelHandshakeConfig::their_channel_reserve_proportional_millionths`]
@@ -15698,15 +15717,11 @@ impl<SP: SignerProvider> Writeable for FundedChannel<SP> {
1569815717 None
1569915718 };
1570015719
15701- let mut old_max_in_flight_percent_config = UserConfig::default().channel_handshake_config;
15702- old_max_in_flight_percent_config.max_inbound_htlc_value_in_flight_percent_of_channel =
15703- MAX_IN_FLIGHT_PERCENT_LEGACY;
15704- let max_in_flight_msat = get_holder_max_htlc_value_in_flight_msat(
15720+ let legacy_max_in_flight_msat = get_legacy_default_holder_max_htlc_value_in_flight_msat(
1570515721 self.funding.get_value_satoshis(),
15706- &old_max_in_flight_percent_config,
1570715722 );
1570815723 let serialized_holder_htlc_max_in_flight =
15709- if self.context.holder_max_htlc_value_in_flight_msat != max_in_flight_msat {
15724+ if self.context.holder_max_htlc_value_in_flight_msat != legacy_max_in_flight_msat {
1571015725 Some(self.context.holder_max_htlc_value_in_flight_msat)
1571115726 } else {
1571215727 None
@@ -16138,11 +16153,9 @@ impl<'a, 'b, 'c, ES: EntropySource, SP: SignerProvider>
1613816153 let mut holder_selected_channel_reserve_satoshis = Some(
1613916154 get_legacy_default_holder_selected_channel_reserve_satoshis(channel_value_satoshis),
1614016155 );
16156+
1614116157 let mut holder_max_htlc_value_in_flight_msat =
16142- Some(get_holder_max_htlc_value_in_flight_msat(
16143- channel_value_satoshis,
16144- &UserConfig::default().channel_handshake_config,
16145- ));
16158+ Some(get_legacy_default_holder_max_htlc_value_in_flight_msat(channel_value_satoshis));
1614616159 // Prior to supporting channel type negotiation, all of our channels were static_remotekey
1614716160 // only, so we default to that if none was written.
1614816161 let mut channel_type = Some(ChannelTypeFeatures::only_static_remote_key());
@@ -17148,8 +17161,13 @@ mod tests {
1714817161 }
1714917162
1715017163 #[test]
17151- #[rustfmt::skip]
1715217164 fn test_configured_holder_max_htlc_value_in_flight() {
17165+ do_test_configured_holder_max_htlc_value_in_flight(true);
17166+ do_test_configured_holder_max_htlc_value_in_flight(false);
17167+ }
17168+
17169+ #[rustfmt::skip]
17170+ fn do_test_configured_holder_max_htlc_value_in_flight(announce_channel: bool) {
1715317171 let test_est = TestFeeEstimator::new(15000);
1715417172 let feeest = LowerBoundedFeeEstimator::new(&test_est);
1715517173 let logger = TestLogger::new();
@@ -17161,13 +17179,49 @@ mod tests {
1716117179 let inbound_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[7; 32]).unwrap());
1716217180
1716317181 let mut config_2_percent = UserConfig::default();
17164- config_2_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 2;
17182+ config_2_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
17183+ if announce_channel {
17184+ config_2_percent
17185+ .channel_handshake_config
17186+ .announced_channel_max_inbound_htlc_value_in_flight_percentage = 2;
17187+ } else {
17188+ config_2_percent
17189+ .channel_handshake_config
17190+ .unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 2;
17191+ }
1716517192 let mut config_99_percent = UserConfig::default();
17166- config_99_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 99;
17193+ config_99_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
17194+ if announce_channel {
17195+ config_99_percent
17196+ .channel_handshake_config
17197+ .announced_channel_max_inbound_htlc_value_in_flight_percentage = 99;
17198+ } else {
17199+ config_99_percent
17200+ .channel_handshake_config
17201+ .unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 99;
17202+ }
1716717203 let mut config_0_percent = UserConfig::default();
17168- config_0_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 0;
17204+ config_0_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
17205+ if announce_channel {
17206+ config_0_percent
17207+ .channel_handshake_config
17208+ .announced_channel_max_inbound_htlc_value_in_flight_percentage = 0;
17209+ } else {
17210+ config_0_percent
17211+ .channel_handshake_config
17212+ .unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 0;
17213+ }
1716917214 let mut config_101_percent = UserConfig::default();
17170- config_101_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 101;
17215+ config_101_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
17216+ if announce_channel {
17217+ config_101_percent
17218+ .channel_handshake_config
17219+ .announced_channel_max_inbound_htlc_value_in_flight_percentage = 101;
17220+ } else {
17221+ config_101_percent
17222+ .channel_handshake_config
17223+ .unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 101;
17224+ }
1717117225
1717217226 // Test that `OutboundV1Channel::new` creates a channel with the correct value for
1717317227 // `holder_max_htlc_value_in_flight_msat`, when configured with a valid percentage value,
@@ -17196,26 +17250,26 @@ mod tests {
1719617250 assert_eq!(chan_4.context.holder_max_htlc_value_in_flight_msat, (chan_4_value_msat as f64 * 0.99) as u64);
1719717251
1719817252 // Test that `OutboundV1Channel::new` uses the lower bound of the configurable percentage values (1%)
17199- // if `max_inbound_htlc_value_in_flight_percent_of_channel ` is set to a value less than 1.
17253+ // if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage ` is set to a value less than 1.
1720017254 let chan_5 = OutboundV1Channel::<&TestKeysInterface>::new(&feeest, &&keys_provider, &&keys_provider, outbound_node_id, &channelmanager::provided_init_features(&config_0_percent), 10000000, 100000, 42, &config_0_percent, 0, 42, None, &logger, None).unwrap();
1720117255 let chan_5_value_msat = chan_5.funding.get_value_satoshis() * 1000;
1720217256 assert_eq!(chan_5.context.holder_max_htlc_value_in_flight_msat, (chan_5_value_msat as f64 * 0.01) as u64);
1720317257
1720417258 // Test that `OutboundV1Channel::new` uses the upper bound of the configurable percentage values
17205- // (100%) if `max_inbound_htlc_value_in_flight_percent_of_channel ` is set to a larger value
17259+ // (100%) if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage ` is set to a larger value
1720617260 // than 100.
1720717261 let chan_6 = OutboundV1Channel::<&TestKeysInterface>::new(&feeest, &&keys_provider, &&keys_provider, outbound_node_id, &channelmanager::provided_init_features(&config_101_percent), 10000000, 100000, 42, &config_101_percent, 0, 42, None, &logger, None).unwrap();
1720817262 let chan_6_value_msat = chan_6.funding.get_value_satoshis() * 1000;
1720917263 assert_eq!(chan_6.context.holder_max_htlc_value_in_flight_msat, chan_6_value_msat);
1721017264
1721117265 // Test that `InboundV1Channel::new` uses the lower bound of the configurable percentage values (1%)
17212- // if `max_inbound_htlc_value_in_flight_percent_of_channel ` is set to a value less than 1.
17266+ // if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage ` is set to a value less than 1.
1721317267 let chan_7 = InboundV1Channel::<&TestKeysInterface>::new(&feeest, &&keys_provider, &&keys_provider, inbound_node_id, &channelmanager::provided_channel_type_features(&config_0_percent), &channelmanager::provided_init_features(&config_0_percent), &chan_1_open_channel_msg, 7, &config_0_percent, 0, &&logger, None).unwrap();
1721417268 let chan_7_value_msat = chan_7.funding.get_value_satoshis() * 1000;
1721517269 assert_eq!(chan_7.context.holder_max_htlc_value_in_flight_msat, (chan_7_value_msat as f64 * 0.01) as u64);
1721617270
1721717271 // Test that `InboundV1Channel::new` uses the upper bound of the configurable percentage values
17218- // (100%) if `max_inbound_htlc_value_in_flight_percent_of_channel ` is set to a larger value
17272+ // (100%) if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage ` is set to a larger value
1721917273 // than 100.
1722017274 let chan_8 = InboundV1Channel::<&TestKeysInterface>::new(&feeest, &&keys_provider, &&keys_provider, inbound_node_id, &channelmanager::provided_channel_type_features(&config_101_percent), &channelmanager::provided_init_features(&config_101_percent), &chan_1_open_channel_msg, 7, &config_101_percent, 0, &&logger, None).unwrap();
1722117275 let chan_8_value_msat = chan_8.funding.get_value_satoshis() * 1000;
0 commit comments