]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Remove unnecessary RecipientOnionFields clone.
authorValentine Wallace <vwallace@protonmail.com>
Mon, 15 Apr 2024 18:30:01 +0000 (14:30 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Tue, 14 May 2024 16:57:51 +0000 (09:57 -0700)
Doable now that we take Vecs by reference in OutboundOnionPayload.

lightning/src/ln/channelmanager.rs
lightning/src/ln/onion_payment.rs
lightning/src/ln/onion_utils.rs
lightning/src/ln/outbound_payment.rs
lightning/src/ln/payment_tests.rs

index f751ae7abcf406d43e7484faf1d8c5457bdd2785..f2b3bf15d39608f93d08774c43306cc31f102ac5 100644 (file)
@@ -4084,8 +4084,8 @@ where
        pub(crate) fn test_send_payment_along_path(&self, path: &Path, payment_hash: &PaymentHash, recipient_onion: RecipientOnionFields, total_value: u64, cur_height: u32, payment_id: PaymentId, keysend_preimage: &Option<PaymentPreimage>, session_priv_bytes: [u8; 32]) -> Result<(), APIError> {
                let _lck = self.total_consistency_lock.read().unwrap();
                self.send_payment_along_path(SendAlongPathArgs {
-                       path, payment_hash, recipient_onion, total_value, cur_height, payment_id, keysend_preimage,
-                       session_priv_bytes
+                       path, payment_hash, recipient_onion: &recipient_onion, total_value,
+                       cur_height, payment_id, keysend_preimage, session_priv_bytes
                })
        }
 
index 0886bf8f2f44a610db0fccabf3fcc7d11de87869..f62ca5d84e637bc4d95bb48d679f00151a756d0e 100644 (file)
@@ -563,8 +563,8 @@ mod tests {
                };
 
                let (onion, amount_msat, cltv_expiry) = create_payment_onion(
-                       &secp_ctx, &path, &session_priv, total_amt_msat, recipient_onion, cur_height,
-                       &payment_hash, &Some(preimage), prng_seed
+                       &secp_ctx, &path, &session_priv, total_amt_msat, &recipient_onion,
+                       cur_height, &payment_hash, &Some(preimage), prng_seed
                ).unwrap();
 
                let msg = make_update_add_msg(amount_msat, cltv_expiry, payment_hash, onion);
index 9b96726f82bd3861f2eb96a2bee0799604287d1f..a90dd837e56792ca329a582252d85b7ec1e60ef9 100644 (file)
@@ -1122,7 +1122,7 @@ where
 /// `cur_block_height` should be set to the best known block height + 1.
 pub fn create_payment_onion<T: secp256k1::Signing>(
        secp_ctx: &Secp256k1<T>, path: &Path, session_priv: &SecretKey, total_msat: u64,
-       recipient_onion: RecipientOnionFields, cur_block_height: u32, payment_hash: &PaymentHash,
+       recipient_onion: &RecipientOnionFields, cur_block_height: u32, payment_hash: &PaymentHash,
        keysend_preimage: &Option<PaymentPreimage>, prng_seed: [u8; 32],
 ) -> Result<(msgs::OnionPacket, u64, u32), APIError> {
        let onion_keys = construct_onion_keys(&secp_ctx, &path, &session_priv).map_err(|_| {
@@ -1131,7 +1131,7 @@ pub fn create_payment_onion<T: secp256k1::Signing>(
        let (onion_payloads, htlc_msat, htlc_cltv) = build_onion_payloads(
                &path,
                total_msat,
-               &recipient_onion,
+               recipient_onion,
                cur_block_height,
                keysend_preimage,
        )?;
index 2dd1e2a74096b50e6b0a69297238e6854f6f3a75..c452a660e4239dee0d96d42ea28552796b25ed35 100644 (file)
@@ -659,7 +659,7 @@ impl RecipientOnionFields {
 pub(super) struct SendAlongPathArgs<'a> {
        pub path: &'a Path,
        pub payment_hash: &'a PaymentHash,
-       pub recipient_onion: RecipientOnionFields,
+       pub recipient_onion: &'a RecipientOnionFields,
        pub total_value: u64,
        pub cur_height: u32,
        pub payment_id: PaymentId,
@@ -711,7 +711,7 @@ impl OutboundPayments {
                F: Fn(SendAlongPathArgs) -> Result<(), APIError>
        {
                let onion_session_privs = self.add_new_pending_payment(payment_hash, recipient_onion.clone(), payment_id, None, route, None, None, entropy_source, best_block_height)?;
-               self.pay_route_internal(route, payment_hash, recipient_onion, None, payment_id, None,
+               self.pay_route_internal(route, payment_hash, &recipient_onion, None, payment_id, None,
                        onion_session_privs, node_signer, best_block_height, &send_payment_along_path)
                        .map_err(|e| { self.remove_outbound_if_all_failed(payment_id, &e); e })
        }
@@ -756,7 +756,7 @@ impl OutboundPayments {
                let onion_session_privs = self.add_new_pending_payment(payment_hash, recipient_onion.clone(),
                        payment_id, Some(preimage), &route, None, None, entropy_source, best_block_height)?;
 
-               match self.pay_route_internal(route, payment_hash, recipient_onion, Some(preimage),
+               match self.pay_route_internal(route, payment_hash, &recipient_onion, Some(preimage),
                        payment_id, None, onion_session_privs, node_signer, best_block_height, &send_payment_along_path
                ) {
                        Ok(()) => Ok(payment_hash),
@@ -932,8 +932,9 @@ impl OutboundPayments {
                                RetryableSendFailure::DuplicatePayment
                        })?;
 
-               let res = self.pay_route_internal(&route, payment_hash, recipient_onion, keysend_preimage, payment_id, None,
-                       onion_session_privs, node_signer, best_block_height, &send_payment_along_path);
+               let res = self.pay_route_internal(&route, payment_hash, &recipient_onion,
+                       keysend_preimage, payment_id, None, onion_session_privs, node_signer,
+                       best_block_height, &send_payment_along_path);
                log_info!(logger, "Sending payment with id {} and hash {} returned {:?}",
                        payment_id, payment_hash, res);
                if let Err(e) = res {
@@ -1090,7 +1091,7 @@ impl OutboundPayments {
                                }
                        }
                };
-               let res = self.pay_route_internal(&route, payment_hash, recipient_onion, keysend_preimage,
+               let res = self.pay_route_internal(&route, payment_hash, &recipient_onion, keysend_preimage,
                        payment_id, Some(total_msat), onion_session_privs, node_signer, best_block_height,
                        &send_payment_along_path);
                log_info!(logger, "Result retrying payment id {}: {:?}", &payment_id, res);
@@ -1201,7 +1202,8 @@ impl OutboundPayments {
                        RecipientOnionFields::secret_only(payment_secret), payment_id, None, &route, None, None,
                        entropy_source, best_block_height)?;
 
-               match self.pay_route_internal(&route, payment_hash, RecipientOnionFields::spontaneous_empty(),
+               let recipient_onion_fields = RecipientOnionFields::spontaneous_empty();
+               match self.pay_route_internal(&route, payment_hash, &recipient_onion_fields,
                        None, payment_id, None, onion_session_privs, node_signer, best_block_height, &send_payment_along_path
                ) {
                        Ok(()) => Ok((payment_hash, payment_id)),
@@ -1309,7 +1311,7 @@ impl OutboundPayments {
        }
 
        fn pay_route_internal<NS: Deref, F>(
-               &self, route: &Route, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields,
+               &self, route: &Route, payment_hash: PaymentHash, recipient_onion: &RecipientOnionFields,
                keysend_preimage: Option<PaymentPreimage>, payment_id: PaymentId, recv_value_msat: Option<u64>,
                onion_session_privs: Vec<[u8; 32]>, node_signer: &NS, best_block_height: u32,
                send_payment_along_path: &F
@@ -1364,8 +1366,9 @@ impl OutboundPayments {
                debug_assert_eq!(route.paths.len(), onion_session_privs.len());
                for (path, session_priv_bytes) in route.paths.iter().zip(onion_session_privs.into_iter()) {
                        let mut path_res = send_payment_along_path(SendAlongPathArgs {
-                               path: &path, payment_hash: &payment_hash, recipient_onion: recipient_onion.clone(),
-                               total_value, cur_height, payment_id, keysend_preimage: &keysend_preimage, session_priv_bytes
+                               path: &path, payment_hash: &payment_hash, recipient_onion, total_value,
+                               cur_height, payment_id, keysend_preimage: &keysend_preimage,
+                               session_priv_bytes
                        });
                        match path_res {
                                Ok(_) => {},
@@ -1448,9 +1451,9 @@ impl OutboundPayments {
                NS::Target: NodeSigner,
                F: Fn(SendAlongPathArgs) -> Result<(), APIError>,
        {
-               self.pay_route_internal(route, payment_hash, recipient_onion, keysend_preimage, payment_id,
-                       recv_value_msat, onion_session_privs, node_signer, best_block_height,
-                       &send_payment_along_path)
+               self.pay_route_internal(route, payment_hash, &recipient_onion,
+                       keysend_preimage, payment_id, recv_value_msat, onion_session_privs,
+                       node_signer, best_block_height, &send_payment_along_path)
                        .map_err(|e| { self.remove_outbound_if_all_failed(payment_id, &e); e })
        }
 
index 274c5d0dfec12203e096da453c39bb379fcb730f..2fc21eb23853612aa4518c09cc81b49cf3098d45 100644 (file)
@@ -4228,7 +4228,7 @@ fn peel_payment_onion_custom_tlvs() {
        let payment_hash = PaymentHash(Sha256::hash(&keysend_preimage.0).to_byte_array());
 
        let (onion_routing_packet, first_hop_msat, cltv_expiry) = onion_utils::create_payment_onion(
-               &secp_ctx, &route.paths[0], &session_priv, amt_msat, recipient_onion.clone(),
+               &secp_ctx, &route.paths[0], &session_priv, amt_msat, &recipient_onion,
                nodes[0].best_block_info().1, &payment_hash, &Some(keysend_preimage), prng_seed
        ).unwrap();