From: Matt Corallo Date: Fri, 27 Jan 2023 20:28:20 +0000 (+0000) Subject: Use the `PaymentParameter` final CLTV delta over `RouteParameters` X-Git-Tag: v0.0.114-beta~32^2~5 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=2b135578e8e88d3e8a16463be7a8ef4458abd33e;p=rust-lightning 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. --- diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 64c3ee6f6..8620c3cc1 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -245,6 +245,10 @@ pub(crate) enum HTLCSource { first_hop_htlc_msat: u64, payment_id: PaymentId, payment_secret: Option, + /// Note that this is now "deprecated" - we write it for forwards (and read it for + /// backwards) compatibility reasons, but prefer to use the data in the + /// [`super::outbound_payment`] module, which stores per-payment data once instead of in + /// each HTLC. payment_params: Option, }, } diff --git a/lightning/src/ln/outbound_payment.rs b/lightning/src/ln/outbound_payment.rs index c91829393..a8acb9e80 100644 --- a/lightning/src/ln/outbound_payment.rs +++ b/lightning/src/ln/outbound_payment.rs @@ -789,7 +789,9 @@ impl OutboundPayments { Some(RouteParameters { payment_params: payment_params.clone(), final_value_msat: pending_amt_unsent, - final_cltv_expiry_delta: max_unsent_cltv_delta, + final_cltv_expiry_delta: + if let Some(delta) = payment_params.final_cltv_expiry_delta { delta } + else { max_unsent_cltv_delta }, }) } else { None } } else { None }, @@ -987,7 +989,9 @@ impl OutboundPayments { Some(RouteParameters { payment_params: payment_params_data.clone(), final_value_msat: path_last_hop.fee_msat, - final_cltv_expiry_delta: path_last_hop.cltv_expiry_delta, + final_cltv_expiry_delta: + if let Some(delta) = payment_params_data.final_cltv_expiry_delta { delta } + else { path_last_hop.cltv_expiry_delta }, }) } else { None }; log_trace!(logger, "Failing outbound payment HTLC with payment_hash {}", log_bytes!(payment_hash.0));