@@ -1279,46 +1279,14 @@ fn successful_probe_yields_event() {
1279
1279
1280
1280
let ( route, _, _, _) = get_route_and_payment_hash ! ( & nodes[ 0 ] , nodes[ 2 ] , 100_000 ) ;
1281
1281
1282
- let ( payment_hash , payment_id ) = nodes[ 0 ] . node . send_probe ( route. paths [ 0 ] . clone ( ) ) . unwrap ( ) ;
1282
+ let res = nodes[ 0 ] . node . send_probe ( route. paths [ 0 ] . clone ( ) ) . unwrap ( ) ;
1283
1283
1284
- // node[0] -- update_add_htlcs -> node[1]
1285
- check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
1286
- let updates = get_htlc_update_msgs ! ( nodes[ 0 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
1287
- let probe_event = SendEvent :: from_commitment_update ( nodes[ 1 ] . node . get_our_node_id ( ) , updates) ;
1288
- nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & probe_event. msgs [ 0 ] ) ;
1289
- check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
1290
- commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 0 ] , probe_event. commitment_msg, false ) ;
1291
- expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
1284
+ let expected_route: & [ & [ & Node ] ] = & [ & [ & nodes[ 1 ] , & nodes[ 2 ] ] ] ;
1292
1285
1293
- // node[1] -- update_add_htlcs -> node[2]
1294
- check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
1295
- let updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 2 ] . node. get_our_node_id( ) ) ;
1296
- let probe_event = SendEvent :: from_commitment_update ( nodes[ 1 ] . node . get_our_node_id ( ) , updates) ;
1297
- nodes[ 2 ] . node . handle_update_add_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & probe_event. msgs [ 0 ] ) ;
1298
- check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
1299
- commitment_signed_dance ! ( nodes[ 2 ] , nodes[ 1 ] , probe_event. commitment_msg, true , true ) ;
1286
+ pass_probe_along_route ( & nodes[ 0 ] , expected_route) ;
1300
1287
1301
- // node[1] <- update_fail_htlcs -- node[2]
1302
- let updates = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
1303
- nodes[ 1 ] . node . handle_update_fail_htlc ( & nodes[ 2 ] . node . get_our_node_id ( ) , & updates. update_fail_htlcs [ 0 ] ) ;
1304
- check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
1305
- commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 2 ] , updates. commitment_signed, true ) ;
1288
+ expect_probe_successful_events ( & nodes[ 0 ] , vec ! [ res] ) ;
1306
1289
1307
- // node[0] <- update_fail_htlcs -- node[1]
1308
- let updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
1309
- nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & updates. update_fail_htlcs [ 0 ] ) ;
1310
- check_added_monitors ! ( nodes[ 0 ] , 0 ) ;
1311
- commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , updates. commitment_signed, false ) ;
1312
-
1313
- let mut events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
1314
- assert_eq ! ( events. len( ) , 1 ) ;
1315
- match events. drain ( ..) . next ( ) . unwrap ( ) {
1316
- crate :: events:: Event :: ProbeSuccessful { payment_id : ev_pid, payment_hash : ev_ph, .. } => {
1317
- assert_eq ! ( payment_id, ev_pid) ;
1318
- assert_eq ! ( payment_hash, ev_ph) ;
1319
- } ,
1320
- _ => panic ! ( ) ,
1321
- } ;
1322
1290
assert ! ( !nodes[ 0 ] . node. has_pending_payments( ) ) ;
1323
1291
}
1324
1292
@@ -1423,6 +1391,92 @@ fn onchain_failed_probe_yields_event() {
1423
1391
assert ! ( !nodes[ 0 ] . node. has_pending_payments( ) ) ;
1424
1392
}
1425
1393
1394
+ #[ test]
1395
+ fn preflight_probes_yield_event_skip_private_hop ( ) {
1396
+ let chanmon_cfgs = create_chanmon_cfgs ( 5 ) ;
1397
+ let node_cfgs = create_node_cfgs ( 5 , & chanmon_cfgs) ;
1398
+
1399
+ // We alleviate the HTLC max-in-flight limit, as otherwise we'd always be limited through that.
1400
+ let mut no_htlc_limit_config = test_default_channel_config ( ) ;
1401
+ no_htlc_limit_config. channel_handshake_config . max_inbound_htlc_value_in_flight_percent_of_channel = 100 ;
1402
+
1403
+ let user_configs = std:: iter:: repeat ( no_htlc_limit_config) . take ( 5 ) . map ( |c| Some ( c) ) . collect :: < Vec < Option < UserConfig > > > ( ) ;
1404
+ let node_chanmgrs = create_node_chanmgrs ( 5 , & node_cfgs, & user_configs) ;
1405
+ let nodes = create_network ( 5 , & node_cfgs, & node_chanmgrs) ;
1406
+
1407
+ // Setup channel topology:
1408
+ // N0 <-(1M:0)-> N1 <-(1M:0)-> N2 <-(70k:0)-> N3 <-(50k:0)-> N4
1409
+
1410
+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
1411
+ create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) ;
1412
+ create_announced_chan_between_nodes_with_value ( & nodes, 2 , 3 , 70_000 , 0 ) ;
1413
+ create_unannounced_chan_between_nodes_with_value ( & nodes, 3 , 4 , 50_000 , 0 ) ;
1414
+
1415
+ let mut invoice_features = Bolt11InvoiceFeatures :: empty ( ) ;
1416
+ invoice_features. set_basic_mpp_optional ( ) ;
1417
+
1418
+ let payment_params = PaymentParameters :: from_node_id ( nodes[ 3 ] . node . get_our_node_id ( ) , TEST_FINAL_CLTV )
1419
+ . with_bolt11_features ( invoice_features) . unwrap ( ) ;
1420
+
1421
+ let route_params = RouteParameters :: from_payment_params_and_value ( payment_params, 50_000_000 ) ;
1422
+ let res = nodes[ 0 ] . node . send_preflight_probes ( route_params, None ) . unwrap ( ) ;
1423
+
1424
+ let expected_route: & [ & [ & Node ] ] = & [ & [ & nodes[ 1 ] , & nodes[ 2 ] , & nodes[ 3 ] ] ] ;
1425
+
1426
+ assert_eq ! ( res. len( ) , expected_route. len( ) ) ;
1427
+
1428
+ pass_probe_along_route ( & nodes[ 0 ] , expected_route) ;
1429
+
1430
+ expect_probe_successful_events ( & nodes[ 0 ] , res) ;
1431
+
1432
+ assert ! ( !nodes[ 0 ] . node. has_pending_payments( ) ) ;
1433
+ }
1434
+
1435
+ #[ test]
1436
+ fn preflight_probes_yield_event ( ) {
1437
+ let chanmon_cfgs = create_chanmon_cfgs ( 4 ) ;
1438
+ let node_cfgs = create_node_cfgs ( 4 , & chanmon_cfgs) ;
1439
+
1440
+ // We alleviate the HTLC max-in-flight limit, as otherwise we'd always be limited through that.
1441
+ let mut no_htlc_limit_config = test_default_channel_config ( ) ;
1442
+ no_htlc_limit_config. channel_handshake_config . max_inbound_htlc_value_in_flight_percent_of_channel = 100 ;
1443
+
1444
+ let user_configs = std:: iter:: repeat ( no_htlc_limit_config) . take ( 4 ) . map ( |c| Some ( c) ) . collect :: < Vec < Option < UserConfig > > > ( ) ;
1445
+ let node_chanmgrs = create_node_chanmgrs ( 4 , & node_cfgs, & user_configs) ;
1446
+ let nodes = create_network ( 4 , & node_cfgs, & node_chanmgrs) ;
1447
+
1448
+ // Setup channel topology:
1449
+ // (1M:0)- N1 -(30k:0)
1450
+ // / \
1451
+ // N0 N4
1452
+ // \ /
1453
+ // (1M:0)- N2 -(70k:0)
1454
+ //
1455
+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
1456
+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 2 , 1_000_000 , 0 ) ;
1457
+ create_announced_chan_between_nodes_with_value ( & nodes, 1 , 3 , 30_000 , 0 ) ;
1458
+ create_announced_chan_between_nodes_with_value ( & nodes, 2 , 3 , 70_000 , 0 ) ;
1459
+
1460
+ let mut invoice_features = Bolt11InvoiceFeatures :: empty ( ) ;
1461
+ invoice_features. set_basic_mpp_optional ( ) ;
1462
+
1463
+ let payment_params = PaymentParameters :: from_node_id ( nodes[ 3 ] . node . get_our_node_id ( ) , TEST_FINAL_CLTV )
1464
+ . with_bolt11_features ( invoice_features) . unwrap ( ) ;
1465
+
1466
+ let route_params = RouteParameters :: from_payment_params_and_value ( payment_params, 50_000_000 ) ;
1467
+ let res = nodes[ 0 ] . node . send_preflight_probes ( route_params, None ) . unwrap ( ) ;
1468
+
1469
+ let expected_route: & [ & [ & Node ] ] = & [ & [ & nodes[ 1 ] , & nodes[ 3 ] ] , & [ & nodes[ 2 ] , & nodes[ 3 ] ] ] ;
1470
+
1471
+ assert_eq ! ( res. len( ) , expected_route. len( ) ) ;
1472
+
1473
+ pass_probe_along_route ( & nodes[ 0 ] , expected_route) ;
1474
+
1475
+ expect_probe_successful_events ( & nodes[ 0 ] , res) ;
1476
+
1477
+ assert ! ( !nodes[ 0 ] . node. has_pending_payments( ) ) ;
1478
+ }
1479
+
1426
1480
#[ test]
1427
1481
fn preflight_probes_yield_event_and_skip ( ) {
1428
1482
let chanmon_cfgs = create_chanmon_cfgs ( 5 ) ;
@@ -1443,7 +1497,7 @@ fn preflight_probes_yield_event_and_skip() {
1443
1497
// \ /
1444
1498
// (70k:0)- N3 -(1M:0)
1445
1499
//
1446
- let first_chan_update = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 100_000 , 0 ) . 0 ;
1500
+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 100_000 , 0 ) ;
1447
1501
create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 30_000 , 0 ) ;
1448
1502
create_announced_chan_between_nodes_with_value ( & nodes, 1 , 3 , 70_000 , 0 ) ;
1449
1503
create_announced_chan_between_nodes_with_value ( & nodes, 2 , 4 , 1_000_000 , 0 ) ;
@@ -1452,70 +1506,21 @@ fn preflight_probes_yield_event_and_skip() {
1452
1506
let mut invoice_features = Bolt11InvoiceFeatures :: empty ( ) ;
1453
1507
invoice_features. set_basic_mpp_optional ( ) ;
1454
1508
1455
- let mut payment_params = PaymentParameters :: from_node_id ( nodes[ 4 ] . node . get_our_node_id ( ) , TEST_FINAL_CLTV )
1509
+ let payment_params = PaymentParameters :: from_node_id ( nodes[ 4 ] . node . get_our_node_id ( ) , TEST_FINAL_CLTV )
1456
1510
. with_bolt11_features ( invoice_features) . unwrap ( ) ;
1457
1511
1458
1512
let route_params = RouteParameters :: from_payment_params_and_value ( payment_params, 80_000_000 ) ;
1459
1513
let res = nodes[ 0 ] . node . send_preflight_probes ( route_params, None ) . unwrap ( ) ;
1460
1514
1515
+ let expected_route : & [ & [ & Node ] ] = & [ & [ & nodes[ 1 ] , & nodes[ 2 ] , & nodes[ 4 ] ] ] ;
1516
+
1461
1517
// We check that only one probe was sent, the other one was skipped due to limited liquidity.
1462
1518
assert_eq ! ( res. len( ) , 1 ) ;
1463
- let log_msg = format ! ( "Skipped sending payment probe to avoid putting channel {} under the liquidity limit." ,
1464
- first_chan_update. contents. short_channel_id) ;
1465
- node_cfgs[ 0 ] . logger . assert_log_contains ( "lightning::ln::channelmanager" , & log_msg, 1 ) ;
1466
1519
1467
- let ( payment_hash , payment_id ) = res . first ( ) . unwrap ( ) ;
1520
+ pass_probe_along_route ( & nodes [ 0 ] , expected_route ) ;
1468
1521
1469
- // node[0] -- update_add_htlcs -> node[1]
1470
- check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
1471
- let probe_event = SendEvent :: from_node ( & nodes[ 0 ] ) ;
1472
- nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & probe_event. msgs [ 0 ] ) ;
1473
- check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
1474
- commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 0 ] , probe_event. commitment_msg, false ) ;
1475
- expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
1522
+ expect_probe_successful_events ( & nodes[ 0 ] , res) ;
1476
1523
1477
- // node[1] -- update_add_htlcs -> node[2]
1478
- check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
1479
- let probe_event = SendEvent :: from_node ( & nodes[ 1 ] ) ;
1480
- nodes[ 2 ] . node . handle_update_add_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & probe_event. msgs [ 0 ] ) ;
1481
- check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
1482
- commitment_signed_dance ! ( nodes[ 2 ] , nodes[ 1 ] , probe_event. commitment_msg, false ) ;
1483
- expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
1484
-
1485
- // node[2] -- update_add_htlcs -> node[4]
1486
- check_added_monitors ! ( nodes[ 2 ] , 1 ) ;
1487
- let probe_event = SendEvent :: from_node ( & nodes[ 2 ] ) ;
1488
- nodes[ 4 ] . node . handle_update_add_htlc ( & nodes[ 2 ] . node . get_our_node_id ( ) , & probe_event. msgs [ 0 ] ) ;
1489
- check_added_monitors ! ( nodes[ 4 ] , 0 ) ;
1490
- commitment_signed_dance ! ( nodes[ 4 ] , nodes[ 2 ] , probe_event. commitment_msg, true , true ) ;
1491
-
1492
- // node[2] <- update_fail_htlcs -- node[4]
1493
- let updates = get_htlc_update_msgs ! ( nodes[ 4 ] , nodes[ 2 ] . node. get_our_node_id( ) ) ;
1494
- nodes[ 2 ] . node . handle_update_fail_htlc ( & nodes[ 4 ] . node . get_our_node_id ( ) , & updates. update_fail_htlcs [ 0 ] ) ;
1495
- check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
1496
- commitment_signed_dance ! ( nodes[ 2 ] , nodes[ 4 ] , updates. commitment_signed, true ) ;
1497
-
1498
- // node[1] <- update_fail_htlcs -- node[2]
1499
- let updates = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
1500
- nodes[ 1 ] . node . handle_update_fail_htlc ( & nodes[ 2 ] . node . get_our_node_id ( ) , & updates. update_fail_htlcs [ 0 ] ) ;
1501
- check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
1502
- commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 2 ] , updates. commitment_signed, true ) ;
1503
-
1504
- // node[0] <- update_fail_htlcs -- node[1]
1505
- let updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
1506
- nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & updates. update_fail_htlcs [ 0 ] ) ;
1507
- check_added_monitors ! ( nodes[ 0 ] , 0 ) ;
1508
- commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , updates. commitment_signed, false ) ;
1509
-
1510
- let mut events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
1511
- assert_eq ! ( events. len( ) , 1 ) ;
1512
- match events. drain ( ..) . next ( ) . unwrap ( ) {
1513
- crate :: events:: Event :: ProbeSuccessful { payment_id : ev_pid, payment_hash : ev_ph, .. } => {
1514
- assert_eq ! ( * payment_id, ev_pid) ;
1515
- assert_eq ! ( * payment_hash, ev_ph) ;
1516
- } ,
1517
- _ => panic ! ( ) ,
1518
- } ;
1519
1524
assert ! ( !nodes[ 0 ] . node. has_pending_payments( ) ) ;
1520
1525
}
1521
1526
0 commit comments