From: Valentine Wallace Date: Wed, 10 Jul 2024 17:54:05 +0000 (-0400) Subject: Add MessageContext for async payments. X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=a3216acb7d5c36f7f7993d76612ff383992e4c14;p=rust-lightning Add MessageContext for async payments. This context will be used in reply paths for outbound held_htlc_available messages, so we can authenticate the corresponding release_held_htlc messages. --- diff --git a/lightning/src/blinded_path/message.rs b/lightning/src/blinded_path/message.rs index 256483fec..e6aa4e340 100644 --- a/lightning/src/blinded_path/message.rs +++ b/lightning/src/blinded_path/message.rs @@ -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( secp_ctx: &Secp256k1, intermediate_nodes: &[MessageForwardNode], diff --git a/lightning/src/onion_message/messenger.rs b/lightning/src/onion_message/messenger.rs index f44e3cb01..18522c0f3 100644 --- a/lightning/src/onion_message/messenger.rs +++ b/lightning/src/onion_message/messenger.rs @@ -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 }