Skip to content

Commit 271522d

Browse files
committed
Utilize ManualRoutingParameters to create new RouteParams
In addition to using PaymentParameters from the invoice, this commit enables the creation of RouteParameters using the values optionally set in ManualRoutingParameters.
1 parent 2297ce3 commit 271522d

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

lightning/src/ln/outbound_payment.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -844,21 +844,19 @@ impl OutboundPayments {
844844
SP: Fn(SendAlongPathArgs) -> Result<(), APIError>,
845845
{
846846
let payment_hash = invoice.payment_hash();
847-
let max_total_routing_fee_msat;
847+
let routing_params;
848848
let retry_strategy;
849849
match self.pending_outbound_payments.lock().unwrap().entry(payment_id) {
850850
hash_map::Entry::Occupied(entry) => match entry.get() {
851851
PendingOutboundPayment::AwaitingInvoice {
852852
retry_strategy: retry, manual_routing_params, ..
853853
} => {
854854
retry_strategy = *retry;
855-
max_total_routing_fee_msat = manual_routing_params.map(
856-
|params| params.max_total_routing_fee_msat
857-
).flatten();
855+
routing_params = manual_routing_params.unwrap_or_else(|| ManualRoutingParameters::new());
858856
*entry.into_mut() = PendingOutboundPayment::InvoiceReceived {
859857
payment_hash,
860858
retry_strategy: *retry,
861-
max_total_routing_fee_msat,
859+
max_total_routing_fee_msat: routing_params.max_total_routing_fee_msat,
862860
};
863861
},
864862
_ => return Err(Bolt12PaymentError::DuplicateInvoice),
@@ -873,12 +871,10 @@ impl OutboundPayments {
873871
return Err(Bolt12PaymentError::UnknownRequiredFeatures);
874872
}
875873

876-
let mut route_params = RouteParameters::from_payment_params_and_value(
877-
PaymentParameters::from_bolt12_invoice(&invoice), invoice.amount_msats()
874+
let route_params = RouteParameters::from_payment_and_manual_params(
875+
PaymentParameters::from_bolt12_invoice(&invoice), invoice.amount_msats(), routing_params
878876
);
879-
if let Some(max_fee_msat) = max_total_routing_fee_msat {
880-
route_params.max_total_routing_fee_msat = Some(max_fee_msat);
881-
}
877+
882878
self.send_payment_for_bolt12_invoice_internal(
883879
payment_id, payment_hash, None, route_params, retry_strategy, router, first_hops,
884880
inflight_htlcs, entropy_source, node_signer, node_id_lookup, secp_ctx, best_block_height,

lightning/src/routing/router.rs

+18
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,24 @@ impl RouteParameters {
607607
Self { payment_params, final_value_msat, max_total_routing_fee_msat: Some(final_value_msat / 100 + 50_000) }
608608
}
609609

610+
/// Constructs [`RouteParameters`] from the given [`PaymentParameters`], a payment amount,
611+
/// and from the provided [`ManualRoutingParameters`].
612+
///
613+
/// [`Self::max_total_routing_fee_msat`] defaults to 1% of the payment amount + 50 sats
614+
pub fn from_payment_and_manual_params(mut payment_params: PaymentParameters, final_value_msat: u64, manual_routing_params: ManualRoutingParameters) -> Self {
615+
manual_routing_params.max_total_cltv_expiry_delta.map(|v| payment_params.max_total_cltv_expiry_delta = v);
616+
manual_routing_params.max_path_count.map(|v| payment_params.max_path_count = v);
617+
manual_routing_params.max_channel_saturation_power_of_half.map(|v| payment_params.max_channel_saturation_power_of_half = v);
618+
619+
let mut route_params = RouteParameters::from_payment_params_and_value(payment_params, final_value_msat);
620+
621+
manual_routing_params.max_total_routing_fee_msat.map(
622+
|fee_msat| route_params.max_total_routing_fee_msat = Some(fee_msat)
623+
);
624+
625+
route_params
626+
}
627+
610628
/// Sets the maximum number of hops that can be included in a payment path, based on the provided
611629
/// [`RecipientOnionFields`] and blinded paths.
612630
pub fn set_max_path_length(

0 commit comments

Comments
 (0)