@@ -1246,7 +1246,7 @@ fn test_duplicate_htlc_different_direction_onchain() {
1246
1246
let ( payment_preimage, payment_hash, _) = route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 900_000 ) ;
1247
1247
1248
1248
let ( route, _, _, _) = get_route_and_payment_hash ! ( nodes[ 1 ] , nodes[ 0 ] , 800_000 ) ;
1249
- let node_a_payment_secret = nodes[ 0 ] . node . create_inbound_payment_for_hash ( payment_hash, None , 7200 ) . unwrap ( ) ;
1249
+ let node_a_payment_secret = nodes[ 0 ] . node . create_inbound_payment_for_hash ( payment_hash, None , 7200 , None ) . unwrap ( ) ;
1250
1250
send_along_route_with_secret ( & nodes[ 1 ] , route, & [ & [ & nodes[ 0 ] ] ] , 800_000 , payment_hash, node_a_payment_secret) ;
1251
1251
1252
1252
// Provide preimage to node 0 by claiming payment
@@ -4712,7 +4712,7 @@ fn test_duplicate_payment_hash_one_failure_one_success() {
4712
4712
4713
4713
let ( our_payment_preimage, duplicate_payment_hash, _) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , 900_000 ) ;
4714
4714
4715
- let payment_secret = nodes[ 3 ] . node . create_inbound_payment_for_hash ( duplicate_payment_hash, None , 7200 ) . unwrap ( ) ;
4715
+ let payment_secret = nodes[ 3 ] . node . create_inbound_payment_for_hash ( duplicate_payment_hash, None , 7200 , None ) . unwrap ( ) ;
4716
4716
// We reduce the final CLTV here by a somewhat arbitrary constant to keep it under the one-byte
4717
4717
// script push size limit so that the below script length checks match
4718
4718
// ACCEPTED_HTLC_SCRIPT_WEIGHT.
@@ -4925,30 +4925,30 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno
4925
4925
let ( _, payment_hash_2, _) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 4 ] ] , ds_dust_limit* 1000 ) ; // not added < dust limit + HTLC tx fee
4926
4926
let ( route, _, _, _) = get_route_and_payment_hash ! ( nodes[ 1 ] , nodes[ 5 ] , ds_dust_limit* 1000 ) ;
4927
4927
// 2nd HTLC:
4928
- send_along_route_with_secret ( & nodes[ 1 ] , route. clone ( ) , & [ & [ & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 5 ] ] ] , ds_dust_limit* 1000 , payment_hash_1, nodes[ 5 ] . node . create_inbound_payment_for_hash ( payment_hash_1, None , 7200 ) . unwrap ( ) ) ; // not added < dust limit + HTLC tx fee
4928
+ send_along_route_with_secret ( & nodes[ 1 ] , route. clone ( ) , & [ & [ & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 5 ] ] ] , ds_dust_limit* 1000 , payment_hash_1, nodes[ 5 ] . node . create_inbound_payment_for_hash ( payment_hash_1, None , 7200 , None ) . unwrap ( ) ) ; // not added < dust limit + HTLC tx fee
4929
4929
// 3rd HTLC:
4930
- send_along_route_with_secret ( & nodes[ 1 ] , route, & [ & [ & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 5 ] ] ] , ds_dust_limit* 1000 , payment_hash_2, nodes[ 5 ] . node . create_inbound_payment_for_hash ( payment_hash_2, None , 7200 ) . unwrap ( ) ) ; // not added < dust limit + HTLC tx fee
4930
+ send_along_route_with_secret ( & nodes[ 1 ] , route, & [ & [ & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 5 ] ] ] , ds_dust_limit* 1000 , payment_hash_2, nodes[ 5 ] . node . create_inbound_payment_for_hash ( payment_hash_2, None , 7200 , None ) . unwrap ( ) ) ; // not added < dust limit + HTLC tx fee
4931
4931
// 4th HTLC:
4932
4932
let ( _, payment_hash_3, _) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 4 ] ] , 1000000 ) ;
4933
4933
// 5th HTLC:
4934
4934
let ( _, payment_hash_4, _) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 4 ] ] , 1000000 ) ;
4935
4935
let ( route, _, _, _) = get_route_and_payment_hash ! ( nodes[ 1 ] , nodes[ 5 ] , 1000000 ) ;
4936
4936
// 6th HTLC:
4937
- send_along_route_with_secret ( & nodes[ 1 ] , route. clone ( ) , & [ & [ & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 5 ] ] ] , 1000000 , payment_hash_3, nodes[ 5 ] . node . create_inbound_payment_for_hash ( payment_hash_3, None , 7200 ) . unwrap ( ) ) ;
4937
+ send_along_route_with_secret ( & nodes[ 1 ] , route. clone ( ) , & [ & [ & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 5 ] ] ] , 1000000 , payment_hash_3, nodes[ 5 ] . node . create_inbound_payment_for_hash ( payment_hash_3, None , 7200 , None ) . unwrap ( ) ) ;
4938
4938
// 7th HTLC:
4939
- send_along_route_with_secret ( & nodes[ 1 ] , route, & [ & [ & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 5 ] ] ] , 1000000 , payment_hash_4, nodes[ 5 ] . node . create_inbound_payment_for_hash ( payment_hash_4, None , 7200 ) . unwrap ( ) ) ;
4939
+ send_along_route_with_secret ( & nodes[ 1 ] , route, & [ & [ & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 5 ] ] ] , 1000000 , payment_hash_4, nodes[ 5 ] . node . create_inbound_payment_for_hash ( payment_hash_4, None , 7200 , None ) . unwrap ( ) ) ;
4940
4940
4941
4941
// 8th HTLC:
4942
4942
let ( _, payment_hash_5, _) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 4 ] ] , 1000000 ) ;
4943
4943
// 9th HTLC:
4944
4944
let ( route, _, _, _) = get_route_and_payment_hash ! ( nodes[ 1 ] , nodes[ 5 ] , ds_dust_limit* 1000 ) ;
4945
- send_along_route_with_secret ( & nodes[ 1 ] , route, & [ & [ & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 5 ] ] ] , ds_dust_limit* 1000 , payment_hash_5, nodes[ 5 ] . node . create_inbound_payment_for_hash ( payment_hash_5, None , 7200 ) . unwrap ( ) ) ; // not added < dust limit + HTLC tx fee
4945
+ send_along_route_with_secret ( & nodes[ 1 ] , route, & [ & [ & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 5 ] ] ] , ds_dust_limit* 1000 , payment_hash_5, nodes[ 5 ] . node . create_inbound_payment_for_hash ( payment_hash_5, None , 7200 , None ) . unwrap ( ) ) ; // not added < dust limit + HTLC tx fee
4946
4946
4947
4947
// 10th HTLC:
4948
4948
let ( _, payment_hash_6, _) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 4 ] ] , ds_dust_limit* 1000 ) ; // not added < dust limit + HTLC tx fee
4949
4949
// 11th HTLC:
4950
4950
let ( route, _, _, _) = get_route_and_payment_hash ! ( nodes[ 1 ] , nodes[ 5 ] , 1000000 ) ;
4951
- send_along_route_with_secret ( & nodes[ 1 ] , route, & [ & [ & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 5 ] ] ] , 1000000 , payment_hash_6, nodes[ 5 ] . node . create_inbound_payment_for_hash ( payment_hash_6, None , 7200 ) . unwrap ( ) ) ;
4951
+ send_along_route_with_secret ( & nodes[ 1 ] , route, & [ & [ & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 5 ] ] ] , 1000000 , payment_hash_6, nodes[ 5 ] . node . create_inbound_payment_for_hash ( payment_hash_6, None , 7200 , None ) . unwrap ( ) ) ;
4952
4952
4953
4953
// Double-check that six of the new HTLC were added
4954
4954
// We now have six HTLCs pending over the dust limit and six HTLCs under the dust limit (ie,
@@ -6922,7 +6922,7 @@ fn test_check_htlc_underpaying() {
6922
6922
let payment_params = PaymentParameters :: from_node_id ( nodes[ 1 ] . node . get_our_node_id ( ) ) . with_features ( nodes[ 1 ] . node . invoice_features ( ) ) ;
6923
6923
let route = get_route ( & nodes[ 0 ] . node . get_our_node_id ( ) , & payment_params, & nodes[ 0 ] . network_graph . read_only ( ) , None , 10_000 , TEST_FINAL_CLTV , nodes[ 0 ] . logger , & scorer, & random_seed_bytes) . unwrap ( ) ;
6924
6924
let ( _, our_payment_hash, _) = get_payment_preimage_hash ! ( nodes[ 0 ] ) ;
6925
- let our_payment_secret = nodes[ 1 ] . node . create_inbound_payment_for_hash ( our_payment_hash, Some ( 100_000 ) , 7200 ) . unwrap ( ) ;
6925
+ let our_payment_secret = nodes[ 1 ] . node . create_inbound_payment_for_hash ( our_payment_hash, Some ( 100_000 ) , 7200 , None ) . unwrap ( ) ;
6926
6926
nodes[ 0 ] . node . send_payment ( & route, our_payment_hash, & Some ( our_payment_secret) , PaymentId ( our_payment_hash. 0 ) ) . unwrap ( ) ;
6927
6927
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
6928
6928
@@ -7917,7 +7917,7 @@ fn test_preimage_storage() {
7917
7917
create_announced_chan_between_nodes ( & nodes, 0 , 1 ) . 0 . contents . short_channel_id ;
7918
7918
7919
7919
{
7920
- let ( payment_hash, payment_secret) = nodes[ 1 ] . node . create_inbound_payment ( Some ( 100_000 ) , 7200 ) . unwrap ( ) ;
7920
+ let ( payment_hash, payment_secret) = nodes[ 1 ] . node . create_inbound_payment ( Some ( 100_000 ) , 7200 , None ) . unwrap ( ) ;
7921
7921
let ( route, _, _, _) = get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 1 ] , 100_000 ) ;
7922
7922
nodes[ 0 ] . node . send_payment ( & route, payment_hash, & Some ( payment_secret) , PaymentId ( payment_hash. 0 ) ) . unwrap ( ) ;
7923
7923
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
@@ -8023,7 +8023,7 @@ fn test_bad_secret_hash() {
8023
8023
8024
8024
let random_payment_hash = PaymentHash ( [ 42 ; 32 ] ) ;
8025
8025
let random_payment_secret = PaymentSecret ( [ 43 ; 32 ] ) ;
8026
- let ( our_payment_hash, our_payment_secret) = nodes[ 1 ] . node . create_inbound_payment ( Some ( 100_000 ) , 2 ) . unwrap ( ) ;
8026
+ let ( our_payment_hash, our_payment_secret) = nodes[ 1 ] . node . create_inbound_payment ( Some ( 100_000 ) , 2 , None ) . unwrap ( ) ;
8027
8027
let ( route, _, _, _) = get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 1 ] , 100_000 ) ;
8028
8028
8029
8029
// All the below cases should end up being handled exactly identically, so we macro the
@@ -9582,3 +9582,60 @@ fn accept_busted_but_better_fee() {
9582
9582
_ => panic ! ( "Unexpected event" ) ,
9583
9583
} ;
9584
9584
}
9585
+
9586
+ fn do_payment_with_custom_min_final_cltv_expiry ( valid_delta : bool , use_user_hash : bool ) {
9587
+ let mut chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
9588
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
9589
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
9590
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
9591
+ let min_final_cltv_expiry_delta = 120 ;
9592
+ let final_cltv_expiry_delta = if valid_delta { min_final_cltv_expiry_delta + 2 } else {
9593
+ min_final_cltv_expiry_delta - 2 } ;
9594
+ let recv_value = 100_000 ;
9595
+
9596
+ create_chan_between_nodes ( & nodes[ 0 ] , & nodes[ 1 ] ) ;
9597
+
9598
+ let payment_parameters = PaymentParameters :: from_node_id ( nodes[ 1 ] . node . get_our_node_id ( ) ) ;
9599
+ let ( payment_hash, payment_preimage, payment_secret) = if use_user_hash {
9600
+ let ( payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash ! ( nodes[ 1 ] ,
9601
+ Some ( recv_value) , Some ( min_final_cltv_expiry_delta) ) ;
9602
+ ( payment_hash, payment_preimage, payment_secret)
9603
+ } else {
9604
+ let ( payment_hash, payment_secret) = nodes[ 1 ] . node . create_inbound_payment ( Some ( recv_value) , 7200 , Some ( min_final_cltv_expiry_delta) ) . unwrap ( ) ;
9605
+ ( payment_hash, nodes[ 1 ] . node . get_payment_preimage ( payment_hash, payment_secret) . unwrap ( ) , payment_secret)
9606
+ } ;
9607
+ let route = get_route ! ( nodes[ 0 ] , payment_parameters, recv_value, final_cltv_expiry_delta as u32 ) . unwrap ( ) ;
9608
+ nodes[ 0 ] . node . send_payment ( & route, payment_hash, & Some ( payment_secret) , PaymentId ( payment_hash. 0 ) ) . unwrap ( ) ;
9609
+ check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
9610
+ let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
9611
+ assert_eq ! ( events. len( ) , 1 ) ;
9612
+ let mut payment_event = SendEvent :: from_event ( events. pop ( ) . unwrap ( ) ) ;
9613
+ nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
9614
+ commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 0 ] , payment_event. commitment_msg, false ) ;
9615
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
9616
+
9617
+ if valid_delta {
9618
+ expect_payment_claimable ! ( nodes[ 1 ] , payment_hash, payment_secret, recv_value, if use_user_hash {
9619
+ None } else { Some ( payment_preimage) } , nodes[ 1 ] . node. get_our_node_id( ) ) ;
9620
+
9621
+ claim_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , payment_preimage) ;
9622
+ } else {
9623
+ expect_pending_htlcs_forwardable_and_htlc_handling_failed ! ( nodes[ 1 ] , vec![ HTLCDestination :: FailedPayment { payment_hash } ] ) ;
9624
+
9625
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
9626
+
9627
+ let fail_updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
9628
+ nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & fail_updates. update_fail_htlcs [ 0 ] ) ;
9629
+ commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , fail_updates. commitment_signed, false , true ) ;
9630
+
9631
+ expect_payment_failed ! ( nodes[ 0 ] , payment_hash, true ) ;
9632
+ }
9633
+ }
9634
+
9635
+ #[ test]
9636
+ fn test_payment_with_custom_min_cltv_expiry_delta ( ) {
9637
+ do_payment_with_custom_min_final_cltv_expiry ( false , false ) ;
9638
+ do_payment_with_custom_min_final_cltv_expiry ( false , true ) ;
9639
+ do_payment_with_custom_min_final_cltv_expiry ( true , false ) ;
9640
+ do_payment_with_custom_min_final_cltv_expiry ( true , true ) ;
9641
+ }
0 commit comments