Skip to content

Commit a9009d3

Browse files
TODO(delete): pass payment id into OffersMessageHandler
Will be replaced by lightningdevkit#3085.
1 parent 0a6dcdd commit a9009d3

File tree

11 files changed

+88
-69
lines changed

11 files changed

+88
-69
lines changed

lightning/src/blinded_path/message.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::blinded_path::{BlindedHop, BlindedPath, IntroductionNode, NextMessage
2020
use crate::blinded_path::utils;
2121
use crate::io;
2222
use crate::io::Cursor;
23+
use crate::ln::channelmanager::PaymentId;
2324
use crate::ln::onion_utils;
2425
use crate::onion_message::packet::ControlTlvs;
2526
use crate::sign::{NodeSigner, Recipient};
@@ -56,6 +57,7 @@ pub(crate) struct ReceiveTlvs {
5657
/// sending to. This is useful for receivers to check that said blinded path is being used in
5758
/// the right context.
5859
pub(crate) path_id: Option<[u8; 32]>,
60+
pub(crate) payment_id: Option<PaymentId>,
5961
}
6062

6163
impl Writeable for ForwardTlvs {
@@ -79,6 +81,7 @@ impl Writeable for ReceiveTlvs {
7981
// TODO: write padding
8082
encode_tlv_stream!(writer, {
8183
(6, self.path_id, option),
84+
(65537, self.payment_id, option),
8285
});
8386
Ok(())
8487
}
@@ -87,7 +90,7 @@ impl Writeable for ReceiveTlvs {
8790
/// Construct blinded onion message hops for the given `intermediate_nodes` and `recipient_node_id`.
8891
pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
8992
secp_ctx: &Secp256k1<T>, intermediate_nodes: &[ForwardNode], recipient_node_id: PublicKey,
90-
session_priv: &SecretKey
93+
session_priv: &SecretKey, payment_id: Option<PaymentId>,
9194
) -> Result<Vec<BlindedHop>, secp256k1::Error> {
9295
let pks = intermediate_nodes.iter().map(|node| &node.node_id)
9396
.chain(core::iter::once(&recipient_node_id));
@@ -99,7 +102,7 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
99102
None => NextMessageHop::NodeId(*pubkey),
100103
})
101104
.map(|next_hop| ControlTlvs::Forward(ForwardTlvs { next_hop, next_blinding_override: None }))
102-
.chain(core::iter::once(ControlTlvs::Receive(ReceiveTlvs { path_id: None })));
105+
.chain(core::iter::once(ControlTlvs::Receive(ReceiveTlvs { path_id: None, payment_id })));
103106

104107
utils::construct_blinded_hops(secp_ctx, pks, tlvs, session_priv)
105108
}

lightning/src/blinded_path/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub(crate) mod utils;
1616
use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey};
1717
use core::ops::Deref;
1818

19+
use crate::ln::channelmanager::PaymentId;
1920
use crate::ln::msgs::DecodeError;
2021
use crate::offers::invoice::BlindedPayInfo;
2122
use crate::routing::gossip::{NodeId, ReadOnlyNetworkGraph};
@@ -123,9 +124,10 @@ pub struct BlindedHop {
123124
impl BlindedPath {
124125
/// Create a one-hop blinded path for a message.
125126
pub fn one_hop_for_message<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
126-
recipient_node_id: PublicKey, entropy_source: ES, secp_ctx: &Secp256k1<T>
127+
recipient_node_id: PublicKey, entropy_source: ES, secp_ctx: &Secp256k1<T>,
128+
payment_id: Option<PaymentId>,
127129
) -> Result<Self, ()> where ES::Target: EntropySource {
128-
Self::new_for_message(&[], recipient_node_id, entropy_source, secp_ctx)
130+
Self::new_for_message(&[], recipient_node_id, entropy_source, secp_ctx, payment_id)
129131
}
130132

131133
/// Create a blinded path for an onion message, to be forwarded along `node_pks`. The last node
@@ -135,7 +137,7 @@ impl BlindedPath {
135137
// TODO: make all payloads the same size with padding + add dummy hops
136138
pub fn new_for_message<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
137139
intermediate_nodes: &[message::ForwardNode], recipient_node_id: PublicKey,
138-
entropy_source: ES, secp_ctx: &Secp256k1<T>
140+
entropy_source: ES, secp_ctx: &Secp256k1<T>, payment_id: Option<PaymentId>,
139141
) -> Result<Self, ()> where ES::Target: EntropySource {
140142
let introduction_node = IntroductionNode::NodeId(
141143
intermediate_nodes.first().map_or(recipient_node_id, |n| n.node_id)
@@ -147,7 +149,7 @@ impl BlindedPath {
147149
introduction_node,
148150
blinding_point: PublicKey::from_secret_key(secp_ctx, &blinding_secret),
149151
blinded_hops: message::blinded_hops(
150-
secp_ctx, intermediate_nodes, recipient_node_id, &blinding_secret,
152+
secp_ctx, intermediate_nodes, recipient_node_id, &blinding_secret, payment_id,
151153
).map_err(|_| ())?,
152154
})
153155
}

lightning/src/ln/channelmanager.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8376,7 +8376,7 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
83768376
let entropy = &*$self.entropy_source;
83778377
let secp_ctx = &$self.secp_ctx;
83788378

8379-
let path = $self.create_blinded_path_using_absolute_expiry(absolute_expiry)
8379+
let path = $self.create_blinded_path_using_absolute_expiry(absolute_expiry, None)
83808380
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
83818381
let builder = OfferBuilder::deriving_signing_pubkey(
83828382
node_id, expanded_key, entropy, secp_ctx
@@ -8448,7 +8448,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
84488448
let entropy = &*$self.entropy_source;
84498449
let secp_ctx = &$self.secp_ctx;
84508450

8451-
let path = $self.create_blinded_path_using_absolute_expiry(Some(absolute_expiry))
8451+
let path = $self.create_blinded_path_using_absolute_expiry(Some(absolute_expiry), Some(payment_id))
84528452
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
84538453
let builder = RefundBuilder::deriving_payer_id(
84548454
node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
@@ -8571,7 +8571,7 @@ where
85718571
Some(payer_note) => builder.payer_note(payer_note),
85728572
};
85738573
let invoice_request = builder.build_and_sign()?;
8574-
let reply_path = self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
8574+
let reply_path = self.create_blinded_path(Some(payment_id)).map_err(|_| Bolt12SemanticError::MissingPaths)?;
85758575

85768576
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
85778577

@@ -8671,7 +8671,7 @@ where
86718671
)?;
86728672
let builder: InvoiceBuilder<DerivedSigningPubkey> = builder.into();
86738673
let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
8674-
let reply_path = self.create_blinded_path()
8674+
let reply_path = self.create_blinded_path(None)
86758675
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
86768676

86778677
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
@@ -8804,15 +8804,15 @@ where
88048804
/// respectively, based on the given `absolute_expiry` as seconds since the Unix epoch. See
88058805
/// [`MAX_SHORT_LIVED_RELATIVE_EXPIRY`].
88068806
fn create_blinded_path_using_absolute_expiry(
8807-
&self, absolute_expiry: Option<Duration>
8807+
&self, absolute_expiry: Option<Duration>, payment_id: Option<PaymentId>
88088808
) -> Result<BlindedPath, ()> {
88098809
let now = self.duration_since_epoch();
88108810
let max_short_lived_absolute_expiry = now.saturating_add(MAX_SHORT_LIVED_RELATIVE_EXPIRY);
88118811

88128812
if absolute_expiry.unwrap_or(Duration::MAX) <= max_short_lived_absolute_expiry {
8813-
self.create_compact_blinded_path()
8813+
self.create_compact_blinded_path(payment_id)
88148814
} else {
8815-
self.create_blinded_path()
8815+
self.create_blinded_path(payment_id)
88168816
}
88178817
}
88188818

@@ -8832,7 +8832,7 @@ where
88328832
/// Creates a blinded path by delegating to [`MessageRouter::create_blinded_paths`].
88338833
///
88348834
/// Errors if the `MessageRouter` errors or returns an empty `Vec`.
8835-
fn create_blinded_path(&self) -> Result<BlindedPath, ()> {
8835+
fn create_blinded_path(&self, payment_id: Option<PaymentId>) -> Result<BlindedPath, ()> {
88368836
let recipient = self.get_our_node_id();
88378837
let secp_ctx = &self.secp_ctx;
88388838

@@ -8845,14 +8845,14 @@ where
88458845
.collect::<Vec<_>>();
88468846

88478847
self.router
8848-
.create_blinded_paths(recipient, peers, secp_ctx)
8848+
.create_blinded_paths(recipient, peers, secp_ctx, payment_id)
88498849
.and_then(|paths| paths.into_iter().next().ok_or(()))
88508850
}
88518851

88528852
/// Creates a blinded path by delegating to [`MessageRouter::create_compact_blinded_paths`].
88538853
///
88548854
/// Errors if the `MessageRouter` errors or returns an empty `Vec`.
8855-
fn create_compact_blinded_path(&self) -> Result<BlindedPath, ()> {
8855+
fn create_compact_blinded_path(&self, payment_id: Option<PaymentId>) -> Result<BlindedPath, ()> {
88568856
let recipient = self.get_our_node_id();
88578857
let secp_ctx = &self.secp_ctx;
88588858

@@ -8872,7 +8872,7 @@ where
88728872
.collect::<Vec<_>>();
88738873

88748874
self.router
8875-
.create_compact_blinded_paths(recipient, peers, secp_ctx)
8875+
.create_compact_blinded_paths(recipient, peers, secp_ctx, payment_id)
88768876
.and_then(|paths| paths.into_iter().next().ok_or(()))
88778877
}
88788878

@@ -10253,7 +10253,9 @@ where
1025310253
R::Target: Router,
1025410254
L::Target: Logger,
1025510255
{
10256-
fn handle_message(&self, message: OffersMessage, responder: Option<Responder>) -> ResponseInstruction<OffersMessage> {
10256+
fn handle_message(
10257+
&self, message: OffersMessage, responder: Option<Responder>, _payment_id: Option<PaymentId>
10258+
) -> ResponseInstruction<OffersMessage> {
1025710259
let secp_ctx = &self.secp_ctx;
1025810260
let expanded_key = &self.inbound_payment_key;
1025910261

lightning/src/ln/offers_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ fn extract_invoice_request<'a, 'b, 'c>(
188188
node: &Node<'a, 'b, 'c>, message: &OnionMessage
189189
) -> (InvoiceRequest, BlindedPath) {
190190
match node.onion_messenger.peel_onion_message(message) {
191-
Ok(PeeledOnion::Receive(message, _, reply_path)) => match message {
191+
Ok(PeeledOnion::Receive(message, _, reply_path, _)) => match message {
192192
ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
193193
OffersMessage::InvoiceRequest(invoice_request) => (invoice_request, reply_path.unwrap()),
194194
OffersMessage::Invoice(invoice) => panic!("Unexpected invoice: {:?}", invoice),
@@ -207,7 +207,7 @@ fn extract_invoice_request<'a, 'b, 'c>(
207207

208208
fn extract_invoice<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, message: &OnionMessage) -> Bolt12Invoice {
209209
match node.onion_messenger.peel_onion_message(message) {
210-
Ok(PeeledOnion::Receive(message, _, _)) => match message {
210+
Ok(PeeledOnion::Receive(message, _, _, _)) => match message {
211211
ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
212212
OffersMessage::InvoiceRequest(invoice_request) => panic!("Unexpected invoice_request: {:?}", invoice_request),
213213
OffersMessage::Invoice(invoice) => invoice,
@@ -228,7 +228,7 @@ fn extract_invoice_error<'a, 'b, 'c>(
228228
node: &Node<'a, 'b, 'c>, message: &OnionMessage
229229
) -> InvoiceError {
230230
match node.onion_messenger.peel_onion_message(message) {
231-
Ok(PeeledOnion::Receive(message, _, _)) => match message {
231+
Ok(PeeledOnion::Receive(message, _, _, _)) => match message {
232232
ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
233233
OffersMessage::InvoiceRequest(invoice_request) => panic!("Unexpected invoice_request: {:?}", invoice_request),
234234
OffersMessage::Invoice(invoice) => panic!("Unexpected invoice: {:?}", invoice),

lightning/src/ln/peer_handler.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use bitcoin::secp256k1::{self, Secp256k1, SecretKey, PublicKey};
2020

2121
use crate::sign::{NodeSigner, Recipient};
2222
use crate::events::{MessageSendEvent, MessageSendEventsProvider};
23+
use crate::ln::channelmanager::PaymentId;
2324
use crate::ln::types::ChannelId;
2425
use crate::ln::features::{InitFeatures, NodeFeatures};
2526
use crate::ln::msgs;
@@ -145,7 +146,7 @@ impl OnionMessageHandler for IgnoringMessageHandler {
145146
}
146147

147148
impl OffersMessageHandler for IgnoringMessageHandler {
148-
fn handle_message(&self, _message: OffersMessage, _responder: Option<Responder>) -> ResponseInstruction<OffersMessage> {
149+
fn handle_message(&self, _message: OffersMessage, _responder: Option<Responder>, _payment_id: Option<PaymentId>) -> ResponseInstruction<OffersMessage> {
149150
ResponseInstruction::NoResponse
150151
}
151152
}

0 commit comments

Comments
 (0)