From 50f3eb7fd94b7ffac1f1124b3b0216135ec42b4f Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Mon, 15 Jul 2024 18:22:43 -0500 Subject: [PATCH] Include OffersContext in Event::InvoiceReceived 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 | 2 +- lightning/src/events/mod.rs | 12 +++++++++--- lightning/src/ln/channelmanager.rs | 4 +++- lightning/src/offers/nonce.rs | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lightning/src/blinded_path/message.rs b/lightning/src/blinded_path/message.rs index e8e0e9b5216..666cdb658ef 100644 --- a/lightning/src/blinded_path/message.rs +++ b/lightning/src/blinded_path/message.rs @@ -106,7 +106,7 @@ pub enum MessageContext { /// Contains the data specific to [`OffersMessage`] /// /// [`OffersMessage`]: crate::onion_message::offers::OffersMessage -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Eq, PartialEq)] pub enum OffersContext { /// Represents an unknown BOLT12 payment context. /// diff --git a/lightning/src/events/mod.rs b/lightning/src/events/mod.rs index e59a3d18501..e408dc105b2 100644 --- a/lightning/src/events/mod.rs +++ b/lightning/src/events/mod.rs @@ -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}; @@ -756,6 +757,8 @@ pub enum Event { payment_id: PaymentId, /// The invoice to pay. invoice: Bolt12Invoice, + /// The context of the [`BlindedPath`] used to send the invoice. + context: OffersContext, /// A responder for replying with an [`InvoiceError`] if needed. /// /// `None` if the invoice wasn't sent with a reply path. @@ -1522,12 +1525,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), }) }, // Note that, going forward, all new events must only write data inside of @@ -1971,11 +1975,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, })) }; diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 0ef01fefb7a..149e0bf0d32 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -10648,7 +10648,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 { diff --git a/lightning/src/offers/nonce.rs b/lightning/src/offers/nonce.rs index be4c1d3d254..1dd21e6c83d 100644 --- a/lightning/src/offers/nonce.rs +++ b/lightning/src/offers/nonce.rs @@ -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 {