]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add MessageContext for async payments.
authorValentine Wallace <vwallace@protonmail.com>
Wed, 10 Jul 2024 17:54:05 +0000 (13:54 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Thu, 12 Sep 2024 15:16:03 +0000 (11:16 -0400)
This context will be used in reply paths for outbound held_htlc_available
messages, so we can authenticate the corresponding release_held_htlc messages.

lightning/src/blinded_path/message.rs
lightning/src/onion_message/messenger.rs

index 256483fec01aebba1030dbd1e130a1b38ad77c38..e6aa4e340cefd2747de89c51dd0a06b1fd4877ac 100644 (file)
@@ -280,6 +280,10 @@ pub enum MessageContext {
        ///
        /// [`OffersMessage`]: crate::onion_message::offers::OffersMessage
        Offers(OffersContext),
+       /// Context specific to an [`AsyncPaymentsMessage`].
+       ///
+       /// [`AsyncPaymentsMessage`]: crate::onion_message::async_payments::AsyncPaymentsMessage
+       AsyncPayments(AsyncPaymentsContext),
        /// Context specific to a [`CustomOnionMessageHandler::CustomMessage`].
        ///
        /// [`CustomOnionMessageHandler::CustomMessage`]: crate::onion_message::messenger::CustomOnionMessageHandler::CustomMessage
@@ -363,9 +367,30 @@ pub enum OffersContext {
        },
 }
 
+/// Contains data specific to an [`AsyncPaymentsMessage`].
+///
+/// [`AsyncPaymentsMessage`]: crate::onion_message::async_payments::AsyncPaymentsMessage
+#[derive(Clone, Debug)]
+pub enum AsyncPaymentsContext {
+       /// Context contained within the reply [`BlindedMessagePath`] we put in outbound
+       /// [`HeldHtlcAvailable`] messages, provided back to us in corresponding [`ReleaseHeldHtlc`]
+       /// messages.
+       ///
+       /// [`HeldHtlcAvailable`]: crate::onion_message::async_payments::HeldHtlcAvailable
+       /// [`ReleaseHeldHtlc`]: crate::onion_message::async_payments::ReleaseHeldHtlc
+       OutboundPayment {
+               /// ID used when payment to the originating [`Offer`] was initiated. Useful for us to identify
+               /// which of our pending outbound payments should be released to its often-offline payee.
+               ///
+               /// [`Offer`]: crate::offers::offer::Offer
+               payment_id: PaymentId
+       },
+}
+
 impl_writeable_tlv_based_enum!(MessageContext,
        {0, Offers} => (),
        {1, Custom} => (),
+       {2, AsyncPayments} => (),
 );
 
 impl_writeable_tlv_based_enum!(OffersContext,
@@ -384,6 +409,12 @@ impl_writeable_tlv_based_enum!(OffersContext,
        },
 );
 
+impl_writeable_tlv_based_enum!(AsyncPaymentsContext,
+       (0, OutboundPayment) => {
+               (0, payment_id, required),
+       },
+);
+
 /// Construct blinded onion message hops for the given `intermediate_nodes` and `recipient_node_id`.
 pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
        secp_ctx: &Secp256k1<T>, intermediate_nodes: &[MessageForwardNode],
index f44e3cb018d3c1b1bb67bbee4f98c654097872d5..18522c0f3088177c8c890f048d72bb75d0ab0ba4 100644 (file)
@@ -979,6 +979,10 @@ where
                                (ParsedOnionMessageContents::Offers(_), Some(MessageContext::Offers(_))) => {
                                        Ok(PeeledOnion::Receive(message, context, reply_path))
                                }
+                               #[cfg(async_payments)]
+                               (ParsedOnionMessageContents::AsyncPayments(_), Some(MessageContext::AsyncPayments(_))) => {
+                                       Ok(PeeledOnion::Receive(message, context, reply_path))
+                               }
                                (ParsedOnionMessageContents::Custom(_), Some(MessageContext::Custom(_))) => {
                                        Ok(PeeledOnion::Receive(message, context, reply_path))
                                }
@@ -1587,7 +1591,7 @@ where
                                                let context = match context {
                                                        None => None,
                                                        Some(MessageContext::Offers(context)) => Some(context),
-                                                       Some(MessageContext::Custom(_)) => {
+                                                       _ => {
                                                                debug_assert!(false, "Checked in peel_onion_message");
                                                                return
                                                        }
@@ -1614,7 +1618,7 @@ where
                                                let context = match context {
                                                        None => None,
                                                        Some(MessageContext::Custom(data)) => Some(data),
-                                                       Some(MessageContext::Offers(_)) => {
+                                                       _ => {
                                                                debug_assert!(false, "Checked in peel_onion_message");
                                                                return
                                                        }