]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Avoid && in public API for onion peeling/decoding.
authorValentine Wallace <vwallace@protonmail.com>
Wed, 24 Jul 2024 18:56:31 +0000 (14:56 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Mon, 19 Aug 2024 16:47:42 +0000 (12:47 -0400)
No reason to take a reference to a Deref.

fuzz/src/onion_hop_data.rs
lightning/src/ln/blinded_payment_tests.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/msgs.rs
lightning/src/ln/onion_payment.rs
lightning/src/ln/onion_utils.rs
lightning/src/ln/payment_tests.rs

index 36aebb4e194e6181cff4b6310e1c481f51148dbd..91bfa142b683192883aa5283a3e8e2f9ab730e09 100644 (file)
@@ -21,7 +21,7 @@ pub fn onion_hop_data_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        let node_signer = test_utils::TestNodeSigner::new(test_utils::privkey(42));
        let _ = <lightning::ln::msgs::InboundOnionPayload as ReadableArgs<(
                Option<PublicKey>,
-               &&test_utils::TestNodeSigner,
+               &test_utils::TestNodeSigner,
        )>>::read(&mut r, (None, &&node_signer));
 }
 
@@ -34,6 +34,6 @@ pub extern "C" fn onion_hop_data_run(data: *const u8, datalen: usize) {
        let node_signer = test_utils::TestNodeSigner::new(test_utils::privkey(42));
        let _ = <lightning::ln::msgs::InboundOnionPayload as ReadableArgs<(
                Option<PublicKey>,
-               &&test_utils::TestNodeSigner,
+               &test_utils::TestNodeSigner,
        )>>::read(&mut r, (None, &&node_signer));
 }
index abc895f871a8fca572d0443c1efdc49cefa0f0ac..12c0dc33a0060f64d1330af28c78e5e7b454b269 100644 (file)
@@ -1483,7 +1483,7 @@ fn route_blinding_spec_test_vector() {
        // < MIN_CLTV_EXPIRY_DELTA).
        let (bob_peeled_onion, _, next_packet_details_opt) =
                match onion_payment::decode_incoming_update_add_htlc_onion(
-                       &bob_update_add, &&bob_node_signer, &&logger, &secp_ctx
+                       &bob_update_add, &bob_node_signer, &logger, &secp_ctx
                ) {
                        Ok(res) => res,
                        _ => panic!("Unexpected error")
@@ -1517,7 +1517,7 @@ fn route_blinding_spec_test_vector() {
        let carol_node_signer = TestEcdhSigner { node_secret: carol_secret };
        let (carol_peeled_onion, _, next_packet_details_opt) =
                match onion_payment::decode_incoming_update_add_htlc_onion(
-                       &carol_update_add, &&carol_node_signer, &&logger, &secp_ctx
+                       &carol_update_add, &carol_node_signer, &logger, &secp_ctx
                ) {
                        Ok(res) => res,
                        _ => panic!("Unexpected error")
@@ -1551,7 +1551,7 @@ fn route_blinding_spec_test_vector() {
        let dave_node_signer = TestEcdhSigner { node_secret: dave_secret };
        let (dave_peeled_onion, _, next_packet_details_opt) =
                match onion_payment::decode_incoming_update_add_htlc_onion(
-                       &dave_update_add, &&dave_node_signer, &&logger, &secp_ctx
+                       &dave_update_add, &dave_node_signer, &logger, &secp_ctx
                ) {
                        Ok(res) => res,
                        _ => panic!("Unexpected error")
@@ -1586,7 +1586,7 @@ fn route_blinding_spec_test_vector() {
        // We can't decode the final payload because it contains a path_id and is missing some LDK
        // specific fields.
        match onion_payment::decode_incoming_update_add_htlc_onion(
-               &eve_update_add, &&eve_node_signer, &&logger, &secp_ctx
+               &eve_update_add, &eve_node_signer, &logger, &secp_ctx
        ) {
                Err(HTLCFailureMsg::Malformed(msg)) => assert_eq!(msg.failure_code, INVALID_ONION_BLINDING),
                _ => panic!("Unexpected error")
index e08b45558c608a06f8793742d9a8d657d3b09f94..c84e11cef80c6e85723a435a64c8a30ff9c06ed4 100644 (file)
@@ -3832,7 +3832,7 @@ where
                (onion_utils::Hop, [u8; 32], Option<Result<PublicKey, secp256k1::Error>>), HTLCFailureMsg
        > {
                let (next_hop, shared_secret, next_packet_details_opt) = decode_incoming_update_add_htlc_onion(
-                       msg, &self.node_signer, &self.logger, &self.secp_ctx
+                       msg, &*self.node_signer, &*self.logger, &self.secp_ctx
                )?;
 
                let next_packet_details = match next_packet_details_opt {
@@ -5049,7 +5049,7 @@ where
                        let mut htlc_fails = Vec::new();
                        for update_add_htlc in &update_add_htlcs {
                                let (next_hop, shared_secret, next_packet_details_opt) = match decode_incoming_update_add_htlc_onion(
-                                       &update_add_htlc, &self.node_signer, &self.logger, &self.secp_ctx
+                                       &update_add_htlc, &*self.node_signer, &*self.logger, &self.secp_ctx
                                ) {
                                        Ok(decoded_onion) => decoded_onion,
                                        Err(htlc_fail) => {
@@ -5226,7 +5226,7 @@ where
                                                                                                let phantom_shared_secret = self.node_signer.ecdh(Recipient::PhantomNode, &onion_packet.public_key.unwrap(), None).unwrap().secret_bytes();
                                                                                                let next_hop = match onion_utils::decode_next_payment_hop(
                                                                                                        phantom_shared_secret, &onion_packet.hop_data, onion_packet.hmac,
-                                                                                                       payment_hash, None, &self.node_signer
+                                                                                                       payment_hash, None, &*self.node_signer
                                                                                                ) {
                                                                                                        Ok(res) => res,
                                                                                                        Err(onion_utils::OnionDecodeErr::Malformed { err_msg, err_code }) => {
index 83ce4f91409a31cb750e599ff0c2913bfb2e52e9..ad63f28e7c86347b4b5f0dc3debe79d4c84c8558 100644 (file)
@@ -2756,8 +2756,8 @@ impl Writeable for OutboundTrampolinePayload {
 }
 
 
-impl<NS: Deref> ReadableArgs<(Option<PublicKey>, &NS)> for InboundOnionPayload where NS::Target: NodeSigner {
-       fn read<R: Read>(r: &mut R, args: (Option<PublicKey>, &NS)) -> Result<Self, DecodeError> {
+impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload where NS::Target: NodeSigner {
+       fn read<R: Read>(r: &mut R, args: (Option<PublicKey>, NS)) -> Result<Self, DecodeError> {
                let (update_add_blinding_point, node_signer) = args;
 
                let mut amt = None;
@@ -4456,7 +4456,7 @@ mod tests {
                assert_eq!(encoded_value, target_value);
 
                let node_signer = test_utils::TestKeysInterface::new(&[42; 32], Network::Testnet);
-               let inbound_msg = ReadableArgs::read(&mut Cursor::new(&target_value[..]), (None, &&node_signer)).unwrap();
+               let inbound_msg = ReadableArgs::read(&mut Cursor::new(&target_value[..]), (None, &node_signer)).unwrap();
                if let msgs::InboundOnionPayload::Forward {
                        short_channel_id, amt_to_forward, outgoing_cltv_value
                } = inbound_msg {
@@ -4481,7 +4481,7 @@ mod tests {
                assert_eq!(encoded_value, target_value);
 
                let node_signer = test_utils::TestKeysInterface::new(&[42; 32], Network::Testnet);
-               let inbound_msg = ReadableArgs::read(&mut Cursor::new(&target_value[..]), (None, &&node_signer)).unwrap();
+               let inbound_msg = ReadableArgs::read(&mut Cursor::new(&target_value[..]), (None, &node_signer)).unwrap();
                if let msgs::InboundOnionPayload::Receive {
                        payment_data: None, sender_intended_htlc_amt_msat, cltv_expiry_height, ..
                } = inbound_msg {
@@ -4509,7 +4509,7 @@ mod tests {
                assert_eq!(encoded_value, target_value);
 
                let node_signer = test_utils::TestKeysInterface::new(&[42; 32], Network::Testnet);
-               let inbound_msg = ReadableArgs::read(&mut Cursor::new(&target_value[..]), (None, &&node_signer)).unwrap();
+               let inbound_msg = ReadableArgs::read(&mut Cursor::new(&target_value[..]), (None, &node_signer)).unwrap();
                if let msgs::InboundOnionPayload::Receive {
                        payment_data: Some(FinalOnionHopData {
                                payment_secret,
@@ -4545,7 +4545,7 @@ mod tests {
                };
                let encoded_value = msg.encode();
                let node_signer = test_utils::TestKeysInterface::new(&[42; 32], Network::Testnet);
-               assert!(msgs::InboundOnionPayload::read(&mut Cursor::new(&encoded_value[..]), (None, &&node_signer)).is_err());
+               assert!(msgs::InboundOnionPayload::read(&mut Cursor::new(&encoded_value[..]), (None, &node_signer)).is_err());
                let good_type_range_tlvs = vec![
                        ((1 << 16) - 3, vec![42]),
                        ((1 << 16) - 1, vec![42; 32]),
@@ -4554,7 +4554,7 @@ mod tests {
                        *custom_tlvs = &good_type_range_tlvs;
                }
                let encoded_value = msg.encode();
-               let inbound_msg = ReadableArgs::read(&mut Cursor::new(&encoded_value[..]), (None, &&node_signer)).unwrap();
+               let inbound_msg = ReadableArgs::read(&mut Cursor::new(&encoded_value[..]), (None, &node_signer)).unwrap();
                match inbound_msg {
                        msgs::InboundOnionPayload::Receive { custom_tlvs, .. } => assert!(custom_tlvs.is_empty()),
                        _ => panic!(),
@@ -4579,7 +4579,7 @@ mod tests {
                let target_value = <Vec<u8>>::from_hex("2e02080badf00d010203040404ffffffffff0000000146c6616b021234ff0000000146c6616f084242424242424242").unwrap();
                assert_eq!(encoded_value, target_value);
                let node_signer = test_utils::TestKeysInterface::new(&[42; 32], Network::Testnet);
-               let inbound_msg: msgs::InboundOnionPayload = ReadableArgs::read(&mut Cursor::new(&target_value[..]), (None, &&node_signer)).unwrap();
+               let inbound_msg: msgs::InboundOnionPayload = ReadableArgs::read(&mut Cursor::new(&target_value[..]), (None, &node_signer)).unwrap();
                if let msgs::InboundOnionPayload::Receive {
                        payment_data: None,
                        payment_metadata: None,
@@ -4809,7 +4809,7 @@ mod tests {
                let mut rd = Cursor::new(&big_payload[..]);
 
                let node_signer = test_utils::TestKeysInterface::new(&[42; 32], Network::Testnet);
-               <msgs::InboundOnionPayload as ReadableArgs<(Option<PublicKey>, &&test_utils::TestKeysInterface)>>
+               <msgs::InboundOnionPayload as ReadableArgs<(Option<PublicKey>, &test_utils::TestKeysInterface)>>
                        ::read(&mut rd, (None, &&node_signer)).unwrap();
        }
        // see above test, needs to be a separate method for use of the serialization macros.
index 1163a5e638fd3f45996171cc51bef3b195b6a2b4..3afe5085966952ab85793848b52739ab99f7e950 100644 (file)
@@ -280,7 +280,7 @@ pub(super) fn create_recv_pending_htlc_info(
 ///
 /// [`Event::PaymentClaimable`]: crate::events::Event::PaymentClaimable
 pub fn peel_payment_onion<NS: Deref, L: Deref, T: secp256k1::Verification>(
-       msg: &msgs::UpdateAddHTLC, node_signer: &NS, logger: &L, secp_ctx: &Secp256k1<T>,
+       msg: &msgs::UpdateAddHTLC, node_signer: NS, logger: L, secp_ctx: &Secp256k1<T>,
        cur_height: u32, accept_mpp_keysend: bool, allow_skimmed_fees: bool,
 ) -> Result<PendingHTLCInfo, InboundHTLCErr>
 where
@@ -346,7 +346,7 @@ pub(super) struct NextPacketDetails {
 }
 
 pub(super) fn decode_incoming_update_add_htlc_onion<NS: Deref, L: Deref, T: secp256k1::Verification>(
-       msg: &msgs::UpdateAddHTLC, node_signer: &NS, logger: &L, secp_ctx: &Secp256k1<T>,
+       msg: &msgs::UpdateAddHTLC, node_signer: NS, logger: L, secp_ctx: &Secp256k1<T>,
 ) -> Result<(onion_utils::Hop, [u8; 32], Option<NextPacketDetails>), HTLCFailureMsg>
 where
        NS::Target: NodeSigner,
@@ -574,7 +574,7 @@ mod tests {
                let msg = make_update_add_msg(amount_msat, cltv_expiry, payment_hash, onion);
                let logger = test_utils::TestLogger::with_id("bob".to_string());
 
-               let peeled = peel_payment_onion(&msg, &&bob, &&logger, &secp_ctx, cur_height, true, false)
+               let peeled = peel_payment_onion(&msg, &bob, &logger, &secp_ctx, cur_height, true, false)
                        .map_err(|e| e.msg).unwrap();
 
                let next_onion = match peeled.routing {
@@ -585,7 +585,7 @@ mod tests {
                };
 
                let msg2 = make_update_add_msg(amount_msat, cltv_expiry, payment_hash, next_onion);
-               let peeled2 = peel_payment_onion(&msg2, &&charlie, &&logger, &secp_ctx, cur_height, true, false)
+               let peeled2 = peel_payment_onion(&msg2, &charlie, &logger, &secp_ctx, cur_height, true, false)
                        .map_err(|e| e.msg).unwrap();
 
                match peeled2.routing {
index 70a7c6bf8bb59db986eba126735244f534b90486..a3372dda8e0623f3202698482962d311bffab213 100644 (file)
@@ -1133,7 +1133,7 @@ pub(crate) enum OnionDecodeErr {
 
 pub(crate) fn decode_next_payment_hop<NS: Deref>(
        shared_secret: [u8; 32], hop_data: &[u8], hmac_bytes: [u8; 32], payment_hash: PaymentHash,
-       blinding_point: Option<PublicKey>, node_signer: &NS,
+       blinding_point: Option<PublicKey>, node_signer: NS,
 ) -> Result<Hop, OnionDecodeErr>
 where
        NS::Target: NodeSigner,
index 083c32e53938e23c8b38e72c971f9a921b6d33ce..00d7b9c475a46c49618eeb0c41d8240340ec30d4 100644 (file)
@@ -4284,7 +4284,7 @@ fn peel_payment_onion_custom_tlvs() {
                blinding_point: None,
        };
        let peeled_onion = crate::ln::onion_payment::peel_payment_onion(
-               &update_add, &&chanmon_cfgs[1].keys_manager, &&chanmon_cfgs[1].logger, &secp_ctx,
+               &update_add, &chanmon_cfgs[1].keys_manager, &chanmon_cfgs[1].logger, &secp_ctx,
                nodes[1].best_block_info().1, true, false
        ).unwrap();
        assert_eq!(peeled_onion.incoming_amt_msat, Some(amt_msat));