@@ -1246,7 +1246,7 @@ fn test_duplicate_htlc_different_direction_onchain() {
12461246 let ( payment_preimage, payment_hash, _) = route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 900_000 ) ;
12471247
12481248 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 ( ) ;
12501250 send_along_route_with_secret ( & nodes[ 1 ] , route, & [ & [ & nodes[ 0 ] ] ] , 800_000 , payment_hash, node_a_payment_secret) ;
12511251
12521252 // Provide preimage to node 0 by claiming payment
@@ -4712,7 +4712,7 @@ fn test_duplicate_payment_hash_one_failure_one_success() {
47124712
47134713 let ( our_payment_preimage, duplicate_payment_hash, _) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , 900_000 ) ;
47144714
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 ( ) ;
47164716 // We reduce the final CLTV here by a somewhat arbitrary constant to keep it under the one-byte
47174717 // script push size limit so that the below script length checks match
47184718 // ACCEPTED_HTLC_SCRIPT_WEIGHT.
@@ -4925,30 +4925,30 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno
49254925 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
49264926 let ( route, _, _, _) = get_route_and_payment_hash ! ( nodes[ 1 ] , nodes[ 5 ] , ds_dust_limit* 1000 ) ;
49274927 // 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
49294929 // 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
49314931 // 4th HTLC:
49324932 let ( _, payment_hash_3, _) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 4 ] ] , 1000000 ) ;
49334933 // 5th HTLC:
49344934 let ( _, payment_hash_4, _) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 4 ] ] , 1000000 ) ;
49354935 let ( route, _, _, _) = get_route_and_payment_hash ! ( nodes[ 1 ] , nodes[ 5 ] , 1000000 ) ;
49364936 // 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 ( ) ) ;
49384938 // 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 ( ) ) ;
49404940
49414941 // 8th HTLC:
49424942 let ( _, payment_hash_5, _) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 4 ] ] , 1000000 ) ;
49434943 // 9th HTLC:
49444944 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
49464946
49474947 // 10th HTLC:
49484948 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
49494949 // 11th HTLC:
49504950 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 ( ) ) ;
49524952
49534953 // Double-check that six of the new HTLC were added
49544954 // 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() {
69226922 let payment_params = PaymentParameters :: from_node_id ( nodes[ 1 ] . node . get_our_node_id ( ) ) . with_features ( nodes[ 1 ] . node . invoice_features ( ) ) ;
69236923 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 ( ) ;
69246924 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 ( ) ;
69266926 nodes[ 0 ] . node . send_payment ( & route, our_payment_hash, & Some ( our_payment_secret) , PaymentId ( our_payment_hash. 0 ) ) . unwrap ( ) ;
69276927 check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
69286928
@@ -7917,7 +7917,7 @@ fn test_preimage_storage() {
79177917 create_announced_chan_between_nodes ( & nodes, 0 , 1 ) . 0 . contents . short_channel_id ;
79187918
79197919 {
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 ( ) ;
79217921 let ( route, _, _, _) = get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 1 ] , 100_000 ) ;
79227922 nodes[ 0 ] . node . send_payment ( & route, payment_hash, & Some ( payment_secret) , PaymentId ( payment_hash. 0 ) ) . unwrap ( ) ;
79237923 check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
@@ -8023,7 +8023,7 @@ fn test_bad_secret_hash() {
80238023
80248024 let random_payment_hash = PaymentHash ( [ 42 ; 32 ] ) ;
80258025 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 ( ) ;
80278027 let ( route, _, _, _) = get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 1 ] , 100_000 ) ;
80288028
80298029 // 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() {
95829582 _ => panic ! ( "Unexpected event" ) ,
95839583 } ;
95849584}
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