@@ -26,7 +26,7 @@ use ln::chan_utils::{htlc_success_tx_weight, htlc_timeout_tx_weight, HTLCOutputI
26
26
use routing::router::{PaymentParameters, Route, RouteHop, RouteParameters, find_route, get_route};
27
27
use ln::features::{ChannelFeatures, InitFeatures, InvoiceFeatures, NodeFeatures};
28
28
use ln::msgs;
29
- use ln:: msgs:: { ChannelMessageHandler , RoutingMessageHandler , ErrorAction } ;
29
+ use ln::msgs::{ChannelMessageHandler, RoutingMessageHandler, OptionalField, ErrorAction};
30
30
use util::enforcing_trait_impls::EnforcingSigner;
31
31
use util::{byte_utils, test_utils};
32
32
use util::events::{Event, MessageSendEvent, MessageSendEventsProvider, PaymentPurpose, ClosureReason};
@@ -8143,6 +8143,58 @@ fn test_override_0msat_htlc_minimum() {
8143
8143
assert_eq!(res.htlc_minimum_msat, 1);
8144
8144
}
8145
8145
8146
+ #[test]
8147
+ fn test_channel_update_has_correct_htlc_maximum_msat() {
8148
+ // Tests that the `ChannelUpdate` message has the correct values for `htlc_maximum_msat` set.
8149
+ // Bolt 7 specifies that if present `htlc_maximum_msat`:
8150
+ // 1. MUST be set to less than or equal to the channel capacity. In LDK, this is capped to
8151
+ // 90% of the `channel_value`.
8152
+ // 2. MUST be set to less than or equal to the `max_htlc_value_in_flight_msat` received from the peer.
8153
+
8154
+ let mut config_30_percent = UserConfig::default();
8155
+ config_30_percent.channel_options.announced_channel = true;
8156
+ config_30_percent.own_channel_config.max_inbound_htlc_value_in_flight_percent_of_channel = 30;
8157
+ let mut config_50_percent = UserConfig::default();
8158
+ config_50_percent.channel_options.announced_channel = true;
8159
+ config_50_percent.own_channel_config.max_inbound_htlc_value_in_flight_percent_of_channel = 50;
8160
+ let mut config_95_percent = UserConfig::default();
8161
+ config_95_percent.channel_options.announced_channel = true;
8162
+ config_95_percent.own_channel_config.max_inbound_htlc_value_in_flight_percent_of_channel = 95;
8163
+ let mut config_100_percent = UserConfig::default();
8164
+ config_100_percent.channel_options.announced_channel = true;
8165
+ config_100_percent.own_channel_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
8166
+
8167
+ let chanmon_cfgs = create_chanmon_cfgs(4);
8168
+ let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
8169
+ let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[Some(config_30_percent), Some(config_50_percent), Some(config_95_percent), Some(config_100_percent)]);
8170
+ let nodes = create_network(4, &node_cfgs, &node_chanmgrs);
8171
+
8172
+ let channel_value_satoshis = 100000;
8173
+ let channel_value_msat = channel_value_satoshis * 1000;
8174
+ let channel_value_30_percent_msat = (channel_value_msat as f64 * 0.3) as u64;
8175
+ let channel_value_50_percent_msat = (channel_value_msat as f64 * 0.5) as u64;
8176
+ let channel_value_90_percent_msat = (channel_value_msat as f64 * 0.9) as u64;
8177
+
8178
+ let (node_0_chan_update, node_1_chan_update, _, _) = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, channel_value_satoshis, 10001, InitFeatures::known(), InitFeatures::known());
8179
+ let (node_2_chan_update, node_3_chan_update, _, _) = create_announced_chan_between_nodes_with_value(&nodes, 2, 3, channel_value_satoshis, 10001, InitFeatures::known(), InitFeatures::known());
8180
+
8181
+ // Assert that `node[0]`'s `ChannelUpdate` is capped at 50 percent of the `channel_value`, as
8182
+ // that's the value of `node[1]`'s `holder_max_htlc_value_in_flight_msat`.
8183
+ assert_eq!(node_0_chan_update.contents.htlc_maximum_msat, OptionalField::Present(channel_value_50_percent_msat));
8184
+ // Assert that `node[1]`'s `ChannelUpdate` is capped at 30 percent of the `channel_value`, as
8185
+ // that's the value of `node[0]`'s `holder_max_htlc_value_in_flight_msat`.
8186
+ assert_eq!(node_1_chan_update.contents.htlc_maximum_msat, OptionalField::Present(channel_value_30_percent_msat));
8187
+
8188
+ // Assert that `node[2]`'s `ChannelUpdate` is capped at 90 percent of the `channel_value`, as
8189
+ // the value of `node[3]`'s `holder_max_htlc_value_in_flight_msat` (100%), exceeds 90% of the
8190
+ // `channel_value`.
8191
+ assert_eq!(node_2_chan_update.contents.htlc_maximum_msat, OptionalField::Present(channel_value_90_percent_msat));
8192
+ // Assert that `node[3]`'s `ChannelUpdate` is capped at 90 percent of the `channel_value`, as
8193
+ // the value of `node[2]`'s `holder_max_htlc_value_in_flight_msat` (95%), exceeds 90% of the
8194
+ // `channel_value`.
8195
+ assert_eq!(node_3_chan_update.contents.htlc_maximum_msat, OptionalField::Present(channel_value_90_percent_msat));
8196
+ }
8197
+
8146
8198
#[test]
8147
8199
fn test_manually_accept_inbound_channel_request() {
8148
8200
let mut manually_accept_conf = UserConfig::default();
0 commit comments