Skip to content

Commit f64ace5

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 88c6357 commit f64ace5

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
@@ -7756,15 +7756,15 @@ where
77567756
let payment_paths = self.create_blinded_payment_paths(amount_msats, payment_secret)
77577757
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
77587758

7759-
#[cfg(not(feature = "no-std"))]
7759+
#[cfg(feature = "std")]
77607760
let builder = refund.respond_using_derived_keys(
77617761
payment_paths, payment_hash, expanded_key, entropy
77627762
)?;
7763-
#[cfg(feature = "no-std")]
7763+
#[cfg(not(feature = "std"))]
77647764
let created_at = Duration::from_secs(
77657765
self.highest_seen_timestamp.load(Ordering::Acquire) as u64
77667766
);
7767-
#[cfg(feature = "no-std")]
7767+
#[cfg(not(feature = "std"))]
77687768
let builder = refund.respond_using_derived_keys_no_std(
77697769
payment_paths, payment_hash, created_at, expanded_key, entropy
77707770
)?;
@@ -9209,17 +9209,17 @@ where
92099209
},
92109210
};
92119211

9212-
#[cfg(feature = "no-std")]
9212+
#[cfg(not(feature = "std"))]
92139213
let created_at = Duration::from_secs(
92149214
self.highest_seen_timestamp.load(Ordering::Acquire) as u64
92159215
);
92169216

92179217
if invoice_request.keys.is_some() {
9218-
#[cfg(not(feature = "no-std"))]
9218+
#[cfg(feature = "std")]
92199219
let builder = invoice_request.respond_using_derived_keys(
92209220
payment_paths, payment_hash
92219221
);
9222-
#[cfg(feature = "no-std")]
9222+
#[cfg(not(feature = "std"))]
92239223
let builder = invoice_request.respond_using_derived_keys_no_std(
92249224
payment_paths, payment_hash, created_at
92259225
);
@@ -9228,9 +9228,9 @@ where
92289228
Err(error) => Some(OffersMessage::InvoiceError(error.into())),
92299229
}
92309230
} else {
9231-
#[cfg(not(feature = "no-std"))]
9231+
#[cfg(feature = "std")]
92329232
let builder = invoice_request.respond_with(payment_paths, payment_hash);
9233-
#[cfg(feature = "no-std")]
9233+
#[cfg(not(feature = "std"))]
92349234
let builder = invoice_request.respond_with_no_std(
92359235
payment_paths, payment_hash, created_at
92369236
);

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
@@ -6882,7 +6882,7 @@ mod tests {
68826882
(route.paths[1].hops[1].short_channel_id == 4 && route.paths[0].hops[1].short_channel_id == 13));
68836883
}
68846884

6885-
#[cfg(not(feature = "no-std"))]
6885+
#[cfg(feature = "std")]
68866886
pub(super) fn random_init_seed() -> u64 {
68876887
// Because the default HashMap in std pulls OS randomness, we can use it as a (bad) RNG.
68886888
use core::hash::{BuildHasher, Hasher};
@@ -6892,7 +6892,7 @@ mod tests {
68926892
}
68936893

68946894
#[test]
6895-
#[cfg(not(feature = "no-std"))]
6895+
#[cfg(feature = "std")]
68966896
fn generate_routes() {
68976897
use crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters};
68986898

@@ -6913,7 +6913,7 @@ mod tests {
69136913
}
69146914

69156915
#[test]
6916-
#[cfg(not(feature = "no-std"))]
6916+
#[cfg(feature = "std")]
69176917
fn generate_routes_mpp() {
69186918
use crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters};
69196919

@@ -6934,7 +6934,7 @@ mod tests {
69346934
}
69356935

69366936
#[test]
6937-
#[cfg(not(feature = "no-std"))]
6937+
#[cfg(feature = "std")]
69386938
fn generate_large_mpp_routes() {
69396939
use crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters};
69406940

@@ -8270,7 +8270,7 @@ mod tests {
82708270
}
82718271
}
82728272

8273-
#[cfg(all(any(test, ldk_bench), not(feature = "no-std")))]
8273+
#[cfg(all(any(test, ldk_bench), feature = "std"))]
82748274
pub(crate) mod bench_utils {
82758275
use super::*;
82768276
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)