Skip to content

Commit 4e0b599

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 5da244e commit 4e0b599

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
@@ -5056,10 +5056,11 @@ where
50565056
///
50575057
/// # Handling Invoice Amounts
50585058
/// Some invoices include a specific amount, while others require you to specify one.
5059-
/// - If the invoice **includes** an amount, user must not provide `amount_msats`.
5059+
/// - If the invoice **includes** an amount, user may provide an amount greater or equal to it
5060+
/// to allow for overpayments.
50605061
/// - If the invoice **doesn't include** an amount, you'll need to specify `amount_msats`.
50615062
///
5062-
/// If these conditions aren’t met, the function will return `Bolt11PaymentError::InvalidAmount`.
5063+
/// If these conditions aren’t met, the function will return [`Bolt11PaymentError::InvalidAmount`].
50635064
///
50645065
/// # Custom Routing Parameters
50655066
/// 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)