Skip to content

Commit f7db553

Browse files
committed
WIP: Include OffersContext in blinded paths
1 parent 2b6788c commit f7db553

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

lightning/src/blinded_path/message.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ 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::onion_utils;
23+
use crate::ln::{PaymentHash, onion_utils};
24+
use crate::ln::channelmanager::PaymentId;
25+
use crate::offers::nonce::Nonce;
2426
use crate::onion_message::packet::ControlTlvs;
2527
use crate::sign::{NodeSigner, Recipient};
2628
use crate::crypto::streams::ChaChaPolyReadAdapter;
@@ -84,6 +86,27 @@ impl Writeable for ReceiveTlvs {
8486
}
8587
}
8688

89+
///
90+
pub enum OffersContext {
91+
///
92+
Unknown {},
93+
///
94+
InvoiceRequest {
95+
///
96+
nonce: Nonce,
97+
},
98+
///
99+
InboundPayment {
100+
///
101+
payment_hash: PaymentHash,
102+
},
103+
///
104+
OutboundPayment {
105+
///
106+
payment_id: PaymentId
107+
},
108+
}
109+
87110
/// Construct blinded onion message hops for the given `intermediate_nodes` and `recipient_node_id`.
88111
pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
89112
secp_ctx: &Secp256k1<T>, intermediate_nodes: &[ForwardNode], recipient_node_id: PublicKey,

lightning/src/ln/channelmanager.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use bitcoin::secp256k1::Secp256k1;
3232
use bitcoin::{secp256k1, Sequence};
3333

3434
use crate::blinded_path::{BlindedPath, NodeIdLookUp};
35-
use crate::blinded_path::message::ForwardNode;
35+
use crate::blinded_path::message::{ForwardNode, OffersContext};
3636
use crate::blinded_path::payment::{Bolt12OfferContext, Bolt12RefundContext, PaymentConstraints, PaymentContext, ReceiveTlvs};
3737
use crate::chain;
3838
use crate::chain::{Confirm, ChannelMonitorUpdateStatus, Watch, BestBlock};
@@ -8377,7 +8377,8 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
83778377
let secp_ctx = &$self.secp_ctx;
83788378

83798379
let nonce = Nonce::from_entropy_source(entropy);
8380-
let path = $self.create_blinded_path_using_absolute_expiry(absolute_expiry)
8380+
let context = OffersContext::InvoiceRequest { nonce };
8381+
let path = $self.create_blinded_path_using_absolute_expiry(context, absolute_expiry)
83818382
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
83828383
let builder = OfferBuilder::deriving_signing_pubkey(node_id, expanded_key, nonce, secp_ctx)
83838384
.chain_hash($self.chain_hash)
@@ -8447,7 +8448,8 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
84478448
let entropy = &*$self.entropy_source;
84488449
let secp_ctx = &$self.secp_ctx;
84498450

8450-
let path = $self.create_blinded_path_using_absolute_expiry(Some(absolute_expiry))
8451+
let context = OffersContext::OutboundPayment { payment_id };
8452+
let path = $self.create_blinded_path_using_absolute_expiry(context, Some(absolute_expiry))
84518453
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
84528454
let builder = RefundBuilder::deriving_payer_id(
84538455
node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
@@ -8570,7 +8572,9 @@ where
85708572
Some(payer_note) => builder.payer_note(payer_note),
85718573
};
85728574
let invoice_request = builder.build_and_sign()?;
8573-
let reply_path = self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
8575+
let context = OffersContext::OutboundPayment { payment_id };
8576+
let reply_path = self.create_blinded_path(context)
8577+
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
85748578

85758579
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
85768580

@@ -8670,7 +8674,8 @@ where
86708674
)?;
86718675
let builder: InvoiceBuilder<DerivedSigningPubkey> = builder.into();
86728676
let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
8673-
let reply_path = self.create_blinded_path()
8677+
let context = OffersContext::InboundPayment { payment_hash };
8678+
let reply_path = self.create_blinded_path(context)
86748679
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
86758680

86768681
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
@@ -8803,15 +8808,15 @@ where
88038808
/// respectively, based on the given `absolute_expiry` as seconds since the Unix epoch. See
88048809
/// [`MAX_SHORT_LIVED_RELATIVE_EXPIRY`].
88058810
fn create_blinded_path_using_absolute_expiry(
8806-
&self, absolute_expiry: Option<Duration>
8811+
&self, context: OffersContext, absolute_expiry: Option<Duration>
88078812
) -> Result<BlindedPath, ()> {
88088813
let now = self.duration_since_epoch();
88098814
let max_short_lived_absolute_expiry = now.saturating_add(MAX_SHORT_LIVED_RELATIVE_EXPIRY);
88108815

88118816
if absolute_expiry.unwrap_or(Duration::MAX) <= max_short_lived_absolute_expiry {
88128817
self.create_compact_blinded_path()
88138818
} else {
8814-
self.create_blinded_path()
8819+
self.create_blinded_path(context)
88158820
}
88168821
}
88178822

@@ -8831,7 +8836,7 @@ where
88318836
/// Creates a blinded path by delegating to [`MessageRouter::create_blinded_paths`].
88328837
///
88338838
/// Errors if the `MessageRouter` errors or returns an empty `Vec`.
8834-
fn create_blinded_path(&self) -> Result<BlindedPath, ()> {
8839+
fn create_blinded_path(&self, _context: OffersContext) -> Result<BlindedPath, ()> {
88358840
let recipient = self.get_our_node_id();
88368841
let secp_ctx = &self.secp_ctx;
88378842

0 commit comments

Comments
 (0)