From: Valentine Wallace Date: Wed, 24 Jul 2024 18:56:31 +0000 (-0400) Subject: Avoid && in public API for onion peeling/decoding. X-Git-Tag: v0.0.124-beta~3^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=6f6115f177b7c0a977166c3be28ee102d166775b;p=rust-lightning Avoid && in public API for onion peeling/decoding. No reason to take a reference to a Deref. --- diff --git a/fuzz/src/onion_hop_data.rs b/fuzz/src/onion_hop_data.rs index 36aebb4e1..91bfa142b 100644 --- a/fuzz/src/onion_hop_data.rs +++ b/fuzz/src/onion_hop_data.rs @@ -21,7 +21,7 @@ pub fn onion_hop_data_test(data: &[u8], _out: Out) { let node_signer = test_utils::TestNodeSigner::new(test_utils::privkey(42)); let _ = , - &&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 _ = , - &&test_utils::TestNodeSigner, + &test_utils::TestNodeSigner, )>>::read(&mut r, (None, &&node_signer)); } diff --git a/lightning/src/ln/blinded_payment_tests.rs b/lightning/src/ln/blinded_payment_tests.rs index abc895f87..12c0dc33a 100644 --- a/lightning/src/ln/blinded_payment_tests.rs +++ b/lightning/src/ln/blinded_payment_tests.rs @@ -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") diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index e08b45558..c84e11cef 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -3832,7 +3832,7 @@ where (onion_utils::Hop, [u8; 32], Option>), 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 }) => { diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 83ce4f914..ad63f28e7 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -2756,8 +2756,8 @@ impl Writeable for OutboundTrampolinePayload { } -impl ReadableArgs<(Option, &NS)> for InboundOnionPayload where NS::Target: NodeSigner { - fn read(r: &mut R, args: (Option, &NS)) -> Result { +impl ReadableArgs<(Option, NS)> for InboundOnionPayload where NS::Target: NodeSigner { + fn read(r: &mut R, args: (Option, NS)) -> Result { 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 = >::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); - , &&test_utils::TestKeysInterface)>> + , &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. diff --git a/lightning/src/ln/onion_payment.rs b/lightning/src/ln/onion_payment.rs index 1163a5e63..3afe50859 100644 --- a/lightning/src/ln/onion_payment.rs +++ b/lightning/src/ln/onion_payment.rs @@ -280,7 +280,7 @@ pub(super) fn create_recv_pending_htlc_info( /// /// [`Event::PaymentClaimable`]: crate::events::Event::PaymentClaimable pub fn peel_payment_onion( - msg: &msgs::UpdateAddHTLC, node_signer: &NS, logger: &L, secp_ctx: &Secp256k1, + msg: &msgs::UpdateAddHTLC, node_signer: NS, logger: L, secp_ctx: &Secp256k1, cur_height: u32, accept_mpp_keysend: bool, allow_skimmed_fees: bool, ) -> Result where @@ -346,7 +346,7 @@ pub(super) struct NextPacketDetails { } pub(super) fn decode_incoming_update_add_htlc_onion( - msg: &msgs::UpdateAddHTLC, node_signer: &NS, logger: &L, secp_ctx: &Secp256k1, + msg: &msgs::UpdateAddHTLC, node_signer: NS, logger: L, secp_ctx: &Secp256k1, ) -> Result<(onion_utils::Hop, [u8; 32], Option), 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 { diff --git a/lightning/src/ln/onion_utils.rs b/lightning/src/ln/onion_utils.rs index 70a7c6bf8..a3372dda8 100644 --- a/lightning/src/ln/onion_utils.rs +++ b/lightning/src/ln/onion_utils.rs @@ -1133,7 +1133,7 @@ pub(crate) enum OnionDecodeErr { pub(crate) fn decode_next_payment_hop( shared_secret: [u8; 32], hop_data: &[u8], hmac_bytes: [u8; 32], payment_hash: PaymentHash, - blinding_point: Option, node_signer: &NS, + blinding_point: Option, node_signer: NS, ) -> Result where NS::Target: NodeSigner, diff --git a/lightning/src/ln/payment_tests.rs b/lightning/src/ln/payment_tests.rs index 083c32e53..00d7b9c47 100644 --- a/lightning/src/ln/payment_tests.rs +++ b/lightning/src/ln/payment_tests.rs @@ -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));