Skip to content

Commit c86da43

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 c7cf712 commit c86da43

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,
@@ -1080,9 +1081,6 @@ where
10801081
/// The user must provide a list of [`MessageForwardNode`] that will be used to generate
10811082
/// valid reply paths for the counterparty to send back the corresponding [`Bolt12Invoice`]
10821083
/// or [`InvoiceError`].
1083-
///
1084-
/// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
1085-
/// [`supports_onion_messages`]: crate::types::features::Features::supports_onion_messages
10861084
pub fn enqueue_invoice_request(
10871085
&self, invoice_request: InvoiceRequest, payment_id: PaymentId, nonce: Nonce,
10881086
peers: Vec<MessageForwardNode>,
@@ -1129,8 +1127,6 @@ where
11291127
/// Reply paths are generated from the given `peers` to allow the counterparty to return
11301128
/// an [`InvoiceError`] in case they fail to process the invoice. If valid reply paths
11311129
/// cannot be constructed, this method returns a [`Bolt12SemanticError::MissingPaths`].
1132-
///
1133-
/// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
11341130
pub fn enqueue_invoice_using_node_id(
11351131
&self, invoice: Bolt12Invoice, destination: PublicKey, peers: Vec<MessageForwardNode>,
11361132
) -> Result<(), Bolt12SemanticError> {
@@ -1185,6 +1181,26 @@ where
11851181
Ok(())
11861182
}
11871183

1184+
/// Enqueues an [`InvoiceError`] to be sent to the counterparty via a specified
1185+
/// [`BlindedMessagePath`].
1186+
///
1187+
/// Since this method returns the invoice error to the counterparty without
1188+
/// expecting back a response, we enqueue it without a reply path.
1189+
pub fn enqueue_invoice_error(
1190+
&self, invoice_error: InvoiceError, path: BlindedMessagePath,
1191+
) -> Result<(), Bolt12SemanticError> {
1192+
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
1193+
1194+
let instructions = MessageSendInstructions::WithoutReplyPath {
1195+
destination: Destination::BlindedPath(path),
1196+
};
1197+
1198+
let message = OffersMessage::InvoiceError(invoice_error);
1199+
pending_offers_messages.push((message, instructions));
1200+
1201+
Ok(())
1202+
}
1203+
11881204
/// Forwards a [`StaticInvoice`] over the provided [`Responder`] in response to an
11891205
/// [`InvoiceRequest`] that we as a static invoice server received on behalf of an often-offline
11901206
/// recipient.
@@ -1215,7 +1231,6 @@ where
12151231
/// reply paths for the recipient to send back the corresponding [`ReleaseHeldHtlc`] onion message.
12161232
///
12171233
/// [`ReleaseHeldHtlc`]: crate::onion_message::async_payments::ReleaseHeldHtlc
1218-
/// [`supports_onion_messages`]: crate::types::features::Features::supports_onion_messages
12191234
pub fn enqueue_held_htlc_available(
12201235
&self, invoice: &StaticInvoice, payment_id: PaymentId, peers: Vec<MessageForwardNode>,
12211236
) -> Result<(), Bolt12SemanticError> {
@@ -1247,8 +1262,6 @@ where
12471262
/// The user must provide a list of [`MessageForwardNode`] that will be used to generate
12481263
/// valid reply paths for the counterparty to send back the corresponding response for
12491264
/// the [`DNSSECQuery`] message.
1250-
///
1251-
/// [`supports_onion_messages`]: crate::types::features::Features::supports_onion_messages
12521265
#[cfg(feature = "dnssec")]
12531266
pub fn enqueue_dns_onion_message(
12541267
&self, message: DNSSECQuery, context: DNSResolverContext, dns_resolvers: Vec<Destination>,

0 commit comments

Comments
 (0)