]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Pass ClaimAlongRouteArgs to claim_payment_along_route
authorJeffrey Czyz <jkczyz@gmail.com>
Fri, 24 May 2024 21:16:13 +0000 (16:16 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Fri, 24 May 2024 21:52:08 +0000 (16:52 -0500)
lightning/src/ln/blinded_payment_tests.rs
lightning/src/ln/chanmon_update_fail_tests.rs
lightning/src/ln/functional_test_utils.rs
lightning/src/ln/functional_tests.rs
lightning/src/ln/max_payment_path_len_tests.rs
lightning/src/ln/payment_tests.rs

index d4570ef8c5de8e65c42ec73288cfd8962b7af0c2..2a7635b5775c93fec20b3be11b1c81146a55ec3b 100644 (file)
@@ -180,7 +180,9 @@ fn mpp_to_one_hop_blinded_path() {
        let ev = remove_first_msg_event_to_node(&nodes[2].node.get_our_node_id(), &mut events);
        pass_along_path(&nodes[0], expected_route[1], amt_msat, payment_hash.clone(),
                Some(payment_secret), ev.clone(), true, None);
-       claim_payment_along_route(&nodes[0], expected_route, false, payment_preimage);
+       claim_payment_along_route(
+               ClaimAlongRouteArgs::new(&nodes[0], expected_route, payment_preimage)
+       );
 }
 
 #[test]
@@ -244,7 +246,9 @@ fn mpp_to_three_hop_blinded_paths() {
        let ev = remove_first_msg_event_to_node(&nodes[2].node.get_our_node_id(), &mut events);
        pass_along_path(&nodes[0], expected_route[1], amt_msat, payment_hash.clone(),
                Some(payment_secret), ev.clone(), true, None);
-       claim_payment_along_route(&nodes[0], expected_route, false, payment_preimage);
+       claim_payment_along_route(
+               ClaimAlongRouteArgs::new(&nodes[0], expected_route, payment_preimage)
+       );
 }
 
 enum ForwardCheckFail {
@@ -1219,7 +1223,9 @@ fn blinded_keysend() {
 
        let ev = remove_first_msg_event_to_node(&nodes[1].node.get_our_node_id(), &mut events);
        pass_along_path(&nodes[0], expected_route[0], amt_msat, payment_hash, Some(payment_secret), ev.clone(), true, Some(keysend_preimage));
-       claim_payment_along_route(&nodes[0], expected_route, false, keysend_preimage);
+       claim_payment_along_route(
+               ClaimAlongRouteArgs::new(&nodes[0], expected_route, keysend_preimage)
+       );
 }
 
 #[test]
@@ -1270,7 +1276,9 @@ fn blinded_mpp_keysend() {
        let ev = remove_first_msg_event_to_node(&nodes[2].node.get_our_node_id(), &mut events);
        pass_along_path(&nodes[0], expected_route[1], amt_msat, payment_hash.clone(),
                Some(payment_secret), ev.clone(), true, Some(keysend_preimage));
-       claim_payment_along_route(&nodes[0], expected_route, false, keysend_preimage);
+       claim_payment_along_route(
+               ClaimAlongRouteArgs::new(&nodes[0], expected_route, keysend_preimage)
+       );
 }
 
 #[test]
index 7d332f2ad78b8897fa3d27e00ae23745a2d49f5b..5e9ce30376be30c0e07b3e6920ece58b53393330 100644 (file)
@@ -2025,7 +2025,9 @@ fn test_path_paused_mpp() {
        assert_eq!(events.len(), 1);
        pass_along_path(&nodes[0], &[&nodes[2], &nodes[3]], 200_000, payment_hash.clone(), Some(payment_secret), events.pop().unwrap(), true, None);
 
-       claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], false, payment_preimage);
+       claim_payment_along_route(
+               ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], payment_preimage)
+       );
 }
 
 #[test]
index fdcdc0986571d069771c854bf1f4abe3ac870de9..0a78a9bf7f21142fb60548b2028a93e7f3ef0dd7 100644 (file)
@@ -2950,18 +2950,20 @@ pub fn pass_claimed_payment_along_route<'a, 'b, 'c, 'd>(args: ClaimAlongRouteArg
 
        expected_total_fee_msat
 }
-pub fn claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_paths: &[&[&Node<'a, 'b, 'c>]], skip_last: bool, our_payment_preimage: PaymentPreimage) {
-       let expected_total_fee_msat = do_claim_payment_along_route(
-               ClaimAlongRouteArgs::new(origin_node, expected_paths, our_payment_preimage)
-                       .skip_last(skip_last)
-       );
+pub fn claim_payment_along_route(args: ClaimAlongRouteArgs) {
+       let origin_node = args.origin_node;
+       let payment_preimage = args.payment_preimage;
+       let skip_last = args.skip_last;
+       let expected_total_fee_msat = do_claim_payment_along_route(args);
        if !skip_last {
-               expect_payment_sent!(origin_node, our_payment_preimage, Some(expected_total_fee_msat));
+               expect_payment_sent!(origin_node, payment_preimage, Some(expected_total_fee_msat));
        }
 }
 
 pub fn claim_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], our_payment_preimage: PaymentPreimage) {
-       claim_payment_along_route(origin_node, &[expected_route], false, our_payment_preimage);
+       claim_payment_along_route(
+               ClaimAlongRouteArgs::new(origin_node, &[expected_route], our_payment_preimage)
+       );
 }
 
 pub const TEST_FINAL_CLTV: u32 = 70;
index 78307d0f95771cd1a2df0a3337f1a44c39704e6a..c0e9461f1a3eb52843c60d7adbcde1a1eba2a45a 100644 (file)
@@ -3780,7 +3780,10 @@ fn test_simple_peer_disconnect() {
        nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id());
        nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id());
 
-       claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], true, payment_preimage_3);
+       claim_payment_along_route(
+               ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage_3)
+                       .skip_last(true)
+       );
        fail_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], true, payment_hash_5);
 
        let mut reconnect_args = ReconnectArgs::new(&nodes[0], &nodes[1]);
@@ -8264,7 +8267,9 @@ fn test_onion_value_mpp_set_calculation() {
        let ev = remove_first_msg_event_to_node(&expected_paths[1][0].node.get_our_node_id(), &mut events);
        pass_along_path(&nodes[0], expected_paths[1], 101_000, our_payment_hash.clone(), Some(our_payment_secret), ev, true, None);
 
-       claim_payment_along_route(&nodes[0], expected_paths, false, our_payment_preimage);
+       claim_payment_along_route(
+               ClaimAlongRouteArgs::new(&nodes[0], expected_paths, our_payment_preimage)
+       );
 }
 
 fn do_test_overshoot_mpp(msat_amounts: &[u64], total_msat: u64) {
@@ -8330,7 +8335,9 @@ fn do_test_overshoot_mpp(msat_amounts: &[u64], total_msat: u64) {
                pass_along_path(&nodes[src_idx], expected_path, amount_received, our_payment_hash.clone(), Some(our_payment_secret), ev, became_claimable_now, None);
        }
 
-       claim_payment_along_route(&nodes[src_idx], &expected_paths, false, our_payment_preimage);
+       claim_payment_along_route(
+               ClaimAlongRouteArgs::new(&nodes[src_idx], &expected_paths, our_payment_preimage)
+       );
 }
 
 #[test]
@@ -8362,7 +8369,9 @@ fn test_simple_mpp() {
        route.paths[1].hops[0].short_channel_id = chan_2_id;
        route.paths[1].hops[1].short_channel_id = chan_4_id;
        send_along_route_with_secret(&nodes[0], route, &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], 200_000, payment_hash, payment_secret);
-       claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], false, payment_preimage);
+       claim_payment_along_route(
+               ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], payment_preimage)
+       );
 }
 
 #[test]
index 36fe098b9ee59a381b09663a79a8ceb09c9ba131..e9e988e4570d57ad5c9b51386eef2607d0ade4e1 100644 (file)
@@ -84,7 +84,9 @@ fn large_payment_metadata() {
                .with_payment_secret(payment_secret)
                .with_payment_metadata(payment_metadata.clone());
        do_pass_along_path(args);
-       claim_payment_along_route(&nodes[0], &[&[&nodes[1]]], false, payment_preimage);
+       claim_payment_along_route(
+               ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1]]], payment_preimage)
+       );
 
        // Check that the payment parameter for max path length will prevent us from routing past our
        // next-hop peer given the payment_metadata size.
@@ -133,7 +135,9 @@ fn large_payment_metadata() {
                .with_payment_secret(payment_secret_2)
                .with_payment_metadata(recipient_onion_allows_2_hops.payment_metadata.unwrap());
        do_pass_along_path(args);
-       claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], false, payment_preimage_2);
+       claim_payment_along_route(
+               ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage_2)
+       );
 }
 
 #[test]
@@ -201,7 +205,9 @@ fn one_hop_blinded_path_with_custom_tlv() {
                .with_payment_secret(payment_secret)
                .with_custom_tlvs(recipient_onion_max_custom_tlv_size.custom_tlvs.clone());
        do_pass_along_path(args);
-       claim_payment_along_route(&nodes[1], &[&[&nodes[2]]], false, payment_preimage);
+       claim_payment_along_route(
+               ClaimAlongRouteArgs::new(&nodes[1], &[&[&nodes[2]]], payment_preimage)
+       );
 
        // If 1 byte is added to the custom TLV value, we'll fail to send prior to pathfinding.
        let mut recipient_onion_too_large_custom_tlv = recipient_onion_max_custom_tlv_size.clone();
@@ -228,7 +234,9 @@ fn one_hop_blinded_path_with_custom_tlv() {
                .with_payment_secret(payment_secret)
                .with_custom_tlvs(recipient_onion_allows_2_hops.custom_tlvs);
        do_pass_along_path(args);
-       claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], false, payment_preimage);
+       claim_payment_along_route(
+               ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage)
+       );
 }
 
 #[test]
@@ -283,7 +291,9 @@ fn blinded_path_with_custom_tlv() {
                .with_payment_secret(payment_secret)
                .with_custom_tlvs(recipient_onion_max_custom_tlv_size.custom_tlvs.clone());
        do_pass_along_path(args);
-       claim_payment_along_route(&nodes[1], &[&[&nodes[2], &nodes[3]]], false, payment_preimage);
+       claim_payment_along_route(
+               ClaimAlongRouteArgs::new(&nodes[1], &[&[&nodes[2], &nodes[3]]], payment_preimage)
+       );
 
        // If 1 byte is added to the custom TLV value, we'll fail to send prior to pathfinding.
        let mut recipient_onion_too_large_custom_tlv = recipient_onion_max_custom_tlv_size.clone();
@@ -322,5 +332,7 @@ fn blinded_path_with_custom_tlv() {
                .with_payment_secret(payment_secret)
                .with_custom_tlvs(recipient_onion_allows_2_hops.custom_tlvs);
        do_pass_along_path(args);
-       claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[2], &nodes[3]]], false, payment_preimage);
+       claim_payment_along_route(
+               ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2], &nodes[3]]], payment_preimage)
+       );
 }
index 0950644369866bf5e8a263af528ae05f6fd5924e..83f3053b6e1528218ca8a0cd2df0e2b9437d736a 100644 (file)
@@ -160,7 +160,9 @@ fn mpp_retry() {
        let mut events = nodes[0].node.get_and_clear_pending_msg_events();
        assert_eq!(events.len(), 1);
        pass_along_path(&nodes[0], &[&nodes[2], &nodes[3]], 2_000_000, payment_hash, Some(payment_secret), events.pop().unwrap(), true, None);
-       claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], false, payment_preimage);
+       claim_payment_along_route(
+               ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], payment_preimage)
+       );
 }
 
 #[test]
@@ -351,7 +353,9 @@ fn do_mpp_receive_timeout(send_partial_mpp: bool) {
                        nodes[3].node.timer_tick_occurred();
                }
 
-               claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], false, payment_preimage);
+               claim_payment_along_route(
+                       ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], payment_preimage)
+               );
        }
 }
 
@@ -466,7 +470,9 @@ fn test_mpp_keysend() {
        let ev = remove_first_msg_event_to_node(&nodes[2].node.get_our_node_id(), &mut events);
        pass_along_path(&nodes[0], expected_route[1], recv_value, payment_hash.clone(),
                Some(payment_secret), ev.clone(), true, Some(payment_preimage));
-       claim_payment_along_route(&nodes[0], expected_route, false, payment_preimage);
+       claim_payment_along_route(
+               ClaimAlongRouteArgs::new(&nodes[0], expected_route, payment_preimage)
+       );
 }
 
 #[test]
@@ -1247,7 +1253,9 @@ fn get_ldk_payment_preimage() {
        let mut events = nodes[0].node.get_and_clear_pending_msg_events();
        assert_eq!(events.len(), 1);
        pass_along_path(&nodes[0], &[&nodes[1]], amt_msat, payment_hash, Some(payment_secret), events.pop().unwrap(), true, Some(payment_preimage));
-       claim_payment_along_route(&nodes[0], &[&[&nodes[1]]], false, payment_preimage);
+       claim_payment_along_route(
+               ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1]]], payment_preimage)
+       );
 }
 
 #[test]
@@ -2276,7 +2284,9 @@ fn do_automatic_retries(test: AutoRetry) {
                let mut msg_events = nodes[0].node.get_and_clear_pending_msg_events();
                assert_eq!(msg_events.len(), 1);
                pass_along_path(&nodes[0], &[&nodes[1], &nodes[2]], amt_msat, payment_hash, Some(payment_secret), msg_events.pop().unwrap(), true, None);
-               claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], false, payment_preimage);
+               claim_payment_along_route(
+                       ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage)
+               );
        } else if test == AutoRetry::Spontaneous {
                nodes[0].node.send_spontaneous_payment_with_retry(Some(payment_preimage),
                        RecipientOnionFields::spontaneous_empty(), PaymentId(payment_hash.0), route_params,
@@ -2293,7 +2303,9 @@ fn do_automatic_retries(test: AutoRetry) {
                let mut msg_events = nodes[0].node.get_and_clear_pending_msg_events();
                assert_eq!(msg_events.len(), 1);
                pass_along_path(&nodes[0], &[&nodes[1], &nodes[2]], amt_msat, payment_hash, None, msg_events.pop().unwrap(), true, Some(payment_preimage));
-               claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], false, payment_preimage);
+               claim_payment_along_route(
+                       ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage)
+               );
        } else if test == AutoRetry::FailAttempts {
                // Ensure ChannelManager will not retry a payment if it has run out of payment attempts.
                nodes[0].node.send_payment(payment_hash, RecipientOnionFields::secret_only(payment_secret),
@@ -3813,7 +3825,9 @@ fn test_retry_custom_tlvs() {
                .with_payment_secret(payment_secret)
                .with_custom_tlvs(custom_tlvs);
        do_pass_along_path(args);
-       claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], false, payment_preimage);
+       claim_payment_along_route(
+               ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage)
+       );
 }
 
 #[test]
@@ -4109,7 +4123,9 @@ fn do_test_payment_metadata_consistency(do_reload: bool, do_modify: bool) {
        } else {
                expect_pending_htlcs_forwardable!(nodes[3]);
                expect_payment_claimable!(nodes[3], payment_hash, payment_secret, amt_msat);
-               claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], false, payment_preimage);
+               claim_payment_along_route(
+                       ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], payment_preimage)
+               );
        }
 }