From ec4395cf6eae14605cd41fc715a08ac0bcd786c3 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 20 Oct 2023 17:31:42 +0000 Subject: [PATCH] Apply a default max fee rather than none when paying for BOLT12 If the user declines to specify a `max_total_routing_fee_msat` in the new BOLT12 payment methods, rather than defaulting to no limit on the fee we pay at all, we should default to our "usual default", ie the one calculated in `RouteParameters::from_payment_params_and_value`. We do this here, as well as documenting the behavior on the payment methods. --- lightning/src/ln/channelmanager.rs | 6 ++++++ lightning/src/ln/outbound_payment.rs | 14 +++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index c9eb534db..4f3caef03 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -7362,6 +7362,9 @@ where /// invoice. If abandoned, or an invoice isn't received before expiration, the payment will fail /// with an [`Event::InvoiceRequestFailed`]. /// + /// If `max_total_routing_fee_msat` is not specified, The default from + /// [`RouteParameters::from_payment_params_and_value`] is applied. + /// /// # Privacy /// /// Uses a one-hop [`BlindedPath`] for the refund with [`ChannelManager::get_our_node_id`] as @@ -7421,6 +7424,9 @@ where /// - `amount_msats` if overpaying what is required for the given `quantity` is desired, and /// - `payer_note` for [`InvoiceRequest::payer_note`]. /// + /// If `max_total_routing_fee_msat` is not specified, The default from + /// [`RouteParameters::from_payment_params_and_value`] is applied. + /// /// # Payment /// /// The provided `payment_id` is used to ensure that only one invoice is paid for the request diff --git a/lightning/src/ln/outbound_payment.rs b/lightning/src/ln/outbound_payment.rs index a0aca5105..0fbb0f5ea 100644 --- a/lightning/src/ln/outbound_payment.rs +++ b/lightning/src/ln/outbound_payment.rs @@ -762,7 +762,6 @@ impl OutboundPayments { } } - #[allow(unused)] pub(super) fn send_payment_for_bolt12_invoice( &self, invoice: &Bolt12Invoice, payment_id: PaymentId, router: &R, first_hops: Vec, inflight_htlcs: IH, entropy_source: &ES, node_signer: &NS, @@ -779,7 +778,7 @@ impl OutboundPayments { SP: Fn(SendAlongPathArgs) -> Result<(), APIError>, { let payment_hash = invoice.payment_hash(); - let mut max_total_routing_fee_msat = None; + let max_total_routing_fee_msat; match self.pending_outbound_payments.lock().unwrap().entry(payment_id) { hash_map::Entry::Occupied(entry) => match entry.get() { PendingOutboundPayment::AwaitingInvoice { retry_strategy, max_total_routing_fee_msat: max_total_fee, .. } => { @@ -795,11 +794,12 @@ impl OutboundPayments { hash_map::Entry::Vacant(_) => return Err(Bolt12PaymentError::UnexpectedInvoice), }; - let route_params = RouteParameters { - payment_params: PaymentParameters::from_bolt12_invoice(&invoice), - final_value_msat: invoice.amount_msats(), - max_total_routing_fee_msat, - }; + let pay_params = PaymentParameters::from_bolt12_invoice(&invoice); + let amount_msat = invoice.amount_msats(); + let mut route_params = RouteParameters::from_payment_params_and_value(pay_params, amount_msat); + if let Some(max_fee_msat) = max_total_routing_fee_msat { + route_params.max_total_routing_fee_msat = Some(max_fee_msat); + } self.find_route_and_send_payment( payment_hash, payment_id, route_params, router, first_hops, &inflight_htlcs, -- 2.39.5