From 716758f5a353e3ea84025dae311f6137ecd628ff Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Mon, 11 Nov 2024 16:32:28 -0600 Subject: [PATCH 1/3] Fix incorrect expect message --- lightning/src/ln/channelmanager.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 4ca95db11b5..5a20c8e2444 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -9266,7 +9266,7 @@ where let duration_since_epoch = { use std::time::SystemTime; SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) - .expect("for the foreseeable future this shouldn't happen") + .expect("SystemTime::now() should be after SystemTime::UNIX_EPOCH") }; #[cfg(not(feature = "std"))] let duration_since_epoch = From e9051f84f2c711387d83f68424bc697bbac1249f Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Mon, 11 Nov 2024 16:43:53 -0600 Subject: [PATCH 2/3] Explain no-std Bolt11Invoice::duration_since_epoch --- lightning/src/ln/channelmanager.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 5a20c8e2444..61c5958ac6c 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -9268,6 +9268,10 @@ where SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) .expect("SystemTime::now() should be after SystemTime::UNIX_EPOCH") }; + + // This may be up to 2 hours in the future because of bitcoin's block time rule or about + // 10-30 minutes in the past if a block hasn't been found recently. This should be fine as + // the default invoice expiration is 2 hours, though shorter expirations may be problematic. #[cfg(not(feature = "std"))] let duration_since_epoch = Duration::from_secs(self.highest_seen_timestamp.load(Ordering::Acquire) as u64); From 20ef21798510c64f1a40fc040f7a907a4e62ab99 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Tue, 12 Nov 2024 12:28:52 -0600 Subject: [PATCH 3/3] Expand Bolt11InvoiceParameters docs for no-std use --- lightning/src/ln/channelmanager.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 61c5958ac6c..d4547be8ff6 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -9360,7 +9360,8 @@ pub struct Bolt11InvoiceParameters { /// [`DEFAULT_EXPIRY_TIME`] by default. /// /// The creation time used is the duration since the Unix epoch for `std` builds. For non-`std` - /// builds, the highest block timestamp seen is used instead. + /// builds, the highest block timestamp seen is used instead. In the latter case, use a long + /// enough expiry to account for the average block time. pub invoice_expiry_delta_secs: Option, /// The minimum `cltv_expiry` for the last HTLC in the route. If not set, will use