Skip to content

Commit 78f6ccb

Browse files
committed
Use RouteParametersConfig to create new RouteParameters
- This finally allow overriding the {Route, Payment} parameters with the RouteParametersConfig value provided by the user.
1 parent 50644df commit 78f6ccb

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

lightning/src/ln/outbound_payment.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -863,15 +863,15 @@ impl OutboundPayments {
863863
SP: Fn(SendAlongPathArgs) -> Result<(), APIError>,
864864
{
865865
let payment_hash = invoice.payment_hash();
866-
let max_total_routing_fee_msat;
866+
let params_config;
867867
let retry_strategy;
868868
match self.pending_outbound_payments.lock().unwrap().entry(payment_id) {
869869
hash_map::Entry::Occupied(entry) => match entry.get() {
870870
PendingOutboundPayment::AwaitingInvoice {
871871
retry_strategy: retry, route_params_config, ..
872872
} => {
873873
retry_strategy = *retry;
874-
max_total_routing_fee_msat = route_params_config.max_total_routing_fee_msat;
874+
params_config = *route_params_config;
875875
*entry.into_mut() = PendingOutboundPayment::InvoiceReceived {
876876
payment_hash,
877877
retry_strategy: *retry,
@@ -891,9 +891,10 @@ impl OutboundPayments {
891891
}
892892

893893
let mut route_params = RouteParameters::from_payment_params_and_value(
894-
PaymentParameters::from_bolt12_invoice(&invoice), invoice.amount_msats()
894+
PaymentParameters::from_bolt12_invoice(&invoice)
895+
.with_user_config_ignoring_fee_limit(params_config), invoice.amount_msats()
895896
);
896-
if let Some(max_fee_msat) = max_total_routing_fee_msat {
897+
if let Some(max_fee_msat) = params_config.max_total_routing_fee_msat {
897898
route_params.max_total_routing_fee_msat = Some(max_fee_msat);
898899
}
899900
self.send_payment_for_bolt12_invoice_internal(
@@ -1066,7 +1067,8 @@ impl OutboundPayments {
10661067
};
10671068
let keysend_preimage = PaymentPreimage(entropy_source.get_secure_random_bytes());
10681069
let payment_hash = PaymentHash(Sha256::hash(&keysend_preimage.0).to_byte_array());
1069-
let pay_params = PaymentParameters::from_static_invoice(invoice);
1070+
let pay_params = PaymentParameters::from_static_invoice(invoice)
1071+
.with_user_config_ignoring_fee_limit(*route_params_config);
10701072
let mut route_params = RouteParameters::from_payment_params_and_value(pay_params, amount_msat);
10711073
route_params.max_total_routing_fee_msat = route_params_config.max_total_routing_fee_msat;
10721074

lightning/src/routing/router.rs

+15
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,21 @@ impl PaymentParameters {
943943
}
944944
}
945945

946+
/// Updates the parameters with the given route parameters configuration.
947+
///
948+
/// Note:
949+
/// We *do not* apply `max_total_routing_fee_msat` here, as it is unique to each route.
950+
/// Instead, we apply only the parameters that are common across multiple route-finding sessions
951+
/// for a payment across retries.
952+
pub(crate) fn with_user_config_ignoring_fee_limit(self, params_config: RouteParametersConfig) -> Self {
953+
Self {
954+
max_total_cltv_expiry_delta: params_config.max_total_cltv_expiry_delta,
955+
max_path_count: params_config.max_path_count,
956+
max_channel_saturation_power_of_half: params_config.max_channel_saturation_power_of_half,
957+
..self
958+
}
959+
}
960+
946961
/// Includes the payee's features. Errors if the parameters were not initialized with
947962
/// [`PaymentParameters::from_bolt12_invoice`].
948963
///

0 commit comments

Comments
 (0)