Skip to content

Commit bf0a5e7

Browse files
committed
Use default for invoice's min_final_cltv_expiry
1 parent 2a857f1 commit bf0a5e7

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lightning-invoice/src/lib.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ const MAX_EXPIRY_TIME: u64 = 60 * 60 * 24 * 356;
5959
/// [BOLT 11]: https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md
6060
const DEFAULT_EXPIRY_TIME: u64 = 3600;
6161

62+
/// Default minimum final CLTV expiry as defined by [BOLT 11].
63+
///
64+
/// [BOLT 11]: https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md
65+
const DEFAULT_MIN_FINAL_CLTV_EXPIRY: u64 = 18;
66+
6267
/// This function is used as a static assert for the size of `SystemTime`. If the crate fails to
6368
/// compile due to it this indicates that your system uses unexpected bounds for `SystemTime`. You
6469
/// can remove this functions and run the test `test_system_time_bounds_assumptions`. In any case,
@@ -1033,9 +1038,12 @@ impl Invoice {
10331038
.unwrap_or(Duration::from_secs(DEFAULT_EXPIRY_TIME))
10341039
}
10351040

1036-
/// Returns the invoice's `min_cltv_expiry` time if present
1037-
pub fn min_final_cltv_expiry(&self) -> Option<&u64> {
1038-
self.signed_invoice.min_final_cltv_expiry().map(|x| &x.0)
1041+
/// Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise
1042+
/// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`].
1043+
pub fn min_final_cltv_expiry(&self) -> u64 {
1044+
self.signed_invoice.min_final_cltv_expiry()
1045+
.map(|x| x.0)
1046+
.unwrap_or(DEFAULT_MIN_FINAL_CLTV_EXPIRY)
10391047
}
10401048

10411049
/// Returns a list of all fallback addresses
@@ -1596,7 +1604,7 @@ mod test {
15961604
);
15971605
assert_eq!(invoice.payee_pub_key(), Some(&public_key));
15981606
assert_eq!(invoice.expiry_time(), Duration::from_secs(54321));
1599-
assert_eq!(invoice.min_final_cltv_expiry(), Some(&144));
1607+
assert_eq!(invoice.min_final_cltv_expiry(), 144);
16001608
assert_eq!(invoice.fallbacks(), vec![&Fallback::PubKeyHash([0;20])]);
16011609
assert_eq!(invoice.routes(), vec![&RouteHint(route_1), &RouteHint(route_2)]);
16021610
assert_eq!(

0 commit comments

Comments
 (0)