Skip to content

Commit 2b13557

Browse files
committed
Use the PaymentParameter final CLTV delta over RouteParameters
`PaymentParams` is all about the parameters for a payment, i.e. the parameters which are static across all the paths of a paymet. `RouteParameters` is about the information specific to a given `Route` (i.e. a set of paths, among multiple potential sets of paths for a payment). The CLTV delta thus doesn't belong in `RouterParameters` but instead in `PaymentParameters`. Worse, because `RouteParameters` is built from the information in the last hops of a `Route`, when we deliberately inflate the CLTV delta in path-finding, retries of the payment will have the final CLTV delta double-inflated as it inflates starting from the final CLTV delta used in the last attempt. When we calculate the `final_cltv_expiry_delta` to put in the `RouteParameters` returned via events after a payment failure, we should re-use the new one in the `PaymentParameters`, rather than the one that was in the route itself.
1 parent fbc0847 commit 2b13557

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ pub(crate) enum HTLCSource {
245245
first_hop_htlc_msat: u64,
246246
payment_id: PaymentId,
247247
payment_secret: Option<PaymentSecret>,
248+
/// Note that this is now "deprecated" - we write it for forwards (and read it for
249+
/// backwards) compatibility reasons, but prefer to use the data in the
250+
/// [`super::outbound_payment`] module, which stores per-payment data once instead of in
251+
/// each HTLC.
248252
payment_params: Option<PaymentParameters>,
249253
},
250254
}

lightning/src/ln/outbound_payment.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,9 @@ impl OutboundPayments {
789789
Some(RouteParameters {
790790
payment_params: payment_params.clone(),
791791
final_value_msat: pending_amt_unsent,
792-
final_cltv_expiry_delta: max_unsent_cltv_delta,
792+
final_cltv_expiry_delta:
793+
if let Some(delta) = payment_params.final_cltv_expiry_delta { delta }
794+
else { max_unsent_cltv_delta },
793795
})
794796
} else { None }
795797
} else { None },
@@ -987,7 +989,9 @@ impl OutboundPayments {
987989
Some(RouteParameters {
988990
payment_params: payment_params_data.clone(),
989991
final_value_msat: path_last_hop.fee_msat,
990-
final_cltv_expiry_delta: path_last_hop.cltv_expiry_delta,
992+
final_cltv_expiry_delta:
993+
if let Some(delta) = payment_params_data.final_cltv_expiry_delta { delta }
994+
else { path_last_hop.cltv_expiry_delta },
991995
})
992996
} else { None };
993997
log_trace!(logger, "Failing outbound payment HTLC with payment_hash {}", log_bytes!(payment_hash.0));

0 commit comments

Comments
 (0)