]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Include OffersContext in Event::InvoiceReceived
authorJeffrey Czyz <jkczyz@gmail.com>
Mon, 15 Jul 2024 23:22:43 +0000 (18:22 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Mon, 22 Jul 2024 16:38:36 +0000 (11:38 -0500)
When authenticating that an invoice is for a valid invoice request, the
payer metadata is needed. Some of this data will be removed in the next
commit and instead be included in the message context of the request's
reply path. Add this data to Event::InvoiceReceived so that asynchronous
invoice handling can verify properly.

lightning/src/blinded_path/message.rs
lightning/src/events/mod.rs
lightning/src/ln/channelmanager.rs
lightning/src/offers/nonce.rs

index 04cb867dac1f5e4561b39e3356e3a25cb7322209..15bf1a9494058ba02961b365593ffbc0947ba1cf 100644 (file)
@@ -106,7 +106,7 @@ pub enum MessageContext {
 /// Contains data specific to an [`OffersMessage`].
 ///
 /// [`OffersMessage`]: crate::onion_message::offers::OffersMessage
-#[derive(Clone, Debug)]
+#[derive(Clone, Debug, Eq, PartialEq)]
 pub enum OffersContext {
        /// Represents an unknown BOLT12 message context.
        ///
index 9b4c203c30d5c12bd4a1acb11bbf2cf1c6f5f042..9aa449efbaa9a32fd7811888fadd386dca4d39ee 100644 (file)
@@ -18,6 +18,7 @@ pub mod bump_transaction;
 
 pub use bump_transaction::BumpTransactionEvent;
 
+use crate::blinded_path::message::OffersContext;
 use crate::blinded_path::payment::{Bolt12OfferContext, Bolt12RefundContext, PaymentContext, PaymentContextRef};
 use crate::chain::transaction;
 use crate::ln::channelmanager::{InterceptId, PaymentId, RecipientOnionFields};
@@ -806,6 +807,10 @@ pub enum Event {
                payment_id: PaymentId,
                /// The invoice to pay.
                invoice: Bolt12Invoice,
+               /// The context of the [`BlindedPath`] used to send the invoice.
+               ///
+               /// [`BlindedPath`]: crate::blinded_path::BlindedPath
+               context: OffersContext,
                /// A responder for replying with an [`InvoiceError`] if needed.
                ///
                /// `None` if the invoice wasn't sent with a reply path.
@@ -1648,12 +1653,13 @@ impl Writeable for Event {
                                        (0, peer_node_id, required),
                                });
                        },
-                       &Event::InvoiceReceived { ref payment_id, ref invoice, ref responder } => {
+                       &Event::InvoiceReceived { ref payment_id, ref invoice, ref context, ref responder } => {
                                41u8.write(writer)?;
                                write_tlv_fields!(writer, {
                                        (0, payment_id, required),
                                        (2, invoice, required),
-                                       (4, responder, option),
+                                       (4, context, required),
+                                       (6, responder, option),
                                });
                        },
                        &Event::FundingTxBroadcastSafe { ref channel_id, ref user_channel_id, ref funding_txo, ref counterparty_node_id, ref former_temporary_channel_id} => {
@@ -2107,11 +2113,13 @@ impl MaybeReadable for Event {
                                        _init_and_read_len_prefixed_tlv_fields!(reader, {
                                                (0, payment_id, required),
                                                (2, invoice, required),
-                                               (4, responder, option),
+                                               (4, context, required),
+                                               (6, responder, option),
                                        });
                                        Ok(Some(Event::InvoiceReceived {
                                                payment_id: payment_id.0.unwrap(),
                                                invoice: invoice.0.unwrap(),
+                                               context: context.0.unwrap(),
                                                responder,
                                        }))
                                };
index 20bcbdc308cc8714d85222d8d74fdd756c45c0bb..9fde3e917414dc091e74fbc9e4fb1848c403329b 100644 (file)
@@ -10832,7 +10832,9 @@ where
                                        if invoice.invoice_features().requires_unknown_bits_from(&features) {
                                                Err(InvoiceError::from(Bolt12SemanticError::UnknownRequiredFeatures))
                                        } else if self.default_configuration.manually_handle_bolt12_invoices {
-                                               let event = Event::InvoiceReceived { payment_id, invoice, responder };
+                                               let event = Event::InvoiceReceived {
+                                                       payment_id, invoice, context, responder,
+                                               };
                                                self.pending_events.lock().unwrap().push_back((event, None));
                                                return ResponseInstruction::NoResponse;
                                        } else {
index be4c1d3d2543a67c7ae4a1330a89a6f72cbf5e05..1dd21e6c83d661e0fa866e9b53abbed5adc2fc11 100644 (file)
@@ -26,7 +26,7 @@ use crate::prelude::*;
 /// [`Offer::metadata`]: crate::offers::offer::Offer::metadata
 /// [`Offer::signing_pubkey`]: crate::offers::offer::Offer::signing_pubkey
 /// [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey
-#[derive(Clone, Copy, Debug, PartialEq)]
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
 pub struct Nonce(pub(crate) [u8; Self::LENGTH]);
 
 impl Nonce {