Skip to content

Commit a91c405

Browse files
valentinewallacetnull
authored andcommitted
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 649b021 commit a91c405

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10143,7 +10143,7 @@ where
1014310143
Ok((payment_hash, payment_secret)) => {
1014410144
let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
1014510145
let payment_paths = self.create_blinded_payment_paths(
10146-
Some(amount_msats), payment_secret, payment_context
10146+
Some(amount_msats), payment_secret, payment_context, relative_expiry,
1014710147
)
1014810148
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
1014910149

@@ -10450,16 +10450,22 @@ where
1045010450
/// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
1045110451
/// [`Router::create_blinded_payment_paths`].
1045210452
fn create_blinded_payment_paths(
10453-
&self, amount_msats: Option<u64>, payment_secret: PaymentSecret, payment_context: PaymentContext
10453+
&self, amount_msats: Option<u64>, payment_secret: PaymentSecret, payment_context: PaymentContext,
10454+
relative_expiry_seconds: u32
1045410455
) -> Result<Vec<BlindedPaymentPath>, ()> {
1045510456
let expanded_key = &self.inbound_payment_key;
1045610457
let entropy = &*self.entropy_source;
1045710458
let secp_ctx = &self.secp_ctx;
1045810459

1045910460
let first_hops = self.list_usable_channels();
1046010461
let payee_node_id = self.get_our_node_id();
10461-
let max_cltv_expiry = self.best_block.read().unwrap().height + CLTV_FAR_FAR_AWAY
10462-
+ LATENCY_GRACE_PERIOD_BLOCKS;
10462+
10463+
// Assume shorter than usual block times to avoid spuriously failing payments too early.
10464+
const SECONDS_PER_BLOCK: u32 = 9 * 60;
10465+
let relative_expiry_blocks = relative_expiry_seconds / SECONDS_PER_BLOCK;
10466+
let max_cltv_expiry = core::cmp::max(relative_expiry_blocks, CLTV_FAR_FAR_AWAY)
10467+
.saturating_add(LATENCY_GRACE_PERIOD_BLOCKS)
10468+
.saturating_add(self.best_block.read().unwrap().height);
1046310469

1046410470
let payee_tlvs = UnauthenticatedReceiveTlvs {
1046510471
payment_secret,
@@ -12004,7 +12010,7 @@ where
1200412010
invoice_request: invoice_request.fields(),
1200512011
});
1200612012
let payment_paths = match self.create_blinded_payment_paths(
12007-
Some(amount_msats), payment_secret, payment_context
12013+
Some(amount_msats), payment_secret, payment_context, relative_expiry
1200812014
) {
1200912015
Ok(payment_paths) => payment_paths,
1201012016
Err(()) => {

0 commit comments

Comments
 (0)