Skip to content

Commit 60f0288

Browse files
Remove unnecessary RecipientOnionFields clone.
Doable now that we take Vecs by reference in OutboundOnionPayload.
1 parent a7b6bac commit 60f0288

File tree

5 files changed

+23
-20
lines changed

5 files changed

+23
-20
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4086,8 +4086,8 @@ where
40864086
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> {
40874087
let _lck = self.total_consistency_lock.read().unwrap();
40884088
self.send_payment_along_path(SendAlongPathArgs {
4089-
path, payment_hash, recipient_onion, total_value, cur_height, payment_id, keysend_preimage,
4090-
session_priv_bytes
4089+
path, payment_hash, recipient_onion: &recipient_onion, total_value,
4090+
cur_height, payment_id, keysend_preimage, session_priv_bytes
40914091
})
40924092
}
40934093

lightning/src/ln/onion_payment.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,8 @@ mod tests {
564564
};
565565

566566
let (onion, amount_msat, cltv_expiry) = create_payment_onion(
567-
&secp_ctx, &path, &session_priv, total_amt_msat, recipient_onion, cur_height,
568-
&payment_hash, &Some(preimage), prng_seed
567+
&secp_ctx, &path, &session_priv, total_amt_msat, &recipient_onion,
568+
cur_height, &payment_hash, &Some(preimage), prng_seed
569569
).unwrap();
570570

571571
let msg = make_update_add_msg(amount_msat, cltv_expiry, payment_hash, onion);

lightning/src/ln/onion_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ where
11221122
/// `cur_block_height` should be set to the best known block height + 1.
11231123
pub fn create_payment_onion<T: secp256k1::Signing>(
11241124
secp_ctx: &Secp256k1<T>, path: &Path, session_priv: &SecretKey, total_msat: u64,
1125-
recipient_onion: RecipientOnionFields, cur_block_height: u32, payment_hash: &PaymentHash,
1125+
recipient_onion: &RecipientOnionFields, cur_block_height: u32, payment_hash: &PaymentHash,
11261126
keysend_preimage: &Option<PaymentPreimage>, prng_seed: [u8; 32],
11271127
) -> Result<(msgs::OnionPacket, u64, u32), APIError> {
11281128
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>(
11311131
let (onion_payloads, htlc_msat, htlc_cltv) = build_onion_payloads(
11321132
&path,
11331133
total_msat,
1134-
&recipient_onion,
1134+
recipient_onion,
11351135
cur_block_height,
11361136
keysend_preimage,
11371137
)?;

lightning/src/ln/outbound_payment.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ impl RecipientOnionFields {
659659
pub(super) struct SendAlongPathArgs<'a> {
660660
pub path: &'a Path,
661661
pub payment_hash: &'a PaymentHash,
662-
pub recipient_onion: RecipientOnionFields,
662+
pub recipient_onion: &'a RecipientOnionFields,
663663
pub total_value: u64,
664664
pub cur_height: u32,
665665
pub payment_id: PaymentId,
@@ -711,7 +711,7 @@ impl OutboundPayments {
711711
F: Fn(SendAlongPathArgs) -> Result<(), APIError>
712712
{
713713
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)?;
714-
self.pay_route_internal(route, payment_hash, recipient_onion, None, payment_id, None,
714+
self.pay_route_internal(route, payment_hash, &recipient_onion, None, payment_id, None,
715715
onion_session_privs, node_signer, best_block_height, &send_payment_along_path)
716716
.map_err(|e| { self.remove_outbound_if_all_failed(payment_id, &e); e })
717717
}
@@ -756,7 +756,7 @@ impl OutboundPayments {
756756
let onion_session_privs = self.add_new_pending_payment(payment_hash, recipient_onion.clone(),
757757
payment_id, Some(preimage), &route, None, None, entropy_source, best_block_height)?;
758758

759-
match self.pay_route_internal(route, payment_hash, recipient_onion, Some(preimage),
759+
match self.pay_route_internal(route, payment_hash, &recipient_onion, Some(preimage),
760760
payment_id, None, onion_session_privs, node_signer, best_block_height, &send_payment_along_path
761761
) {
762762
Ok(()) => Ok(payment_hash),
@@ -932,8 +932,9 @@ impl OutboundPayments {
932932
RetryableSendFailure::DuplicatePayment
933933
})?;
934934

935-
let res = self.pay_route_internal(&route, payment_hash, recipient_onion, keysend_preimage, payment_id, None,
936-
onion_session_privs, node_signer, best_block_height, &send_payment_along_path);
935+
let res = self.pay_route_internal(&route, payment_hash, &recipient_onion,
936+
keysend_preimage, payment_id, None, onion_session_privs, node_signer,
937+
best_block_height, &send_payment_along_path);
937938
log_info!(logger, "Sending payment with id {} and hash {} returned {:?}",
938939
payment_id, payment_hash, res);
939940
if let Err(e) = res {
@@ -1090,7 +1091,7 @@ impl OutboundPayments {
10901091
}
10911092
}
10921093
};
1093-
let res = self.pay_route_internal(&route, payment_hash, recipient_onion, keysend_preimage,
1094+
let res = self.pay_route_internal(&route, payment_hash, &recipient_onion, keysend_preimage,
10941095
payment_id, Some(total_msat), onion_session_privs, node_signer, best_block_height,
10951096
&send_payment_along_path);
10961097
log_info!(logger, "Result retrying payment id {}: {:?}", &payment_id, res);
@@ -1201,7 +1202,8 @@ impl OutboundPayments {
12011202
RecipientOnionFields::secret_only(payment_secret), payment_id, None, &route, None, None,
12021203
entropy_source, best_block_height)?;
12031204

1204-
match self.pay_route_internal(&route, payment_hash, RecipientOnionFields::spontaneous_empty(),
1205+
let recipient_onion_fields = RecipientOnionFields::spontaneous_empty();
1206+
match self.pay_route_internal(&route, payment_hash, &recipient_onion_fields,
12051207
None, payment_id, None, onion_session_privs, node_signer, best_block_height, &send_payment_along_path
12061208
) {
12071209
Ok(()) => Ok((payment_hash, payment_id)),
@@ -1309,7 +1311,7 @@ impl OutboundPayments {
13091311
}
13101312

13111313
fn pay_route_internal<NS: Deref, F>(
1312-
&self, route: &Route, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields,
1314+
&self, route: &Route, payment_hash: PaymentHash, recipient_onion: &RecipientOnionFields,
13131315
keysend_preimage: Option<PaymentPreimage>, payment_id: PaymentId, recv_value_msat: Option<u64>,
13141316
onion_session_privs: Vec<[u8; 32]>, node_signer: &NS, best_block_height: u32,
13151317
send_payment_along_path: &F
@@ -1364,8 +1366,9 @@ impl OutboundPayments {
13641366
debug_assert_eq!(route.paths.len(), onion_session_privs.len());
13651367
for (path, session_priv_bytes) in route.paths.iter().zip(onion_session_privs.into_iter()) {
13661368
let mut path_res = send_payment_along_path(SendAlongPathArgs {
1367-
path: &path, payment_hash: &payment_hash, recipient_onion: recipient_onion.clone(),
1368-
total_value, cur_height, payment_id, keysend_preimage: &keysend_preimage, session_priv_bytes
1369+
path: &path, payment_hash: &payment_hash, recipient_onion, total_value,
1370+
cur_height, payment_id, keysend_preimage: &keysend_preimage,
1371+
session_priv_bytes
13691372
});
13701373
match path_res {
13711374
Ok(_) => {},
@@ -1448,9 +1451,9 @@ impl OutboundPayments {
14481451
NS::Target: NodeSigner,
14491452
F: Fn(SendAlongPathArgs) -> Result<(), APIError>,
14501453
{
1451-
self.pay_route_internal(route, payment_hash, recipient_onion, keysend_preimage, payment_id,
1452-
recv_value_msat, onion_session_privs, node_signer, best_block_height,
1453-
&send_payment_along_path)
1454+
self.pay_route_internal(route, payment_hash, &recipient_onion,
1455+
keysend_preimage, payment_id, recv_value_msat, onion_session_privs,
1456+
node_signer, best_block_height, &send_payment_along_path)
14541457
.map_err(|e| { self.remove_outbound_if_all_failed(payment_id, &e); e })
14551458
}
14561459

lightning/src/ln/payment_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4241,7 +4241,7 @@ fn peel_payment_onion_custom_tlvs() {
42414241
let payment_hash = PaymentHash(Sha256::hash(&keysend_preimage.0).to_byte_array());
42424242

42434243
let (onion_routing_packet, first_hop_msat, cltv_expiry) = onion_utils::create_payment_onion(
4244-
&secp_ctx, &route.paths[0], &session_priv, amt_msat, recipient_onion.clone(),
4244+
&secp_ctx, &route.paths[0], &session_priv, amt_msat, &recipient_onion,
42454245
nodes[0].best_block_info().1, &payment_hash, &Some(keysend_preimage), prng_seed
42464246
).unwrap();
42474247

0 commit comments

Comments
 (0)