]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Pass context into held_htlc_available message handling.
authorValentine Wallace <vwallace@protonmail.com>
Wed, 10 Jul 2024 17:58:53 +0000 (13:58 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Thu, 12 Sep 2024 15:16:03 +0000 (11:16 -0400)
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.

fuzz/src/onion_message.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/peer_handler.rs
lightning/src/onion_message/async_payments.rs
lightning/src/onion_message/functional_tests.rs
lightning/src/onion_message/messenger.rs

index 19666847a236f89d3ff735a57fe68b73d456205c..26bb0bc0ee45e00ccd138ad4709e3c163dc80bf7 100644 (file)
@@ -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)]
index 5f8dc1e5541fa1689caf22276b28bf9624d6a9c8..f21a0a20be596f7accb3d2947db63ee8d9496b51 100644 (file)
@@ -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()
index 3c0d724ad9423a2b18da59b734dd3e08d4bef287..626eabfebd69a5d36184e6d36dfc7a04b4e05797 100644 (file)
@@ -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;
index 89756d9f1f32bc09c3083ef304a50d66b2104215..e2a7f7bf74e2307b31c0f5b0c463f312897ed68d 100644 (file)
@@ -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.
        ///
index 7966e2a40ab16ef8bae134ecd3f2229cb44948cd..ef733b0893c803cbb9c75ea06895fff0b6619eff 100644 (file)
@@ -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)]
index 18522c0f3088177c8c890f048d72bb75d0ab0ba4..6883b02c145730eb3f2bc97ecfd734da6c84d4c2 100644 (file)
@@ -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 {