From e6ee1943e0ed33370b20ebd88b188ca9a2e344b5 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 | 14 +++++++++++--- lightning/src/ln/channelmanager.rs | 4 +++- lightning/src/offers/nonce.rs | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lightning/src/blinded_path/message.rs b/lightning/src/blinded_path/message.rs index 04cb867da..15bf1a949 100644 --- a/lightning/src/blinded_path/message.rs +++ b/lightning/src/blinded_path/message.rs @@ -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. /// diff --git a/lightning/src/events/mod.rs b/lightning/src/events/mod.rs index 9b4c203c3..9aa449efb 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}; @@ -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, })) }; diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 20bcbdc30..9fde3e917 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -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 { diff --git a/lightning/src/offers/nonce.rs b/lightning/src/offers/nonce.rs index be4c1d3d2..1dd21e6c8 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 { -- 2.39.5