Skip to content

Commit 389d169

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 b34443f commit 389d169

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
@@ -10152,7 +10152,7 @@ where
1015210152
Ok((payment_hash, payment_secret)) => {
1015310153
let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
1015410154
let payment_paths = self.create_blinded_payment_paths(
10155-
Some(amount_msats), payment_secret, payment_context
10155+
Some(amount_msats), payment_secret, payment_context, relative_expiry,
1015610156
)
1015710157
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
1015810158

@@ -10459,16 +10459,22 @@ where
1045910459
/// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
1046010460
/// [`Router::create_blinded_payment_paths`].
1046110461
fn create_blinded_payment_paths(
10462-
&self, amount_msats: Option<u64>, payment_secret: PaymentSecret, payment_context: PaymentContext
10462+
&self, amount_msats: Option<u64>, payment_secret: PaymentSecret, payment_context: PaymentContext,
10463+
relative_expiry_seconds: u32
1046310464
) -> Result<Vec<BlindedPaymentPath>, ()> {
1046410465
let expanded_key = &self.inbound_payment_key;
1046510466
let entropy = &*self.entropy_source;
1046610467
let secp_ctx = &self.secp_ctx;
1046710468

1046810469
let first_hops = self.list_usable_channels();
1046910470
let payee_node_id = self.get_our_node_id();
10470-
let max_cltv_expiry = self.best_block.read().unwrap().height + CLTV_FAR_FAR_AWAY
10471-
+ LATENCY_GRACE_PERIOD_BLOCKS;
10471+
10472+
// Assume shorter than usual block times to avoid spuriously failing payments too early.
10473+
const SECONDS_PER_BLOCK: u32 = 9 * 60;
10474+
let relative_expiry_blocks = relative_expiry_seconds / SECONDS_PER_BLOCK;
10475+
let max_cltv_expiry = core::cmp::max(relative_expiry_blocks, CLTV_FAR_FAR_AWAY)
10476+
.saturating_add(LATENCY_GRACE_PERIOD_BLOCKS)
10477+
.saturating_add(self.best_block.read().unwrap().height);
1047210478

1047310479
let payee_tlvs = UnauthenticatedReceiveTlvs {
1047410480
payment_secret,
@@ -12030,7 +12036,7 @@ where
1203012036
invoice_request: invoice_request.fields(),
1203112037
});
1203212038
let payment_paths = match self.create_blinded_payment_paths(
12033-
Some(amount_msats), payment_secret, payment_context
12039+
Some(amount_msats), payment_secret, payment_context, relative_expiry
1203412040
) {
1203512041
Ok(payment_paths) => payment_paths,
1203612042
Err(()) => {

0 commit comments

Comments
 (0)