Skip to content

Commit 8113ced

Browse files
committed
f - remove duration_since_epoch
1 parent edcc063 commit 8113ced

File tree

2 files changed

+12
-46
lines changed

2 files changed

+12
-46
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9104,7 +9104,7 @@ where
91049104
&self, params: Bolt11InvoiceParameters,
91059105
) -> Result<Bolt11Invoice, SignOrCreationError<()>> {
91069106
let Bolt11InvoiceParameters {
9107-
currency, amount_msats, description, duration_since_epoch, invoice_expiry_delta_secs,
9107+
currency, amount_msats, description, invoice_expiry_delta_secs,
91089108
min_final_cltv_expiry_delta, payment_hash,
91099109
} = params;
91109110

@@ -9114,16 +9114,14 @@ where
91149114
};
91159115

91169116
#[cfg(feature = "std")]
9117-
let duration_since_epoch = duration_since_epoch
9118-
.unwrap_or_else(|| {
9119-
use std::time::SystemTime;
9120-
SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)
9121-
.expect("for the foreseeable future this shouldn't happen")
9122-
});
9117+
let duration_since_epoch = {
9118+
use std::time::SystemTime;
9119+
SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)
9120+
.expect("for the foreseeable future this shouldn't happen")
9121+
};
91239122
#[cfg(not(feature = "std"))]
9124-
let duration_since_epoch = duration_since_epoch.unwrap_or_else(||
9125-
Duration::from_secs(self.highest_seen_timestamp.load(Ordering::Acquire) as u64)
9126-
);
9123+
let duration_since_epoch =
9124+
Duration::from_secs(self.highest_seen_timestamp.load(Ordering::Acquire) as u64);
91279125

91289126
if let Some(min_final_cltv_expiry_delta) = min_final_cltv_expiry_delta {
91299127
if min_final_cltv_expiry_delta.saturating_add(3) < MIN_FINAL_CLTV_EXPIRY_DELTA {
@@ -9209,14 +9207,11 @@ pub struct Bolt11InvoiceParameters {
92099207
/// The description for what the invoice is for, or hash of such description.
92109208
pub description: Bolt11InvoiceDescription,
92119209

9212-
/// The duration since the Unix epoch signifying when the invoice was created. If not set,
9213-
/// the current time is used or the highest timestamp seen for non-`std` builds.
9214-
pub duration_since_epoch: Option<Duration>,
9215-
9216-
/// The invoice expiration relative to [`duration_since_epoch`]. If not set, the invoice will
9217-
/// expire in [`DEFAULT_EXPIRY_TIME`] by default.
9210+
/// The invoice expiration relative to its creation time. If not set, the invoice will expire in
9211+
/// [`DEFAULT_EXPIRY_TIME`] by default.
92189212
///
9219-
/// [`duration_since_epoch`]: Self::duration_since_epoch
9213+
/// The creation time used is the duration since the Unix epoch for `std` builds. For non-`std`
9214+
/// builds, the highest block timestamp seen is used instead.
92209215
pub invoice_expiry_delta_secs: Option<u32>,
92219216

92229217
/// The minimum `cltv_expiry` for the last HTLC in the route. If not set, will use
@@ -9241,7 +9236,6 @@ impl Default for Bolt11InvoiceParameters {
92419236
currency: None,
92429237
amount_msats: None,
92439238
description: Bolt11InvoiceDescription::Direct(Description::empty()),
9244-
duration_since_epoch: None,
92459239
invoice_expiry_delta_secs: None,
92469240
min_final_cltv_expiry_delta: None,
92479241
payment_hash: None,

lightning/src/ln/invoice_utils.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ fn rotate_through_iterators<T, I: Iterator<Item = T>>(mut vecs: Vec<I>) -> impl
313313
})
314314
}
315315

316-
#[cfg(feature = "std")]
317316
/// Utility to construct an invoice. Generally, unless you want to do something like a custom
318317
/// cltv_expiry, this is what you should be using to create an invoice. The reason being, this
319318
/// method stores the invoice's payment secret and preimage in `ChannelManager`, so (a) the user
@@ -345,25 +344,18 @@ where
345344
MR::Target: MessageRouter,
346345
L::Target: Logger,
347346
{
348-
use std::time::SystemTime;
349-
let duration_since_epoch = SystemTime::now()
350-
.duration_since(SystemTime::UNIX_EPOCH)
351-
.expect("for the foreseeable future this shouldn't happen");
352-
353347
let description = Description::new(description).map_err(SignOrCreationError::CreationError)?;
354348
let params = Bolt11InvoiceParameters {
355349
currency: Some(network),
356350
amount_msats: amt_msat,
357351
description: Bolt11InvoiceDescription::Direct(description),
358-
duration_since_epoch: Some(duration_since_epoch),
359352
invoice_expiry_delta_secs: Some(invoice_expiry_delta_secs),
360353
min_final_cltv_expiry_delta,
361354
payment_hash: None,
362355
};
363356
channelmanager.create_bolt11_invoice(params)
364357
}
365358

366-
#[cfg(feature = "std")]
367359
/// Utility to construct an invoice. Generally, unless you want to do something like a custom
368360
/// cltv_expiry, this is what you should be using to create an invoice. The reason being, this
369361
/// method stores the invoice's payment secret and preimage in `ChannelManager`, so (a) the user
@@ -396,16 +388,10 @@ where
396388
MR::Target: MessageRouter,
397389
L::Target: Logger,
398390
{
399-
use std::time::SystemTime;
400-
let duration_since_epoch = SystemTime::now()
401-
.duration_since(SystemTime::UNIX_EPOCH)
402-
.expect("for the foreseeable future this shouldn't happen");
403-
404391
let params = Bolt11InvoiceParameters {
405392
currency: Some(network),
406393
amount_msats: amt_msat,
407394
description: Bolt11InvoiceDescription::Hash(description_hash),
408-
duration_since_epoch: Some(duration_since_epoch),
409395
invoice_expiry_delta_secs: Some(invoice_expiry_delta_secs),
410396
min_final_cltv_expiry_delta,
411397
payment_hash: None,
@@ -414,7 +400,6 @@ where
414400
}
415401

416402

417-
#[cfg(feature = "std")]
418403
/// See [`create_invoice_from_channelmanager`]
419404
/// This version allows for providing custom [`PaymentHash`] and description hash for the invoice.
420405
///
@@ -437,24 +422,17 @@ where
437422
MR::Target: MessageRouter,
438423
L::Target: Logger,
439424
{
440-
use std::time::SystemTime;
441-
let duration_since_epoch = SystemTime::now()
442-
.duration_since(SystemTime::UNIX_EPOCH)
443-
.expect("for the foreseeable future this shouldn't happen");
444-
445425
let params = Bolt11InvoiceParameters {
446426
currency: Some(network),
447427
amount_msats: amt_msat,
448428
description: Bolt11InvoiceDescription::Hash(description_hash),
449-
duration_since_epoch: Some(duration_since_epoch),
450429
invoice_expiry_delta_secs: Some(invoice_expiry_delta_secs),
451430
min_final_cltv_expiry_delta,
452431
payment_hash: Some(payment_hash),
453432
};
454433
channelmanager.create_bolt11_invoice(params)
455434
}
456435

457-
#[cfg(feature = "std")]
458436
/// See [`create_invoice_from_channelmanager`]
459437
/// This version allows for providing a custom [`PaymentHash`] for the invoice.
460438
/// This may be useful if you're building an on-chain swap or involving another protocol where
@@ -475,17 +453,11 @@ where
475453
MR::Target: MessageRouter,
476454
L::Target: Logger,
477455
{
478-
use std::time::SystemTime;
479-
let duration_since_epoch = SystemTime::now()
480-
.duration_since(SystemTime::UNIX_EPOCH)
481-
.expect("for the foreseeable future this shouldn't happen");
482-
483456
let description = Description::new(description).map_err(SignOrCreationError::CreationError)?;
484457
let params = Bolt11InvoiceParameters {
485458
currency: Some(network),
486459
amount_msats: amt_msat,
487460
description: Bolt11InvoiceDescription::Direct(description),
488-
duration_since_epoch: Some(duration_since_epoch),
489461
invoice_expiry_delta_secs: Some(invoice_expiry_delta_secs),
490462
min_final_cltv_expiry_delta,
491463
payment_hash: Some(payment_hash),

0 commit comments

Comments
 (0)