From: Valentine Wallace Date: Wed, 10 Jul 2024 17:58:53 +0000 (-0400) Subject: Pass context into held_htlc_available message handling. X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=e162278bc8ad3ac8b7132016fa36f96d0afbb896;p=rust-lightning Pass context into held_htlc_available message handling. Useful for using the payment_id within to look up the corresponding outbound async payment so we know we can safely release the HTLCs to the now-onlinen recipient. --- diff --git a/fuzz/src/onion_message.rs b/fuzz/src/onion_message.rs index 19666847a..26bb0bc0e 100644 --- a/fuzz/src/onion_message.rs +++ b/fuzz/src/onion_message.rs @@ -5,7 +5,9 @@ use bitcoin::secp256k1::ecdsa::RecoverableSignature; use bitcoin::secp256k1::schnorr; use bitcoin::secp256k1::{self, PublicKey, Scalar, Secp256k1, SecretKey}; -use lightning::blinded_path::message::{BlindedMessagePath, MessageContext, OffersContext}; +use lightning::blinded_path::message::{ + AsyncPaymentsContext, BlindedMessagePath, MessageContext, OffersContext, +}; use lightning::blinded_path::EmptyNodeIdLookUp; use lightning::ln::features::InitFeatures; use lightning::ln::msgs::{self, DecodeError, OnionMessageHandler}; @@ -129,7 +131,7 @@ impl AsyncPaymentsMessageHandler for TestAsyncPaymentsMessageHandler { responder.respond(), )) } - fn release_held_htlc(&self, _message: ReleaseHeldHtlc) {} + fn release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {} } #[derive(Debug)] diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 5f8dc1e55..f21a0a20b 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -33,7 +33,7 @@ use bitcoin::secp256k1::Secp256k1; use bitcoin::{secp256k1, Sequence}; use crate::events::FundingInfo; -use crate::blinded_path::message::{MessageContext, OffersContext}; +use crate::blinded_path::message::{AsyncPaymentsContext, MessageContext, OffersContext}; use crate::blinded_path::NodeIdLookUp; use crate::blinded_path::message::{BlindedMessagePath, MessageForwardNode}; use crate::blinded_path::payment::{BlindedPaymentPath, Bolt12OfferContext, Bolt12RefundContext, PaymentConstraints, PaymentContext, ReceiveTlvs}; @@ -11094,7 +11094,7 @@ where None } - fn release_held_htlc(&self, _message: ReleaseHeldHtlc) {} + fn release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {} fn release_pending_messages(&self) -> Vec<(AsyncPaymentsMessage, MessageSendInstructions)> { Vec::new() diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 3c0d724ad..626eabfeb 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -18,7 +18,7 @@ use bitcoin::constants::ChainHash; use bitcoin::secp256k1::{self, Secp256k1, SecretKey, PublicKey}; -use crate::blinded_path::message::OffersContext; +use crate::blinded_path::message::{AsyncPaymentsContext, OffersContext}; use crate::sign::{NodeSigner, Recipient}; use crate::events::{MessageSendEvent, MessageSendEventsProvider}; use crate::ln::types::ChannelId; @@ -152,7 +152,7 @@ impl AsyncPaymentsMessageHandler for IgnoringMessageHandler { ) -> Option<(ReleaseHeldHtlc, ResponseInstruction)> { None } - fn release_held_htlc(&self, _message: ReleaseHeldHtlc) {} + fn release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {} } impl CustomOnionMessageHandler for IgnoringMessageHandler { type CustomMessage = Infallible; diff --git a/lightning/src/onion_message/async_payments.rs b/lightning/src/onion_message/async_payments.rs index 89756d9f1..e2a7f7bf7 100644 --- a/lightning/src/onion_message/async_payments.rs +++ b/lightning/src/onion_message/async_payments.rs @@ -9,6 +9,7 @@ //! Message handling for async payments. +use crate::blinded_path::message::AsyncPaymentsContext; use crate::io; use crate::ln::msgs::DecodeError; use crate::onion_message::messenger::{MessageSendInstructions, Responder, ResponseInstruction}; @@ -32,7 +33,7 @@ pub trait AsyncPaymentsMessageHandler { /// Handle a [`ReleaseHeldHtlc`] message. If authentication of the message succeeds, an HTLC /// should be released to the corresponding payee. - fn release_held_htlc(&self, message: ReleaseHeldHtlc); + fn release_held_htlc(&self, message: ReleaseHeldHtlc, context: AsyncPaymentsContext); /// Release any [`AsyncPaymentsMessage`]s that need to be sent. /// diff --git a/lightning/src/onion_message/functional_tests.rs b/lightning/src/onion_message/functional_tests.rs index 7966e2a40..ef733b089 100644 --- a/lightning/src/onion_message/functional_tests.rs +++ b/lightning/src/onion_message/functional_tests.rs @@ -10,7 +10,7 @@ //! Onion message testing and test utilities live here. use crate::blinded_path::EmptyNodeIdLookUp; -use crate::blinded_path::message::{BlindedMessagePath, MessageForwardNode, MessageContext, OffersContext}; +use crate::blinded_path::message::{AsyncPaymentsContext, BlindedMessagePath, MessageForwardNode, MessageContext, OffersContext}; use crate::events::{Event, EventsProvider}; use crate::ln::features::{ChannelFeatures, InitFeatures}; use crate::ln::msgs::{self, DecodeError, OnionMessageHandler}; @@ -87,7 +87,7 @@ impl AsyncPaymentsMessageHandler for TestAsyncPaymentsMessageHandler { ) -> Option<(ReleaseHeldHtlc, ResponseInstruction)> { None } - fn release_held_htlc(&self, _message: ReleaseHeldHtlc) {} + fn release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {} } #[derive(Clone, Debug, PartialEq)] diff --git a/lightning/src/onion_message/messenger.rs b/lightning/src/onion_message/messenger.rs index 18522c0f3..6883b02c1 100644 --- a/lightning/src/onion_message/messenger.rs +++ b/lightning/src/onion_message/messenger.rs @@ -1612,7 +1612,15 @@ where }, #[cfg(async_payments)] ParsedOnionMessageContents::AsyncPayments(AsyncPaymentsMessage::ReleaseHeldHtlc(msg)) => { - self.async_payments_handler.release_held_htlc(msg); + let context = match context { + Some(MessageContext::AsyncPayments(context)) => context, + Some(_) => { + debug_assert!(false, "Checked in peel_onion_message"); + return + }, + None => return, + }; + self.async_payments_handler.release_held_htlc(msg, context); }, ParsedOnionMessageContents::Custom(msg) => { let context = match context {