Skip to content

Commit b806a04

Browse files
committed
Include Offer context in blinded payment paths
When constructing blinded payment paths for a Bolt12Invoice response, include the OfferId so that the eventual payment can be correlated with the Offer.
1 parent 885a0aa commit b806a04

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

lightning/src/blinded_path/payment.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::ln::channelmanager::CounterpartyForwardingInfo;
1212
use crate::ln::features::BlindedHopFeatures;
1313
use crate::ln::msgs::DecodeError;
1414
use crate::offers::invoice::BlindedPayInfo;
15+
use crate::offers::offer::OfferId;
1516
use crate::prelude::*;
1617
use crate::util::ser::{HighZeroBytesDroppedBigSize, Readable, Writeable, Writer};
1718

@@ -108,6 +109,15 @@ pub struct PaymentConstraints {
108109
pub enum PaymentContext {
109110
/// The payment was made for a BOLT 11 invoice.
110111
Bolt11Invoice {},
112+
/// The payment was made for an invoice requested from a BOLT 12 [`Offer`].
113+
///
114+
/// [`Offer`]: crate::offers::offer::Offer
115+
Bolt12Offer {
116+
/// The identifier of the [`Offer`].
117+
///
118+
/// [`Offer`]: crate::offers::offer::Offer
119+
offer_id: OfferId,
120+
},
111121
}
112122

113123
impl TryFrom<CounterpartyForwardingInfo> for PaymentRelay {
@@ -329,6 +339,9 @@ impl Readable for PaymentConstraints {
329339

330340
impl_writeable_tlv_based_enum!(PaymentContext,
331341
(0, Bolt11Invoice) => {},
342+
(1, Bolt12Offer) => {
343+
(0, offer_id, required),
344+
},
332345
;
333346
);
334347

lightning/src/ln/channelmanager.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8168,7 +8168,10 @@ where
81688168

81698169
match self.create_inbound_payment(Some(amount_msats), relative_expiry, None) {
81708170
Ok((payment_hash, payment_secret)) => {
8171-
let payment_paths = self.create_blinded_payment_paths(amount_msats, payment_secret)
8171+
let payment_context = PaymentContext::Bolt11Invoice {};
8172+
let payment_paths = self.create_blinded_payment_paths(
8173+
amount_msats, payment_secret, payment_context
8174+
)
81728175
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
81738176

81748177
#[cfg(feature = "std")]
@@ -8334,7 +8337,7 @@ where
83348337
/// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
83358338
/// [`Router::create_blinded_payment_paths`].
83368339
fn create_blinded_payment_paths(
8337-
&self, amount_msats: u64, payment_secret: PaymentSecret
8340+
&self, amount_msats: u64, payment_secret: PaymentSecret, payment_context: PaymentContext
83388341
) -> Result<Vec<(BlindedPayInfo, BlindedPath)>, ()> {
83398342
let secp_ctx = &self.secp_ctx;
83408343

@@ -8348,7 +8351,7 @@ where
83488351
max_cltv_expiry,
83498352
htlc_minimum_msat: 1,
83508353
},
8351-
payment_context: PaymentContext::Bolt11Invoice {},
8354+
payment_context,
83528355
};
83538356
self.router.create_blinded_payment_paths(
83548357
payee_node_id, first_hops, payee_tlvs, amount_msats, secp_ctx
@@ -9682,8 +9685,11 @@ where
96829685
},
96839686
};
96849687

9688+
let payment_context = PaymentContext::Bolt12Offer {
9689+
offer_id: invoice_request.offer_id,
9690+
};
96859691
let payment_paths = match self.create_blinded_payment_paths(
9686-
amount_msats, payment_secret
9692+
amount_msats, payment_secret, payment_context
96879693
) {
96889694
Ok(payment_paths) => payment_paths,
96899695
Err(()) => {

lightning/src/offers/offer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ use std::time::SystemTime;
115115
pub(super) const IV_BYTES: &[u8; IV_LEN] = b"LDK Offer ~~~~~~";
116116

117117
/// An identifier for an [`Offer`] built using [`DerivedMetadata`].
118-
#[derive(Clone, Copy, Debug, PartialEq)]
118+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
119119
pub struct OfferId([u8; 32]);
120120

121121
impl OfferId {

0 commit comments

Comments
 (0)