@@ -34,6 +34,7 @@ use bitcoin::network::constants::Network;
34
34
use crate :: prelude:: * ;
35
35
36
36
use crate :: ln:: functional_test_utils:: * ;
37
+ use crate :: routing:: gossip:: NodeId ;
37
38
38
39
#[ test]
39
40
fn retry_single_path_payment ( ) {
@@ -1385,3 +1386,109 @@ fn abandoned_send_payment_idempotent() {
1385
1386
pass_along_route ( & nodes[ 0 ] , & [ & [ & nodes[ 1 ] ] ] , 100_000 , second_payment_hash, second_payment_secret) ;
1386
1387
claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , second_payment_preimage) ;
1387
1388
}
1389
+
1390
+
1391
+ #[ test]
1392
+ fn test_trivial_inflight_htlc_tracking ( ) {
1393
+ // In this test, we test three scenarios:
1394
+ // (1) Sending + claiming a payment successfully should return `None` when querying InFlightHtlcs
1395
+ // (2) Sending a payment without claiming it shoudl return the payment's value (500000) when querying InFlightHtlcs
1396
+ // (3) After we claim the payment sent in (2), InFlightHtlcs should return `None` for the query.
1397
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
1398
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
1399
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
1400
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1401
+
1402
+ let ( _, _, chan_id, _) = create_announced_chan_between_nodes ( & nodes, 0 , 1 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) ;
1403
+
1404
+ // Send and claim the payment. Inflight HTLCs should be empty.
1405
+ send_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 500000 ) ;
1406
+ {
1407
+ let inflight_htlcs = node_chanmgrs[ 0 ] . compute_inflight_htlcs ( ) ;
1408
+
1409
+ let channel_lock = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) ;
1410
+ let channel = channel_lock. by_id . get ( & chan_id) . unwrap ( ) ;
1411
+
1412
+ let used_liquidity = inflight_htlcs. used_liquidity_msat (
1413
+ & NodeId :: from_pubkey ( & nodes[ 0 ] . node . get_our_node_id ( ) ) ,
1414
+ & NodeId :: from_pubkey ( & nodes[ 1 ] . node . get_our_node_id ( ) ) ,
1415
+ channel. get_short_channel_id ( ) . unwrap ( )
1416
+ ) ;
1417
+
1418
+ assert_eq ! ( used_liquidity, None ) ;
1419
+ }
1420
+
1421
+ // Send the payment, but do not claim it. Our inflight HTLCs should contain the pending payment.
1422
+ let ( payment_preimage, _, _) = route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 500000 ) ;
1423
+ {
1424
+ let inflight_htlcs = node_chanmgrs[ 0 ] . compute_inflight_htlcs ( ) ;
1425
+
1426
+ let channel_lock = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) ;
1427
+ let channel = channel_lock. by_id . get ( & chan_id) . unwrap ( ) ;
1428
+
1429
+ let used_liquidity = inflight_htlcs. used_liquidity_msat (
1430
+ & NodeId :: from_pubkey ( & nodes[ 0 ] . node . get_our_node_id ( ) ) ,
1431
+ & NodeId :: from_pubkey ( & nodes[ 1 ] . node . get_our_node_id ( ) ) ,
1432
+ channel. get_short_channel_id ( ) . unwrap ( )
1433
+ ) ;
1434
+
1435
+ assert_eq ! ( used_liquidity, Some ( 500000 ) ) ;
1436
+ }
1437
+
1438
+ // Now, let's claim the payment. This should result in the used liquidity to return `None`.
1439
+ claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , payment_preimage) ;
1440
+
1441
+ {
1442
+ let inflight_htlcs = node_chanmgrs[ 0 ] . compute_inflight_htlcs ( ) ;
1443
+
1444
+ let channel_lock = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) ;
1445
+ let channel = channel_lock. by_id . get ( & chan_id) . unwrap ( ) ;
1446
+
1447
+ let used_liquidity = inflight_htlcs. used_liquidity_msat (
1448
+ & NodeId :: from_pubkey ( & nodes[ 0 ] . node . get_our_node_id ( ) ) ,
1449
+ & NodeId :: from_pubkey ( & nodes[ 1 ] . node . get_our_node_id ( ) ) ,
1450
+ channel. get_short_channel_id ( ) . unwrap ( )
1451
+ ) ;
1452
+
1453
+ assert_eq ! ( used_liquidity, None ) ;
1454
+ }
1455
+ }
1456
+
1457
+ #[ test]
1458
+ fn test_holding_cell_inflight_htlcs ( ) {
1459
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
1460
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
1461
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
1462
+ let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1463
+ let channel_id = create_announced_chan_between_nodes ( & nodes, 0 , 1 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) . 2 ;
1464
+
1465
+ let ( route, payment_hash_1, _, payment_secret_1) = get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 1 ] , 1000000 ) ;
1466
+ let ( _, payment_hash_2, payment_secret_2) = get_payment_preimage_hash ! ( nodes[ 1 ] ) ;
1467
+
1468
+ // Queue up two payments - one will be delivered right away, one immediately goes into the
1469
+ // holding cell as nodes[0] is AwaitingRAA.
1470
+ {
1471
+ nodes[ 0 ] . node . send_payment ( & route, payment_hash_1, & Some ( payment_secret_1) , PaymentId ( payment_hash_1. 0 ) ) . unwrap ( ) ;
1472
+ check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
1473
+ nodes[ 0 ] . node . send_payment ( & route, payment_hash_2, & Some ( payment_secret_2) , PaymentId ( payment_hash_2. 0 ) ) . unwrap ( ) ;
1474
+ check_added_monitors ! ( nodes[ 0 ] , 0 ) ;
1475
+ }
1476
+
1477
+ let inflight_htlcs = node_chanmgrs[ 0 ] . compute_inflight_htlcs ( ) ;
1478
+
1479
+ {
1480
+ let channel_lock = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) ;
1481
+ let channel = channel_lock. by_id . get ( & channel_id) . unwrap ( ) ;
1482
+
1483
+ let used_liquidity = inflight_htlcs. used_liquidity_msat (
1484
+ & NodeId :: from_pubkey ( & nodes[ 0 ] . node . get_our_node_id ( ) ) ,
1485
+ & NodeId :: from_pubkey ( & nodes[ 1 ] . node . get_our_node_id ( ) ) ,
1486
+ channel. get_short_channel_id ( ) . unwrap ( )
1487
+ ) ;
1488
+
1489
+ assert_eq ! ( used_liquidity, Some ( 2000000 ) ) ;
1490
+ }
1491
+
1492
+ // Clear pending events so test doesn't throw a "Had excess message on node..." error
1493
+ nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
1494
+ }
0 commit comments