From: Valentine Wallace Date: Mon, 15 Apr 2024 18:30:01 +0000 (-0400) Subject: Remove unnecessary RecipientOnionFields clone. X-Git-Tag: v0.0.124-beta~116^2~9 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=960dd658db6e66edd5255a5a4bddcbeb89a1e238;p=rust-lightning Remove unnecessary RecipientOnionFields clone. Doable now that we take Vecs by reference in OutboundOnionPayload. --- diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index f751ae7ab..f2b3bf15d 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -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, 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 }) } diff --git a/lightning/src/ln/onion_payment.rs b/lightning/src/ln/onion_payment.rs index 0886bf8f2..f62ca5d84 100644 --- a/lightning/src/ln/onion_payment.rs +++ b/lightning/src/ln/onion_payment.rs @@ -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); diff --git a/lightning/src/ln/onion_utils.rs b/lightning/src/ln/onion_utils.rs index 9b96726f8..a90dd837e 100644 --- a/lightning/src/ln/onion_utils.rs +++ b/lightning/src/ln/onion_utils.rs @@ -1122,7 +1122,7 @@ where /// `cur_block_height` should be set to the best known block height + 1. pub fn create_payment_onion( secp_ctx: &Secp256k1, 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, 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( let (onion_payloads, htlc_msat, htlc_cltv) = build_onion_payloads( &path, total_msat, - &recipient_onion, + recipient_onion, cur_block_height, keysend_preimage, )?; diff --git a/lightning/src/ln/outbound_payment.rs b/lightning/src/ln/outbound_payment.rs index 2dd1e2a74..c452a660e 100644 --- a/lightning/src/ln/outbound_payment.rs +++ b/lightning/src/ln/outbound_payment.rs @@ -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( - &self, route: &Route, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields, + &self, route: &Route, payment_hash: PaymentHash, recipient_onion: &RecipientOnionFields, keysend_preimage: Option, payment_id: PaymentId, recv_value_msat: Option, 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 }) } diff --git a/lightning/src/ln/payment_tests.rs b/lightning/src/ln/payment_tests.rs index 274c5d0df..2fc21eb23 100644 --- a/lightning/src/ln/payment_tests.rs +++ b/lightning/src/ln/payment_tests.rs @@ -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();