Skip to content

Commit ff1a3da

Browse files
committed
Add min_final_cltv_expiry parameter to invoice utils
All utility functions for invoice construction will now also accept an Option<>al `min_final_cltv_expiry_delta` which is useful for things like swaps etc. The `min_final_cltv_expiry_delta` will default back to `MIN_FINAL_CLTV_EXPIRY_DELTA` if `None` is provided.
1 parent e20d53a commit ff1a3da

File tree

4 files changed

+169
-32
lines changed

4 files changed

+169
-32
lines changed

lightning-invoice/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,11 @@ pub enum CreationError {
14481448
///
14491449
/// [phantom invoices]: crate::utils::create_phantom_invoice
14501450
MissingRouteHints,
1451+
1452+
/// The provided `min_final_cltv_expiry_delta` was less than [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
1453+
///
1454+
/// [`MIN_FINAL_CLTV_EXPIRY_DELTA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
1455+
MinFinalCltvExpiryDeltaTooShort,
14511456
}
14521457

14531458
impl Display for CreationError {
@@ -1458,6 +1463,8 @@ impl Display for CreationError {
14581463
CreationError::TimestampOutOfBounds => f.write_str("The Unix timestamp of the supplied date is less than zero or greater than 35-bits"),
14591464
CreationError::InvalidAmount => f.write_str("The supplied millisatoshi amount was greater than the total bitcoin supply"),
14601465
CreationError::MissingRouteHints => f.write_str("The invoice required route hints and they weren't provided"),
1466+
CreationError::MinFinalCltvExpiryDeltaTooShort => f.write_str(
1467+
"The supplied final CLTV expiry delta was less than LDK's `MIN_FINAL_CLTV_EXPIRY_DELTA`"),
14611468
}
14621469
}
14631470
}

lightning-invoice/src/payment.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,7 +2085,7 @@ mod tests {
20852085

20862086
assert!(invoice_payer.pay_invoice(&create_invoice_from_channelmanager_and_duration_since_epoch(
20872087
&nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::Bitcoin,
2088-
Some(100_010_000), "Invoice".to_string(), duration_since_epoch(), 3600).unwrap())
2088+
Some(100_010_000), "Invoice".to_string(), duration_since_epoch(), 3600, None).unwrap())
20892089
.is_ok());
20902090
let htlc_msgs = nodes[0].node.get_and_clear_pending_msg_events();
20912091
assert_eq!(htlc_msgs.len(), 2);
@@ -2130,7 +2130,7 @@ mod tests {
21302130

21312131
assert!(invoice_payer.pay_invoice(&create_invoice_from_channelmanager_and_duration_since_epoch(
21322132
&nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::Bitcoin,
2133-
Some(100_010_000), "Invoice".to_string(), duration_since_epoch(), 3600).unwrap())
2133+
Some(100_010_000), "Invoice".to_string(), duration_since_epoch(), 3600, None).unwrap())
21342134
.is_ok());
21352135
let htlc_msgs = nodes[0].node.get_and_clear_pending_msg_events();
21362136
assert_eq!(htlc_msgs.len(), 2);
@@ -2211,7 +2211,7 @@ mod tests {
22112211

22122212
assert!(invoice_payer.pay_invoice(&create_invoice_from_channelmanager_and_duration_since_epoch(
22132213
&nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::Bitcoin,
2214-
Some(100_010_000), "Invoice".to_string(), duration_since_epoch(), 3600).unwrap())
2214+
Some(100_010_000), "Invoice".to_string(), duration_since_epoch(), 3600, None).unwrap())
22152215
.is_ok());
22162216
let htlc_updates = SendEvent::from_node(&nodes[0]);
22172217
check_added_monitors!(nodes[0], 1);

0 commit comments

Comments
 (0)