Skip to content

Commit 542deeb

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 e810075 commit 542deeb

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lightning/src/ln/channelmanager.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -10182,7 +10182,7 @@ where
1018210182
Ok((payment_hash, payment_secret)) => {
1018310183
let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
1018410184
let payment_paths = self.create_blinded_payment_paths(
10185-
Some(amount_msats), payment_secret, payment_context
10185+
Some(amount_msats), payment_secret, payment_context, relative_expiry,
1018610186
)
1018710187
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
1018810188

@@ -10489,16 +10489,22 @@ where
1048910489
/// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
1049010490
/// [`Router::create_blinded_payment_paths`].
1049110491
fn create_blinded_payment_paths(
10492-
&self, amount_msats: Option<u64>, payment_secret: PaymentSecret, payment_context: PaymentContext
10492+
&self, amount_msats: Option<u64>, payment_secret: PaymentSecret, payment_context: PaymentContext,
10493+
relative_expiry_seconds: u32
1049310494
) -> Result<Vec<BlindedPaymentPath>, ()> {
1049410495
let expanded_key = &self.inbound_payment_key;
1049510496
let entropy = &*self.entropy_source;
1049610497
let secp_ctx = &self.secp_ctx;
1049710498

1049810499
let first_hops = self.list_usable_channels();
1049910500
let payee_node_id = self.get_our_node_id();
10500-
let max_cltv_expiry = self.best_block.read().unwrap().height + CLTV_FAR_FAR_AWAY
10501-
+ LATENCY_GRACE_PERIOD_BLOCKS;
10501+
10502+
// Assume shorter than usual block times to avoid spuriously failing payments too early.
10503+
const SECONDS_PER_BLOCK: u32 = 9 * 60;
10504+
let relative_expiry_blocks = relative_expiry_seconds / SECONDS_PER_BLOCK;
10505+
let max_cltv_expiry = core::cmp::max(relative_expiry_blocks, CLTV_FAR_FAR_AWAY)
10506+
.saturating_add(LATENCY_GRACE_PERIOD_BLOCKS)
10507+
.saturating_add(self.best_block.read().unwrap().height);
1050210508

1050310509
let payee_tlvs = UnauthenticatedReceiveTlvs {
1050410510
payment_secret,
@@ -12048,7 +12054,7 @@ where
1204812054
invoice_request: invoice_request.fields(),
1204912055
});
1205012056
let payment_paths = match self.create_blinded_payment_paths(
12051-
Some(amount_msats), payment_secret, payment_context
12057+
Some(amount_msats), payment_secret, payment_context, relative_expiry
1205212058
) {
1205312059
Ok(payment_paths) => payment_paths,
1205412060
Err(()) => {

0 commit comments

Comments
 (0)