@@ -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,74 @@ 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
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
1394
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
1395
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
1396
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1397
+
1398
+ let ( _, _, chan_id, _) = create_announced_chan_between_nodes ( & nodes, 0 , 1 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) ;
1399
+
1400
+ // Send and claim the payment. Inflight HTLCs should be empty.
1401
+ send_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 500000 ) ;
1402
+ assert_eq ! ( node_chanmgrs[ 0 ] . compute_inflight_htlcs( ) . 0 . len( ) , 0 ) ;
1403
+
1404
+ // Send the payment, but do not claim it. Our inflight HTLCs should contain the pending payment
1405
+ route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 500000 ) ;
1406
+ let inflight_htlcs = node_chanmgrs[ 0 ] . compute_inflight_htlcs ( ) ;
1407
+
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, Some ( 500000 ) ) ;
1419
+ }
1420
+ }
1421
+
1422
+ #[ test]
1423
+ fn test_holding_cell_inflight_htlcs ( ) {
1424
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
1425
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
1426
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
1427
+ let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1428
+ let channel_id = create_announced_chan_between_nodes ( & nodes, 0 , 1 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) . 2 ;
1429
+
1430
+ let ( route, payment_hash_1, _, payment_secret_1) = get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 1 ] , 1000000 ) ;
1431
+ let ( _, payment_hash_2, payment_secret_2) = get_payment_preimage_hash ! ( nodes[ 1 ] ) ;
1432
+
1433
+ // Queue up two payments - one will be delivered right away, one immediately goes into the
1434
+ // holding cell as nodes[0] is AwaitingRAA.
1435
+ {
1436
+ nodes[ 0 ] . node . send_payment ( & route, payment_hash_1, & Some ( payment_secret_1) , PaymentId ( payment_hash_1. 0 ) ) . unwrap ( ) ;
1437
+ check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
1438
+ nodes[ 0 ] . node . send_payment ( & route, payment_hash_2, & Some ( payment_secret_2) , PaymentId ( payment_hash_2. 0 ) ) . unwrap ( ) ;
1439
+ check_added_monitors ! ( nodes[ 0 ] , 0 ) ;
1440
+ }
1441
+
1442
+ let inflight_htlcs = node_chanmgrs[ 0 ] . compute_inflight_htlcs ( ) ;
1443
+
1444
+ {
1445
+ let channel_lock = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) ;
1446
+ let channel = channel_lock. by_id . get ( & channel_id) . unwrap ( ) ;
1447
+
1448
+ let used_liquidity = inflight_htlcs. used_liquidity_msat (
1449
+ & NodeId :: from_pubkey ( & nodes[ 0 ] . node . get_our_node_id ( ) ) ,
1450
+ & NodeId :: from_pubkey ( & nodes[ 1 ] . node . get_our_node_id ( ) ) ,
1451
+ channel. get_short_channel_id ( ) . unwrap ( )
1452
+ ) ;
1453
+
1454
+ assert_eq ! ( used_liquidity, Some ( 2000000 ) ) ;
1455
+ }
1456
+
1457
+ // Clear pending events so test doesn't throw a "Had excess message on node..." error
1458
+ nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
1459
+ }
0 commit comments