Skip to content

Commit 48d9245

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 ac6d4cb commit 48d9245

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

lightning/src/blinded_path/payment.rs

Lines changed: 22 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::util::ser::{HighZeroBytesDroppedBigSize, Readable, Writeable, Writer};
1617

1718
#[allow(unused_imports)]
@@ -108,12 +109,28 @@ pub struct PaymentConstraints {
108109
pub enum PaymentContext {
109110
/// The payment context was unknown.
110111
Unknown(UnknownPaymentContext),
112+
113+
/// The payment was made for an invoice requested from a BOLT 12 [`Offer`].
114+
///
115+
/// [`Offer`]: crate::offers::offer::Offer
116+
Bolt12Offer(Bolt12OfferContext),
111117
}
112118

113119
/// An unknown payment context.
114120
#[derive(Clone, Debug, Eq, PartialEq)]
115121
pub struct UnknownPaymentContext(());
116122

123+
/// The context of a payment made for an invoice requested from a BOLT 12 [`Offer`].
124+
///
125+
/// [`Offer`]: crate::offers::offer::Offer
126+
#[derive(Clone, Debug, Eq, PartialEq)]
127+
pub struct Bolt12OfferContext {
128+
/// The identifier of the [`Offer`].
129+
///
130+
/// [`Offer`]: crate::offers::offer::Offer
131+
pub offer_id: OfferId,
132+
}
133+
117134
impl PaymentContext {
118135
pub(crate) fn unknown() -> Self {
119136
PaymentContext::Unknown(UnknownPaymentContext(()))
@@ -340,6 +357,7 @@ impl Readable for PaymentConstraints {
340357
impl_writeable_tlv_based_enum!(PaymentContext,
341358
;
342359
(0, Unknown),
360+
(1, Bolt12Offer),
343361
);
344362

345363
impl Writeable for UnknownPaymentContext {
@@ -354,6 +372,10 @@ impl Readable for UnknownPaymentContext {
354372
}
355373
}
356374

375+
impl_writeable_tlv_based!(Bolt12OfferContext, {
376+
(0, offer_id, required),
377+
});
378+
357379
#[cfg(test)]
358380
mod tests {
359381
use bitcoin::secp256k1::PublicKey;

lightning/src/ln/channelmanager.rs

Lines changed: 11 additions & 5 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::payment::{PaymentConstraints, PaymentContext, ReceiveTlvs};
35+
use crate::blinded_path::payment::{Bolt12OfferContext, PaymentConstraints, PaymentContext, ReceiveTlvs};
3636
use crate::chain;
3737
use crate::chain::{Confirm, ChannelMonitorUpdateStatus, Watch, BestBlock};
3838
use crate::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator};
@@ -8826,7 +8826,10 @@ where
88268826

88278827
match self.create_inbound_payment(Some(amount_msats), relative_expiry, None) {
88288828
Ok((payment_hash, payment_secret)) => {
8829-
let payment_paths = self.create_blinded_payment_paths(amount_msats, payment_secret)
8829+
let payment_context = PaymentContext::unknown();
8830+
let payment_paths = self.create_blinded_payment_paths(
8831+
amount_msats, payment_secret, payment_context
8832+
)
88308833
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
88318834

88328835
#[cfg(feature = "std")]
@@ -8992,7 +8995,7 @@ where
89928995
/// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
89938996
/// [`Router::create_blinded_payment_paths`].
89948997
fn create_blinded_payment_paths(
8995-
&self, amount_msats: u64, payment_secret: PaymentSecret
8998+
&self, amount_msats: u64, payment_secret: PaymentSecret, payment_context: PaymentContext
89968999
) -> Result<Vec<(BlindedPayInfo, BlindedPath)>, ()> {
89979000
let secp_ctx = &self.secp_ctx;
89989001

@@ -9006,7 +9009,7 @@ where
90069009
max_cltv_expiry,
90079010
htlc_minimum_msat: 1,
90089011
},
9009-
payment_context: PaymentContext::unknown(),
9012+
payment_context,
90109013
};
90119014
self.router.create_blinded_payment_paths(
90129015
payee_node_id, first_hops, payee_tlvs, amount_msats, secp_ctx
@@ -10360,8 +10363,11 @@ where
1036010363
},
1036110364
};
1036210365

10366+
let payment_context = PaymentContext::Bolt12Offer(Bolt12OfferContext {
10367+
offer_id: invoice_request.offer_id,
10368+
});
1036310369
let payment_paths = match self.create_blinded_payment_paths(
10364-
amount_msats, payment_secret
10370+
amount_msats, payment_secret, payment_context
1036510371
) {
1036610372
Ok(payment_paths) => payment_paths,
1036710373
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(pub [u8; 32]);
120120

121121
impl OfferId {

0 commit comments

Comments
 (0)