Skip to content

Commit 5d1dd58

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 a3a49e5 commit 5d1dd58

File tree

4 files changed

+126
-33
lines changed

4 files changed

+126
-33
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
@@ -2081,7 +2081,7 @@ mod tests {
20812081

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

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

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

0 commit comments

Comments
 (0)