Skip to content

Commit 30c0702

Browse files
committed
Remove "no-std" feature checks
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.
1 parent b578363 commit 30c0702

File tree

6 files changed

+36
-36
lines changed

6 files changed

+36
-36
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7779,15 +7779,15 @@ where
77797779
let payment_paths = self.create_blinded_payment_paths(amount_msats, payment_secret)
77807780
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
77817781

7782-
#[cfg(not(feature = "no-std"))]
7782+
#[cfg(feature = "std")]
77837783
let builder = refund.respond_using_derived_keys(
77847784
payment_paths, payment_hash, expanded_key, entropy
77857785
)?;
7786-
#[cfg(feature = "no-std")]
7786+
#[cfg(not(feature = "std"))]
77877787
let created_at = Duration::from_secs(
77887788
self.highest_seen_timestamp.load(Ordering::Acquire) as u64
77897789
);
7790-
#[cfg(feature = "no-std")]
7790+
#[cfg(not(feature = "std"))]
77917791
let builder = refund.respond_using_derived_keys_no_std(
77927792
payment_paths, payment_hash, created_at, expanded_key, entropy
77937793
)?;
@@ -9224,17 +9224,17 @@ where
92249224
},
92259225
};
92269226

9227-
#[cfg(feature = "no-std")]
9227+
#[cfg(not(feature = "std"))]
92289228
let created_at = Duration::from_secs(
92299229
self.highest_seen_timestamp.load(Ordering::Acquire) as u64
92309230
);
92319231

92329232
if invoice_request.keys.is_some() {
9233-
#[cfg(not(feature = "no-std"))]
9233+
#[cfg(feature = "std")]
92349234
let builder = invoice_request.respond_using_derived_keys(
92359235
payment_paths, payment_hash
92369236
);
9237-
#[cfg(feature = "no-std")]
9237+
#[cfg(not(feature = "std"))]
92389238
let builder = invoice_request.respond_using_derived_keys_no_std(
92399239
payment_paths, payment_hash, created_at
92409240
);
@@ -9243,9 +9243,9 @@ where
92439243
Err(error) => Some(OffersMessage::InvoiceError(error.into())),
92449244
}
92459245
} else {
9246-
#[cfg(not(feature = "no-std"))]
9246+
#[cfg(feature = "std")]
92479247
let builder = invoice_request.respond_with(payment_paths, payment_hash);
9248-
#[cfg(feature = "no-std")]
9248+
#[cfg(not(feature = "std"))]
92499249
let builder = invoice_request.respond_with_no_std(
92509250
payment_paths, payment_hash, created_at
92519251
);

lightning/src/ln/outbound_payment.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::routing::router::{InFlightHtlcs, Path, PaymentParameters, Route, Rout
2323
use crate::util::errors::APIError;
2424
use crate::util::logger::Logger;
2525
use crate::util::time::Time;
26-
#[cfg(all(not(feature = "no-std"), test))]
26+
#[cfg(all(feature = "std", test))]
2727
use crate::util::time::tests::SinceEpoch;
2828
use crate::util::ser::ReadableArgs;
2929

@@ -282,21 +282,21 @@ pub enum Retry {
282282
/// retry, and may retry multiple failed HTLCs at once if they failed around the same time and
283283
/// were retried along a route from a single call to [`Router::find_route_with_id`].
284284
Attempts(u32),
285-
#[cfg(not(feature = "no-std"))]
285+
#[cfg(feature = "std")]
286286
/// Time elapsed before abandoning retries for a payment. At least one attempt at payment is made;
287287
/// see [`PaymentParameters::expiry_time`] to avoid any attempt at payment after a specific time.
288288
///
289289
/// [`PaymentParameters::expiry_time`]: crate::routing::router::PaymentParameters::expiry_time
290290
Timeout(core::time::Duration),
291291
}
292292

293-
#[cfg(feature = "no-std")]
293+
#[cfg(not(feature = "std"))]
294294
impl_writeable_tlv_based_enum!(Retry,
295295
;
296296
(0, Attempts)
297297
);
298298

299-
#[cfg(not(feature = "no-std"))]
299+
#[cfg(feature = "std")]
300300
impl_writeable_tlv_based_enum!(Retry,
301301
;
302302
(0, Attempts),
@@ -309,10 +309,10 @@ impl Retry {
309309
(Retry::Attempts(max_retry_count), PaymentAttempts { count, .. }) => {
310310
max_retry_count > count
311311
},
312-
#[cfg(all(not(feature = "no-std"), not(test)))]
312+
#[cfg(all(feature = "std", not(test)))]
313313
(Retry::Timeout(max_duration), PaymentAttempts { first_attempted_at, .. }) =>
314314
*max_duration >= crate::util::time::MonotonicTime::now().duration_since(*first_attempted_at),
315-
#[cfg(all(not(feature = "no-std"), test))]
315+
#[cfg(all(feature = "std", test))]
316316
(Retry::Timeout(max_duration), PaymentAttempts { first_attempted_at, .. }) =>
317317
*max_duration >= SinceEpoch::now().duration_since(*first_attempted_at),
318318
}
@@ -338,37 +338,37 @@ pub(crate) struct PaymentAttemptsUsingTime<T: Time> {
338338
/// it means the result of the first attempt is not known yet.
339339
pub(crate) count: u32,
340340
/// This field is only used when retry is `Retry::Timeout` which is only build with feature std
341-
#[cfg(not(feature = "no-std"))]
341+
#[cfg(feature = "std")]
342342
first_attempted_at: T,
343-
#[cfg(feature = "no-std")]
343+
#[cfg(not(feature = "std"))]
344344
phantom: core::marker::PhantomData<T>,
345345

346346
}
347347

348-
#[cfg(not(any(feature = "no-std", test)))]
348+
#[cfg(not(any(not(feature = "std"), test)))]
349349
type ConfiguredTime = crate::util::time::MonotonicTime;
350-
#[cfg(feature = "no-std")]
350+
#[cfg(not(feature = "std"))]
351351
type ConfiguredTime = crate::util::time::Eternity;
352-
#[cfg(all(not(feature = "no-std"), test))]
352+
#[cfg(all(feature = "std", test))]
353353
type ConfiguredTime = SinceEpoch;
354354

355355
impl<T: Time> PaymentAttemptsUsingTime<T> {
356356
pub(crate) fn new() -> Self {
357357
PaymentAttemptsUsingTime {
358358
count: 0,
359-
#[cfg(not(feature = "no-std"))]
359+
#[cfg(feature = "std")]
360360
first_attempted_at: T::now(),
361-
#[cfg(feature = "no-std")]
361+
#[cfg(not(feature = "std"))]
362362
phantom: core::marker::PhantomData,
363363
}
364364
}
365365
}
366366

367367
impl<T: Time> Display for PaymentAttemptsUsingTime<T> {
368368
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
369-
#[cfg(feature = "no-std")]
369+
#[cfg(not(feature = "std"))]
370370
return write!(f, "attempts: {}", self.count);
371-
#[cfg(not(feature = "no-std"))]
371+
#[cfg(feature = "std")]
372372
return write!(
373373
f,
374374
"attempts: {}, duration: {}s",

lightning/src/ln/payment_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use crate::ln::functional_test_utils::*;
4444
use crate::routing::gossip::NodeId;
4545
#[cfg(feature = "std")]
4646
use std::time::{SystemTime, Instant, Duration};
47-
#[cfg(not(feature = "no-std"))]
47+
#[cfg(feature = "std")]
4848
use crate::util::time::tests::SinceEpoch;
4949

5050
#[test]
@@ -2313,7 +2313,7 @@ fn do_automatic_retries(test: AutoRetry) {
23132313
let mut msg_events = nodes[0].node.get_and_clear_pending_msg_events();
23142314
assert_eq!(msg_events.len(), 0);
23152315
} else if test == AutoRetry::FailTimeout {
2316-
#[cfg(not(feature = "no-std"))] {
2316+
#[cfg(feature = "std")] {
23172317
// Ensure ChannelManager will not retry a payment if it times out due to Retry::Timeout.
23182318
nodes[0].node.send_payment(payment_hash, RecipientOnionFields::secret_only(payment_secret),
23192319
PaymentId(payment_hash.0), route_params, Retry::Timeout(Duration::from_secs(60))).unwrap();

lightning/src/routing/gossip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1845,7 +1845,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
18451845
// NOTE: In the case of no-std, we won't have access to the current UNIX time at the time of removal,
18461846
// so we'll just set the removal time here to the current UNIX time on the very next invocation
18471847
// of this function.
1848-
#[cfg(feature = "no-std")]
1848+
#[cfg(not(feature = "std"))]
18491849
{
18501850
let mut tracked_time = Some(current_time_unix);
18511851
core::mem::swap(time, &mut tracked_time);

lightning/src/routing/router.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6902,7 +6902,7 @@ mod tests {
69026902
(route.paths[1].hops[1].short_channel_id == 4 && route.paths[0].hops[1].short_channel_id == 13));
69036903
}
69046904

6905-
#[cfg(not(feature = "no-std"))]
6905+
#[cfg(feature = "std")]
69066906
pub(super) fn random_init_seed() -> u64 {
69076907
// Because the default HashMap in std pulls OS randomness, we can use it as a (bad) RNG.
69086908
use core::hash::{BuildHasher, Hasher};
@@ -6912,7 +6912,7 @@ mod tests {
69126912
}
69136913

69146914
#[test]
6915-
#[cfg(not(feature = "no-std"))]
6915+
#[cfg(feature = "std")]
69166916
fn generate_routes() {
69176917
use crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters};
69186918

@@ -6933,7 +6933,7 @@ mod tests {
69336933
}
69346934

69356935
#[test]
6936-
#[cfg(not(feature = "no-std"))]
6936+
#[cfg(feature = "std")]
69376937
fn generate_routes_mpp() {
69386938
use crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters};
69396939

@@ -6954,7 +6954,7 @@ mod tests {
69546954
}
69556955

69566956
#[test]
6957-
#[cfg(not(feature = "no-std"))]
6957+
#[cfg(feature = "std")]
69586958
fn generate_large_mpp_routes() {
69596959
use crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters};
69606960

@@ -8290,7 +8290,7 @@ mod tests {
82908290
}
82918291
}
82928292

8293-
#[cfg(all(any(test, ldk_bench), not(feature = "no-std")))]
8293+
#[cfg(all(any(test, ldk_bench), feature = "std"))]
82948294
pub(crate) mod bench_utils {
82958295
use super::*;
82968296
use std::fs::File;

lightning/src/util/time.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ impl Sub<Duration> for Eternity {
5959
}
6060

6161
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
62-
#[cfg(not(feature = "no-std"))]
62+
#[cfg(feature = "std")]
6363
pub struct MonotonicTime(std::time::Instant);
6464

6565
/// The amount of time to shift `Instant` forward to prevent overflow when subtracting a `Duration`
6666
/// from `Instant::now` on some operating systems (e.g., iOS representing `Instance` as `u64`).
67-
#[cfg(not(feature = "no-std"))]
67+
#[cfg(feature = "std")]
6868
const SHIFT: Duration = Duration::from_secs(10 * 365 * 24 * 60 * 60); // 10 years.
6969

70-
#[cfg(not(feature = "no-std"))]
70+
#[cfg(feature = "std")]
7171
impl Time for MonotonicTime {
7272
fn now() -> Self {
7373
let instant = std::time::Instant::now().checked_add(SHIFT).expect("Overflow on MonotonicTime instantiation");
@@ -93,7 +93,7 @@ impl Time for MonotonicTime {
9393
}
9494
}
9595

96-
#[cfg(not(feature = "no-std"))]
96+
#[cfg(feature = "std")]
9797
impl Sub<Duration> for MonotonicTime {
9898
type Output = Self;
9999

@@ -177,7 +177,7 @@ pub mod tests {
177177
}
178178

179179
#[test]
180-
#[cfg(not(feature = "no-std"))]
180+
#[cfg(feature = "std")]
181181
fn monotonic_time_subtracts() {
182182
let now = super::MonotonicTime::now();
183183
assert!(now.elapsed() < Duration::from_secs(10));

0 commit comments

Comments
 (0)