Skip to content

Various BOLT11 payment interface fixes #3810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -5055,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`].
Expand Down
7 changes: 4 additions & 3 deletions lightning/src/ln/outbound_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/routing/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
Loading