From da3b1392083f6330e24d6eea88c4b470d66dd789 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Wed, 21 May 2025 13:31:15 +0200 Subject: [PATCH 1/3] Expose `Bolt11PaymentError` We previously changed the BOLT11 payment API, also introducing a new error type in `outbound_payment`. However, we didn't actualy re-export that in `ChannelManager`, so it's currently inaccessible. --- lightning/src/ln/channelmanager.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 50ef6d70464..0e1f0a2c167 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -82,8 +82,8 @@ use crate::ln::our_peer_storage::EncryptedOurPeerStorage; #[cfg(test)] use crate::ln::outbound_payment; use crate::ln::outbound_payment::{ - Bolt11PaymentError, OutboundPayments, PendingOutboundPayment, RetryableInvoiceRequest, - SendAlongPathArgs, StaleExpiration, + OutboundPayments, PendingOutboundPayment, RetryableInvoiceRequest, SendAlongPathArgs, + StaleExpiration, }; use crate::ln::types::ChannelId; use crate::offers::flow::OffersMessageFlow; @@ -187,7 +187,8 @@ use core::{cmp, mem}; #[cfg(any(test, feature = "_externalize_tests"))] pub(crate) use crate::ln::outbound_payment::PaymentSendFailure; pub use crate::ln::outbound_payment::{ - Bolt12PaymentError, ProbeSendFailure, RecipientOnionFields, Retry, RetryableSendFailure, + Bolt11PaymentError, Bolt12PaymentError, ProbeSendFailure, RecipientOnionFields, Retry, + RetryableSendFailure, }; use crate::ln::script::ShutdownScript; From 5da244eb8d06ce7b9e3688b54a6dca9e22163244 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Wed, 21 May 2025 14:35:57 +0200 Subject: [PATCH 2/3] Derive `Debug` for `RouteParametersConfig` .. as we'll reuse it in LDK Node, where we'll need `Debug`. --- lightning/src/routing/router.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 1a76e682668..d27fe1db2f7 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -1075,7 +1075,7 @@ impl PaymentParameters { } /// A struct for configuring parameters for routing the payment. -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] pub struct RouteParametersConfig { /// The maximum total fees, in millisatoshi, that may accrue during route finding. /// From 4e0b59901d1839c28a54bb8377257ee738d791b7 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Thu, 29 May 2025 14:39:41 +0200 Subject: [PATCH 3/3] Allow for BOLT11 overpayments again Previously, we refactored our BOLT11 payment API which made invoice-provided and user-provided amounts mutually exclusive. Here, we restore the original behavior that allows overpaying for invoices, even if they specify a (default) amount. --- lightning/src/ln/channelmanager.rs | 5 +++-- lightning/src/ln/outbound_payment.rs | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 0e1f0a2c167..8179e35a395 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -5056,10 +5056,11 @@ where /// /// # Handling Invoice Amounts /// Some invoices include a specific amount, while others require you to specify one. - /// - If the invoice **includes** an amount, user must not provide `amount_msats`. + /// - If the invoice **includes** an amount, user may provide an amount greater or equal to it + /// to allow for overpayments. /// - If the invoice **doesn't include** an amount, you'll need to specify `amount_msats`. /// - /// If these conditions aren’t met, the function will return `Bolt11PaymentError::InvalidAmount`. + /// If these conditions aren’t met, the function will return [`Bolt11PaymentError::InvalidAmount`]. /// /// # Custom Routing Parameters /// Users can customize routing parameters via [`RouteParametersConfig`]. diff --git a/lightning/src/ln/outbound_payment.rs b/lightning/src/ln/outbound_payment.rs index 1beeb3574db..62bd535d5d4 100644 --- a/lightning/src/ln/outbound_payment.rs +++ b/lightning/src/ln/outbound_payment.rs @@ -589,8 +589,7 @@ pub(crate) enum PaymentSendFailure { #[derive(Debug)] pub enum Bolt11PaymentError { /// Incorrect amount was provided to [`ChannelManager::pay_for_bolt11_invoice`]. - /// This happens when an amount is specified when [`Bolt11Invoice`] already contains - /// an amount, or vice versa. + /// This happens when the user-provided amount is less than an amount specified in the [`Bolt11Invoice`]. /// /// [`Bolt11Invoice`]: lightning_invoice::Bolt11Invoice /// [`ChannelManager::pay_for_bolt11_invoice`]: crate::ln::channelmanager::ChannelManager::pay_for_bolt11_invoice @@ -895,7 +894,9 @@ impl OutboundPayments { let amount = match (invoice.amount_milli_satoshis(), amount_msats) { (Some(amt), None) | (None, Some(amt)) => amt, - (None, None) | (Some(_), Some(_)) => return Err(Bolt11PaymentError::InvalidAmount), + (Some(inv_amt), Some(user_amt)) if user_amt < inv_amt => return Err(Bolt11PaymentError::InvalidAmount), + (Some(_), Some(user_amt)) => user_amt, + (None, None) => return Err(Bolt11PaymentError::InvalidAmount), }; let mut recipient_onion = RecipientOnionFields::secret_only(*invoice.payment_secret());