]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Avoid slices without inner references
authorMatt Corallo <git@bluematt.me>
Thu, 28 Sep 2023 03:05:09 +0000 (03:05 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 3 Sep 2024 14:00:24 +0000 (14:00 +0000)
As we cannot express slices without inner references in bindings
wrappers.

lightning/src/blinded_path/payment.rs
lightning/src/ln/channelmanager.rs
lightning/src/routing/gossip.rs
lightning/src/routing/router.rs

index f741cead26dc256d113b2be6a442a50efa396e7b..320547962ce9ed98d87146bad62955e1cbd007ad 100644 (file)
@@ -90,7 +90,7 @@ impl BlindedPaymentPath {
                // be in relation to a specific channel.
                let htlc_maximum_msat = u64::max_value();
                Self::new(
-                       &[], payee_node_id, payee_tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta,
+                       Vec::new(), payee_node_id, payee_tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta,
                        entropy_source, secp_ctx
                )
        }
@@ -103,7 +103,7 @@ impl BlindedPaymentPath {
        /// * any unknown features are required in the provided [`ForwardTlvs`]
        //  TODO: make all payloads the same size with padding + add dummy hops
        pub fn new<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
-               intermediate_nodes: &[PaymentForwardNode], payee_node_id: PublicKey,
+               intermediate_nodes: Vec<PaymentForwardNode>, payee_node_id: PublicKey,
                payee_tlvs: ReceiveTlvs, htlc_maximum_msat: u64, min_final_cltv_expiry_delta: u16,
                entropy_source: ES, secp_ctx: &Secp256k1<T>,
        ) -> Result<Self, ()> where ES::Target: EntropySource {
@@ -114,14 +114,14 @@ impl BlindedPaymentPath {
                let blinding_secret = SecretKey::from_slice(&blinding_secret_bytes[..]).expect("RNG is busted");
 
                let blinded_payinfo = compute_payinfo(
-                       intermediate_nodes, &payee_tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta
+                       &intermediate_nodes, &payee_tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta
                )?;
                Ok(Self {
                        inner_path: BlindedPath {
                                introduction_node,
                                blinding_point: PublicKey::from_secret_key(secp_ctx, &blinding_secret),
                                blinded_hops: blinded_hops(
-                                       secp_ctx, intermediate_nodes, payee_node_id, payee_tlvs, &blinding_secret
+                                       secp_ctx, &intermediate_nodes, payee_node_id, payee_tlvs, &blinding_secret
                                ).map_err(|_| ())?,
                        },
                        payinfo: blinded_payinfo
index 6bcf3099b6de39a01c3b323aa261a2931dbaee7a..2a16a30182f0833d11bdc6ba49c7f0c95e41502a 100644 (file)
@@ -4818,7 +4818,7 @@ where
        /// [`ChannelUnavailable`]: APIError::ChannelUnavailable
        /// [`APIMisuseError`]: APIError::APIMisuseError
        pub fn update_partial_channel_config(
-               &self, counterparty_node_id: &PublicKey, channel_ids: &[ChannelId], config_update: &ChannelConfigUpdate,
+               &self, counterparty_node_id: &PublicKey, channel_ids: Vec<ChannelId>, config_update: &ChannelConfigUpdate,
        ) -> Result<(), APIError> {
                if config_update.cltv_expiry_delta.map(|delta| delta < MIN_CLTV_EXPIRY_DELTA).unwrap_or(false) {
                        return Err(APIError::APIMisuseError {
@@ -4833,14 +4833,14 @@ where
                let mut peer_state_lock = peer_state_mutex.lock().unwrap();
                let peer_state = &mut *peer_state_lock;
 
-               for channel_id in channel_ids {
+               for channel_id in channel_ids.iter() {
                        if !peer_state.has_channel(channel_id) {
                                return Err(APIError::ChannelUnavailable {
                                        err: format!("Channel with id {} not found for the passed counterparty node_id {}", channel_id, counterparty_node_id),
                                });
                        };
                }
-               for channel_id in channel_ids {
+               for channel_id in channel_ids.iter() {
                        if let Some(channel_phase) = peer_state.channel_by_id.get_mut(channel_id) {
                                let mut config = channel_phase.context().config();
                                config.apply(config_update);
@@ -4895,7 +4895,7 @@ where
        /// [`ChannelUnavailable`]: APIError::ChannelUnavailable
        /// [`APIMisuseError`]: APIError::APIMisuseError
        pub fn update_channel_config(
-               &self, counterparty_node_id: &PublicKey, channel_ids: &[ChannelId], config: &ChannelConfig,
+               &self, counterparty_node_id: &PublicKey, channel_ids: Vec<ChannelId>, config: &ChannelConfig,
        ) -> Result<(), APIError> {
                return self.update_partial_channel_config(counterparty_node_id, channel_ids, &(*config).into());
        }
index 25d531f5fc97e5ffa0e616ec4cf0fcdf727f044c..3ca52ab94200281ba1f9c062fb02c93bd2b29e8f 100644 (file)
@@ -91,7 +91,7 @@ impl NodeId {
        }
 
        /// Get the public key as an array from this NodeId
-       pub fn as_array(&self) -> &[u8; PUBLIC_KEY_SIZE] {
+       pub fn as_array(&self) -> &[u8; 33] {
                &self.0
        }
 
index 969b60f39e2ba439a534fc9a658ccc1c35259cc8..47db2f3ec660b4ee0f5289fe7778b74e296814c7 100644 (file)
@@ -160,7 +160,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, ES: Deref, S: Deref> Router f
                        })
                        .map(|forward_node| {
                                BlindedPaymentPath::new(
-                                       &[forward_node], recipient, tlvs.clone(), u64::MAX, MIN_FINAL_CLTV_EXPIRY_DELTA,
+                                       vec![forward_node], recipient, tlvs.clone(), u64::MAX, MIN_FINAL_CLTV_EXPIRY_DELTA,
                                        &*self.entropy_source, secp_ctx
                                )
                        })
@@ -172,7 +172,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, ES: Deref, S: Deref> Router f
                        _ => {
                                if network_graph.nodes().contains_key(&NodeId::from_pubkey(&recipient)) {
                                        BlindedPaymentPath::new(
-                                               &[], recipient, tlvs, u64::MAX, MIN_FINAL_CLTV_EXPIRY_DELTA, &*self.entropy_source,
+                                               Vec::new(), recipient, tlvs, u64::MAX, MIN_FINAL_CLTV_EXPIRY_DELTA, &*self.entropy_source,
                                                secp_ctx
                                        ).map(|path| vec![path])
                                } else {