mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-25 07:17:40 +01:00
Use PublicKey values in construct_keys_callback
Instead of accepting iterators yielding PublicKey by reference in utils::construct_keys_callback, take iterators yielding values since these implement Copy and need to be copied anyway. This will help avoid a situation when padding where both a reference and mutable reference are needed.
This commit is contained in:
parent
8d22f99740
commit
4922548bf2
4 changed files with 12 additions and 11 deletions
|
@ -374,14 +374,14 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
|
|||
secp_ctx: &Secp256k1<T>, intermediate_nodes: &[ForwardNode], recipient_node_id: PublicKey,
|
||||
context: MessageContext, session_priv: &SecretKey
|
||||
) -> Result<Vec<BlindedHop>, secp256k1::Error> {
|
||||
let pks = intermediate_nodes.iter().map(|node| &node.node_id)
|
||||
.chain(core::iter::once(&recipient_node_id));
|
||||
let pks = intermediate_nodes.iter().map(|node| node.node_id)
|
||||
.chain(core::iter::once(recipient_node_id));
|
||||
let tlvs = pks.clone()
|
||||
.skip(1) // The first node's TLVs contains the next node's pubkey
|
||||
.zip(intermediate_nodes.iter().map(|node| node.short_channel_id))
|
||||
.map(|(pubkey, scid)| match scid {
|
||||
Some(scid) => NextMessageHop::ShortChannelId(scid),
|
||||
None => NextMessageHop::NodeId(*pubkey),
|
||||
None => NextMessageHop::NodeId(pubkey),
|
||||
})
|
||||
.map(|next_hop| ControlTlvs::Forward(ForwardTlvs { next_hop, next_blinding_override: None }))
|
||||
.chain(core::iter::once(ControlTlvs::Receive(ReceiveTlvs{ context: Some(context) })));
|
||||
|
|
|
@ -462,8 +462,8 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
|
|||
secp_ctx: &Secp256k1<T>, intermediate_nodes: &[ForwardNode],
|
||||
payee_node_id: PublicKey, payee_tlvs: ReceiveTlvs, session_priv: &SecretKey
|
||||
) -> Result<Vec<BlindedHop>, secp256k1::Error> {
|
||||
let pks = intermediate_nodes.iter().map(|node| &node.node_id)
|
||||
.chain(core::iter::once(&payee_node_id));
|
||||
let pks = intermediate_nodes.iter().map(|node| node.node_id)
|
||||
.chain(core::iter::once(payee_node_id));
|
||||
let tlvs = intermediate_nodes.iter().map(|node| BlindedPaymentTlvsRef::Forward(&node.tlvs))
|
||||
.chain(core::iter::once(BlindedPaymentTlvsRef::Receive(&payee_tlvs)));
|
||||
utils::construct_blinded_hops(secp_ctx, pks, tlvs, session_priv)
|
||||
|
|
|
@ -91,13 +91,13 @@ pub(crate) fn construct_keys_callback<'a, T, I, F>(
|
|||
) -> Result<(), secp256k1::Error>
|
||||
where
|
||||
T: secp256k1::Signing + secp256k1::Verification,
|
||||
I: Iterator<Item=&'a PublicKey>,
|
||||
I: Iterator<Item=PublicKey>,
|
||||
F: FnMut(PublicKey, SharedSecret, PublicKey, [u8; 32], Option<PublicKey>, Option<Vec<u8>>),
|
||||
{
|
||||
build_keys_helper!(session_priv, secp_ctx, callback);
|
||||
|
||||
for pk in unblinded_path {
|
||||
build_keys_in_loop!(*pk, false, None);
|
||||
build_keys_in_loop!(pk, false, None);
|
||||
}
|
||||
if let Some(dest) = destination {
|
||||
match dest {
|
||||
|
@ -120,7 +120,7 @@ pub(crate) fn construct_blinded_hops<'a, T, I1, I2>(
|
|||
) -> Result<Vec<BlindedHop>, secp256k1::Error>
|
||||
where
|
||||
T: secp256k1::Signing + secp256k1::Verification,
|
||||
I1: Iterator<Item=&'a PublicKey>,
|
||||
I1: Iterator<Item=PublicKey>,
|
||||
I2: Iterator,
|
||||
I2::Item: Writeable
|
||||
{
|
||||
|
|
|
@ -925,7 +925,7 @@ where
|
|||
}
|
||||
};
|
||||
let (packet_payloads, packet_keys) = packet_payloads_and_keys(
|
||||
&secp_ctx, &intermediate_nodes, destination, contents, reply_path, &blinding_secret
|
||||
&secp_ctx, intermediate_nodes, destination, contents, reply_path, &blinding_secret
|
||||
)?;
|
||||
|
||||
let prng_seed = entropy_source.get_secure_random_bytes();
|
||||
|
@ -1784,7 +1784,7 @@ pub type SimpleRefOnionMessenger<
|
|||
/// Construct onion packet payloads and keys for sending an onion message along the given
|
||||
/// `unblinded_path` to the given `destination`.
|
||||
fn packet_payloads_and_keys<T: OnionMessageContents, S: secp256k1::Signing + secp256k1::Verification>(
|
||||
secp_ctx: &Secp256k1<S>, unblinded_path: &[PublicKey], destination: Destination, message: T,
|
||||
secp_ctx: &Secp256k1<S>, unblinded_path: Vec<PublicKey>, destination: Destination, message: T,
|
||||
mut reply_path: Option<BlindedMessagePath>, session_priv: &SecretKey
|
||||
) -> Result<(Vec<(Payload<T>, [u8; 32])>, Vec<onion_utils::OnionKeys>), SendError> {
|
||||
let num_hops = unblinded_path.len() + destination.num_hops();
|
||||
|
@ -1809,7 +1809,8 @@ fn packet_payloads_and_keys<T: OnionMessageContents, S: secp256k1::Signing + sec
|
|||
let mut blinded_path_idx = 0;
|
||||
let mut prev_control_tlvs_ss = None;
|
||||
let mut final_control_tlvs = None;
|
||||
utils::construct_keys_callback(secp_ctx, unblinded_path.iter(), Some(destination), session_priv,
|
||||
utils::construct_keys_callback(
|
||||
secp_ctx, unblinded_path.into_iter(), Some(destination), session_priv,
|
||||
|_, onion_packet_ss, ephemeral_pubkey, control_tlvs_ss, unblinded_pk_opt, enc_payload_opt| {
|
||||
if num_unblinded_hops != 0 && unblinded_path_idx < num_unblinded_hops {
|
||||
if let Some(ss) = prev_control_tlvs_ss.take() {
|
||||
|
|
Loading…
Add table
Reference in a new issue