Skip to content

Commit d24b953

Browse files
committed
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.
1 parent 0766fbe commit d24b953

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5057,10 +5057,11 @@ where
50575057
///
50585058
/// # Handling Invoice Amounts
50595059
/// Some invoices include a specific amount, while others require you to specify one.
5060-
/// - If the invoice **includes** an amount, user must not provide `amount_msats`.
5060+
/// - If the invoice **includes** an amount, user may provide an amount greater or equal to it
5061+
/// to allow for overpayments.
50615062
/// - If the invoice **doesn't include** an amount, you'll need to specify `amount_msats`.
50625063
///
5063-
/// If these conditions aren’t met, the function will return `Bolt11PaymentError::InvalidAmount`.
5064+
/// If these conditions aren’t met, the function will return [`Bolt11PaymentError::InvalidAmount`].
50645065
///
50655066
/// # Custom Routing Parameters
50665067
/// Users can customize routing parameters via [`RouteParametersConfig`].

lightning/src/ln/outbound_payment.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,7 @@ pub(crate) enum PaymentSendFailure {
589589
#[derive(Debug)]
590590
pub enum Bolt11PaymentError {
591591
/// Incorrect amount was provided to [`ChannelManager::pay_for_bolt11_invoice`].
592-
/// This happens when an amount is specified when [`Bolt11Invoice`] already contains
593-
/// an amount, or vice versa.
592+
/// This happens when the user-provided amount is less than an amount specified in the [`Bolt11Invoice`].
594593
///
595594
/// [`Bolt11Invoice`]: lightning_invoice::Bolt11Invoice
596595
/// [`ChannelManager::pay_for_bolt11_invoice`]: crate::ln::channelmanager::ChannelManager::pay_for_bolt11_invoice
@@ -895,7 +894,9 @@ impl OutboundPayments {
895894

896895
let amount = match (invoice.amount_milli_satoshis(), amount_msats) {
897896
(Some(amt), None) | (None, Some(amt)) => amt,
898-
(None, None) | (Some(_), Some(_)) => return Err(Bolt11PaymentError::InvalidAmount),
897+
(Some(inv_amt), Some(user_amt)) if user_amt < inv_amt => return Err(Bolt11PaymentError::InvalidAmount),
898+
(Some(_), Some(user_amt)) => user_amt,
899+
(None, None) => return Err(Bolt11PaymentError::InvalidAmount),
899900
};
900901

901902
let mut recipient_onion = RecipientOnionFields::secret_only(*invoice.payment_secret());

0 commit comments

Comments
 (0)