Skip to content

Commit e9b2cf4

Browse files
committed
f - fix no-std
1 parent 2e50e17 commit e9b2cf4

File tree

3 files changed

+20
-28
lines changed

3 files changed

+20
-28
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9006,6 +9006,17 @@ where
90069006
) -> Result<BlindedPath, ()> {
90079007
const MAX_SHORT_LIVED_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 60 * 24);
90089008

9009+
let now = self.duration_since_epoch();
9010+
let max_short_lived_absolute_expiry = now.saturating_add(MAX_SHORT_LIVED_RELATIVE_EXPIRY);
9011+
9012+
if absolute_expiry.unwrap_or(Duration::MAX) <= max_short_lived_absolute_expiry {
9013+
self.create_compact_blinded_path()
9014+
} else {
9015+
self.create_blinded_path()
9016+
}
9017+
}
9018+
9019+
pub(super) fn duration_since_epoch(&self) -> Duration {
90099020
#[cfg(not(feature = "std"))]
90109021
let now = Duration::from_secs(
90119022
self.highest_seen_timestamp.load(Ordering::Acquire) as u64
@@ -9015,12 +9026,7 @@ where
90159026
.duration_since(std::time::SystemTime::UNIX_EPOCH)
90169027
.expect("SystemTime::now() should come after SystemTime::UNIX_EPOCH");
90179028

9018-
let max_short_lived_absolute_expiry = now.saturating_add(MAX_SHORT_LIVED_RELATIVE_EXPIRY);
9019-
if absolute_expiry.unwrap_or(Duration::MAX) <= max_short_lived_absolute_expiry {
9020-
self.create_compact_blinded_path()
9021-
} else {
9022-
self.create_blinded_path()
9023-
}
9029+
now
90249030
}
90259031

90269032
/// Creates a blinded path by delegating to [`MessageRouter::create_blinded_paths`].

lightning/src/ln/functional_test_utils.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ use core::cell::RefCell;
5050
use core::iter::repeat;
5151
use core::mem;
5252
use core::ops::Deref;
53-
use core::time::Duration;
5453
use crate::io;
5554
use crate::prelude::*;
5655
use crate::sync::{Arc, Mutex, LockTestExt, RwLock};
@@ -465,19 +464,6 @@ impl<'a, 'b, 'c> Node<'a, 'b, 'c> {
465464
self.override_init_features.borrow().clone()
466465
.unwrap_or_else(|| self.node.init_features() | self.onion_messenger.provided_init_features(peer_node_id))
467466
}
468-
469-
pub fn duration_since_epoch(&self) -> Duration {
470-
#[cfg(not(feature = "std"))]
471-
let now = Duration::from_secs(
472-
self.node.highest_seen_timestamp.load(Ordering::Acquire) as u64
473-
);
474-
#[cfg(feature = "std")]
475-
let now = std::time::SystemTime::now()
476-
.duration_since(std::time::SystemTime::UNIX_EPOCH)
477-
.expect("SystemTime::now() should come after SystemTime::UNIX_EPOCH");
478-
479-
now
480-
}
481467
}
482468

483469
#[cfg(feature = "std")]

lightning/src/ln/offers_tests.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,11 @@ fn creates_short_lived_offer() {
366366
let alice_id = alice.node.get_our_node_id();
367367
let bob = &nodes[1];
368368

369-
let absolute_expiry = Some(alice.duration_since_epoch() + Duration::from_secs(60 * 60 * 24));
369+
let absolute_expiry = alice.node.duration_since_epoch() + Duration::from_secs(60 * 60 * 24);
370370
let offer = alice.node
371-
.create_offer_builder(absolute_expiry).unwrap()
371+
.create_offer_builder(Some(absolute_expiry)).unwrap()
372372
.build().unwrap();
373-
assert_eq!(offer.absolute_expiry(), absolute_expiry);
373+
assert_eq!(offer.absolute_expiry(), Some(absolute_expiry));
374374
assert!(!offer.paths().is_empty());
375375
for path in offer.paths() {
376376
let introduction_node_id = resolve_introduction_node(bob, &path);
@@ -392,11 +392,11 @@ fn creates_long_lived_offer() {
392392
let alice = &nodes[0];
393393
let alice_id = alice.node.get_our_node_id();
394394

395-
let absolute_expiry = Some(alice.duration_since_epoch() + Duration::from_secs(60 * 60 * 25));
395+
let absolute_expiry = alice.node.duration_since_epoch() + Duration::from_secs(60 * 60 * 25);
396396
let offer = alice.node
397-
.create_offer_builder(absolute_expiry).unwrap()
397+
.create_offer_builder(Some(absolute_expiry)).unwrap()
398398
.build().unwrap();
399-
assert_eq!(offer.absolute_expiry(), absolute_expiry);
399+
assert_eq!(offer.absolute_expiry(), Some(absolute_expiry));
400400
assert!(!offer.paths().is_empty());
401401
for path in offer.paths() {
402402
assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
@@ -426,7 +426,7 @@ fn creates_short_lived_refund() {
426426
let bob = &nodes[1];
427427
let bob_id = bob.node.get_our_node_id();
428428

429-
let absolute_expiry = bob.duration_since_epoch() + Duration::from_secs(60 * 60 * 24);
429+
let absolute_expiry = bob.node.duration_since_epoch() + Duration::from_secs(60 * 60 * 24);
430430
let payment_id = PaymentId([1; 32]);
431431
let refund = bob.node
432432
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
@@ -454,7 +454,7 @@ fn creates_long_lived_refund() {
454454
let bob = &nodes[1];
455455
let bob_id = bob.node.get_our_node_id();
456456

457-
let absolute_expiry = bob.duration_since_epoch() + Duration::from_secs(60 * 60 * 25);
457+
let absolute_expiry = bob.node.duration_since_epoch() + Duration::from_secs(60 * 60 * 25);
458458
let payment_id = PaymentId([1; 32]);
459459
let refund = bob.node
460460
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)

0 commit comments

Comments
 (0)