Merged
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
7 changes: 7 additions & 0 deletions lightning/src/ln/async_payments_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -504,6 +504,9 @@ fn often_offline_node_cfg() -> UserConfig {
cfg.channel_handshake_config.announce_for_forwarding = false;
cfg.channel_handshake_limits.force_announced_channel_preference = true;
cfg.hold_outbound_htlcs_at_next_hop = true;
// Use the setting that matches the default at the time these tests were written
cfg.channel_handshake_config.unannounced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
cfg
}

Expand DownExpand Up@@ -1310,6 +1313,10 @@ fn async_receive_mpp() {

let mut allow_priv_chan_fwds_cfg = test_default_channel_config();
allow_priv_chan_fwds_cfg.accept_forwards_to_priv_channels = true;
// Set the percentage to the default value at the time this test was written
allow_priv_chan_fwds_cfg
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 10;

let node_chanmgrs = create_node_chanmgrs(
4,
Expand Down
12 changes: 10 additions & 2 deletions lightning/src/ln/blinded_payment_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -269,7 +269,11 @@ fn one_hop_blinded_path_with_dummy_hops() {
fn mpp_to_one_hop_blinded_path() {
let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage = 10;
let configs: [Option<UserConfig>; 4] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &configs);
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);
let mut secp_ctx = Secp256k1::new();

Expand DownExpand Up@@ -349,7 +353,11 @@ fn mpp_to_one_hop_blinded_path() {
fn mpp_to_three_hop_blinded_paths() {
let chanmon_cfgs = create_chanmon_cfgs(6);
let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage = 10;
let configs: [Option<UserConfig>; 6] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &configs);
let nodes = create_network(6, &node_cfgs, &node_chanmgrs);

// Create this network topology so node 0 MPP's over 2 3-hop blinded paths:
Expand Down
7 changes: 6 additions & 1 deletion lightning/src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -4656,6 +4656,7 @@ fn test_claim_to_closed_channel_blocks_claimed_event() {
#[test]
#[cfg(all(feature = "std", not(target_os = "windows")))]
fn test_single_channel_multiple_mpp() {
use crate::util::config::UserConfig;
use std::sync::atomic::{AtomicBool, Ordering};

// Test what happens when we attempt to claim an MPP with many parts that came to us through
Expand All@@ -4667,7 +4668,11 @@ fn test_single_channel_multiple_mpp() {
// for more info.
let chanmon_cfgs = create_chanmon_cfgs(9);
let node_cfgs = create_node_cfgs(9, &chanmon_cfgs);
let configs = [None, None, None, None, None, None, None, None, None];
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
let configs: [Option<UserConfig>; 9] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(9, &node_cfgs, &configs);
let mut nodes = create_network(9, &node_cfgs, &node_chanmgrs);

Expand Down
104 changes: 79 additions & 25 deletions lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -4102,6 +4102,7 @@ impl<SP: SignerProvider> ChannelContext<SP> {
),
holder_max_htlc_value_in_flight_msat: get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis,
announce_for_forwarding,
&config.channel_handshake_config,
),
counterparty_htlc_minimum_msat: open_channel_fields.htlc_minimum_msat,
Expand DownExpand Up@@ -4405,6 +4406,7 @@ impl<SP: SignerProvider> ChannelContext<SP> {
// receive `accept_channel2`.
holder_max_htlc_value_in_flight_msat: get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis,
config.channel_handshake_config.announce_for_forwarding,
&config.channel_handshake_config,
),
counterparty_htlc_minimum_msat: 0,
Expand DownExpand Up@@ -6678,24 +6680,41 @@ impl<SP: SignerProvider> ChannelContext<SP> {

/// Returns the value to use for `holder_max_htlc_value_in_flight_msat` as a percentage of the
/// `channel_value_satoshis` in msat, set through
/// [`ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel`]
/// [`ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage`]
/// or [`ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage`]
/// depending on the value of [`ChannelHandshakeConfig::announce_for_forwarding`].
///
/// The effective percentage is lower bounded by 1% and upper bounded by 100%.
///
/// [`ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel`]: crate::util::config::ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel
/// [`ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage`]: crate::util::config::ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage
/// [`ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage`]: crate::util::config::ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage
/// [`ChannelHandshakeConfig::announce_for_forwarding`]: crate::util::config::ChannelHandshakeConfig::announce_for_forwarding
fn get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis: u64, config: &ChannelHandshakeConfig,
channel_value_satoshis: u64, is_announced_channel: bool, config: &ChannelHandshakeConfig,
) -> u64 {
let configured_percent = if config.max_inbound_htlc_value_in_flight_percent_of_channel < 1 {
let config_setting = if is_announced_channel {
config.announced_channel_max_inbound_htlc_value_in_flight_percentage
} else {
config.unannounced_channel_max_inbound_htlc_value_in_flight_percentage
};
let configured_percent = if config_setting < 1 {
1
} else if config.max_inbound_htlc_value_in_flight_percent_of_channel > 100 {
} else if config_setting > 100 {
100
} else {
config.max_inbound_htlc_value_in_flight_percent_of_channel as u64
config_setting as u64
};
channel_value_satoshis * 10 * configured_percent
}

/// This is for legacy reasons, present for forward-compatibility.
/// LDK versions older than 0.0.104 don't know how read/handle values other than the legacy
/// percentage from storage. Hence, we use this function to not persist legacy values of
/// `holder_max_htlc_value_in_flight_msat` for channels into storage.
fn get_legacy_default_holder_max_htlc_value_in_flight_msat(channel_value_satoshis: u64) -> u64 {
channel_value_satoshis * 10 * MAX_IN_FLIGHT_PERCENT_LEGACY as u64
}

/// Returns a minimum channel reserve value the remote needs to maintain,
/// required by us according to the configured or default
/// [`ChannelHandshakeConfig::their_channel_reserve_proportional_millionths`]
Expand DownExpand Up@@ -15691,15 +15710,11 @@ impl<SP: SignerProvider> Writeable for FundedChannel<SP> {
None
};

let mut old_max_in_flight_percent_config = UserConfig::default().channel_handshake_config;
old_max_in_flight_percent_config.max_inbound_htlc_value_in_flight_percent_of_channel =
MAX_IN_FLIGHT_PERCENT_LEGACY;
let max_in_flight_msat = get_holder_max_htlc_value_in_flight_msat(
let legacy_max_in_flight_msat = get_legacy_default_holder_max_htlc_value_in_flight_msat(
self.funding.get_value_satoshis(),
&old_max_in_flight_percent_config,
);
let serialized_holder_htlc_max_in_flight =
if self.context.holder_max_htlc_value_in_flight_msat != max_in_flight_msat {
if self.context.holder_max_htlc_value_in_flight_msat != legacy_max_in_flight_msat {
Some(self.context.holder_max_htlc_value_in_flight_msat)
} else {
None
Expand DownExpand Up@@ -16131,11 +16146,9 @@ impl<'a, 'b, 'c, ES: EntropySource, SP: SignerProvider>
let mut holder_selected_channel_reserve_satoshis = Some(
get_legacy_default_holder_selected_channel_reserve_satoshis(channel_value_satoshis),
);

let mut holder_max_htlc_value_in_flight_msat =
Some(get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis,
&UserConfig::default().channel_handshake_config,
));
Some(get_legacy_default_holder_max_htlc_value_in_flight_msat(channel_value_satoshis));
// Prior to supporting channel type negotiation, all of our channels were static_remotekey
// only, so we default to that if none was written.
let mut channel_type = Some(ChannelTypeFeatures::only_static_remote_key());
Expand DownExpand Up@@ -17141,8 +17154,13 @@ mod tests {
}

#[test]
#[rustfmt::skip]
fn test_configured_holder_max_htlc_value_in_flight() {
do_test_configured_holder_max_htlc_value_in_flight(true);
do_test_configured_holder_max_htlc_value_in_flight(false);
}

#[rustfmt::skip]
fn do_test_configured_holder_max_htlc_value_in_flight(announce_channel: bool) {
let test_est = TestFeeEstimator::new(15000);
let feeest = LowerBoundedFeeEstimator::new(&test_est);
let logger = TestLogger::new();
Expand All@@ -17154,13 +17172,49 @@ mod tests {
let inbound_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[7; 32]).unwrap());

let mut config_2_percent = UserConfig::default();
config_2_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 2;
config_2_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_2_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 2;
} else {
config_2_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 2;
}
let mut config_99_percent = UserConfig::default();
config_99_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 99;
config_99_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_99_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 99;
} else {
config_99_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 99;
}
let mut config_0_percent = UserConfig::default();
config_0_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 0;
config_0_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_0_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 0;
} else {
config_0_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 0;
}
let mut config_101_percent = UserConfig::default();
config_101_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 101;
config_101_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_101_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 101;
} else {
config_101_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 101;
}

// Test that `OutboundV1Channel::new` creates a channel with the correct value for
// `holder_max_htlc_value_in_flight_msat`, when configured with a valid percentage value,
Expand DownExpand Up@@ -17189,26 +17243,26 @@ mod tests {
assert_eq!(chan_4.context.holder_max_htlc_value_in_flight_msat, (chan_4_value_msat as f64 * 0.99) as u64);

// Test that `OutboundV1Channel::new` uses the lower bound of the configurable percentage values (1%)
// if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a value less than 1.
// if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a value less than 1.
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();
let chan_5_value_msat = chan_5.funding.get_value_satoshis() * 1000;
assert_eq!(chan_5.context.holder_max_htlc_value_in_flight_msat, (chan_5_value_msat as f64 * 0.01) as u64);

// Test that `OutboundV1Channel::new` uses the upper bound of the configurable percentage values
// (100%) if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a larger value
// (100%) if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a larger value
// than 100.
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();
let chan_6_value_msat = chan_6.funding.get_value_satoshis() * 1000;
assert_eq!(chan_6.context.holder_max_htlc_value_in_flight_msat, chan_6_value_msat);

// Test that `InboundV1Channel::new` uses the lower bound of the configurable percentage values (1%)
// if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a value less than 1.
// if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a value less than 1.
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();
let chan_7_value_msat = chan_7.funding.get_value_satoshis() * 1000;
assert_eq!(chan_7.context.holder_max_htlc_value_in_flight_msat, (chan_7_value_msat as f64 * 0.01) as u64);

// Test that `InboundV1Channel::new` uses the upper bound of the configurable percentage values
// (100%) if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a larger value
// (100%) if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a larger value
// than 100.
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();
let chan_8_value_msat = chan_8.funding.get_value_satoshis() * 1000;
Expand Down
6 changes: 4 additions & 2 deletions lightning/src/ln/channel_open_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -182,7 +182,8 @@ fn test_inbound_anchors_manual_acceptance() {
fn test_inbound_anchors_config_overridden() {
let overrides = ChannelConfigOverrides {
handshake_overrides: Some(ChannelHandshakeConfigUpdate {
max_inbound_htlc_value_in_flight_percent_of_channel: Some(5),
announced_channel_max_inbound_htlc_value_in_flight_percentage: Some(5),
unannounced_channel_max_inbound_htlc_value_in_flight_percentage: None,
htlc_minimum_msat: Some(1000),
minimum_depth: Some(2),
to_self_delay: Some(200),
Expand DownExpand Up@@ -1070,7 +1071,8 @@ pub fn test_accept_inbound_channel_config_override() {

let config_overrides = ChannelConfigOverrides {
handshake_overrides: Some(ChannelHandshakeConfigUpdate {
max_inbound_htlc_value_in_flight_percent_of_channel: None,
announced_channel_max_inbound_htlc_value_in_flight_percentage: None,
unannounced_channel_max_inbound_htlc_value_in_flight_percentage: None,
htlc_minimum_msat: None,
minimum_depth: None,
to_self_delay: None,
Expand Down
28 changes: 20 additions & 8 deletions lightning/src/ln/functional_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6903,22 +6903,22 @@ pub fn test_channel_update_has_correct_htlc_maximum_msat() {
config_30_percent.channel_handshake_config.announce_for_forwarding = true;
config_30_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 30;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 30;
let mut config_50_percent = UserConfig::default();
config_50_percent.channel_handshake_config.announce_for_forwarding = true;
config_50_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 50;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 50;
let mut config_95_percent = UserConfig::default();
config_95_percent.channel_handshake_config.announce_for_forwarding = true;
config_95_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 95;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 95;
let mut config_100_percent = UserConfig::default();
config_100_percent.channel_handshake_config.announce_for_forwarding = true;
config_100_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 100;

let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
Expand DownExpand Up@@ -8436,7 +8436,12 @@ pub fn test_inconsistent_mpp_params() {
// such HTLC and allow the second to stay.
let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
let configs: [Option<UserConfig>; 4] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &configs);
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);

let node_a_id = nodes[0].node.get_our_node_id();
Expand DownExpand Up@@ -8580,7 +8585,12 @@ pub fn test_double_partial_claim() {
// amount.
let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
let configs: [Option<UserConfig>; 4] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &configs);
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);

let node_b_id = nodes[1].node.get_our_node_id();
Expand DownExpand Up@@ -9067,7 +9077,8 @@ pub fn test_nondust_htlc_excess_fees_are_dust() {
config.channel_handshake_limits.min_max_accepted_htlcs = chan_utils::max_htlcs(&chan_ty);
config.channel_handshake_config.our_max_accepted_htlcs = chan_utils::max_htlcs(&chan_ty);
config.channel_handshake_config.our_htlc_minimum_msat = 1;
config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
100;

let node_chanmgrs = create_node_chanmgrs(
3,
Expand DownExpand Up@@ -10039,7 +10050,8 @@ pub fn test_dust_exposure_holding_cell_assertion() {
// Use a fixed dust exposure limit to make the test simpler
const DUST_HTLC_VALUE_MSAT: u64 = 500_000;
config.channel_config.max_dust_htlc_exposure = MaxDustHTLCExposure::FixedLimitMsat(5_000_000);
config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
100;

let configs = [Some(config.clone()), Some(config.clone()), Some(config.clone())];
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &configs);
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
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
7 changes: 7 additions & 0 deletions lightning/src/ln/async_payments_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -504,6 +504,9 @@ fn often_offline_node_cfg() -> UserConfig {
cfg.channel_handshake_config.announce_for_forwarding = false;
cfg.channel_handshake_limits.force_announced_channel_preference = true;
cfg.hold_outbound_htlcs_at_next_hop = true;
// Use the setting that matches the default at the time these tests were written
cfg.channel_handshake_config.unannounced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
cfg
}

Expand DownExpand Up@@ -1310,6 +1313,10 @@ fn async_receive_mpp() {

let mut allow_priv_chan_fwds_cfg = test_default_channel_config();
allow_priv_chan_fwds_cfg.accept_forwards_to_priv_channels = true;
// Set the percentage to the default value at the time this test was written
allow_priv_chan_fwds_cfg
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 10;

let node_chanmgrs = create_node_chanmgrs(
4,
Expand Down
12 changes: 10 additions & 2 deletions lightning/src/ln/blinded_payment_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -269,7 +269,11 @@ fn one_hop_blinded_path_with_dummy_hops() {
fn mpp_to_one_hop_blinded_path() {
let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage = 10;
let configs: [Option<UserConfig>; 4] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &configs);
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);
let mut secp_ctx = Secp256k1::new();

Expand DownExpand Up@@ -349,7 +353,11 @@ fn mpp_to_one_hop_blinded_path() {
fn mpp_to_three_hop_blinded_paths() {
let chanmon_cfgs = create_chanmon_cfgs(6);
let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage = 10;
let configs: [Option<UserConfig>; 6] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &configs);
let nodes = create_network(6, &node_cfgs, &node_chanmgrs);

// Create this network topology so node 0 MPP's over 2 3-hop blinded paths:
Expand Down
7 changes: 6 additions & 1 deletion lightning/src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -4656,6 +4656,7 @@ fn test_claim_to_closed_channel_blocks_claimed_event() {
#[test]
#[cfg(all(feature = "std", not(target_os = "windows")))]
fn test_single_channel_multiple_mpp() {
use crate::util::config::UserConfig;
use std::sync::atomic::{AtomicBool, Ordering};

// Test what happens when we attempt to claim an MPP with many parts that came to us through
Expand All@@ -4667,7 +4668,11 @@ fn test_single_channel_multiple_mpp() {
// for more info.
let chanmon_cfgs = create_chanmon_cfgs(9);
let node_cfgs = create_node_cfgs(9, &chanmon_cfgs);
let configs = [None, None, None, None, None, None, None, None, None];
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
let configs: [Option<UserConfig>; 9] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(9, &node_cfgs, &configs);
let mut nodes = create_network(9, &node_cfgs, &node_chanmgrs);

Expand Down
104 changes: 79 additions & 25 deletions lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -4102,6 +4102,7 @@ impl<SP: SignerProvider> ChannelContext<SP> {
),
holder_max_htlc_value_in_flight_msat: get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis,
announce_for_forwarding,
&config.channel_handshake_config,
),
counterparty_htlc_minimum_msat: open_channel_fields.htlc_minimum_msat,
Expand DownExpand Up@@ -4405,6 +4406,7 @@ impl<SP: SignerProvider> ChannelContext<SP> {
// receive `accept_channel2`.
holder_max_htlc_value_in_flight_msat: get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis,
config.channel_handshake_config.announce_for_forwarding,
&config.channel_handshake_config,
),
counterparty_htlc_minimum_msat: 0,
Expand DownExpand Up@@ -6678,24 +6680,41 @@ impl<SP: SignerProvider> ChannelContext<SP> {

/// Returns the value to use for `holder_max_htlc_value_in_flight_msat` as a percentage of the
/// `channel_value_satoshis` in msat, set through
/// [`ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel`]
/// [`ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage`]
/// or [`ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage`]
/// depending on the value of [`ChannelHandshakeConfig::announce_for_forwarding`].
///
/// The effective percentage is lower bounded by 1% and upper bounded by 100%.
///
/// [`ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel`]: crate::util::config::ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel
/// [`ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage`]: crate::util::config::ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage
/// [`ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage`]: crate::util::config::ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage
/// [`ChannelHandshakeConfig::announce_for_forwarding`]: crate::util::config::ChannelHandshakeConfig::announce_for_forwarding
fn get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis: u64, config: &ChannelHandshakeConfig,
channel_value_satoshis: u64, is_announced_channel: bool, config: &ChannelHandshakeConfig,
) -> u64 {
let configured_percent = if config.max_inbound_htlc_value_in_flight_percent_of_channel < 1 {
let config_setting = if is_announced_channel {
config.announced_channel_max_inbound_htlc_value_in_flight_percentage
} else {
config.unannounced_channel_max_inbound_htlc_value_in_flight_percentage
};
let configured_percent = if config_setting < 1 {
1
} else if config.max_inbound_htlc_value_in_flight_percent_of_channel > 100 {
} else if config_setting > 100 {
100
} else {
config.max_inbound_htlc_value_in_flight_percent_of_channel as u64
config_setting as u64
};
channel_value_satoshis * 10 * configured_percent
}

/// This is for legacy reasons, present for forward-compatibility.
/// LDK versions older than 0.0.104 don't know how read/handle values other than the legacy
/// percentage from storage. Hence, we use this function to not persist legacy values of
/// `holder_max_htlc_value_in_flight_msat` for channels into storage.
fn get_legacy_default_holder_max_htlc_value_in_flight_msat(channel_value_satoshis: u64) -> u64 {
channel_value_satoshis * 10 * MAX_IN_FLIGHT_PERCENT_LEGACY as u64
}

/// Returns a minimum channel reserve value the remote needs to maintain,
/// required by us according to the configured or default
/// [`ChannelHandshakeConfig::their_channel_reserve_proportional_millionths`]
Expand DownExpand Up@@ -15691,15 +15710,11 @@ impl<SP: SignerProvider> Writeable for FundedChannel<SP> {
None
};

let mut old_max_in_flight_percent_config = UserConfig::default().channel_handshake_config;
old_max_in_flight_percent_config.max_inbound_htlc_value_in_flight_percent_of_channel =
MAX_IN_FLIGHT_PERCENT_LEGACY;
let max_in_flight_msat = get_holder_max_htlc_value_in_flight_msat(
let legacy_max_in_flight_msat = get_legacy_default_holder_max_htlc_value_in_flight_msat(
self.funding.get_value_satoshis(),
&old_max_in_flight_percent_config,
);
let serialized_holder_htlc_max_in_flight =
if self.context.holder_max_htlc_value_in_flight_msat != max_in_flight_msat {
if self.context.holder_max_htlc_value_in_flight_msat != legacy_max_in_flight_msat {
Some(self.context.holder_max_htlc_value_in_flight_msat)
} else {
None
Expand DownExpand Up@@ -16131,11 +16146,9 @@ impl<'a, 'b, 'c, ES: EntropySource, SP: SignerProvider>
let mut holder_selected_channel_reserve_satoshis = Some(
get_legacy_default_holder_selected_channel_reserve_satoshis(channel_value_satoshis),
);

let mut holder_max_htlc_value_in_flight_msat =
Some(get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis,
&UserConfig::default().channel_handshake_config,
));
Some(get_legacy_default_holder_max_htlc_value_in_flight_msat(channel_value_satoshis));
// Prior to supporting channel type negotiation, all of our channels were static_remotekey
// only, so we default to that if none was written.
let mut channel_type = Some(ChannelTypeFeatures::only_static_remote_key());
Expand DownExpand Up@@ -17141,8 +17154,13 @@ mod tests {
}

#[test]
#[rustfmt::skip]
fn test_configured_holder_max_htlc_value_in_flight() {
do_test_configured_holder_max_htlc_value_in_flight(true);
do_test_configured_holder_max_htlc_value_in_flight(false);
}

#[rustfmt::skip]
fn do_test_configured_holder_max_htlc_value_in_flight(announce_channel: bool) {
let test_est = TestFeeEstimator::new(15000);
let feeest = LowerBoundedFeeEstimator::new(&test_est);
let logger = TestLogger::new();
Expand All@@ -17154,13 +17172,49 @@ mod tests {
let inbound_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[7; 32]).unwrap());

let mut config_2_percent = UserConfig::default();
config_2_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 2;
config_2_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_2_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 2;
} else {
config_2_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 2;
}
let mut config_99_percent = UserConfig::default();
config_99_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 99;
config_99_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_99_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 99;
} else {
config_99_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 99;
}
let mut config_0_percent = UserConfig::default();
config_0_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 0;
config_0_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_0_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 0;
} else {
config_0_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 0;
}
let mut config_101_percent = UserConfig::default();
config_101_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 101;
config_101_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_101_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 101;
} else {
config_101_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 101;
}

// Test that `OutboundV1Channel::new` creates a channel with the correct value for
// `holder_max_htlc_value_in_flight_msat`, when configured with a valid percentage value,
Expand DownExpand Up@@ -17189,26 +17243,26 @@ mod tests {
assert_eq!(chan_4.context.holder_max_htlc_value_in_flight_msat, (chan_4_value_msat as f64 * 0.99) as u64);

// Test that `OutboundV1Channel::new` uses the lower bound of the configurable percentage values (1%)
// if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a value less than 1.
// if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a value less than 1.
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();
let chan_5_value_msat = chan_5.funding.get_value_satoshis() * 1000;
assert_eq!(chan_5.context.holder_max_htlc_value_in_flight_msat, (chan_5_value_msat as f64 * 0.01) as u64);

// Test that `OutboundV1Channel::new` uses the upper bound of the configurable percentage values
// (100%) if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a larger value
// (100%) if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a larger value
// than 100.
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();
let chan_6_value_msat = chan_6.funding.get_value_satoshis() * 1000;
assert_eq!(chan_6.context.holder_max_htlc_value_in_flight_msat, chan_6_value_msat);

// Test that `InboundV1Channel::new` uses the lower bound of the configurable percentage values (1%)
// if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a value less than 1.
// if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a value less than 1.
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();
let chan_7_value_msat = chan_7.funding.get_value_satoshis() * 1000;
assert_eq!(chan_7.context.holder_max_htlc_value_in_flight_msat, (chan_7_value_msat as f64 * 0.01) as u64);

// Test that `InboundV1Channel::new` uses the upper bound of the configurable percentage values
// (100%) if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a larger value
// (100%) if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a larger value
// than 100.
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();
let chan_8_value_msat = chan_8.funding.get_value_satoshis() * 1000;
Expand Down
6 changes: 4 additions & 2 deletions lightning/src/ln/channel_open_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -182,7 +182,8 @@ fn test_inbound_anchors_manual_acceptance() {
fn test_inbound_anchors_config_overridden() {
let overrides = ChannelConfigOverrides {
handshake_overrides: Some(ChannelHandshakeConfigUpdate {
max_inbound_htlc_value_in_flight_percent_of_channel: Some(5),
announced_channel_max_inbound_htlc_value_in_flight_percentage: Some(5),
unannounced_channel_max_inbound_htlc_value_in_flight_percentage: None,
htlc_minimum_msat: Some(1000),
minimum_depth: Some(2),
to_self_delay: Some(200),
Expand DownExpand Up@@ -1070,7 +1071,8 @@ pub fn test_accept_inbound_channel_config_override() {

let config_overrides = ChannelConfigOverrides {
handshake_overrides: Some(ChannelHandshakeConfigUpdate {
max_inbound_htlc_value_in_flight_percent_of_channel: None,
announced_channel_max_inbound_htlc_value_in_flight_percentage: None,
unannounced_channel_max_inbound_htlc_value_in_flight_percentage: None,
htlc_minimum_msat: None,
minimum_depth: None,
to_self_delay: None,
Expand Down
28 changes: 20 additions & 8 deletions lightning/src/ln/functional_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6903,22 +6903,22 @@ pub fn test_channel_update_has_correct_htlc_maximum_msat() {
config_30_percent.channel_handshake_config.announce_for_forwarding = true;
config_30_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 30;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 30;
let mut config_50_percent = UserConfig::default();
config_50_percent.channel_handshake_config.announce_for_forwarding = true;
config_50_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 50;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 50;
let mut config_95_percent = UserConfig::default();
config_95_percent.channel_handshake_config.announce_for_forwarding = true;
config_95_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 95;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 95;
let mut config_100_percent = UserConfig::default();
config_100_percent.channel_handshake_config.announce_for_forwarding = true;
config_100_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 100;

let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
Expand DownExpand Up@@ -8436,7 +8436,12 @@ pub fn test_inconsistent_mpp_params() {
// such HTLC and allow the second to stay.
let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
let configs: [Option<UserConfig>; 4] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &configs);
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);

let node_a_id = nodes[0].node.get_our_node_id();
Expand DownExpand Up@@ -8580,7 +8585,12 @@ pub fn test_double_partial_claim() {
// amount.
let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
let configs: [Option<UserConfig>; 4] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &configs);
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);

let node_b_id = nodes[1].node.get_our_node_id();
Expand DownExpand Up@@ -9067,7 +9077,8 @@ pub fn test_nondust_htlc_excess_fees_are_dust() {
config.channel_handshake_limits.min_max_accepted_htlcs = chan_utils::max_htlcs(&chan_ty);
config.channel_handshake_config.our_max_accepted_htlcs = chan_utils::max_htlcs(&chan_ty);
config.channel_handshake_config.our_htlc_minimum_msat = 1;
config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
100;

let node_chanmgrs = create_node_chanmgrs(
3,
Expand DownExpand Up@@ -10039,7 +10050,8 @@ pub fn test_dust_exposure_holding_cell_assertion() {
// Use a fixed dust exposure limit to make the test simpler
const DUST_HTLC_VALUE_MSAT: u64 = 500_000;
config.channel_config.max_dust_htlc_exposure = MaxDustHTLCExposure::FixedLimitMsat(5_000_000);
config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
100;

let configs = [Some(config.clone()), Some(config.clone()), Some(config.clone())];
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &configs);
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
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
7 changes: 7 additions & 0 deletions lightning/src/ln/async_payments_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -504,6 +504,9 @@ fn often_offline_node_cfg() -> UserConfig {
cfg.channel_handshake_config.announce_for_forwarding = false;
cfg.channel_handshake_limits.force_announced_channel_preference = true;
cfg.hold_outbound_htlcs_at_next_hop = true;
// Use the setting that matches the default at the time these tests were written
cfg.channel_handshake_config.unannounced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
cfg
}

Expand DownExpand Up@@ -1310,6 +1313,10 @@ fn async_receive_mpp() {

let mut allow_priv_chan_fwds_cfg = test_default_channel_config();
allow_priv_chan_fwds_cfg.accept_forwards_to_priv_channels = true;
// Set the percentage to the default value at the time this test was written
allow_priv_chan_fwds_cfg
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 10;

let node_chanmgrs = create_node_chanmgrs(
4,
Expand Down
12 changes: 10 additions & 2 deletions lightning/src/ln/blinded_payment_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -269,7 +269,11 @@ fn one_hop_blinded_path_with_dummy_hops() {
fn mpp_to_one_hop_blinded_path() {
let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage = 10;
let configs: [Option<UserConfig>; 4] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &configs);
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);
let mut secp_ctx = Secp256k1::new();

Expand DownExpand Up@@ -349,7 +353,11 @@ fn mpp_to_one_hop_blinded_path() {
fn mpp_to_three_hop_blinded_paths() {
let chanmon_cfgs = create_chanmon_cfgs(6);
let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage = 10;
let configs: [Option<UserConfig>; 6] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &configs);
let nodes = create_network(6, &node_cfgs, &node_chanmgrs);

// Create this network topology so node 0 MPP's over 2 3-hop blinded paths:
Expand Down
7 changes: 6 additions & 1 deletion lightning/src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -4656,6 +4656,7 @@ fn test_claim_to_closed_channel_blocks_claimed_event() {
#[test]
#[cfg(all(feature = "std", not(target_os = "windows")))]
fn test_single_channel_multiple_mpp() {
use crate::util::config::UserConfig;
use std::sync::atomic::{AtomicBool, Ordering};

// Test what happens when we attempt to claim an MPP with many parts that came to us through
Expand All@@ -4667,7 +4668,11 @@ fn test_single_channel_multiple_mpp() {
// for more info.
let chanmon_cfgs = create_chanmon_cfgs(9);
let node_cfgs = create_node_cfgs(9, &chanmon_cfgs);
let configs = [None, None, None, None, None, None, None, None, None];
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
let configs: [Option<UserConfig>; 9] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(9, &node_cfgs, &configs);
let mut nodes = create_network(9, &node_cfgs, &node_chanmgrs);

Expand Down
104 changes: 79 additions & 25 deletions lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -4102,6 +4102,7 @@ impl<SP: SignerProvider> ChannelContext<SP> {
),
holder_max_htlc_value_in_flight_msat: get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis,
announce_for_forwarding,
&config.channel_handshake_config,
),
counterparty_htlc_minimum_msat: open_channel_fields.htlc_minimum_msat,
Expand DownExpand Up@@ -4405,6 +4406,7 @@ impl<SP: SignerProvider> ChannelContext<SP> {
// receive `accept_channel2`.
holder_max_htlc_value_in_flight_msat: get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis,
config.channel_handshake_config.announce_for_forwarding,
&config.channel_handshake_config,
),
counterparty_htlc_minimum_msat: 0,
Expand DownExpand Up@@ -6678,24 +6680,41 @@ impl<SP: SignerProvider> ChannelContext<SP> {

/// Returns the value to use for `holder_max_htlc_value_in_flight_msat` as a percentage of the
/// `channel_value_satoshis` in msat, set through
/// [`ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel`]
/// [`ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage`]
/// or [`ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage`]
/// depending on the value of [`ChannelHandshakeConfig::announce_for_forwarding`].
///
/// The effective percentage is lower bounded by 1% and upper bounded by 100%.
///
/// [`ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel`]: crate::util::config::ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel
/// [`ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage`]: crate::util::config::ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage
/// [`ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage`]: crate::util::config::ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage
/// [`ChannelHandshakeConfig::announce_for_forwarding`]: crate::util::config::ChannelHandshakeConfig::announce_for_forwarding
fn get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis: u64, config: &ChannelHandshakeConfig,
channel_value_satoshis: u64, is_announced_channel: bool, config: &ChannelHandshakeConfig,
) -> u64 {
let configured_percent = if config.max_inbound_htlc_value_in_flight_percent_of_channel < 1 {
let config_setting = if is_announced_channel {
config.announced_channel_max_inbound_htlc_value_in_flight_percentage
} else {
config.unannounced_channel_max_inbound_htlc_value_in_flight_percentage
};
let configured_percent = if config_setting < 1 {
1
} else if config.max_inbound_htlc_value_in_flight_percent_of_channel > 100 {
} else if config_setting > 100 {
100
} else {
config.max_inbound_htlc_value_in_flight_percent_of_channel as u64
config_setting as u64
};
channel_value_satoshis * 10 * configured_percent
}

/// This is for legacy reasons, present for forward-compatibility.
/// LDK versions older than 0.0.104 don't know how read/handle values other than the legacy
/// percentage from storage. Hence, we use this function to not persist legacy values of
/// `holder_max_htlc_value_in_flight_msat` for channels into storage.
fn get_legacy_default_holder_max_htlc_value_in_flight_msat(channel_value_satoshis: u64) -> u64 {
channel_value_satoshis * 10 * MAX_IN_FLIGHT_PERCENT_LEGACY as u64
}

/// Returns a minimum channel reserve value the remote needs to maintain,
/// required by us according to the configured or default
/// [`ChannelHandshakeConfig::their_channel_reserve_proportional_millionths`]
Expand DownExpand Up@@ -15691,15 +15710,11 @@ impl<SP: SignerProvider> Writeable for FundedChannel<SP> {
None
};

let mut old_max_in_flight_percent_config = UserConfig::default().channel_handshake_config;
old_max_in_flight_percent_config.max_inbound_htlc_value_in_flight_percent_of_channel =
MAX_IN_FLIGHT_PERCENT_LEGACY;
let max_in_flight_msat = get_holder_max_htlc_value_in_flight_msat(
let legacy_max_in_flight_msat = get_legacy_default_holder_max_htlc_value_in_flight_msat(
self.funding.get_value_satoshis(),
&old_max_in_flight_percent_config,
);
let serialized_holder_htlc_max_in_flight =
if self.context.holder_max_htlc_value_in_flight_msat != max_in_flight_msat {
if self.context.holder_max_htlc_value_in_flight_msat != legacy_max_in_flight_msat {
Some(self.context.holder_max_htlc_value_in_flight_msat)
} else {
None
Expand DownExpand Up@@ -16131,11 +16146,9 @@ impl<'a, 'b, 'c, ES: EntropySource, SP: SignerProvider>
let mut holder_selected_channel_reserve_satoshis = Some(
get_legacy_default_holder_selected_channel_reserve_satoshis(channel_value_satoshis),
);

let mut holder_max_htlc_value_in_flight_msat =
Some(get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis,
&UserConfig::default().channel_handshake_config,
));
Some(get_legacy_default_holder_max_htlc_value_in_flight_msat(channel_value_satoshis));
// Prior to supporting channel type negotiation, all of our channels were static_remotekey
// only, so we default to that if none was written.
let mut channel_type = Some(ChannelTypeFeatures::only_static_remote_key());
Expand DownExpand Up@@ -17141,8 +17154,13 @@ mod tests {
}

#[test]
#[rustfmt::skip]
fn test_configured_holder_max_htlc_value_in_flight() {
do_test_configured_holder_max_htlc_value_in_flight(true);
do_test_configured_holder_max_htlc_value_in_flight(false);
}

#[rustfmt::skip]
fn do_test_configured_holder_max_htlc_value_in_flight(announce_channel: bool) {
let test_est = TestFeeEstimator::new(15000);
let feeest = LowerBoundedFeeEstimator::new(&test_est);
let logger = TestLogger::new();
Expand All@@ -17154,13 +17172,49 @@ mod tests {
let inbound_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[7; 32]).unwrap());

let mut config_2_percent = UserConfig::default();
config_2_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 2;
config_2_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_2_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 2;
} else {
config_2_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 2;
}
let mut config_99_percent = UserConfig::default();
config_99_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 99;
config_99_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_99_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 99;
} else {
config_99_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 99;
}
let mut config_0_percent = UserConfig::default();
config_0_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 0;
config_0_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_0_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 0;
} else {
config_0_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 0;
}
let mut config_101_percent = UserConfig::default();
config_101_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 101;
config_101_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_101_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 101;
} else {
config_101_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 101;
}

// Test that `OutboundV1Channel::new` creates a channel with the correct value for
// `holder_max_htlc_value_in_flight_msat`, when configured with a valid percentage value,
Expand DownExpand Up@@ -17189,26 +17243,26 @@ mod tests {
assert_eq!(chan_4.context.holder_max_htlc_value_in_flight_msat, (chan_4_value_msat as f64 * 0.99) as u64);

// Test that `OutboundV1Channel::new` uses the lower bound of the configurable percentage values (1%)
// if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a value less than 1.
// if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a value less than 1.
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();
let chan_5_value_msat = chan_5.funding.get_value_satoshis() * 1000;
assert_eq!(chan_5.context.holder_max_htlc_value_in_flight_msat, (chan_5_value_msat as f64 * 0.01) as u64);

// Test that `OutboundV1Channel::new` uses the upper bound of the configurable percentage values
// (100%) if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a larger value
// (100%) if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a larger value
// than 100.
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();
let chan_6_value_msat = chan_6.funding.get_value_satoshis() * 1000;
assert_eq!(chan_6.context.holder_max_htlc_value_in_flight_msat, chan_6_value_msat);

// Test that `InboundV1Channel::new` uses the lower bound of the configurable percentage values (1%)
// if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a value less than 1.
// if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a value less than 1.
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();
let chan_7_value_msat = chan_7.funding.get_value_satoshis() * 1000;
assert_eq!(chan_7.context.holder_max_htlc_value_in_flight_msat, (chan_7_value_msat as f64 * 0.01) as u64);

// Test that `InboundV1Channel::new` uses the upper bound of the configurable percentage values
// (100%) if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a larger value
// (100%) if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a larger value
// than 100.
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();
let chan_8_value_msat = chan_8.funding.get_value_satoshis() * 1000;
Expand Down
6 changes: 4 additions & 2 deletions lightning/src/ln/channel_open_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -182,7 +182,8 @@ fn test_inbound_anchors_manual_acceptance() {
fn test_inbound_anchors_config_overridden() {
let overrides = ChannelConfigOverrides {
handshake_overrides: Some(ChannelHandshakeConfigUpdate {
max_inbound_htlc_value_in_flight_percent_of_channel: Some(5),
announced_channel_max_inbound_htlc_value_in_flight_percentage: Some(5),
unannounced_channel_max_inbound_htlc_value_in_flight_percentage: None,
htlc_minimum_msat: Some(1000),
minimum_depth: Some(2),
to_self_delay: Some(200),
Expand DownExpand Up@@ -1070,7 +1071,8 @@ pub fn test_accept_inbound_channel_config_override() {

let config_overrides = ChannelConfigOverrides {
handshake_overrides: Some(ChannelHandshakeConfigUpdate {
max_inbound_htlc_value_in_flight_percent_of_channel: None,
announced_channel_max_inbound_htlc_value_in_flight_percentage: None,
unannounced_channel_max_inbound_htlc_value_in_flight_percentage: None,
htlc_minimum_msat: None,
minimum_depth: None,
to_self_delay: None,
Expand Down
28 changes: 20 additions & 8 deletions lightning/src/ln/functional_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6903,22 +6903,22 @@ pub fn test_channel_update_has_correct_htlc_maximum_msat() {
config_30_percent.channel_handshake_config.announce_for_forwarding = true;
config_30_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 30;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 30;
let mut config_50_percent = UserConfig::default();
config_50_percent.channel_handshake_config.announce_for_forwarding = true;
config_50_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 50;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 50;
let mut config_95_percent = UserConfig::default();
config_95_percent.channel_handshake_config.announce_for_forwarding = true;
config_95_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 95;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 95;
let mut config_100_percent = UserConfig::default();
config_100_percent.channel_handshake_config.announce_for_forwarding = true;
config_100_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 100;

let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
Expand DownExpand Up@@ -8436,7 +8436,12 @@ pub fn test_inconsistent_mpp_params() {
// such HTLC and allow the second to stay.
let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
let configs: [Option<UserConfig>; 4] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &configs);
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);

let node_a_id = nodes[0].node.get_our_node_id();
Expand DownExpand Up@@ -8580,7 +8585,12 @@ pub fn test_double_partial_claim() {
// amount.
let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
let configs: [Option<UserConfig>; 4] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &configs);
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);

let node_b_id = nodes[1].node.get_our_node_id();
Expand DownExpand Up@@ -9067,7 +9077,8 @@ pub fn test_nondust_htlc_excess_fees_are_dust() {
config.channel_handshake_limits.min_max_accepted_htlcs = chan_utils::max_htlcs(&chan_ty);
config.channel_handshake_config.our_max_accepted_htlcs = chan_utils::max_htlcs(&chan_ty);
config.channel_handshake_config.our_htlc_minimum_msat = 1;
config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
100;

let node_chanmgrs = create_node_chanmgrs(
3,
Expand DownExpand Up@@ -10039,7 +10050,8 @@ pub fn test_dust_exposure_holding_cell_assertion() {
// Use a fixed dust exposure limit to make the test simpler
const DUST_HTLC_VALUE_MSAT: u64 = 500_000;
config.channel_config.max_dust_htlc_exposure = MaxDustHTLCExposure::FixedLimitMsat(5_000_000);
config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
100;

let configs = [Some(config.clone()), Some(config.clone()), Some(config.clone())];
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &configs);
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
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
7 changes: 7 additions & 0 deletions lightning/src/ln/async_payments_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -504,6 +504,9 @@ fn often_offline_node_cfg() -> UserConfig {
cfg.channel_handshake_config.announce_for_forwarding = false;
cfg.channel_handshake_limits.force_announced_channel_preference = true;
cfg.hold_outbound_htlcs_at_next_hop = true;
// Use the setting that matches the default at the time these tests were written
cfg.channel_handshake_config.unannounced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
cfg
}

Expand DownExpand Up@@ -1310,6 +1313,10 @@ fn async_receive_mpp() {

let mut allow_priv_chan_fwds_cfg = test_default_channel_config();
allow_priv_chan_fwds_cfg.accept_forwards_to_priv_channels = true;
// Set the percentage to the default value at the time this test was written
allow_priv_chan_fwds_cfg
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 10;

let node_chanmgrs = create_node_chanmgrs(
4,
Expand Down
12 changes: 10 additions & 2 deletions lightning/src/ln/blinded_payment_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -269,7 +269,11 @@ fn one_hop_blinded_path_with_dummy_hops() {
fn mpp_to_one_hop_blinded_path() {
let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage = 10;
let configs: [Option<UserConfig>; 4] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &configs);
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);
let mut secp_ctx = Secp256k1::new();

Expand DownExpand Up@@ -349,7 +353,11 @@ fn mpp_to_one_hop_blinded_path() {
fn mpp_to_three_hop_blinded_paths() {
let chanmon_cfgs = create_chanmon_cfgs(6);
let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage = 10;
let configs: [Option<UserConfig>; 6] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &configs);
let nodes = create_network(6, &node_cfgs, &node_chanmgrs);

// Create this network topology so node 0 MPP's over 2 3-hop blinded paths:
Expand Down
7 changes: 6 additions & 1 deletion lightning/src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -4656,6 +4656,7 @@ fn test_claim_to_closed_channel_blocks_claimed_event() {
#[test]
#[cfg(all(feature = "std", not(target_os = "windows")))]
fn test_single_channel_multiple_mpp() {
use crate::util::config::UserConfig;
use std::sync::atomic::{AtomicBool, Ordering};

// Test what happens when we attempt to claim an MPP with many parts that came to us through
Expand All@@ -4667,7 +4668,11 @@ fn test_single_channel_multiple_mpp() {
// for more info.
let chanmon_cfgs = create_chanmon_cfgs(9);
let node_cfgs = create_node_cfgs(9, &chanmon_cfgs);
let configs = [None, None, None, None, None, None, None, None, None];
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
let configs: [Option<UserConfig>; 9] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(9, &node_cfgs, &configs);
let mut nodes = create_network(9, &node_cfgs, &node_chanmgrs);

Expand Down
104 changes: 79 additions & 25 deletions lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -4102,6 +4102,7 @@ impl<SP: SignerProvider> ChannelContext<SP> {
),
holder_max_htlc_value_in_flight_msat: get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis,
announce_for_forwarding,
&config.channel_handshake_config,
),
counterparty_htlc_minimum_msat: open_channel_fields.htlc_minimum_msat,
Expand DownExpand Up@@ -4405,6 +4406,7 @@ impl<SP: SignerProvider> ChannelContext<SP> {
// receive `accept_channel2`.
holder_max_htlc_value_in_flight_msat: get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis,
config.channel_handshake_config.announce_for_forwarding,
&config.channel_handshake_config,
),
counterparty_htlc_minimum_msat: 0,
Expand DownExpand Up@@ -6678,24 +6680,41 @@ impl<SP: SignerProvider> ChannelContext<SP> {

/// Returns the value to use for `holder_max_htlc_value_in_flight_msat` as a percentage of the
/// `channel_value_satoshis` in msat, set through
/// [`ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel`]
/// [`ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage`]
/// or [`ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage`]
/// depending on the value of [`ChannelHandshakeConfig::announce_for_forwarding`].
///
/// The effective percentage is lower bounded by 1% and upper bounded by 100%.
///
/// [`ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel`]: crate::util::config::ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel
/// [`ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage`]: crate::util::config::ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage
/// [`ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage`]: crate::util::config::ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage
/// [`ChannelHandshakeConfig::announce_for_forwarding`]: crate::util::config::ChannelHandshakeConfig::announce_for_forwarding
fn get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis: u64, config: &ChannelHandshakeConfig,
channel_value_satoshis: u64, is_announced_channel: bool, config: &ChannelHandshakeConfig,
) -> u64 {
let configured_percent = if config.max_inbound_htlc_value_in_flight_percent_of_channel < 1 {
let config_setting = if is_announced_channel {
config.announced_channel_max_inbound_htlc_value_in_flight_percentage
} else {
config.unannounced_channel_max_inbound_htlc_value_in_flight_percentage
};
let configured_percent = if config_setting < 1 {
1
} else if config.max_inbound_htlc_value_in_flight_percent_of_channel > 100 {
} else if config_setting > 100 {
100
} else {
config.max_inbound_htlc_value_in_flight_percent_of_channel as u64
config_setting as u64
};
channel_value_satoshis * 10 * configured_percent
}

/// This is for legacy reasons, present for forward-compatibility.
/// LDK versions older than 0.0.104 don't know how read/handle values other than the legacy
/// percentage from storage. Hence, we use this function to not persist legacy values of
/// `holder_max_htlc_value_in_flight_msat` for channels into storage.
fn get_legacy_default_holder_max_htlc_value_in_flight_msat(channel_value_satoshis: u64) -> u64 {
channel_value_satoshis * 10 * MAX_IN_FLIGHT_PERCENT_LEGACY as u64
}

/// Returns a minimum channel reserve value the remote needs to maintain,
/// required by us according to the configured or default
/// [`ChannelHandshakeConfig::their_channel_reserve_proportional_millionths`]
Expand DownExpand Up@@ -15691,15 +15710,11 @@ impl<SP: SignerProvider> Writeable for FundedChannel<SP> {
None
};

let mut old_max_in_flight_percent_config = UserConfig::default().channel_handshake_config;
old_max_in_flight_percent_config.max_inbound_htlc_value_in_flight_percent_of_channel =
MAX_IN_FLIGHT_PERCENT_LEGACY;
let max_in_flight_msat = get_holder_max_htlc_value_in_flight_msat(
let legacy_max_in_flight_msat = get_legacy_default_holder_max_htlc_value_in_flight_msat(
self.funding.get_value_satoshis(),
&old_max_in_flight_percent_config,
);
let serialized_holder_htlc_max_in_flight =
if self.context.holder_max_htlc_value_in_flight_msat != max_in_flight_msat {
if self.context.holder_max_htlc_value_in_flight_msat != legacy_max_in_flight_msat {
Some(self.context.holder_max_htlc_value_in_flight_msat)
} else {
None
Expand DownExpand Up@@ -16131,11 +16146,9 @@ impl<'a, 'b, 'c, ES: EntropySource, SP: SignerProvider>
let mut holder_selected_channel_reserve_satoshis = Some(
get_legacy_default_holder_selected_channel_reserve_satoshis(channel_value_satoshis),
);

let mut holder_max_htlc_value_in_flight_msat =
Some(get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis,
&UserConfig::default().channel_handshake_config,
));
Some(get_legacy_default_holder_max_htlc_value_in_flight_msat(channel_value_satoshis));
// Prior to supporting channel type negotiation, all of our channels were static_remotekey
// only, so we default to that if none was written.
let mut channel_type = Some(ChannelTypeFeatures::only_static_remote_key());
Expand DownExpand Up@@ -17141,8 +17154,13 @@ mod tests {
}

#[test]
#[rustfmt::skip]
fn test_configured_holder_max_htlc_value_in_flight() {
do_test_configured_holder_max_htlc_value_in_flight(true);
do_test_configured_holder_max_htlc_value_in_flight(false);
}

#[rustfmt::skip]
fn do_test_configured_holder_max_htlc_value_in_flight(announce_channel: bool) {
let test_est = TestFeeEstimator::new(15000);
let feeest = LowerBoundedFeeEstimator::new(&test_est);
let logger = TestLogger::new();
Expand All@@ -17154,13 +17172,49 @@ mod tests {
let inbound_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[7; 32]).unwrap());

let mut config_2_percent = UserConfig::default();
config_2_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 2;
config_2_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_2_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 2;
} else {
config_2_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 2;
}
let mut config_99_percent = UserConfig::default();
config_99_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 99;
config_99_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_99_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 99;
} else {
config_99_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 99;
}
let mut config_0_percent = UserConfig::default();
config_0_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 0;
config_0_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_0_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 0;
} else {
config_0_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 0;
}
let mut config_101_percent = UserConfig::default();
config_101_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 101;
config_101_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_101_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 101;
} else {
config_101_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 101;
}

// Test that `OutboundV1Channel::new` creates a channel with the correct value for
// `holder_max_htlc_value_in_flight_msat`, when configured with a valid percentage value,
Expand DownExpand Up@@ -17189,26 +17243,26 @@ mod tests {
assert_eq!(chan_4.context.holder_max_htlc_value_in_flight_msat, (chan_4_value_msat as f64 * 0.99) as u64);

// Test that `OutboundV1Channel::new` uses the lower bound of the configurable percentage values (1%)
// if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a value less than 1.
// if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a value less than 1.
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();
let chan_5_value_msat = chan_5.funding.get_value_satoshis() * 1000;
assert_eq!(chan_5.context.holder_max_htlc_value_in_flight_msat, (chan_5_value_msat as f64 * 0.01) as u64);

// Test that `OutboundV1Channel::new` uses the upper bound of the configurable percentage values
// (100%) if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a larger value
// (100%) if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a larger value
// than 100.
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();
let chan_6_value_msat = chan_6.funding.get_value_satoshis() * 1000;
assert_eq!(chan_6.context.holder_max_htlc_value_in_flight_msat, chan_6_value_msat);

// Test that `InboundV1Channel::new` uses the lower bound of the configurable percentage values (1%)
// if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a value less than 1.
// if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a value less than 1.
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();
let chan_7_value_msat = chan_7.funding.get_value_satoshis() * 1000;
assert_eq!(chan_7.context.holder_max_htlc_value_in_flight_msat, (chan_7_value_msat as f64 * 0.01) as u64);

// Test that `InboundV1Channel::new` uses the upper bound of the configurable percentage values
// (100%) if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a larger value
// (100%) if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a larger value
// than 100.
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();
let chan_8_value_msat = chan_8.funding.get_value_satoshis() * 1000;
Expand Down
6 changes: 4 additions & 2 deletions lightning/src/ln/channel_open_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -182,7 +182,8 @@ fn test_inbound_anchors_manual_acceptance() {
fn test_inbound_anchors_config_overridden() {
let overrides = ChannelConfigOverrides {
handshake_overrides: Some(ChannelHandshakeConfigUpdate {
max_inbound_htlc_value_in_flight_percent_of_channel: Some(5),
announced_channel_max_inbound_htlc_value_in_flight_percentage: Some(5),
unannounced_channel_max_inbound_htlc_value_in_flight_percentage: None,
htlc_minimum_msat: Some(1000),
minimum_depth: Some(2),
to_self_delay: Some(200),
Expand DownExpand Up@@ -1070,7 +1071,8 @@ pub fn test_accept_inbound_channel_config_override() {

let config_overrides = ChannelConfigOverrides {
handshake_overrides: Some(ChannelHandshakeConfigUpdate {
max_inbound_htlc_value_in_flight_percent_of_channel: None,
announced_channel_max_inbound_htlc_value_in_flight_percentage: None,
unannounced_channel_max_inbound_htlc_value_in_flight_percentage: None,
htlc_minimum_msat: None,
minimum_depth: None,
to_self_delay: None,
Expand Down
28 changes: 20 additions & 8 deletions lightning/src/ln/functional_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6903,22 +6903,22 @@ pub fn test_channel_update_has_correct_htlc_maximum_msat() {
config_30_percent.channel_handshake_config.announce_for_forwarding = true;
config_30_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 30;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 30;
let mut config_50_percent = UserConfig::default();
config_50_percent.channel_handshake_config.announce_for_forwarding = true;
config_50_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 50;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 50;
let mut config_95_percent = UserConfig::default();
config_95_percent.channel_handshake_config.announce_for_forwarding = true;
config_95_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 95;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 95;
let mut config_100_percent = UserConfig::default();
config_100_percent.channel_handshake_config.announce_for_forwarding = true;
config_100_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 100;

let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
Expand DownExpand Up@@ -8436,7 +8436,12 @@ pub fn test_inconsistent_mpp_params() {
// such HTLC and allow the second to stay.
let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
let configs: [Option<UserConfig>; 4] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &configs);
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);

let node_a_id = nodes[0].node.get_our_node_id();
Expand DownExpand Up@@ -8580,7 +8585,12 @@ pub fn test_double_partial_claim() {
// amount.
let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
let configs: [Option<UserConfig>; 4] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &configs);
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);

let node_b_id = nodes[1].node.get_our_node_id();
Expand DownExpand Up@@ -9067,7 +9077,8 @@ pub fn test_nondust_htlc_excess_fees_are_dust() {
config.channel_handshake_limits.min_max_accepted_htlcs = chan_utils::max_htlcs(&chan_ty);
config.channel_handshake_config.our_max_accepted_htlcs = chan_utils::max_htlcs(&chan_ty);
config.channel_handshake_config.our_htlc_minimum_msat = 1;
config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
100;

let node_chanmgrs = create_node_chanmgrs(
3,
Expand DownExpand Up@@ -10039,7 +10050,8 @@ pub fn test_dust_exposure_holding_cell_assertion() {
// Use a fixed dust exposure limit to make the test simpler
const DUST_HTLC_VALUE_MSAT: u64 = 500_000;
config.channel_config.max_dust_htlc_exposure = MaxDustHTLCExposure::FixedLimitMsat(5_000_000);
config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
100;

let configs = [Some(config.clone()), Some(config.clone()), Some(config.clone())];
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &configs);
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
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
7 changes: 7 additions & 0 deletions lightning/src/ln/async_payments_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -504,6 +504,9 @@ fn often_offline_node_cfg() -> UserConfig {
cfg.channel_handshake_config.announce_for_forwarding = false;
cfg.channel_handshake_limits.force_announced_channel_preference = true;
cfg.hold_outbound_htlcs_at_next_hop = true;
// Use the setting that matches the default at the time these tests were written
cfg.channel_handshake_config.unannounced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
cfg
}

Expand DownExpand Up@@ -1310,6 +1313,10 @@ fn async_receive_mpp() {

let mut allow_priv_chan_fwds_cfg = test_default_channel_config();
allow_priv_chan_fwds_cfg.accept_forwards_to_priv_channels = true;
// Set the percentage to the default value at the time this test was written
allow_priv_chan_fwds_cfg
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 10;

let node_chanmgrs = create_node_chanmgrs(
4,
Expand Down
12 changes: 10 additions & 2 deletions lightning/src/ln/blinded_payment_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -269,7 +269,11 @@ fn one_hop_blinded_path_with_dummy_hops() {
fn mpp_to_one_hop_blinded_path() {
let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage = 10;
let configs: [Option<UserConfig>; 4] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &configs);
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);
let mut secp_ctx = Secp256k1::new();

Expand DownExpand Up@@ -349,7 +353,11 @@ fn mpp_to_one_hop_blinded_path() {
fn mpp_to_three_hop_blinded_paths() {
let chanmon_cfgs = create_chanmon_cfgs(6);
let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage = 10;
let configs: [Option<UserConfig>; 6] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &configs);
let nodes = create_network(6, &node_cfgs, &node_chanmgrs);

// Create this network topology so node 0 MPP's over 2 3-hop blinded paths:
Expand Down
7 changes: 6 additions & 1 deletion lightning/src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -4656,6 +4656,7 @@ fn test_claim_to_closed_channel_blocks_claimed_event() {
#[test]
#[cfg(all(feature = "std", not(target_os = "windows")))]
fn test_single_channel_multiple_mpp() {
use crate::util::config::UserConfig;
use std::sync::atomic::{AtomicBool, Ordering};

// Test what happens when we attempt to claim an MPP with many parts that came to us through
Expand All@@ -4667,7 +4668,11 @@ fn test_single_channel_multiple_mpp() {
// for more info.
let chanmon_cfgs = create_chanmon_cfgs(9);
let node_cfgs = create_node_cfgs(9, &chanmon_cfgs);
let configs = [None, None, None, None, None, None, None, None, None];
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
let configs: [Option<UserConfig>; 9] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(9, &node_cfgs, &configs);
let mut nodes = create_network(9, &node_cfgs, &node_chanmgrs);

Expand Down
104 changes: 79 additions & 25 deletions lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -4102,6 +4102,7 @@ impl<SP: SignerProvider> ChannelContext<SP> {
),
holder_max_htlc_value_in_flight_msat: get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis,
announce_for_forwarding,
&config.channel_handshake_config,
),
counterparty_htlc_minimum_msat: open_channel_fields.htlc_minimum_msat,
Expand DownExpand Up@@ -4405,6 +4406,7 @@ impl<SP: SignerProvider> ChannelContext<SP> {
// receive `accept_channel2`.
holder_max_htlc_value_in_flight_msat: get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis,
config.channel_handshake_config.announce_for_forwarding,
&config.channel_handshake_config,
),
counterparty_htlc_minimum_msat: 0,
Expand DownExpand Up@@ -6678,24 +6680,41 @@ impl<SP: SignerProvider> ChannelContext<SP> {

/// Returns the value to use for `holder_max_htlc_value_in_flight_msat` as a percentage of the
/// `channel_value_satoshis` in msat, set through
/// [`ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel`]
/// [`ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage`]
/// or [`ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage`]
/// depending on the value of [`ChannelHandshakeConfig::announce_for_forwarding`].
///
/// The effective percentage is lower bounded by 1% and upper bounded by 100%.
///
/// [`ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel`]: crate::util::config::ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel
/// [`ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage`]: crate::util::config::ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage
/// [`ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage`]: crate::util::config::ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage
/// [`ChannelHandshakeConfig::announce_for_forwarding`]: crate::util::config::ChannelHandshakeConfig::announce_for_forwarding
fn get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis: u64, config: &ChannelHandshakeConfig,
channel_value_satoshis: u64, is_announced_channel: bool, config: &ChannelHandshakeConfig,
) -> u64 {
let configured_percent = if config.max_inbound_htlc_value_in_flight_percent_of_channel < 1 {
let config_setting = if is_announced_channel {
config.announced_channel_max_inbound_htlc_value_in_flight_percentage
} else {
config.unannounced_channel_max_inbound_htlc_value_in_flight_percentage
};
let configured_percent = if config_setting < 1 {
1
} else if config.max_inbound_htlc_value_in_flight_percent_of_channel > 100 {
} else if config_setting > 100 {
100
} else {
config.max_inbound_htlc_value_in_flight_percent_of_channel as u64
config_setting as u64
};
channel_value_satoshis * 10 * configured_percent
}

/// This is for legacy reasons, present for forward-compatibility.
/// LDK versions older than 0.0.104 don't know how read/handle values other than the legacy
/// percentage from storage. Hence, we use this function to not persist legacy values of
/// `holder_max_htlc_value_in_flight_msat` for channels into storage.
fn get_legacy_default_holder_max_htlc_value_in_flight_msat(channel_value_satoshis: u64) -> u64 {
channel_value_satoshis * 10 * MAX_IN_FLIGHT_PERCENT_LEGACY as u64
}

/// Returns a minimum channel reserve value the remote needs to maintain,
/// required by us according to the configured or default
/// [`ChannelHandshakeConfig::their_channel_reserve_proportional_millionths`]
Expand DownExpand Up@@ -15691,15 +15710,11 @@ impl<SP: SignerProvider> Writeable for FundedChannel<SP> {
None
};

let mut old_max_in_flight_percent_config = UserConfig::default().channel_handshake_config;
old_max_in_flight_percent_config.max_inbound_htlc_value_in_flight_percent_of_channel =
MAX_IN_FLIGHT_PERCENT_LEGACY;
let max_in_flight_msat = get_holder_max_htlc_value_in_flight_msat(
let legacy_max_in_flight_msat = get_legacy_default_holder_max_htlc_value_in_flight_msat(
self.funding.get_value_satoshis(),
&old_max_in_flight_percent_config,
);
let serialized_holder_htlc_max_in_flight =
if self.context.holder_max_htlc_value_in_flight_msat != max_in_flight_msat {
if self.context.holder_max_htlc_value_in_flight_msat != legacy_max_in_flight_msat {
Some(self.context.holder_max_htlc_value_in_flight_msat)
} else {
None
Expand DownExpand Up@@ -16131,11 +16146,9 @@ impl<'a, 'b, 'c, ES: EntropySource, SP: SignerProvider>
let mut holder_selected_channel_reserve_satoshis = Some(
get_legacy_default_holder_selected_channel_reserve_satoshis(channel_value_satoshis),
);

let mut holder_max_htlc_value_in_flight_msat =
Some(get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis,
&UserConfig::default().channel_handshake_config,
));
Some(get_legacy_default_holder_max_htlc_value_in_flight_msat(channel_value_satoshis));
// Prior to supporting channel type negotiation, all of our channels were static_remotekey
// only, so we default to that if none was written.
let mut channel_type = Some(ChannelTypeFeatures::only_static_remote_key());
Expand DownExpand Up@@ -17141,8 +17154,13 @@ mod tests {
}

#[test]
#[rustfmt::skip]
fn test_configured_holder_max_htlc_value_in_flight() {
do_test_configured_holder_max_htlc_value_in_flight(true);
do_test_configured_holder_max_htlc_value_in_flight(false);
}

#[rustfmt::skip]
fn do_test_configured_holder_max_htlc_value_in_flight(announce_channel: bool) {
let test_est = TestFeeEstimator::new(15000);
let feeest = LowerBoundedFeeEstimator::new(&test_est);
let logger = TestLogger::new();
Expand All@@ -17154,13 +17172,49 @@ mod tests {
let inbound_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[7; 32]).unwrap());

let mut config_2_percent = UserConfig::default();
config_2_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 2;
config_2_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_2_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 2;
} else {
config_2_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 2;
}
let mut config_99_percent = UserConfig::default();
config_99_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 99;
config_99_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_99_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 99;
} else {
config_99_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 99;
}
let mut config_0_percent = UserConfig::default();
config_0_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 0;
config_0_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_0_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 0;
} else {
config_0_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 0;
}
let mut config_101_percent = UserConfig::default();
config_101_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 101;
config_101_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_101_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 101;
} else {
config_101_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 101;
}

// Test that `OutboundV1Channel::new` creates a channel with the correct value for
// `holder_max_htlc_value_in_flight_msat`, when configured with a valid percentage value,
Expand DownExpand Up@@ -17189,26 +17243,26 @@ mod tests {
assert_eq!(chan_4.context.holder_max_htlc_value_in_flight_msat, (chan_4_value_msat as f64 * 0.99) as u64);

// Test that `OutboundV1Channel::new` uses the lower bound of the configurable percentage values (1%)
// if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a value less than 1.
// if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a value less than 1.
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();
let chan_5_value_msat = chan_5.funding.get_value_satoshis() * 1000;
assert_eq!(chan_5.context.holder_max_htlc_value_in_flight_msat, (chan_5_value_msat as f64 * 0.01) as u64);

// Test that `OutboundV1Channel::new` uses the upper bound of the configurable percentage values
// (100%) if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a larger value
// (100%) if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a larger value
// than 100.
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();
let chan_6_value_msat = chan_6.funding.get_value_satoshis() * 1000;
assert_eq!(chan_6.context.holder_max_htlc_value_in_flight_msat, chan_6_value_msat);

// Test that `InboundV1Channel::new` uses the lower bound of the configurable percentage values (1%)
// if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a value less than 1.
// if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a value less than 1.
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();
let chan_7_value_msat = chan_7.funding.get_value_satoshis() * 1000;
assert_eq!(chan_7.context.holder_max_htlc_value_in_flight_msat, (chan_7_value_msat as f64 * 0.01) as u64);

// Test that `InboundV1Channel::new` uses the upper bound of the configurable percentage values
// (100%) if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a larger value
// (100%) if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a larger value
// than 100.
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();
let chan_8_value_msat = chan_8.funding.get_value_satoshis() * 1000;
Expand Down
6 changes: 4 additions & 2 deletions lightning/src/ln/channel_open_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -182,7 +182,8 @@ fn test_inbound_anchors_manual_acceptance() {
fn test_inbound_anchors_config_overridden() {
let overrides = ChannelConfigOverrides {
handshake_overrides: Some(ChannelHandshakeConfigUpdate {
max_inbound_htlc_value_in_flight_percent_of_channel: Some(5),
announced_channel_max_inbound_htlc_value_in_flight_percentage: Some(5),
unannounced_channel_max_inbound_htlc_value_in_flight_percentage: None,
htlc_minimum_msat: Some(1000),
minimum_depth: Some(2),
to_self_delay: Some(200),
Expand DownExpand Up@@ -1070,7 +1071,8 @@ pub fn test_accept_inbound_channel_config_override() {

let config_overrides = ChannelConfigOverrides {
handshake_overrides: Some(ChannelHandshakeConfigUpdate {
max_inbound_htlc_value_in_flight_percent_of_channel: None,
announced_channel_max_inbound_htlc_value_in_flight_percentage: None,
unannounced_channel_max_inbound_htlc_value_in_flight_percentage: None,
htlc_minimum_msat: None,
minimum_depth: None,
to_self_delay: None,
Expand Down
28 changes: 20 additions & 8 deletions lightning/src/ln/functional_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6903,22 +6903,22 @@ pub fn test_channel_update_has_correct_htlc_maximum_msat() {
config_30_percent.channel_handshake_config.announce_for_forwarding = true;
config_30_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 30;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 30;
let mut config_50_percent = UserConfig::default();
config_50_percent.channel_handshake_config.announce_for_forwarding = true;
config_50_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 50;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 50;
let mut config_95_percent = UserConfig::default();
config_95_percent.channel_handshake_config.announce_for_forwarding = true;
config_95_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 95;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 95;
let mut config_100_percent = UserConfig::default();
config_100_percent.channel_handshake_config.announce_for_forwarding = true;
config_100_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 100;

let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
Expand DownExpand Up@@ -8436,7 +8436,12 @@ pub fn test_inconsistent_mpp_params() {
// such HTLC and allow the second to stay.
let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
let configs: [Option<UserConfig>; 4] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &configs);
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);

let node_a_id = nodes[0].node.get_our_node_id();
Expand DownExpand Up@@ -8580,7 +8585,12 @@ pub fn test_double_partial_claim() {
// amount.
let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
let configs: [Option<UserConfig>; 4] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &configs);
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);

let node_b_id = nodes[1].node.get_our_node_id();
Expand DownExpand Up@@ -9067,7 +9077,8 @@ pub fn test_nondust_htlc_excess_fees_are_dust() {
config.channel_handshake_limits.min_max_accepted_htlcs = chan_utils::max_htlcs(&chan_ty);
config.channel_handshake_config.our_max_accepted_htlcs = chan_utils::max_htlcs(&chan_ty);
config.channel_handshake_config.our_htlc_minimum_msat = 1;
config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
100;

let node_chanmgrs = create_node_chanmgrs(
3,
Expand DownExpand Up@@ -10039,7 +10050,8 @@ pub fn test_dust_exposure_holding_cell_assertion() {
// Use a fixed dust exposure limit to make the test simpler
const DUST_HTLC_VALUE_MSAT: u64 = 500_000;
config.channel_config.max_dust_htlc_exposure = MaxDustHTLCExposure::FixedLimitMsat(5_000_000);
config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
100;

let configs = [Some(config.clone()), Some(config.clone()), Some(config.clone())];
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &configs);
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
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
7 changes: 7 additions & 0 deletions lightning/src/ln/async_payments_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -504,6 +504,9 @@ fn often_offline_node_cfg() -> UserConfig {
cfg.channel_handshake_config.announce_for_forwarding = false;
cfg.channel_handshake_limits.force_announced_channel_preference = true;
cfg.hold_outbound_htlcs_at_next_hop = true;
// Use the setting that matches the default at the time these tests were written
cfg.channel_handshake_config.unannounced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
cfg
}

Expand DownExpand Up@@ -1310,6 +1313,10 @@ fn async_receive_mpp() {

let mut allow_priv_chan_fwds_cfg = test_default_channel_config();
allow_priv_chan_fwds_cfg.accept_forwards_to_priv_channels = true;
// Set the percentage to the default value at the time this test was written
allow_priv_chan_fwds_cfg
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 10;

let node_chanmgrs = create_node_chanmgrs(
4,
Expand Down
12 changes: 10 additions & 2 deletions lightning/src/ln/blinded_payment_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -269,7 +269,11 @@ fn one_hop_blinded_path_with_dummy_hops() {
fn mpp_to_one_hop_blinded_path() {
let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage = 10;
let configs: [Option<UserConfig>; 4] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &configs);
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);
let mut secp_ctx = Secp256k1::new();

Expand DownExpand Up@@ -349,7 +353,11 @@ fn mpp_to_one_hop_blinded_path() {
fn mpp_to_three_hop_blinded_paths() {
let chanmon_cfgs = create_chanmon_cfgs(6);
let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage = 10;
let configs: [Option<UserConfig>; 6] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &configs);
let nodes = create_network(6, &node_cfgs, &node_chanmgrs);

// Create this network topology so node 0 MPP's over 2 3-hop blinded paths:
Expand Down
7 changes: 6 additions & 1 deletion lightning/src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -4656,6 +4656,7 @@ fn test_claim_to_closed_channel_blocks_claimed_event() {
#[test]
#[cfg(all(feature = "std", not(target_os = "windows")))]
fn test_single_channel_multiple_mpp() {
use crate::util::config::UserConfig;
use std::sync::atomic::{AtomicBool, Ordering};

// Test what happens when we attempt to claim an MPP with many parts that came to us through
Expand All@@ -4667,7 +4668,11 @@ fn test_single_channel_multiple_mpp() {
// for more info.
let chanmon_cfgs = create_chanmon_cfgs(9);
let node_cfgs = create_node_cfgs(9, &chanmon_cfgs);
let configs = [None, None, None, None, None, None, None, None, None];
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
let configs: [Option<UserConfig>; 9] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(9, &node_cfgs, &configs);
let mut nodes = create_network(9, &node_cfgs, &node_chanmgrs);

Expand Down
104 changes: 79 additions & 25 deletions lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -4102,6 +4102,7 @@ impl<SP: SignerProvider> ChannelContext<SP> {
),
holder_max_htlc_value_in_flight_msat: get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis,
announce_for_forwarding,
&config.channel_handshake_config,
),
counterparty_htlc_minimum_msat: open_channel_fields.htlc_minimum_msat,
Expand DownExpand Up@@ -4405,6 +4406,7 @@ impl<SP: SignerProvider> ChannelContext<SP> {
// receive `accept_channel2`.
holder_max_htlc_value_in_flight_msat: get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis,
config.channel_handshake_config.announce_for_forwarding,
&config.channel_handshake_config,
),
counterparty_htlc_minimum_msat: 0,
Expand DownExpand Up@@ -6678,24 +6680,41 @@ impl<SP: SignerProvider> ChannelContext<SP> {

/// Returns the value to use for `holder_max_htlc_value_in_flight_msat` as a percentage of the
/// `channel_value_satoshis` in msat, set through
/// [`ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel`]
/// [`ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage`]
/// or [`ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage`]
/// depending on the value of [`ChannelHandshakeConfig::announce_for_forwarding`].
///
/// The effective percentage is lower bounded by 1% and upper bounded by 100%.
///
/// [`ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel`]: crate::util::config::ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel
/// [`ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage`]: crate::util::config::ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage
/// [`ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage`]: crate::util::config::ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage
/// [`ChannelHandshakeConfig::announce_for_forwarding`]: crate::util::config::ChannelHandshakeConfig::announce_for_forwarding
fn get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis: u64, config: &ChannelHandshakeConfig,
channel_value_satoshis: u64, is_announced_channel: bool, config: &ChannelHandshakeConfig,
) -> u64 {
let configured_percent = if config.max_inbound_htlc_value_in_flight_percent_of_channel < 1 {
let config_setting = if is_announced_channel {
config.announced_channel_max_inbound_htlc_value_in_flight_percentage
} else {
config.unannounced_channel_max_inbound_htlc_value_in_flight_percentage
};
let configured_percent = if config_setting < 1 {
1
} else if config.max_inbound_htlc_value_in_flight_percent_of_channel > 100 {
} else if config_setting > 100 {
100
} else {
config.max_inbound_htlc_value_in_flight_percent_of_channel as u64
config_setting as u64
};
channel_value_satoshis * 10 * configured_percent
}

/// This is for legacy reasons, present for forward-compatibility.
/// LDK versions older than 0.0.104 don't know how read/handle values other than the legacy
/// percentage from storage. Hence, we use this function to not persist legacy values of
/// `holder_max_htlc_value_in_flight_msat` for channels into storage.
fn get_legacy_default_holder_max_htlc_value_in_flight_msat(channel_value_satoshis: u64) -> u64 {
channel_value_satoshis * 10 * MAX_IN_FLIGHT_PERCENT_LEGACY as u64
}

/// Returns a minimum channel reserve value the remote needs to maintain,
/// required by us according to the configured or default
/// [`ChannelHandshakeConfig::their_channel_reserve_proportional_millionths`]
Expand DownExpand Up@@ -15691,15 +15710,11 @@ impl<SP: SignerProvider> Writeable for FundedChannel<SP> {
None
};

let mut old_max_in_flight_percent_config = UserConfig::default().channel_handshake_config;
old_max_in_flight_percent_config.max_inbound_htlc_value_in_flight_percent_of_channel =
MAX_IN_FLIGHT_PERCENT_LEGACY;
let max_in_flight_msat = get_holder_max_htlc_value_in_flight_msat(
let legacy_max_in_flight_msat = get_legacy_default_holder_max_htlc_value_in_flight_msat(
self.funding.get_value_satoshis(),
&old_max_in_flight_percent_config,
);
let serialized_holder_htlc_max_in_flight =
if self.context.holder_max_htlc_value_in_flight_msat != max_in_flight_msat {
if self.context.holder_max_htlc_value_in_flight_msat != legacy_max_in_flight_msat {
Some(self.context.holder_max_htlc_value_in_flight_msat)
} else {
None
Expand DownExpand Up@@ -16131,11 +16146,9 @@ impl<'a, 'b, 'c, ES: EntropySource, SP: SignerProvider>
let mut holder_selected_channel_reserve_satoshis = Some(
get_legacy_default_holder_selected_channel_reserve_satoshis(channel_value_satoshis),
);

let mut holder_max_htlc_value_in_flight_msat =
Some(get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis,
&UserConfig::default().channel_handshake_config,
));
Some(get_legacy_default_holder_max_htlc_value_in_flight_msat(channel_value_satoshis));
// Prior to supporting channel type negotiation, all of our channels were static_remotekey
// only, so we default to that if none was written.
let mut channel_type = Some(ChannelTypeFeatures::only_static_remote_key());
Expand DownExpand Up@@ -17141,8 +17154,13 @@ mod tests {
}

#[test]
#[rustfmt::skip]
fn test_configured_holder_max_htlc_value_in_flight() {
do_test_configured_holder_max_htlc_value_in_flight(true);
do_test_configured_holder_max_htlc_value_in_flight(false);
}

#[rustfmt::skip]
fn do_test_configured_holder_max_htlc_value_in_flight(announce_channel: bool) {
let test_est = TestFeeEstimator::new(15000);
let feeest = LowerBoundedFeeEstimator::new(&test_est);
let logger = TestLogger::new();
Expand All@@ -17154,13 +17172,49 @@ mod tests {
let inbound_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[7; 32]).unwrap());

let mut config_2_percent = UserConfig::default();
config_2_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 2;
config_2_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_2_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 2;
} else {
config_2_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 2;
}
let mut config_99_percent = UserConfig::default();
config_99_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 99;
config_99_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_99_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 99;
} else {
config_99_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 99;
}
let mut config_0_percent = UserConfig::default();
config_0_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 0;
config_0_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_0_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 0;
} else {
config_0_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 0;
}
let mut config_101_percent = UserConfig::default();
config_101_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 101;
config_101_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_101_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 101;
} else {
config_101_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 101;
}

// Test that `OutboundV1Channel::new` creates a channel with the correct value for
// `holder_max_htlc_value_in_flight_msat`, when configured with a valid percentage value,
Expand DownExpand Up@@ -17189,26 +17243,26 @@ mod tests {
assert_eq!(chan_4.context.holder_max_htlc_value_in_flight_msat, (chan_4_value_msat as f64 * 0.99) as u64);

// Test that `OutboundV1Channel::new` uses the lower bound of the configurable percentage values (1%)
// if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a value less than 1.
// if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a value less than 1.
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();
let chan_5_value_msat = chan_5.funding.get_value_satoshis() * 1000;
assert_eq!(chan_5.context.holder_max_htlc_value_in_flight_msat, (chan_5_value_msat as f64 * 0.01) as u64);

// Test that `OutboundV1Channel::new` uses the upper bound of the configurable percentage values
// (100%) if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a larger value
// (100%) if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a larger value
// than 100.
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();
let chan_6_value_msat = chan_6.funding.get_value_satoshis() * 1000;
assert_eq!(chan_6.context.holder_max_htlc_value_in_flight_msat, chan_6_value_msat);

// Test that `InboundV1Channel::new` uses the lower bound of the configurable percentage values (1%)
// if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a value less than 1.
// if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a value less than 1.
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();
let chan_7_value_msat = chan_7.funding.get_value_satoshis() * 1000;
assert_eq!(chan_7.context.holder_max_htlc_value_in_flight_msat, (chan_7_value_msat as f64 * 0.01) as u64);

// Test that `InboundV1Channel::new` uses the upper bound of the configurable percentage values
// (100%) if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a larger value
// (100%) if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a larger value
// than 100.
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();
let chan_8_value_msat = chan_8.funding.get_value_satoshis() * 1000;
Expand Down
6 changes: 4 additions & 2 deletions lightning/src/ln/channel_open_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -182,7 +182,8 @@ fn test_inbound_anchors_manual_acceptance() {
fn test_inbound_anchors_config_overridden() {
let overrides = ChannelConfigOverrides {
handshake_overrides: Some(ChannelHandshakeConfigUpdate {
max_inbound_htlc_value_in_flight_percent_of_channel: Some(5),
announced_channel_max_inbound_htlc_value_in_flight_percentage: Some(5),
unannounced_channel_max_inbound_htlc_value_in_flight_percentage: None,
htlc_minimum_msat: Some(1000),
minimum_depth: Some(2),
to_self_delay: Some(200),
Expand DownExpand Up@@ -1070,7 +1071,8 @@ pub fn test_accept_inbound_channel_config_override() {

let config_overrides = ChannelConfigOverrides {
handshake_overrides: Some(ChannelHandshakeConfigUpdate {
max_inbound_htlc_value_in_flight_percent_of_channel: None,
announced_channel_max_inbound_htlc_value_in_flight_percentage: None,
unannounced_channel_max_inbound_htlc_value_in_flight_percentage: None,
htlc_minimum_msat: None,
minimum_depth: None,
to_self_delay: None,
Expand Down
28 changes: 20 additions & 8 deletions lightning/src/ln/functional_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6903,22 +6903,22 @@ pub fn test_channel_update_has_correct_htlc_maximum_msat() {
config_30_percent.channel_handshake_config.announce_for_forwarding = true;
config_30_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 30;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 30;
let mut config_50_percent = UserConfig::default();
config_50_percent.channel_handshake_config.announce_for_forwarding = true;
config_50_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 50;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 50;
let mut config_95_percent = UserConfig::default();
config_95_percent.channel_handshake_config.announce_for_forwarding = true;
config_95_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 95;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 95;
let mut config_100_percent = UserConfig::default();
config_100_percent.channel_handshake_config.announce_for_forwarding = true;
config_100_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 100;

let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
Expand DownExpand Up@@ -8436,7 +8436,12 @@ pub fn test_inconsistent_mpp_params() {
// such HTLC and allow the second to stay.
let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
let configs: [Option<UserConfig>; 4] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &configs);
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);

let node_a_id = nodes[0].node.get_our_node_id();
Expand DownExpand Up@@ -8580,7 +8585,12 @@ pub fn test_double_partial_claim() {
// amount.
let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
let configs: [Option<UserConfig>; 4] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &configs);
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);

let node_b_id = nodes[1].node.get_our_node_id();
Expand DownExpand Up@@ -9067,7 +9077,8 @@ pub fn test_nondust_htlc_excess_fees_are_dust() {
config.channel_handshake_limits.min_max_accepted_htlcs = chan_utils::max_htlcs(&chan_ty);
config.channel_handshake_config.our_max_accepted_htlcs = chan_utils::max_htlcs(&chan_ty);
config.channel_handshake_config.our_htlc_minimum_msat = 1;
config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
100;

let node_chanmgrs = create_node_chanmgrs(
3,
Expand DownExpand Up@@ -10039,7 +10050,8 @@ pub fn test_dust_exposure_holding_cell_assertion() {
// Use a fixed dust exposure limit to make the test simpler
const DUST_HTLC_VALUE_MSAT: u64 = 500_000;
config.channel_config.max_dust_htlc_exposure = MaxDustHTLCExposure::FixedLimitMsat(5_000_000);
config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
100;

let configs = [Some(config.clone()), Some(config.clone()), Some(config.clone())];
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &configs);
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
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
7 changes: 7 additions & 0 deletions lightning/src/ln/async_payments_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -504,6 +504,9 @@ fn often_offline_node_cfg() -> UserConfig {
cfg.channel_handshake_config.announce_for_forwarding = false;
cfg.channel_handshake_limits.force_announced_channel_preference = true;
cfg.hold_outbound_htlcs_at_next_hop = true;
// Use the setting that matches the default at the time these tests were written
cfg.channel_handshake_config.unannounced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
cfg
}

Expand DownExpand Up@@ -1310,6 +1313,10 @@ fn async_receive_mpp() {

let mut allow_priv_chan_fwds_cfg = test_default_channel_config();
allow_priv_chan_fwds_cfg.accept_forwards_to_priv_channels = true;
// Set the percentage to the default value at the time this test was written
allow_priv_chan_fwds_cfg
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 10;

let node_chanmgrs = create_node_chanmgrs(
4,
Expand Down
12 changes: 10 additions & 2 deletions lightning/src/ln/blinded_payment_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -269,7 +269,11 @@ fn one_hop_blinded_path_with_dummy_hops() {
fn mpp_to_one_hop_blinded_path() {
let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage = 10;
let configs: [Option<UserConfig>; 4] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &configs);
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);
let mut secp_ctx = Secp256k1::new();

Expand DownExpand Up@@ -349,7 +353,11 @@ fn mpp_to_one_hop_blinded_path() {
fn mpp_to_three_hop_blinded_paths() {
let chanmon_cfgs = create_chanmon_cfgs(6);
let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage = 10;
let configs: [Option<UserConfig>; 6] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &configs);
let nodes = create_network(6, &node_cfgs, &node_chanmgrs);

// Create this network topology so node 0 MPP's over 2 3-hop blinded paths:
Expand Down
7 changes: 6 additions & 1 deletion lightning/src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -4656,6 +4656,7 @@ fn test_claim_to_closed_channel_blocks_claimed_event() {
#[test]
#[cfg(all(feature = "std", not(target_os = "windows")))]
fn test_single_channel_multiple_mpp() {
use crate::util::config::UserConfig;
use std::sync::atomic::{AtomicBool, Ordering};

// Test what happens when we attempt to claim an MPP with many parts that came to us through
Expand All@@ -4667,7 +4668,11 @@ fn test_single_channel_multiple_mpp() {
// for more info.
let chanmon_cfgs = create_chanmon_cfgs(9);
let node_cfgs = create_node_cfgs(9, &chanmon_cfgs);
let configs = [None, None, None, None, None, None, None, None, None];
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
let configs: [Option<UserConfig>; 9] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(9, &node_cfgs, &configs);
let mut nodes = create_network(9, &node_cfgs, &node_chanmgrs);

Expand Down
104 changes: 79 additions & 25 deletions lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -4102,6 +4102,7 @@ impl<SP: SignerProvider> ChannelContext<SP> {
),
holder_max_htlc_value_in_flight_msat: get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis,
announce_for_forwarding,
&config.channel_handshake_config,
),
counterparty_htlc_minimum_msat: open_channel_fields.htlc_minimum_msat,
Expand DownExpand Up@@ -4405,6 +4406,7 @@ impl<SP: SignerProvider> ChannelContext<SP> {
// receive `accept_channel2`.
holder_max_htlc_value_in_flight_msat: get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis,
config.channel_handshake_config.announce_for_forwarding,
&config.channel_handshake_config,
),
counterparty_htlc_minimum_msat: 0,
Expand DownExpand Up@@ -6678,24 +6680,41 @@ impl<SP: SignerProvider> ChannelContext<SP> {

/// Returns the value to use for `holder_max_htlc_value_in_flight_msat` as a percentage of the
/// `channel_value_satoshis` in msat, set through
/// [`ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel`]
/// [`ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage`]
/// or [`ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage`]
/// depending on the value of [`ChannelHandshakeConfig::announce_for_forwarding`].
///
/// The effective percentage is lower bounded by 1% and upper bounded by 100%.
///
/// [`ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel`]: crate::util::config::ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel
/// [`ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage`]: crate::util::config::ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage
/// [`ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage`]: crate::util::config::ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage
/// [`ChannelHandshakeConfig::announce_for_forwarding`]: crate::util::config::ChannelHandshakeConfig::announce_for_forwarding
fn get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis: u64, config: &ChannelHandshakeConfig,
channel_value_satoshis: u64, is_announced_channel: bool, config: &ChannelHandshakeConfig,
) -> u64 {
let configured_percent = if config.max_inbound_htlc_value_in_flight_percent_of_channel < 1 {
let config_setting = if is_announced_channel {
config.announced_channel_max_inbound_htlc_value_in_flight_percentage
} else {
config.unannounced_channel_max_inbound_htlc_value_in_flight_percentage
};
let configured_percent = if config_setting < 1 {
1
} else if config.max_inbound_htlc_value_in_flight_percent_of_channel > 100 {
} else if config_setting > 100 {
100
} else {
config.max_inbound_htlc_value_in_flight_percent_of_channel as u64
config_setting as u64
};
channel_value_satoshis * 10 * configured_percent
}

/// This is for legacy reasons, present for forward-compatibility.
/// LDK versions older than 0.0.104 don't know how read/handle values other than the legacy
/// percentage from storage. Hence, we use this function to not persist legacy values of
/// `holder_max_htlc_value_in_flight_msat` for channels into storage.
fn get_legacy_default_holder_max_htlc_value_in_flight_msat(channel_value_satoshis: u64) -> u64 {
channel_value_satoshis * 10 * MAX_IN_FLIGHT_PERCENT_LEGACY as u64
}

/// Returns a minimum channel reserve value the remote needs to maintain,
/// required by us according to the configured or default
/// [`ChannelHandshakeConfig::their_channel_reserve_proportional_millionths`]
Expand DownExpand Up@@ -15691,15 +15710,11 @@ impl<SP: SignerProvider> Writeable for FundedChannel<SP> {
None
};

let mut old_max_in_flight_percent_config = UserConfig::default().channel_handshake_config;
old_max_in_flight_percent_config.max_inbound_htlc_value_in_flight_percent_of_channel =
MAX_IN_FLIGHT_PERCENT_LEGACY;
let max_in_flight_msat = get_holder_max_htlc_value_in_flight_msat(
let legacy_max_in_flight_msat = get_legacy_default_holder_max_htlc_value_in_flight_msat(
self.funding.get_value_satoshis(),
&old_max_in_flight_percent_config,
);
let serialized_holder_htlc_max_in_flight =
if self.context.holder_max_htlc_value_in_flight_msat != max_in_flight_msat {
if self.context.holder_max_htlc_value_in_flight_msat != legacy_max_in_flight_msat {
Some(self.context.holder_max_htlc_value_in_flight_msat)
} else {
None
Expand DownExpand Up@@ -16131,11 +16146,9 @@ impl<'a, 'b, 'c, ES: EntropySource, SP: SignerProvider>
let mut holder_selected_channel_reserve_satoshis = Some(
get_legacy_default_holder_selected_channel_reserve_satoshis(channel_value_satoshis),
);

let mut holder_max_htlc_value_in_flight_msat =
Some(get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis,
&UserConfig::default().channel_handshake_config,
));
Some(get_legacy_default_holder_max_htlc_value_in_flight_msat(channel_value_satoshis));
// Prior to supporting channel type negotiation, all of our channels were static_remotekey
// only, so we default to that if none was written.
let mut channel_type = Some(ChannelTypeFeatures::only_static_remote_key());
Expand DownExpand Up@@ -17141,8 +17154,13 @@ mod tests {
}

#[test]
#[rustfmt::skip]
fn test_configured_holder_max_htlc_value_in_flight() {
do_test_configured_holder_max_htlc_value_in_flight(true);
do_test_configured_holder_max_htlc_value_in_flight(false);
}

#[rustfmt::skip]
fn do_test_configured_holder_max_htlc_value_in_flight(announce_channel: bool) {
let test_est = TestFeeEstimator::new(15000);
let feeest = LowerBoundedFeeEstimator::new(&test_est);
let logger = TestLogger::new();
Expand All@@ -17154,13 +17172,49 @@ mod tests {
let inbound_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[7; 32]).unwrap());

let mut config_2_percent = UserConfig::default();
config_2_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 2;
config_2_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_2_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 2;
} else {
config_2_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 2;
}
let mut config_99_percent = UserConfig::default();
config_99_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 99;
config_99_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_99_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 99;
} else {
config_99_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 99;
}
let mut config_0_percent = UserConfig::default();
config_0_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 0;
config_0_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_0_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 0;
} else {
config_0_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 0;
}
let mut config_101_percent = UserConfig::default();
config_101_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 101;
config_101_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_101_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 101;
} else {
config_101_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 101;
}

// Test that `OutboundV1Channel::new` creates a channel with the correct value for
// `holder_max_htlc_value_in_flight_msat`, when configured with a valid percentage value,
Expand DownExpand Up@@ -17189,26 +17243,26 @@ mod tests {
assert_eq!(chan_4.context.holder_max_htlc_value_in_flight_msat, (chan_4_value_msat as f64 * 0.99) as u64);

// Test that `OutboundV1Channel::new` uses the lower bound of the configurable percentage values (1%)
// if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a value less than 1.
// if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a value less than 1.
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();
let chan_5_value_msat = chan_5.funding.get_value_satoshis() * 1000;
assert_eq!(chan_5.context.holder_max_htlc_value_in_flight_msat, (chan_5_value_msat as f64 * 0.01) as u64);

// Test that `OutboundV1Channel::new` uses the upper bound of the configurable percentage values
// (100%) if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a larger value
// (100%) if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a larger value
// than 100.
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();
let chan_6_value_msat = chan_6.funding.get_value_satoshis() * 1000;
assert_eq!(chan_6.context.holder_max_htlc_value_in_flight_msat, chan_6_value_msat);

// Test that `InboundV1Channel::new` uses the lower bound of the configurable percentage values (1%)
// if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a value less than 1.
// if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a value less than 1.
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();
let chan_7_value_msat = chan_7.funding.get_value_satoshis() * 1000;
assert_eq!(chan_7.context.holder_max_htlc_value_in_flight_msat, (chan_7_value_msat as f64 * 0.01) as u64);

// Test that `InboundV1Channel::new` uses the upper bound of the configurable percentage values
// (100%) if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a larger value
// (100%) if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a larger value
// than 100.
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();
let chan_8_value_msat = chan_8.funding.get_value_satoshis() * 1000;
Expand Down
6 changes: 4 additions & 2 deletions lightning/src/ln/channel_open_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -182,7 +182,8 @@ fn test_inbound_anchors_manual_acceptance() {
fn test_inbound_anchors_config_overridden() {
let overrides = ChannelConfigOverrides {
handshake_overrides: Some(ChannelHandshakeConfigUpdate {
max_inbound_htlc_value_in_flight_percent_of_channel: Some(5),
announced_channel_max_inbound_htlc_value_in_flight_percentage: Some(5),
unannounced_channel_max_inbound_htlc_value_in_flight_percentage: None,
htlc_minimum_msat: Some(1000),
minimum_depth: Some(2),
to_self_delay: Some(200),
Expand DownExpand Up@@ -1070,7 +1071,8 @@ pub fn test_accept_inbound_channel_config_override() {

let config_overrides = ChannelConfigOverrides {
handshake_overrides: Some(ChannelHandshakeConfigUpdate {
max_inbound_htlc_value_in_flight_percent_of_channel: None,
announced_channel_max_inbound_htlc_value_in_flight_percentage: None,
unannounced_channel_max_inbound_htlc_value_in_flight_percentage: None,
htlc_minimum_msat: None,
minimum_depth: None,
to_self_delay: None,
Expand Down
28 changes: 20 additions & 8 deletions lightning/src/ln/functional_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6903,22 +6903,22 @@ pub fn test_channel_update_has_correct_htlc_maximum_msat() {
config_30_percent.channel_handshake_config.announce_for_forwarding = true;
config_30_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 30;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 30;
let mut config_50_percent = UserConfig::default();
config_50_percent.channel_handshake_config.announce_for_forwarding = true;
config_50_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 50;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 50;
let mut config_95_percent = UserConfig::default();
config_95_percent.channel_handshake_config.announce_for_forwarding = true;
config_95_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 95;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 95;
let mut config_100_percent = UserConfig::default();
config_100_percent.channel_handshake_config.announce_for_forwarding = true;
config_100_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 100;

let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
Expand DownExpand Up@@ -8436,7 +8436,12 @@ pub fn test_inconsistent_mpp_params() {
// such HTLC and allow the second to stay.
let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
let configs: [Option<UserConfig>; 4] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &configs);
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);

let node_a_id = nodes[0].node.get_our_node_id();
Expand DownExpand Up@@ -8580,7 +8585,12 @@ pub fn test_double_partial_claim() {
// amount.
let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
let configs: [Option<UserConfig>; 4] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &configs);
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);

let node_b_id = nodes[1].node.get_our_node_id();
Expand DownExpand Up@@ -9067,7 +9077,8 @@ pub fn test_nondust_htlc_excess_fees_are_dust() {
config.channel_handshake_limits.min_max_accepted_htlcs = chan_utils::max_htlcs(&chan_ty);
config.channel_handshake_config.our_max_accepted_htlcs = chan_utils::max_htlcs(&chan_ty);
config.channel_handshake_config.our_htlc_minimum_msat = 1;
config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
100;

let node_chanmgrs = create_node_chanmgrs(
3,
Expand DownExpand Up@@ -10039,7 +10050,8 @@ pub fn test_dust_exposure_holding_cell_assertion() {
// Use a fixed dust exposure limit to make the test simpler
const DUST_HTLC_VALUE_MSAT: u64 = 500_000;
config.channel_config.max_dust_htlc_exposure = MaxDustHTLCExposure::FixedLimitMsat(5_000_000);
config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
100;

let configs = [Some(config.clone()), Some(config.clone()), Some(config.clone())];
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &configs);
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
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
7 changes: 7 additions & 0 deletions lightning/src/ln/async_payments_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -504,6 +504,9 @@ fn often_offline_node_cfg() -> UserConfig {
cfg.channel_handshake_config.announce_for_forwarding = false;
cfg.channel_handshake_limits.force_announced_channel_preference = true;
cfg.hold_outbound_htlcs_at_next_hop = true;
// Use the setting that matches the default at the time these tests were written
cfg.channel_handshake_config.unannounced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
cfg
}

Expand DownExpand Up@@ -1310,6 +1313,10 @@ fn async_receive_mpp() {

let mut allow_priv_chan_fwds_cfg = test_default_channel_config();
allow_priv_chan_fwds_cfg.accept_forwards_to_priv_channels = true;
// Set the percentage to the default value at the time this test was written
allow_priv_chan_fwds_cfg
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 10;

let node_chanmgrs = create_node_chanmgrs(
4,
Expand Down
12 changes: 10 additions & 2 deletions lightning/src/ln/blinded_payment_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -269,7 +269,11 @@ fn one_hop_blinded_path_with_dummy_hops() {
fn mpp_to_one_hop_blinded_path() {
let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage = 10;
let configs: [Option<UserConfig>; 4] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &configs);
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);
let mut secp_ctx = Secp256k1::new();

Expand DownExpand Up@@ -349,7 +353,11 @@ fn mpp_to_one_hop_blinded_path() {
fn mpp_to_three_hop_blinded_paths() {
let chanmon_cfgs = create_chanmon_cfgs(6);
let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage = 10;
let configs: [Option<UserConfig>; 6] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &configs);
let nodes = create_network(6, &node_cfgs, &node_chanmgrs);

// Create this network topology so node 0 MPP's over 2 3-hop blinded paths:
Expand Down
7 changes: 6 additions & 1 deletion lightning/src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -4656,6 +4656,7 @@ fn test_claim_to_closed_channel_blocks_claimed_event() {
#[test]
#[cfg(all(feature = "std", not(target_os = "windows")))]
fn test_single_channel_multiple_mpp() {
use crate::util::config::UserConfig;
use std::sync::atomic::{AtomicBool, Ordering};

// Test what happens when we attempt to claim an MPP with many parts that came to us through
Expand All@@ -4667,7 +4668,11 @@ fn test_single_channel_multiple_mpp() {
// for more info.
let chanmon_cfgs = create_chanmon_cfgs(9);
let node_cfgs = create_node_cfgs(9, &chanmon_cfgs);
let configs = [None, None, None, None, None, None, None, None, None];
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
let configs: [Option<UserConfig>; 9] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(9, &node_cfgs, &configs);
let mut nodes = create_network(9, &node_cfgs, &node_chanmgrs);

Expand Down
104 changes: 79 additions & 25 deletions lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -4102,6 +4102,7 @@ impl<SP: SignerProvider> ChannelContext<SP> {
),
holder_max_htlc_value_in_flight_msat: get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis,
announce_for_forwarding,
&config.channel_handshake_config,
),
counterparty_htlc_minimum_msat: open_channel_fields.htlc_minimum_msat,
Expand DownExpand Up@@ -4405,6 +4406,7 @@ impl<SP: SignerProvider> ChannelContext<SP> {
// receive `accept_channel2`.
holder_max_htlc_value_in_flight_msat: get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis,
config.channel_handshake_config.announce_for_forwarding,
&config.channel_handshake_config,
),
counterparty_htlc_minimum_msat: 0,
Expand DownExpand Up@@ -6678,24 +6680,41 @@ impl<SP: SignerProvider> ChannelContext<SP> {

/// Returns the value to use for `holder_max_htlc_value_in_flight_msat` as a percentage of the
/// `channel_value_satoshis` in msat, set through
/// [`ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel`]
/// [`ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage`]
/// or [`ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage`]
/// depending on the value of [`ChannelHandshakeConfig::announce_for_forwarding`].
///
/// The effective percentage is lower bounded by 1% and upper bounded by 100%.
///
/// [`ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel`]: crate::util::config::ChannelHandshakeConfig::max_inbound_htlc_value_in_flight_percent_of_channel
/// [`ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage`]: crate::util::config::ChannelHandshakeConfig::announced_channel_max_inbound_htlc_value_in_flight_percentage
/// [`ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage`]: crate::util::config::ChannelHandshakeConfig::unannounced_channel_max_inbound_htlc_value_in_flight_percentage
/// [`ChannelHandshakeConfig::announce_for_forwarding`]: crate::util::config::ChannelHandshakeConfig::announce_for_forwarding
fn get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis: u64, config: &ChannelHandshakeConfig,
channel_value_satoshis: u64, is_announced_channel: bool, config: &ChannelHandshakeConfig,
) -> u64 {
let configured_percent = if config.max_inbound_htlc_value_in_flight_percent_of_channel < 1 {
let config_setting = if is_announced_channel {
config.announced_channel_max_inbound_htlc_value_in_flight_percentage
} else {
config.unannounced_channel_max_inbound_htlc_value_in_flight_percentage
};
let configured_percent = if config_setting < 1 {
1
} else if config.max_inbound_htlc_value_in_flight_percent_of_channel > 100 {
} else if config_setting > 100 {
100
} else {
config.max_inbound_htlc_value_in_flight_percent_of_channel as u64
config_setting as u64
};
channel_value_satoshis * 10 * configured_percent
}

/// This is for legacy reasons, present for forward-compatibility.
/// LDK versions older than 0.0.104 don't know how read/handle values other than the legacy
/// percentage from storage. Hence, we use this function to not persist legacy values of
/// `holder_max_htlc_value_in_flight_msat` for channels into storage.
fn get_legacy_default_holder_max_htlc_value_in_flight_msat(channel_value_satoshis: u64) -> u64 {
channel_value_satoshis * 10 * MAX_IN_FLIGHT_PERCENT_LEGACY as u64
}

/// Returns a minimum channel reserve value the remote needs to maintain,
/// required by us according to the configured or default
/// [`ChannelHandshakeConfig::their_channel_reserve_proportional_millionths`]
Expand DownExpand Up@@ -15691,15 +15710,11 @@ impl<SP: SignerProvider> Writeable for FundedChannel<SP> {
None
};

let mut old_max_in_flight_percent_config = UserConfig::default().channel_handshake_config;
old_max_in_flight_percent_config.max_inbound_htlc_value_in_flight_percent_of_channel =
MAX_IN_FLIGHT_PERCENT_LEGACY;
let max_in_flight_msat = get_holder_max_htlc_value_in_flight_msat(
let legacy_max_in_flight_msat = get_legacy_default_holder_max_htlc_value_in_flight_msat(
self.funding.get_value_satoshis(),
&old_max_in_flight_percent_config,
);
let serialized_holder_htlc_max_in_flight =
if self.context.holder_max_htlc_value_in_flight_msat != max_in_flight_msat {
if self.context.holder_max_htlc_value_in_flight_msat != legacy_max_in_flight_msat {
Some(self.context.holder_max_htlc_value_in_flight_msat)
} else {
None
Expand DownExpand Up@@ -16131,11 +16146,9 @@ impl<'a, 'b, 'c, ES: EntropySource, SP: SignerProvider>
let mut holder_selected_channel_reserve_satoshis = Some(
get_legacy_default_holder_selected_channel_reserve_satoshis(channel_value_satoshis),
);

let mut holder_max_htlc_value_in_flight_msat =
Some(get_holder_max_htlc_value_in_flight_msat(
channel_value_satoshis,
&UserConfig::default().channel_handshake_config,
));
Some(get_legacy_default_holder_max_htlc_value_in_flight_msat(channel_value_satoshis));
// Prior to supporting channel type negotiation, all of our channels were static_remotekey
// only, so we default to that if none was written.
let mut channel_type = Some(ChannelTypeFeatures::only_static_remote_key());
Expand DownExpand Up@@ -17141,8 +17154,13 @@ mod tests {
}

#[test]
#[rustfmt::skip]
fn test_configured_holder_max_htlc_value_in_flight() {
do_test_configured_holder_max_htlc_value_in_flight(true);
do_test_configured_holder_max_htlc_value_in_flight(false);
}

#[rustfmt::skip]
fn do_test_configured_holder_max_htlc_value_in_flight(announce_channel: bool) {
let test_est = TestFeeEstimator::new(15000);
let feeest = LowerBoundedFeeEstimator::new(&test_est);
let logger = TestLogger::new();
Expand All@@ -17154,13 +17172,49 @@ mod tests {
let inbound_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[7; 32]).unwrap());

let mut config_2_percent = UserConfig::default();
config_2_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 2;
config_2_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_2_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 2;
} else {
config_2_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 2;
}
let mut config_99_percent = UserConfig::default();
config_99_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 99;
config_99_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_99_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 99;
} else {
config_99_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 99;
}
let mut config_0_percent = UserConfig::default();
config_0_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 0;
config_0_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_0_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 0;
} else {
config_0_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 0;
}
let mut config_101_percent = UserConfig::default();
config_101_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 101;
config_101_percent.channel_handshake_config.announce_for_forwarding = announce_channel;
if announce_channel {
config_101_percent
.channel_handshake_config
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 101;
} else {
config_101_percent
.channel_handshake_config
.unannounced_channel_max_inbound_htlc_value_in_flight_percentage = 101;
}

// Test that `OutboundV1Channel::new` creates a channel with the correct value for
// `holder_max_htlc_value_in_flight_msat`, when configured with a valid percentage value,
Expand DownExpand Up@@ -17189,26 +17243,26 @@ mod tests {
assert_eq!(chan_4.context.holder_max_htlc_value_in_flight_msat, (chan_4_value_msat as f64 * 0.99) as u64);

// Test that `OutboundV1Channel::new` uses the lower bound of the configurable percentage values (1%)
// if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a value less than 1.
// if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a value less than 1.
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();
let chan_5_value_msat = chan_5.funding.get_value_satoshis() * 1000;
assert_eq!(chan_5.context.holder_max_htlc_value_in_flight_msat, (chan_5_value_msat as f64 * 0.01) as u64);

// Test that `OutboundV1Channel::new` uses the upper bound of the configurable percentage values
// (100%) if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a larger value
// (100%) if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a larger value
// than 100.
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();
let chan_6_value_msat = chan_6.funding.get_value_satoshis() * 1000;
assert_eq!(chan_6.context.holder_max_htlc_value_in_flight_msat, chan_6_value_msat);

// Test that `InboundV1Channel::new` uses the lower bound of the configurable percentage values (1%)
// if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a value less than 1.
// if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a value less than 1.
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();
let chan_7_value_msat = chan_7.funding.get_value_satoshis() * 1000;
assert_eq!(chan_7.context.holder_max_htlc_value_in_flight_msat, (chan_7_value_msat as f64 * 0.01) as u64);

// Test that `InboundV1Channel::new` uses the upper bound of the configurable percentage values
// (100%) if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a larger value
// (100%) if `(un)announced_channel_max_inbound_htlc_value_in_flight_percentage` is set to a larger value
// than 100.
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();
let chan_8_value_msat = chan_8.funding.get_value_satoshis() * 1000;
Expand Down
6 changes: 4 additions & 2 deletions lightning/src/ln/channel_open_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -182,7 +182,8 @@ fn test_inbound_anchors_manual_acceptance() {
fn test_inbound_anchors_config_overridden() {
let overrides = ChannelConfigOverrides {
handshake_overrides: Some(ChannelHandshakeConfigUpdate {
max_inbound_htlc_value_in_flight_percent_of_channel: Some(5),
announced_channel_max_inbound_htlc_value_in_flight_percentage: Some(5),
unannounced_channel_max_inbound_htlc_value_in_flight_percentage: None,
htlc_minimum_msat: Some(1000),
minimum_depth: Some(2),
to_self_delay: Some(200),
Expand DownExpand Up@@ -1070,7 +1071,8 @@ pub fn test_accept_inbound_channel_config_override() {

let config_overrides = ChannelConfigOverrides {
handshake_overrides: Some(ChannelHandshakeConfigUpdate {
max_inbound_htlc_value_in_flight_percent_of_channel: None,
announced_channel_max_inbound_htlc_value_in_flight_percentage: None,
unannounced_channel_max_inbound_htlc_value_in_flight_percentage: None,
htlc_minimum_msat: None,
minimum_depth: None,
to_self_delay: None,
Expand Down
28 changes: 20 additions & 8 deletions lightning/src/ln/functional_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6903,22 +6903,22 @@ pub fn test_channel_update_has_correct_htlc_maximum_msat() {
config_30_percent.channel_handshake_config.announce_for_forwarding = true;
config_30_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 30;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 30;
let mut config_50_percent = UserConfig::default();
config_50_percent.channel_handshake_config.announce_for_forwarding = true;
config_50_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 50;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 50;
let mut config_95_percent = UserConfig::default();
config_95_percent.channel_handshake_config.announce_for_forwarding = true;
config_95_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 95;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 95;
let mut config_100_percent = UserConfig::default();
config_100_percent.channel_handshake_config.announce_for_forwarding = true;
config_100_percent
.channel_handshake_config
.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
.announced_channel_max_inbound_htlc_value_in_flight_percentage = 100;

let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
Expand DownExpand Up@@ -8436,7 +8436,12 @@ pub fn test_inconsistent_mpp_params() {
// such HTLC and allow the second to stay.
let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
let configs: [Option<UserConfig>; 4] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &configs);
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);

let node_a_id = nodes[0].node.get_our_node_id();
Expand DownExpand Up@@ -8580,7 +8585,12 @@ pub fn test_double_partial_claim() {
// amount.
let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
let mut config = test_default_channel_config();
// Set the percentage to the default value at the time this test was written
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
10;
let configs: [Option<UserConfig>; 4] = core::array::from_fn(|_| Some(config.clone()));
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &configs);
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);

let node_b_id = nodes[1].node.get_our_node_id();
Expand DownExpand Up@@ -9067,7 +9077,8 @@ pub fn test_nondust_htlc_excess_fees_are_dust() {
config.channel_handshake_limits.min_max_accepted_htlcs = chan_utils::max_htlcs(&chan_ty);
config.channel_handshake_config.our_max_accepted_htlcs = chan_utils::max_htlcs(&chan_ty);
config.channel_handshake_config.our_htlc_minimum_msat = 1;
config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
100;

let node_chanmgrs = create_node_chanmgrs(
3,
Expand DownExpand Up@@ -10039,7 +10050,8 @@ pub fn test_dust_exposure_holding_cell_assertion() {
// Use a fixed dust exposure limit to make the test simpler
const DUST_HTLC_VALUE_MSAT: u64 = 500_000;
config.channel_config.max_dust_htlc_exposure = MaxDustHTLCExposure::FixedLimitMsat(5_000_000);
config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
config.channel_handshake_config.announced_channel_max_inbound_htlc_value_in_flight_percentage =
100;

let configs = [Some(config.clone()), Some(config.clone()), Some(config.clone())];
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &configs);
Expand Down
Loading
Loading