]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Remove "no-std" feature checks
authorJeffrey Czyz <jkczyz@gmail.com>
Thu, 4 Jan 2024 16:30:51 +0000 (10:30 -0600)
committerJeffrey Czyz <jkczyz@gmail.com>
Tue, 16 Jan 2024 17:12:34 +0000 (11:12 -0600)
An upcoming rust-bitcoin release will remove the "no-std" feature.
Replace "no-std" in feature checks with "std", negating as needed. Using
a single feature flag makes the checks more consistent across modules.

lightning/src/ln/channelmanager.rs
lightning/src/ln/outbound_payment.rs
lightning/src/ln/payment_tests.rs
lightning/src/routing/gossip.rs
lightning/src/routing/router.rs
lightning/src/util/time.rs

index 01888b202b725e57d07dee7df2409659882abe89..d0badb8b2cc7ca8e0a3688740c2a24aefe2c5f6d 100644 (file)
@@ -7779,15 +7779,15 @@ where
                                let payment_paths = self.create_blinded_payment_paths(amount_msats, payment_secret)
                                        .map_err(|_| Bolt12SemanticError::MissingPaths)?;
 
-                               #[cfg(not(feature = "no-std"))]
+                               #[cfg(feature = "std")]
                                let builder = refund.respond_using_derived_keys(
                                        payment_paths, payment_hash, expanded_key, entropy
                                )?;
-                               #[cfg(feature = "no-std")]
+                               #[cfg(not(feature = "std"))]
                                let created_at = Duration::from_secs(
                                        self.highest_seen_timestamp.load(Ordering::Acquire) as u64
                                );
-                               #[cfg(feature = "no-std")]
+                               #[cfg(not(feature = "std"))]
                                let builder = refund.respond_using_derived_keys_no_std(
                                        payment_paths, payment_hash, created_at, expanded_key, entropy
                                )?;
@@ -9224,17 +9224,17 @@ where
                                        },
                                };
 
-                               #[cfg(feature = "no-std")]
+                               #[cfg(not(feature = "std"))]
                                let created_at = Duration::from_secs(
                                        self.highest_seen_timestamp.load(Ordering::Acquire) as u64
                                );
 
                                if invoice_request.keys.is_some() {
-                                       #[cfg(not(feature = "no-std"))]
+                                       #[cfg(feature = "std")]
                                        let builder = invoice_request.respond_using_derived_keys(
                                                payment_paths, payment_hash
                                        );
-                                       #[cfg(feature = "no-std")]
+                                       #[cfg(not(feature = "std"))]
                                        let builder = invoice_request.respond_using_derived_keys_no_std(
                                                payment_paths, payment_hash, created_at
                                        );
@@ -9243,9 +9243,9 @@ where
                                                Err(error) => Some(OffersMessage::InvoiceError(error.into())),
                                        }
                                } else {
-                                       #[cfg(not(feature = "no-std"))]
+                                       #[cfg(feature = "std")]
                                        let builder = invoice_request.respond_with(payment_paths, payment_hash);
-                                       #[cfg(feature = "no-std")]
+                                       #[cfg(not(feature = "std"))]
                                        let builder = invoice_request.respond_with_no_std(
                                                payment_paths, payment_hash, created_at
                                        );
index 46ec2977044db7dc5d824941bb47cb86562169e4..66c9ee62e5e8a9044a536da7dedc784a4a0154ae 100644 (file)
@@ -23,7 +23,7 @@ use crate::routing::router::{InFlightHtlcs, Path, PaymentParameters, Route, Rout
 use crate::util::errors::APIError;
 use crate::util::logger::Logger;
 use crate::util::time::Time;
-#[cfg(all(not(feature = "no-std"), test))]
+#[cfg(all(feature = "std", test))]
 use crate::util::time::tests::SinceEpoch;
 use crate::util::ser::ReadableArgs;
 
@@ -282,7 +282,7 @@ pub enum Retry {
        /// retry, and may retry multiple failed HTLCs at once if they failed around the same time and
        /// were retried along a route from a single call to [`Router::find_route_with_id`].
        Attempts(u32),
-       #[cfg(not(feature = "no-std"))]
+       #[cfg(feature = "std")]
        /// Time elapsed before abandoning retries for a payment. At least one attempt at payment is made;
        /// see [`PaymentParameters::expiry_time`] to avoid any attempt at payment after a specific time.
        ///
@@ -290,13 +290,13 @@ pub enum Retry {
        Timeout(core::time::Duration),
 }
 
-#[cfg(feature = "no-std")]
+#[cfg(not(feature = "std"))]
 impl_writeable_tlv_based_enum!(Retry,
        ;
        (0, Attempts)
 );
 
-#[cfg(not(feature = "no-std"))]
+#[cfg(feature = "std")]
 impl_writeable_tlv_based_enum!(Retry,
        ;
        (0, Attempts),
@@ -309,10 +309,10 @@ impl Retry {
                        (Retry::Attempts(max_retry_count), PaymentAttempts { count, .. }) => {
                                max_retry_count > count
                        },
-                       #[cfg(all(not(feature = "no-std"), not(test)))]
+                       #[cfg(all(feature = "std", not(test)))]
                        (Retry::Timeout(max_duration), PaymentAttempts { first_attempted_at, .. }) =>
                                *max_duration >= crate::util::time::MonotonicTime::now().duration_since(*first_attempted_at),
-                       #[cfg(all(not(feature = "no-std"), test))]
+                       #[cfg(all(feature = "std", test))]
                        (Retry::Timeout(max_duration), PaymentAttempts { first_attempted_at, .. }) =>
                                *max_duration >= SinceEpoch::now().duration_since(*first_attempted_at),
                }
@@ -338,27 +338,27 @@ pub(crate) struct PaymentAttemptsUsingTime<T: Time> {
        /// it means the result of the first attempt is not known yet.
        pub(crate) count: u32,
        /// This field is only used when retry is `Retry::Timeout` which is only build with feature std
-       #[cfg(not(feature = "no-std"))]
+       #[cfg(feature = "std")]
        first_attempted_at: T,
-       #[cfg(feature = "no-std")]
+       #[cfg(not(feature = "std"))]
        phantom: core::marker::PhantomData<T>,
 
 }
 
-#[cfg(not(any(feature = "no-std", test)))]
+#[cfg(not(any(not(feature = "std"), test)))]
 type ConfiguredTime = crate::util::time::MonotonicTime;
-#[cfg(feature = "no-std")]
+#[cfg(not(feature = "std"))]
 type ConfiguredTime = crate::util::time::Eternity;
-#[cfg(all(not(feature = "no-std"), test))]
+#[cfg(all(feature = "std", test))]
 type ConfiguredTime = SinceEpoch;
 
 impl<T: Time> PaymentAttemptsUsingTime<T> {
        pub(crate) fn new() -> Self {
                PaymentAttemptsUsingTime {
                        count: 0,
-                       #[cfg(not(feature = "no-std"))]
+                       #[cfg(feature = "std")]
                        first_attempted_at: T::now(),
-                       #[cfg(feature = "no-std")]
+                       #[cfg(not(feature = "std"))]
                        phantom: core::marker::PhantomData,
                }
        }
@@ -366,9 +366,9 @@ impl<T: Time> PaymentAttemptsUsingTime<T> {
 
 impl<T: Time> Display for PaymentAttemptsUsingTime<T> {
        fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
-               #[cfg(feature = "no-std")]
+               #[cfg(not(feature = "std"))]
                return write!(f, "attempts: {}", self.count);
-               #[cfg(not(feature = "no-std"))]
+               #[cfg(feature = "std")]
                return write!(
                        f,
                        "attempts: {}, duration: {}s",
index 73cdf59bbb699fb6966ad964ac99d6f00f3efeb9..15870dc57132001b58af8da323876c5358a3cc0d 100644 (file)
@@ -44,7 +44,7 @@ use crate::ln::functional_test_utils::*;
 use crate::routing::gossip::NodeId;
 #[cfg(feature = "std")]
 use std::time::{SystemTime, Instant, Duration};
-#[cfg(not(feature = "no-std"))]
+#[cfg(feature = "std")]
 use crate::util::time::tests::SinceEpoch;
 
 #[test]
@@ -2313,7 +2313,7 @@ fn do_automatic_retries(test: AutoRetry) {
                let mut msg_events = nodes[0].node.get_and_clear_pending_msg_events();
                assert_eq!(msg_events.len(), 0);
        } else if test == AutoRetry::FailTimeout {
-               #[cfg(not(feature = "no-std"))] {
+               #[cfg(feature = "std")] {
                        // Ensure ChannelManager will not retry a payment if it times out due to Retry::Timeout.
                        nodes[0].node.send_payment(payment_hash, RecipientOnionFields::secret_only(payment_secret),
                                PaymentId(payment_hash.0), route_params, Retry::Timeout(Duration::from_secs(60))).unwrap();
index 9b4e41ae174d7b8a73cb8f64b7918f62a0dbf01b..9c8fd40af1358f1e1c8ae04646607da68a4e7abe 100644 (file)
@@ -1845,7 +1845,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
                                // NOTE: In the case of no-std, we won't have access to the current UNIX time at the time of removal,
                                // so we'll just set the removal time here to the current UNIX time on the very next invocation
                                // of this function.
-                               #[cfg(feature = "no-std")]
+                               #[cfg(not(feature = "std"))]
                                {
                                        let mut tracked_time = Some(current_time_unix);
                                        core::mem::swap(time, &mut tracked_time);
index 485fd239128df8ab39b0806723a7d3d6b6e24e3a..4a32a5e48b88c0fd8f7b39577bcba710bec563a8 100644 (file)
@@ -6902,7 +6902,7 @@ mod tests {
                        (route.paths[1].hops[1].short_channel_id == 4 && route.paths[0].hops[1].short_channel_id == 13));
        }
 
-       #[cfg(not(feature = "no-std"))]
+       #[cfg(feature = "std")]
        pub(super) fn random_init_seed() -> u64 {
                // Because the default HashMap in std pulls OS randomness, we can use it as a (bad) RNG.
                use core::hash::{BuildHasher, Hasher};
@@ -6912,7 +6912,7 @@ mod tests {
        }
 
        #[test]
-       #[cfg(not(feature = "no-std"))]
+       #[cfg(feature = "std")]
        fn generate_routes() {
                use crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters};
 
@@ -6933,7 +6933,7 @@ mod tests {
        }
 
        #[test]
-       #[cfg(not(feature = "no-std"))]
+       #[cfg(feature = "std")]
        fn generate_routes_mpp() {
                use crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters};
 
@@ -6954,7 +6954,7 @@ mod tests {
        }
 
        #[test]
-       #[cfg(not(feature = "no-std"))]
+       #[cfg(feature = "std")]
        fn generate_large_mpp_routes() {
                use crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters};
 
@@ -8290,7 +8290,7 @@ mod tests {
        }
 }
 
-#[cfg(all(any(test, ldk_bench), not(feature = "no-std")))]
+#[cfg(all(any(test, ldk_bench), feature = "std"))]
 pub(crate) mod bench_utils {
        use super::*;
        use std::fs::File;
index 0d969e7470952625d8db04965220c25df589f30f..a6e6f4d1fda6b6e58a102a0baeb97cbed102159f 100644 (file)
@@ -59,15 +59,15 @@ impl Sub<Duration> for Eternity {
 }
 
 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
-#[cfg(not(feature = "no-std"))]
+#[cfg(feature = "std")]
 pub struct MonotonicTime(std::time::Instant);
 
 /// The amount of time to shift `Instant` forward to prevent overflow when subtracting a `Duration`
 /// from `Instant::now` on some operating systems (e.g., iOS representing `Instance` as `u64`).
-#[cfg(not(feature = "no-std"))]
+#[cfg(feature = "std")]
 const SHIFT: Duration = Duration::from_secs(10 * 365 * 24 * 60 * 60); // 10 years.
 
-#[cfg(not(feature = "no-std"))]
+#[cfg(feature = "std")]
 impl Time for MonotonicTime {
        fn now() -> Self {
                let instant = std::time::Instant::now().checked_add(SHIFT).expect("Overflow on MonotonicTime instantiation");
@@ -93,7 +93,7 @@ impl Time for MonotonicTime {
        }
 }
 
-#[cfg(not(feature = "no-std"))]
+#[cfg(feature = "std")]
 impl Sub<Duration> for MonotonicTime {
        type Output = Self;
 
@@ -177,7 +177,7 @@ pub mod tests {
        }
 
        #[test]
-       #[cfg(not(feature = "no-std"))]
+       #[cfg(feature = "std")]
        fn monotonic_time_subtracts() {
                let now = super::MonotonicTime::now();
                assert!(now.elapsed() < Duration::from_secs(10));