Skip to content

Commit ec4395c

Browse files
committed
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.
1 parent be8797e commit ec4395c

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7362,6 +7362,9 @@ where
73627362
/// invoice. If abandoned, or an invoice isn't received before expiration, the payment will fail
73637363
/// with an [`Event::InvoiceRequestFailed`].
73647364
///
7365+
/// If `max_total_routing_fee_msat` is not specified, The default from
7366+
/// [`RouteParameters::from_payment_params_and_value`] is applied.
7367+
///
73657368
/// # Privacy
73667369
///
73677370
/// Uses a one-hop [`BlindedPath`] for the refund with [`ChannelManager::get_our_node_id`] as
@@ -7421,6 +7424,9 @@ where
74217424
/// - `amount_msats` if overpaying what is required for the given `quantity` is desired, and
74227425
/// - `payer_note` for [`InvoiceRequest::payer_note`].
74237426
///
7427+
/// If `max_total_routing_fee_msat` is not specified, The default from
7428+
/// [`RouteParameters::from_payment_params_and_value`] is applied.
7429+
///
74247430
/// # Payment
74257431
///
74267432
/// The provided `payment_id` is used to ensure that only one invoice is paid for the request

lightning/src/ln/outbound_payment.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,6 @@ impl OutboundPayments {
762762
}
763763
}
764764

765-
#[allow(unused)]
766765
pub(super) fn send_payment_for_bolt12_invoice<R: Deref, ES: Deref, NS: Deref, IH, SP, L: Deref>(
767766
&self, invoice: &Bolt12Invoice, payment_id: PaymentId, router: &R,
768767
first_hops: Vec<ChannelDetails>, inflight_htlcs: IH, entropy_source: &ES, node_signer: &NS,
@@ -779,7 +778,7 @@ impl OutboundPayments {
779778
SP: Fn(SendAlongPathArgs) -> Result<(), APIError>,
780779
{
781780
let payment_hash = invoice.payment_hash();
782-
let mut max_total_routing_fee_msat = None;
781+
let max_total_routing_fee_msat;
783782
match self.pending_outbound_payments.lock().unwrap().entry(payment_id) {
784783
hash_map::Entry::Occupied(entry) => match entry.get() {
785784
PendingOutboundPayment::AwaitingInvoice { retry_strategy, max_total_routing_fee_msat: max_total_fee, .. } => {
@@ -795,11 +794,12 @@ impl OutboundPayments {
795794
hash_map::Entry::Vacant(_) => return Err(Bolt12PaymentError::UnexpectedInvoice),
796795
};
797796

798-
let route_params = RouteParameters {
799-
payment_params: PaymentParameters::from_bolt12_invoice(&invoice),
800-
final_value_msat: invoice.amount_msats(),
801-
max_total_routing_fee_msat,
802-
};
797+
let pay_params = PaymentParameters::from_bolt12_invoice(&invoice);
798+
let amount_msat = invoice.amount_msats();
799+
let mut route_params = RouteParameters::from_payment_params_and_value(pay_params, amount_msat);
800+
if let Some(max_fee_msat) = max_total_routing_fee_msat {
801+
route_params.max_total_routing_fee_msat = Some(max_fee_msat);
802+
}
803803

804804
self.find_route_and_send_payment(
805805
payment_hash, payment_id, route_params, router, first_hops, &inflight_htlcs,

0 commit comments

Comments
 (0)