Skip to content

Commit 7146763

Browse files
committed
Introduce enqueue_invoice_error API
Adds an API to send an `InvoiceError` to the counterparty via the flow. This becomes useful with the introduction of Flow events in upcoming commits, where the user can choose to either respond to Offers Messages or return an `InvoiceError`. Note: Given the small scope of changes in this commit, we also take the opportunity to perform minor documentation cleanups in `flow.rs`.
1 parent be799c2 commit 7146763

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

lightning/src/offers/flow.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use crate::offers::invoice::{
3939
Bolt12Invoice, DerivedSigningPubkey, ExplicitSigningPubkey, InvoiceBuilder,
4040
DEFAULT_RELATIVE_EXPIRY,
4141
};
42+
use crate::offers::invoice_error::InvoiceError;
4243
use crate::offers::invoice_request::{
4344
CurrencyConversion, InvoiceRequest, InvoiceRequestBuilder, InvoiceRequestVerifiedFromOffer,
4445
VerifiedInvoiceRequest,
@@ -1095,9 +1096,6 @@ where
10951096
/// The user must provide a list of [`MessageForwardNode`] that will be used to generate
10961097
/// valid reply paths for the counterparty to send back the corresponding [`Bolt12Invoice`]
10971098
/// or [`InvoiceError`].
1098-
///
1099-
/// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
1100-
/// [`supports_onion_messages`]: crate::types::features::Features::supports_onion_messages
11011099
pub fn enqueue_invoice_request(
11021100
&self, invoice_request: InvoiceRequest, payment_id: PaymentId, nonce: Nonce,
11031101
peers: Vec<MessageForwardNode>,
@@ -1144,8 +1142,6 @@ where
11441142
/// Reply paths are generated from the given `peers` to allow the counterparty to return
11451143
/// an [`InvoiceError`] in case they fail to process the invoice. If valid reply paths
11461144
/// cannot be constructed, this method returns a [`Bolt12SemanticError::MissingPaths`].
1147-
///
1148-
/// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
11491145
pub fn enqueue_invoice_using_node_id(
11501146
&self, invoice: Bolt12Invoice, destination: PublicKey, peers: Vec<MessageForwardNode>,
11511147
) -> Result<(), Bolt12SemanticError> {
@@ -1200,6 +1196,26 @@ where
12001196
Ok(())
12011197
}
12021198

1199+
/// Enqueues an [`InvoiceError`] to be sent to the counterparty via a specified
1200+
/// [`BlindedMessagePath`].
1201+
///
1202+
/// Since this method returns the invoice error to the counterparty without
1203+
/// expecting back a response, we enqueue it without a reply path.
1204+
pub fn enqueue_invoice_error(
1205+
&self, invoice_error: InvoiceError, path: BlindedMessagePath,
1206+
) -> Result<(), Bolt12SemanticError> {
1207+
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
1208+
1209+
let instructions = MessageSendInstructions::WithoutReplyPath {
1210+
destination: Destination::BlindedPath(path),
1211+
};
1212+
1213+
let message = OffersMessage::InvoiceError(invoice_error);
1214+
pending_offers_messages.push((message, instructions));
1215+
1216+
Ok(())
1217+
}
1218+
12031219
/// Forwards a [`StaticInvoice`] over the provided [`Responder`] in response to an
12041220
/// [`InvoiceRequest`] that we as a static invoice server received on behalf of an often-offline
12051221
/// recipient.
@@ -1252,7 +1268,6 @@ where
12521268
/// reply paths for the recipient to send back the corresponding [`ReleaseHeldHtlc`] onion message.
12531269
///
12541270
/// [`ReleaseHeldHtlc`]: crate::onion_message::async_payments::ReleaseHeldHtlc
1255-
/// [`supports_onion_messages`]: crate::types::features::Features::supports_onion_messages
12561271
pub fn enqueue_held_htlc_available(
12571272
&self, invoice: &StaticInvoice, payment_id: PaymentId, peers: Vec<MessageForwardNode>,
12581273
) -> Result<(), Bolt12SemanticError> {
@@ -1311,8 +1326,6 @@ where
13111326
/// The user must provide a list of [`MessageForwardNode`] that will be used to generate
13121327
/// valid reply paths for the counterparty to send back the corresponding response for
13131328
/// the [`DNSSECQuery`] message.
1314-
///
1315-
/// [`supports_onion_messages`]: crate::types::features::Features::supports_onion_messages
13161329
#[cfg(feature = "dnssec")]
13171330
pub fn enqueue_dns_onion_message(
13181331
&self, message: DNSSECQuery, context: DNSResolverContext, dns_resolvers: Vec<Destination>,

0 commit comments

Comments
 (0)