Skip to content

Commit 2b57d9e

Browse files
Factor invoice expiry into blinded path max_cltv_expiry
Will be useful for static invoices' blinded paths, which may have long expiries. Rather than having a default max_cltv_expiry, we now base it on the invoice expiry.
1 parent 5c31700 commit 2b57d9e

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9748,7 +9748,7 @@ where
97489748
Ok((payment_hash, payment_secret)) => {
97499749
let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
97509750
let payment_paths = self.create_blinded_payment_paths(
9751-
Some(amount_msats), payment_secret, payment_context
9751+
Some(amount_msats), payment_secret, payment_context, relative_expiry,
97529752
)
97539753
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
97549754

@@ -10055,14 +10055,21 @@ where
1005510055
/// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
1005610056
/// [`Router::create_blinded_payment_paths`].
1005710057
fn create_blinded_payment_paths(
10058-
&self, amount_msats: Option<u64>, payment_secret: PaymentSecret, payment_context: PaymentContext
10058+
&self, amount_msats: Option<u64>, payment_secret: PaymentSecret, payment_context: PaymentContext,
10059+
relative_expiry_seconds: u32
1005910060
) -> Result<Vec<BlindedPaymentPath>, ()> {
1006010061
let secp_ctx = &self.secp_ctx;
1006110062

1006210063
let first_hops = self.list_usable_channels();
1006310064
let payee_node_id = self.get_our_node_id();
10064-
let max_cltv_expiry = self.best_block.read().unwrap().height + CLTV_FAR_FAR_AWAY
10065-
+ LATENCY_GRACE_PERIOD_BLOCKS;
10065+
10066+
// Assume shorter than usual block times to avoid spuriously failing payments too early.
10067+
const SECONDS_PER_BLOCK: u32 = 9 * 60;
10068+
let relative_expiry_blocks = relative_expiry_seconds / SECONDS_PER_BLOCK;
10069+
let max_cltv_expiry = core::cmp::max(relative_expiry_blocks, CLTV_FAR_FAR_AWAY)
10070+
.saturating_add(LATENCY_GRACE_PERIOD_BLOCKS)
10071+
.saturating_add(self.best_block.read().unwrap().height);
10072+
1006610073
let payee_tlvs = ReceiveTlvs {
1006710074
payment_secret,
1006810075
payment_constraints: PaymentConstraints {
@@ -11585,7 +11592,7 @@ where
1158511592
invoice_request: invoice_request.fields(),
1158611593
});
1158711594
let payment_paths = match self.create_blinded_payment_paths(
11588-
Some(amount_msats), payment_secret, payment_context
11595+
Some(amount_msats), payment_secret, payment_context, relative_expiry
1158911596
) {
1159011597
Ok(payment_paths) => payment_paths,
1159111598
Err(()) => {

0 commit comments

Comments
 (0)