Skip to content

Commit aa2c6fe

Browse files
authored
Merge pull request #3408 from valentinewallace/2024-11-async-receive-offer-utils
Add static invoice creation utils to `ChannelManager`
2 parents 3fbf97d + d3a7efa commit aa2c6fe

15 files changed

+829
-195
lines changed

fuzz/src/chanmon_consistency.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl Router for FuzzRouter {
133133

134134
fn create_blinded_payment_paths<T: secp256k1::Signing + secp256k1::Verification>(
135135
&self, _recipient: PublicKey, _first_hops: Vec<ChannelDetails>, _tlvs: ReceiveTlvs,
136-
_amount_msats: u64, _secp_ctx: &Secp256k1<T>,
136+
_amount_msats: Option<u64>, _secp_ctx: &Secp256k1<T>,
137137
) -> Result<Vec<BlindedPaymentPath>, ()> {
138138
unreachable!()
139139
}

fuzz/src/full_stack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl Router for FuzzRouter {
160160

161161
fn create_blinded_payment_paths<T: secp256k1::Signing + secp256k1::Verification>(
162162
&self, _recipient: PublicKey, _first_hops: Vec<ChannelDetails>, _tlvs: ReceiveTlvs,
163-
_amount_msats: u64, _secp_ctx: &Secp256k1<T>,
163+
_amount_msats: Option<u64>, _secp_ctx: &Secp256k1<T>,
164164
) -> Result<Vec<BlindedPaymentPath>, ()> {
165165
unreachable!()
166166
}

lightning/src/blinded_path/message.rs

+22
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,24 @@ pub enum AsyncPaymentsContext {
402402
/// containing the expected [`PaymentId`].
403403
hmac: Hmac<Sha256>,
404404
},
405+
/// Context contained within the [`BlindedMessagePath`]s we put in static invoices, provided back
406+
/// to us in corresponding [`HeldHtlcAvailable`] messages.
407+
///
408+
/// [`HeldHtlcAvailable`]: crate::onion_message::async_payments::HeldHtlcAvailable
409+
InboundPayment {
410+
/// A nonce used for authenticating that a [`HeldHtlcAvailable`] message is valid for a
411+
/// preceding static invoice.
412+
///
413+
/// [`HeldHtlcAvailable`]: crate::onion_message::async_payments::HeldHtlcAvailable
414+
nonce: Nonce,
415+
/// Authentication code for the [`HeldHtlcAvailable`] message.
416+
///
417+
/// Prevents nodes from creating their own blinded path to us, sending a [`HeldHtlcAvailable`]
418+
/// message and trivially getting notified whenever we come online.
419+
///
420+
/// [`HeldHtlcAvailable`]: crate::onion_message::async_payments::HeldHtlcAvailable
421+
hmac: Hmac<Sha256>,
422+
},
405423
}
406424

407425
impl_writeable_tlv_based_enum!(MessageContext,
@@ -433,6 +451,10 @@ impl_writeable_tlv_based_enum!(AsyncPaymentsContext,
433451
(2, nonce, required),
434452
(4, hmac, required),
435453
},
454+
(1, InboundPayment) => {
455+
(0, nonce, required),
456+
(2, hmac, required),
457+
},
436458
);
437459

438460
/// Contains a simple nonce for use in a blinded path's context.

lightning/src/blinded_path/payment.rs

+22
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,11 @@ pub enum PaymentContext {
349349
/// [`Offer`]: crate::offers::offer::Offer
350350
Bolt12Offer(Bolt12OfferContext),
351351

352+
/// The payment was made for a static invoice requested from a BOLT 12 [`Offer`].
353+
///
354+
/// [`Offer`]: crate::offers::offer::Offer
355+
AsyncBolt12Offer(AsyncBolt12OfferContext),
356+
352357
/// The payment was made for an invoice sent for a BOLT 12 [`Refund`].
353358
///
354359
/// [`Refund`]: crate::offers::refund::Refund
@@ -378,6 +383,18 @@ pub struct Bolt12OfferContext {
378383
pub invoice_request: InvoiceRequestFields,
379384
}
380385

386+
/// The context of a payment made for a static invoice requested from a BOLT 12 [`Offer`].
387+
///
388+
/// [`Offer`]: crate::offers::offer::Offer
389+
#[derive(Clone, Debug, Eq, PartialEq)]
390+
pub struct AsyncBolt12OfferContext {
391+
/// The [`Nonce`] used to verify that an inbound [`InvoiceRequest`] corresponds to this static
392+
/// invoice's offer.
393+
///
394+
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
395+
pub offer_nonce: Nonce,
396+
}
397+
381398
/// The context of a payment made for an invoice sent for a BOLT 12 [`Refund`].
382399
///
383400
/// [`Refund`]: crate::offers::refund::Refund
@@ -627,6 +644,7 @@ impl_writeable_tlv_based_enum_legacy!(PaymentContext,
627644
// 0 for Unknown removed in version 0.1.
628645
(1, Bolt12Offer),
629646
(2, Bolt12Refund),
647+
(3, AsyncBolt12Offer),
630648
);
631649

632650
impl<'a> Writeable for PaymentContextRef<'a> {
@@ -651,6 +669,10 @@ impl_writeable_tlv_based!(Bolt12OfferContext, {
651669
(2, invoice_request, required),
652670
});
653671

672+
impl_writeable_tlv_based!(AsyncBolt12OfferContext, {
673+
(0, offer_nonce, required),
674+
});
675+
654676
impl_writeable_tlv_based!(Bolt12RefundContext, {});
655677

656678
#[cfg(test)]

lightning/src/events/mod.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -181,27 +181,32 @@ impl PaymentPurpose {
181181
pub(crate) fn from_parts(
182182
payment_preimage: Option<PaymentPreimage>, payment_secret: PaymentSecret,
183183
payment_context: Option<PaymentContext>,
184-
) -> Self {
184+
) -> Result<Self, ()> {
185185
match payment_context {
186186
None => {
187-
PaymentPurpose::Bolt11InvoicePayment {
187+
Ok(PaymentPurpose::Bolt11InvoicePayment {
188188
payment_preimage,
189189
payment_secret,
190-
}
190+
})
191191
},
192192
Some(PaymentContext::Bolt12Offer(context)) => {
193-
PaymentPurpose::Bolt12OfferPayment {
193+
Ok(PaymentPurpose::Bolt12OfferPayment {
194194
payment_preimage,
195195
payment_secret,
196196
payment_context: context,
197-
}
197+
})
198198
},
199199
Some(PaymentContext::Bolt12Refund(context)) => {
200-
PaymentPurpose::Bolt12RefundPayment {
200+
Ok(PaymentPurpose::Bolt12RefundPayment {
201201
payment_preimage,
202202
payment_secret,
203203
payment_context: context,
204-
}
204+
})
205+
},
206+
Some(PaymentContext::AsyncBolt12Offer(_context)) => {
207+
// This code will change to return Self::Bolt12OfferPayment when we add support for async
208+
// receive.
209+
Err(())
205210
},
206211
}
207212
}
@@ -1865,7 +1870,8 @@ impl MaybeReadable for Event {
18651870
(13, payment_id, option),
18661871
});
18671872
let purpose = match payment_secret {
1868-
Some(secret) => PaymentPurpose::from_parts(payment_preimage, secret, payment_context),
1873+
Some(secret) => PaymentPurpose::from_parts(payment_preimage, secret, payment_context)
1874+
.map_err(|()| msgs::DecodeError::InvalidValue)?,
18691875
None if payment_preimage.is_some() => PaymentPurpose::SpontaneousPayment(payment_preimage.unwrap()),
18701876
None => return Err(msgs::DecodeError::InvalidValue),
18711877
};

0 commit comments

Comments
 (0)