Skip to content

Commit 63b08a4

Browse files
committed
Use RouteParametersConfig to create new RouteParameters
1 parent a98f623 commit 63b08a4

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

lightning/src/ln/outbound_payment.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ impl OutboundPayments {
851851
SP: Fn(SendAlongPathArgs) -> Result<(), APIError>,
852852
{
853853
let payment_hash = invoice.payment_hash();
854-
let max_total_routing_fee_msat;
854+
let params_config;
855855
let retry_strategy;
856856
match self.pending_outbound_payments.lock().unwrap().entry(payment_id) {
857857
hash_map::Entry::Occupied(entry) => match entry.get() {
@@ -860,14 +860,17 @@ impl OutboundPayments {
860860
} => {
861861
retry_strategy = *retry;
862862
// If max_total_fee is present, update route_params_config with the specified fee.
863-
// This supports the standard behavior during downgrades.
864-
let route_params_config = max_total_fee.map_or(*route_params_config, |fee_msat| route_params_config.with_max_total_routing_fee_msat(fee_msat));
865-
max_total_routing_fee_msat = route_params_config.max_total_routing_fee_msat;
863+
// This supports the standard behavior during downgrades.
864+
let route_params_config = max_total_fee.map_or(
865+
*route_params_config,
866+
|fee_msat| route_params_config.with_max_total_routing_fee_msat(fee_msat),
867+
);
868+
params_config = route_params_config;
866869
*entry.into_mut() = PendingOutboundPayment::InvoiceReceived {
867870
payment_hash,
868871
retry_strategy: *retry,
869872
max_total_routing_fee_msat: *max_total_fee,
870-
route_params_config: route_params_config,
873+
route_params_config,
871874
};
872875
},
873876
_ => return Err(Bolt12PaymentError::DuplicateInvoice),
@@ -883,11 +886,11 @@ impl OutboundPayments {
883886
}
884887

885888
let mut route_params = RouteParameters::from_payment_params_and_value(
886-
PaymentParameters::from_bolt12_invoice(&invoice), invoice.amount_msats()
889+
PaymentParameters::from_bolt12_invoice(&invoice).with_user_config(params_config), invoice.amount_msats()
887890
);
888-
if let Some(max_fee_msat) = max_total_routing_fee_msat {
889-
route_params.max_total_routing_fee_msat = Some(max_fee_msat);
890-
}
891+
892+
params_config.max_total_routing_fee_msat.map(|fee_msat| route_params.max_total_routing_fee_msat = Some(fee_msat));
893+
891894
self.send_payment_for_bolt12_invoice_internal(
892895
payment_id, payment_hash, None, route_params, retry_strategy, router, first_hops,
893896
inflight_htlcs, entropy_source, node_signer, node_id_lookup, secp_ctx, best_block_height,

lightning/src/routing/router.rs

+10
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,16 @@ impl PaymentParameters {
875875
}
876876
}
877877

878+
/// Update the parameters with the configuration provided by user.
879+
pub fn with_user_config(self, params_config: RouteParametersConfig) -> Self {
880+
Self {
881+
max_total_cltv_expiry_delta: params_config.max_total_cltv_expiry_delta,
882+
max_path_count: params_config.max_path_count,
883+
max_channel_saturation_power_of_half: params_config.max_channel_saturation_power_of_half,
884+
.. self
885+
}
886+
}
887+
878888
/// Includes the payee's features. Errors if the parameters were not initialized with
879889
/// [`PaymentParameters::from_bolt12_invoice`].
880890
///

0 commit comments

Comments
 (0)