]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Check custom_tlvs in Event::PaymentClaimed
authorJeffrey Czyz <jkczyz@gmail.com>
Fri, 24 May 2024 21:44:04 +0000 (16:44 -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/functional_test_utils.rs
lightning/src/ln/max_payment_path_len_tests.rs
lightning/src/ln/payment_tests.rs

index 2a7635b5775c93fec20b3be11b1c81146a55ec3b..03c0e49fb4682899cef605c2a016491701b36edd 100644 (file)
@@ -1326,5 +1326,8 @@ fn custom_tlvs_to_blinded_path() {
                .with_payment_secret(payment_secret)
                .with_custom_tlvs(recipient_onion_fields.custom_tlvs.clone());
        do_pass_along_path(args);
-       claim_payment(&nodes[0], &[&nodes[1]], payment_preimage);
+       claim_payment_along_route(
+               ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1]]], payment_preimage)
+                       .with_custom_tlvs(recipient_onion_fields.custom_tlvs.clone())
+       );
 }
index 0a78a9bf7f21142fb60548b2028a93e7f3ef0dd7..b9688d04348e22a6d111167e62ecdadfc390ed90 100644 (file)
@@ -2731,6 +2731,7 @@ pub struct ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
        pub expected_min_htlc_overpay: Vec<u32>,
        pub skip_last: bool,
        pub payment_preimage: PaymentPreimage,
+       pub custom_tlvs: Vec<(u64, Vec<u8>)>,
        // Allow forwarding nodes to have taken 1 msat more fee than expected based on the downstream
        // fulfill amount.
        //
@@ -2749,7 +2750,7 @@ impl<'a, 'b, 'c, 'd> ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
                Self {
                        origin_node, expected_paths, expected_extra_fees: vec![0; expected_paths.len()],
                        expected_min_htlc_overpay: vec![0; expected_paths.len()], skip_last: false, payment_preimage,
-                       allow_1_msat_fee_overpay: false,
+                       allow_1_msat_fee_overpay: false, custom_tlvs: vec![],
                }
        }
        pub fn skip_last(mut self, skip_last: bool) -> Self {
@@ -2768,12 +2769,16 @@ impl<'a, 'b, 'c, 'd> ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
                self.allow_1_msat_fee_overpay = true;
                self
        }
+       pub fn with_custom_tlvs(mut self, custom_tlvs: Vec<(u64, Vec<u8>)>) -> Self {
+               self.custom_tlvs = custom_tlvs;
+               self
+       }
 }
 
-pub fn pass_claimed_payment_along_route<'a, 'b, 'c, 'd>(args: ClaimAlongRouteArgs) -> u64 {
+pub fn pass_claimed_payment_along_route(args: ClaimAlongRouteArgs) -> u64 {
        let ClaimAlongRouteArgs {
                origin_node, expected_paths, expected_extra_fees, expected_min_htlc_overpay, skip_last,
-               payment_preimage: our_payment_preimage, allow_1_msat_fee_overpay,
+               payment_preimage: our_payment_preimage, allow_1_msat_fee_overpay, custom_tlvs,
        } = args;
        let claim_event = expected_paths[0].last().unwrap().node.get_and_clear_pending_events();
        assert_eq!(claim_event.len(), 1);
@@ -2787,11 +2792,13 @@ pub fn pass_claimed_payment_along_route<'a, 'b, 'c, 'd>(args: ClaimAlongRouteArg
                                | PaymentPurpose::Bolt12RefundPayment { payment_preimage: Some(preimage), .. },
                        amount_msat,
                        ref htlcs,
+                       ref onion_fields,
                        ..
                } => {
                        assert_eq!(preimage, our_payment_preimage);
                        assert_eq!(htlcs.len(), expected_paths.len());  // One per path.
                        assert_eq!(htlcs.iter().map(|h| h.value_msat).sum::<u64>(), amount_msat);
+                       assert_eq!(onion_fields.as_ref().unwrap().custom_tlvs, custom_tlvs);
                        expected_paths.iter().zip(htlcs).for_each(|(path, htlc)| check_claimed_htlc_channel(origin_node, path, htlc));
                        fwd_amt_msat = amount_msat;
                },
@@ -2802,11 +2809,13 @@ pub fn pass_claimed_payment_along_route<'a, 'b, 'c, 'd>(args: ClaimAlongRouteArg
                        payment_hash,
                        amount_msat,
                        ref htlcs,
+                       ref onion_fields,
                        ..
                } => {
                        assert_eq!(&payment_hash.0, &Sha256::hash(&our_payment_preimage.0)[..]);
                        assert_eq!(htlcs.len(), expected_paths.len());  // One per path.
                        assert_eq!(htlcs.iter().map(|h| h.value_msat).sum::<u64>(), amount_msat);
+                       assert_eq!(onion_fields.as_ref().unwrap().custom_tlvs, custom_tlvs);
                        expected_paths.iter().zip(htlcs).for_each(|(path, htlc)| check_claimed_htlc_channel(origin_node, path, htlc));
                        fwd_amt_msat = amount_msat;
                }
index e9e988e4570d57ad5c9b51386eef2607d0ade4e1..7bd605c9ddfeeeee275fb636b8ae38f8a1b4ff30 100644 (file)
@@ -207,6 +207,7 @@ fn one_hop_blinded_path_with_custom_tlv() {
        do_pass_along_path(args);
        claim_payment_along_route(
                ClaimAlongRouteArgs::new(&nodes[1], &[&[&nodes[2]]], payment_preimage)
+                       .with_custom_tlvs(recipient_onion_max_custom_tlv_size.custom_tlvs.clone())
        );
 
        // If 1 byte is added to the custom TLV value, we'll fail to send prior to pathfinding.
@@ -232,10 +233,11 @@ fn one_hop_blinded_path_with_custom_tlv() {
        let path = &[&nodes[1], &nodes[2]];
        let args = PassAlongPathArgs::new(&nodes[0], path, amt_msat, payment_hash, events.pop().unwrap())
                .with_payment_secret(payment_secret)
-               .with_custom_tlvs(recipient_onion_allows_2_hops.custom_tlvs);
+               .with_custom_tlvs(recipient_onion_allows_2_hops.custom_tlvs.clone());
        do_pass_along_path(args);
        claim_payment_along_route(
                ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage)
+                       .with_custom_tlvs(recipient_onion_allows_2_hops.custom_tlvs)
        );
 }
 
@@ -293,6 +295,7 @@ fn blinded_path_with_custom_tlv() {
        do_pass_along_path(args);
        claim_payment_along_route(
                ClaimAlongRouteArgs::new(&nodes[1], &[&[&nodes[2], &nodes[3]]], payment_preimage)
+                       .with_custom_tlvs(recipient_onion_max_custom_tlv_size.custom_tlvs.clone())
        );
 
        // If 1 byte is added to the custom TLV value, we'll fail to send prior to pathfinding.
@@ -330,9 +333,10 @@ fn blinded_path_with_custom_tlv() {
        let path = &[&nodes[1], &nodes[2], &nodes[3]];
        let args = PassAlongPathArgs::new(&nodes[0], path, amt_msat, payment_hash, events.pop().unwrap())
                .with_payment_secret(payment_secret)
-               .with_custom_tlvs(recipient_onion_allows_2_hops.custom_tlvs);
+               .with_custom_tlvs(recipient_onion_allows_2_hops.custom_tlvs.clone());
        do_pass_along_path(args);
        claim_payment_along_route(
                ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2], &nodes[3]]], payment_preimage)
+                       .with_custom_tlvs(recipient_onion_allows_2_hops.custom_tlvs)
        );
 }
index 83f3053b6e1528218ca8a0cd2df0e2b9437d736a..fdc44dee7b83b8140c6c2280e007058f38cb2c42 100644 (file)
@@ -3732,11 +3732,17 @@ fn do_test_custom_tlvs(spontaneous: bool, even_tlvs: bool, known_tlvs: bool) {
        match (known_tlvs, even_tlvs) {
                (true, _) => {
                        nodes[1].node.claim_funds_with_known_custom_tlvs(our_payment_preimage);
-                       let expected_total_fee_msat = pass_claimed_payment_along_route(ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1]]], our_payment_preimage));
+                       let expected_total_fee_msat = pass_claimed_payment_along_route(
+                               ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1]]], our_payment_preimage)
+                                       .with_custom_tlvs(custom_tlvs)
+                       );
                        expect_payment_sent!(&nodes[0], our_payment_preimage, Some(expected_total_fee_msat));
                },
                (false, false) => {
-                       claim_payment(&nodes[0], &[&nodes[1]], our_payment_preimage);
+                       claim_payment_along_route(
+                               ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1]]], our_payment_preimage)
+                                       .with_custom_tlvs(custom_tlvs)
+                       );
                },
                (false, true) => {
                        nodes[1].node.claim_funds(our_payment_preimage);
@@ -3823,10 +3829,11 @@ fn test_retry_custom_tlvs() {
        let path = &[&nodes[1], &nodes[2]];
        let args = PassAlongPathArgs::new(&nodes[0], path, 1_000_000, payment_hash, events.pop().unwrap())
                .with_payment_secret(payment_secret)
-               .with_custom_tlvs(custom_tlvs);
+               .with_custom_tlvs(custom_tlvs.clone());
        do_pass_along_path(args);
        claim_payment_along_route(
                ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage)
+                       .with_custom_tlvs(custom_tlvs)
        );
 }
 
@@ -3960,6 +3967,7 @@ fn do_test_custom_tlvs_consistency(first_tlvs: Vec<(u64, Vec<u8>)>, second_tlvs:
 
                do_claim_payment_along_route(
                        ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], our_payment_preimage)
+                               .with_custom_tlvs(expected_tlvs)
                );
                expect_payment_sent(&nodes[0], our_payment_preimage, Some(Some(2000)), true, true);
        } else {