Skip to content

Commit abc9be8

Browse files
committed
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.
1 parent 4ec7d29 commit abc9be8

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

lightning/src/blinded_path/message.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub enum MessageContext {
106106
/// Contains the data specific to [`OffersMessage`]
107107
///
108108
/// [`OffersMessage`]: crate::onion_message::offers::OffersMessage
109-
#[derive(Clone, Debug)]
109+
#[derive(Clone, Debug, Eq, PartialEq)]
110110
pub enum OffersContext {
111111
/// Represents an unknown BOLT12 payment context.
112112
///

lightning/src/events/mod.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub mod bump_transaction;
1818

1919
pub use bump_transaction::BumpTransactionEvent;
2020

21+
use crate::blinded_path::message::OffersContext;
2122
use crate::blinded_path::payment::{Bolt12OfferContext, Bolt12RefundContext, PaymentContext, PaymentContextRef};
2223
use crate::chain::transaction;
2324
use crate::ln::channelmanager::{InterceptId, PaymentId, RecipientOnionFields};
@@ -756,6 +757,8 @@ pub enum Event {
756757
payment_id: PaymentId,
757758
/// The invoice to pay.
758759
invoice: Bolt12Invoice,
760+
/// The context of the [`BlindedPath`] used to send the invoice.
761+
context: OffersContext,
759762
/// A responder for replying with an [`InvoiceError`] if needed.
760763
///
761764
/// `None` if the invoice wasn't sent with a reply path.
@@ -1522,12 +1525,13 @@ impl Writeable for Event {
15221525
(0, peer_node_id, required),
15231526
});
15241527
},
1525-
&Event::InvoiceReceived { ref payment_id, ref invoice, ref responder } => {
1528+
&Event::InvoiceReceived { ref payment_id, ref invoice, ref context, ref responder } => {
15261529
41u8.write(writer)?;
15271530
write_tlv_fields!(writer, {
15281531
(0, payment_id, required),
15291532
(2, invoice, required),
1530-
(4, responder, option),
1533+
(4, context, required),
1534+
(6, responder, option),
15311535
})
15321536
},
15331537
// Note that, going forward, all new events must only write data inside of
@@ -1971,11 +1975,13 @@ impl MaybeReadable for Event {
19711975
_init_and_read_len_prefixed_tlv_fields!(reader, {
19721976
(0, payment_id, required),
19731977
(2, invoice, required),
1974-
(4, responder, option),
1978+
(4, context, required),
1979+
(6, responder, option),
19751980
});
19761981
Ok(Some(Event::InvoiceReceived {
19771982
payment_id: payment_id.0.unwrap(),
19781983
invoice: invoice.0.unwrap(),
1984+
context: context.0.unwrap(),
19791985
responder,
19801986
}))
19811987
};

lightning/src/ln/channelmanager.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -10652,7 +10652,9 @@ where
1065210652
if invoice.invoice_features().requires_unknown_bits_from(&features) {
1065310653
Err(InvoiceError::from(Bolt12SemanticError::UnknownRequiredFeatures))
1065410654
} else if self.default_configuration.manually_handle_bolt12_invoices {
10655-
let event = Event::InvoiceReceived { payment_id, invoice, responder };
10655+
let event = Event::InvoiceReceived {
10656+
payment_id, invoice, context, responder,
10657+
};
1065610658
self.pending_events.lock().unwrap().push_back((event, None));
1065710659
return ResponseInstruction::NoResponse;
1065810660
} else {

lightning/src/offers/nonce.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::prelude::*;
2626
/// [`Offer::metadata`]: crate::offers::offer::Offer::metadata
2727
/// [`Offer::signing_pubkey`]: crate::offers::offer::Offer::signing_pubkey
2828
/// [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey
29-
#[derive(Clone, Copy, Debug, PartialEq)]
29+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
3030
pub struct Nonce(pub(crate) [u8; Self::LENGTH]);
3131

3232
impl Nonce {

0 commit comments

Comments
 (0)