Skip to content

Commit f35da46

Browse files
add preflight_probes_yield_event_skip_private_hop and preflight_probes_yield_event
1 parent 2c7907d commit f35da46

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

lightning/src/ln/payment_tests.rs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,92 @@ fn onchain_failed_probe_yields_event() {
12711271
assert!(!nodes[0].node.has_pending_payments());
12721272
}
12731273

1274+
#[test]
1275+
fn preflight_probes_yield_event_skip_private_hop() {
1276+
let chanmon_cfgs = create_chanmon_cfgs(5);
1277+
let node_cfgs = create_node_cfgs(5, &chanmon_cfgs);
1278+
1279+
// We alleviate the HTLC max-in-flight limit, as otherwise we'd always be limited through that.
1280+
let mut no_htlc_limit_config = test_default_channel_config();
1281+
no_htlc_limit_config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
1282+
1283+
let user_configs = std::iter::repeat(no_htlc_limit_config).take(5).map(|c| Some(c)).collect::<Vec<Option<UserConfig>>>();
1284+
let node_chanmgrs = create_node_chanmgrs(5, &node_cfgs, &user_configs);
1285+
let nodes = create_network(5, &node_cfgs, &node_chanmgrs);
1286+
1287+
// Setup channel topology:
1288+
// (1M:0)- N1 -(30k:0)
1289+
// / \
1290+
// N0 N4
1291+
// \ /
1292+
// (1M:0)- N2 -(70k:0)
1293+
//
1294+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0);
1295+
create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 1_000_000, 0);
1296+
create_announced_chan_between_nodes_with_value(&nodes, 2, 3, 70_000, 0);
1297+
create_unannounced_chan_between_nodes_with_value(&nodes, 3, 4, 30_000, 0);
1298+
1299+
let mut invoice_features = Bolt11InvoiceFeatures::empty();
1300+
invoice_features.set_basic_mpp_optional();
1301+
1302+
let mut payment_params = PaymentParameters::from_node_id(nodes[3].node.get_our_node_id(), TEST_FINAL_CLTV)
1303+
.with_bolt11_features(invoice_features).unwrap();
1304+
1305+
let route_params = RouteParameters { payment_params, final_value_msat: 50_000_000 };
1306+
let res = nodes[0].node.send_preflight_probes(route_params, None).unwrap();
1307+
1308+
let expected_route: &[&[&Node]] = &[&[&nodes[1], &nodes[2], &nodes[3]]];
1309+
1310+
assert_eq!(res.len(), expected_route.len());
1311+
1312+
pass_probe_along_route(&nodes[0], expected_route);
1313+
1314+
expect_probe_successful_events(&nodes[0], res);
1315+
}
1316+
1317+
#[test]
1318+
fn preflight_probes_yield_event() {
1319+
let chanmon_cfgs = create_chanmon_cfgs(4);
1320+
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
1321+
1322+
// We alleviate the HTLC max-in-flight limit, as otherwise we'd always be limited through that.
1323+
let mut no_htlc_limit_config = test_default_channel_config();
1324+
no_htlc_limit_config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
1325+
1326+
let user_configs = std::iter::repeat(no_htlc_limit_config).take(4).map(|c| Some(c)).collect::<Vec<Option<UserConfig>>>();
1327+
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &user_configs);
1328+
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);
1329+
1330+
// Setup channel topology:
1331+
// (1M:0)- N1 -(30k:0)
1332+
// / \
1333+
// N0 N4
1334+
// \ /
1335+
// (1M:0)- N2 -(70k:0)
1336+
//
1337+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0);
1338+
create_announced_chan_between_nodes_with_value(&nodes, 0, 2, 1_000_000, 0);
1339+
create_announced_chan_between_nodes_with_value(&nodes, 1, 3, 30_000, 0);
1340+
create_announced_chan_between_nodes_with_value(&nodes, 2, 3, 70_000, 0);
1341+
1342+
let mut invoice_features = Bolt11InvoiceFeatures::empty();
1343+
invoice_features.set_basic_mpp_optional();
1344+
1345+
let mut payment_params = PaymentParameters::from_node_id(nodes[3].node.get_our_node_id(), TEST_FINAL_CLTV)
1346+
.with_bolt11_features(invoice_features).unwrap();
1347+
1348+
let route_params = RouteParameters { payment_params, final_value_msat: 50_000_000 };
1349+
let res = nodes[0].node.send_preflight_probes(route_params, None).unwrap();
1350+
1351+
let expected_route: &[&[&Node]] = &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]];
1352+
1353+
assert_eq!(res.len(), expected_route.len());
1354+
1355+
pass_probe_along_route(&nodes[0], expected_route);
1356+
1357+
expect_probe_successful_events(&nodes[0], res);
1358+
}
1359+
12741360
#[test]
12751361
fn preflight_probes_yield_event_and_skip() {
12761362
let chanmon_cfgs = create_chanmon_cfgs(5);

0 commit comments

Comments
 (0)