]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Pass ClaimAlongRouteArgs to do_claim_payment_along_route
authorJeffrey Czyz <jkczyz@gmail.com>
Fri, 24 May 2024 20:30:40 +0000 (15:30 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Fri, 24 May 2024 21:52:08 +0000 (16:52 -0500)
lightning-invoice/src/utils.rs
lightning/src/ln/blinded_payment_tests.rs
lightning/src/ln/functional_test_utils.rs
lightning/src/ln/functional_tests.rs
lightning/src/ln/monitor_tests.rs
lightning/src/ln/payment_tests.rs

index 22e493ae1c570705da884a22b3c42a4e1ec02c0d..94033bc072cb206e574831a9074d935d72e0b8d6 100644 (file)
@@ -1397,7 +1397,9 @@ mod test {
                let payment_preimage_opt = if user_generated_pmt_hash { None } else { Some(payment_preimage) };
                assert_eq!(other_events.borrow().len(), 1);
                check_payment_claimable(&other_events.borrow()[0], payment_hash, payment_secret, payment_amt, payment_preimage_opt, invoice.recover_payee_pub_key());
-               do_claim_payment_along_route(&nodes[0], &[&vec!(&nodes[fwd_idx])[..]], false, payment_preimage);
+               do_claim_payment_along_route(
+                       ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[fwd_idx]]], payment_preimage)
+               );
                expect_payment_sent(&nodes[0], payment_preimage, None, true, true);
        }
 
index 4c254628de6ec63525473aa927802ec6a8eb270c..d4570ef8c5de8e65c42ec73288cfd8962b7af0c2 100644 (file)
@@ -643,7 +643,9 @@ fn do_blinded_intercept_payment(intercept_node_fails: bool) {
        expect_pending_htlcs_forwardable!(nodes[2]);
 
        expect_payment_claimable!(&nodes[2], payment_hash, payment_secret, amt_msat, None, nodes[2].node.get_our_node_id());
-       do_claim_payment_along_route(&nodes[0], &vec!(&vec!(&nodes[1], &nodes[2])[..]), false, payment_preimage);
+       do_claim_payment_along_route(
+               ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage)
+       );
        expect_payment_sent(&nodes[0], payment_preimage, Some(Some(1000)), true, true);
 }
 
index cbb2b0f2197c18ef34490d703026cffa706853d2..fdcdc0986571d069771c854bf1f4abe3ac870de9 100644 (file)
@@ -2716,18 +2716,12 @@ pub fn send_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, route: Route
        (our_payment_preimage, our_payment_hash, our_payment_secret, payment_id)
 }
 
-pub fn do_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
-) -> u64 {
-       for path in expected_paths.iter() {
-               assert_eq!(path.last().unwrap().node.get_our_node_id(), expected_paths[0].last().unwrap().node.get_our_node_id());
+pub fn do_claim_payment_along_route(args: ClaimAlongRouteArgs) -> u64 {
+       for path in args.expected_paths.iter() {
+               assert_eq!(path.last().unwrap().node.get_our_node_id(), args.expected_paths[0].last().unwrap().node.get_our_node_id());
        }
-       expected_paths[0].last().unwrap().node.claim_funds(our_payment_preimage);
-       pass_claimed_payment_along_route(
-               ClaimAlongRouteArgs::new(origin_node, expected_paths, our_payment_preimage)
-                       .skip_last(skip_last)
-       )
+       args.expected_paths[0].last().unwrap().node.claim_funds(args.payment_preimage);
+       pass_claimed_payment_along_route(args)
 }
 
 pub struct ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
@@ -2957,7 +2951,10 @@ 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(origin_node, expected_paths, skip_last, our_payment_preimage);
+       let expected_total_fee_msat = do_claim_payment_along_route(
+               ClaimAlongRouteArgs::new(origin_node, expected_paths, our_payment_preimage)
+                       .skip_last(skip_last)
+       );
        if !skip_last {
                expect_payment_sent!(origin_node, our_payment_preimage, Some(expected_total_fee_msat));
        }
index 5b1420e3d6b55b073ff790046831ebd68ad5b56c..78307d0f95771cd1a2df0a3337f1a44c39704e6a 100644 (file)
@@ -9806,7 +9806,9 @@ fn test_inconsistent_mpp_params() {
        assert_eq!(events.len(), 1);
        pass_along_path(&nodes[0], &[&nodes[2], &nodes[3]], 15_000_000, our_payment_hash, Some(our_payment_secret), events.pop().unwrap(), true, None);
 
-       do_claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], false, our_payment_preimage);
+       do_claim_payment_along_route(
+               ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], our_payment_preimage)
+       );
        expect_payment_sent(&nodes[0], our_payment_preimage, Some(None), true, true);
 }
 
index 761d4b5316c69b4a728c60f654733ccf5330ab3b..90964a006ba18b6f3dd2a8195c0e23daa81d9857 100644 (file)
@@ -2896,7 +2896,9 @@ fn test_event_replay_causing_monitor_replay() {
 
        let payment_preimage = route_payment(&nodes[0], &[&nodes[1]], 1_000_000).0;
 
-       do_claim_payment_along_route(&nodes[0], &[&[&nodes[1]]], false, payment_preimage);
+       do_claim_payment_along_route(
+               ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1]]], payment_preimage)
+       );
 
        // At this point the `PaymentSent` event has not been processed but the full commitment signed
        // dance has completed.
index 2fc21eb23853612aa4518c09cc81b49cf3098d45..0950644369866bf5e8a263af528ae05f6fd5924e 100644 (file)
@@ -817,7 +817,9 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) {
        let mut events = nodes[0].node.get_and_clear_pending_msg_events();
        assert_eq!(events.len(), 1);
        pass_along_path(&nodes[0], &[&nodes[1], &nodes[2]], 1_000_000, payment_hash, Some(payment_secret), events.pop().unwrap(), true, None);
-       do_claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], false, payment_preimage);
+       do_claim_payment_along_route(
+               ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage)
+       );
        expect_payment_sent!(nodes[0], payment_preimage, Some(new_route.paths[0].hops[0].fee_msat));
 }
 
@@ -1579,7 +1581,9 @@ fn claimed_send_payment_idempotent() {
        // Claim the payment backwards, but note that the PaymentSent event is still pending and has
        // not been seen by the user. At this point, from the user perspective nothing has changed, so
        // we must remain just as idempotent as we were before.
-       do_claim_payment_along_route(&nodes[0], &[&[&nodes[1]]], false, first_payment_preimage);
+       do_claim_payment_along_route(
+               ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1]]], first_payment_preimage)
+       );
 
        for _ in 0..=IDEMPOTENCY_TIMEOUT_TICKS {
                nodes[0].node.timer_tick_occurred();
@@ -1980,7 +1984,9 @@ fn do_test_intercepted_payment(test: InterceptTest) {
 
                let payment_preimage = nodes[2].node.get_payment_preimage(payment_hash, payment_secret).unwrap();
                expect_payment_claimable!(&nodes[2], payment_hash, payment_secret, amt_msat, Some(payment_preimage), nodes[2].node.get_our_node_id());
-               do_claim_payment_along_route(&nodes[0], &vec!(&vec!(&nodes[1], &nodes[2])[..]), false, payment_preimage);
+               do_claim_payment_along_route(
+                       ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage)
+               );
                let events = nodes[0].node.get_and_clear_pending_events();
                assert_eq!(events.len(), 2);
                match events[0] {
@@ -3938,8 +3944,9 @@ fn do_test_custom_tlvs_consistency(first_tlvs: Vec<(u64, Vec<u8>)>, second_tlvs:
                        _ => panic!("Unexpected event"),
                }
 
-               do_claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]],
-                       false, our_payment_preimage);
+               do_claim_payment_along_route(
+                       ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], our_payment_preimage)
+               );
                expect_payment_sent(&nodes[0], our_payment_preimage, Some(Some(2000)), true, true);
        } else {
                // Expect fail back