]> git.bitcoin.ninja Git - rust-lightning/commitdiff
3/3 Use `MessageSendInstructions` instead of `PendingOnionMessage`
authorMatt Corallo <git@bluematt.me>
Wed, 21 Aug 2024 19:10:46 +0000 (19:10 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 22 Aug 2024 22:29:18 +0000 (22:29 +0000)
Now that the `MessageRouter` can `create_blinded_paths` forcing
callers of the `OnionMessenger` to provide it with a reply path up
front is unnecessary complexity, doubly so in message handlers.

Here we take the next step towards untangling that, moving from
`PendingOnionMessage` to `MessageSendInstructions` for the outbound
message queue in `AsyncPaymentsMessageHandler`. Better, we can also
drop the `c_bindings`-specific message queue variant, unifying the
APIs.

Here we also drop `PendingOnionMessage` entirely.

lightning/src/ln/channelmanager.rs
lightning/src/onion_message/async_payments.rs
lightning/src/onion_message/messenger.rs

index b215880c9868bab9e51e8c13556b5f701eba0f0b..855af0d8903daf4f6823d962979be5d81c7d6d59 100644 (file)
@@ -71,7 +71,7 @@ use crate::offers::parse::Bolt12SemanticError;
 use crate::offers::refund::{Refund, RefundBuilder};
 use crate::offers::signer;
 use crate::onion_message::async_payments::{AsyncPaymentsMessage, HeldHtlcAvailable, ReleaseHeldHtlc, AsyncPaymentsMessageHandler};
-use crate::onion_message::messenger::{Destination, MessageRouter, PendingOnionMessage, Responder, ResponseInstruction, MessageSendInstructions};
+use crate::onion_message::messenger::{Destination, MessageRouter, Responder, ResponseInstruction, MessageSendInstructions};
 use crate::onion_message::offers::{OffersMessage, OffersMessageHandler};
 use crate::sign::{EntropySource, NodeSigner, Recipient, SignerProvider};
 use crate::sign::ecdsa::EcdsaChannelSigner;
@@ -10962,7 +10962,7 @@ where
 
        fn release_held_htlc(&self, _message: ReleaseHeldHtlc) {}
 
-       fn release_pending_messages(&self) -> Vec<PendingOnionMessage<AsyncPaymentsMessage>> {
+       fn release_pending_messages(&self) -> Vec<(AsyncPaymentsMessage, MessageSendInstructions)> {
                Vec::new()
        }
 }
index dcc528305663f5d79f8440a1e884ba22d9e3da6a..37e4a534180b26018afc104e7031d92b9b8285ca 100644 (file)
@@ -11,9 +11,7 @@
 
 use crate::io;
 use crate::ln::msgs::DecodeError;
-#[cfg(not(c_bindings))]
-use crate::onion_message::messenger::PendingOnionMessage;
-use crate::onion_message::messenger::{Responder, ResponseInstruction};
+use crate::onion_message::messenger::{MessageSendInstructions, Responder, ResponseInstruction};
 use crate::onion_message::packet::OnionMessageContents;
 use crate::prelude::*;
 use crate::util::ser::{Readable, ReadableArgs, Writeable, Writer};
@@ -40,23 +38,7 @@ pub trait AsyncPaymentsMessageHandler {
        ///
        /// Typically, this is used for messages initiating an async payment flow rather than in response
        /// to another message.
-       #[cfg(not(c_bindings))]
-       fn release_pending_messages(&self) -> Vec<PendingOnionMessage<AsyncPaymentsMessage>> {
-               vec![]
-       }
-
-       /// Release any [`AsyncPaymentsMessage`]s that need to be sent.
-       ///
-       /// Typically, this is used for messages initiating a payment flow rather than in response to
-       /// another message.
-       #[cfg(c_bindings)]
-       fn release_pending_messages(
-               &self,
-       ) -> Vec<(
-               AsyncPaymentsMessage,
-               crate::onion_message::messenger::Destination,
-               Option<crate::blinded_path::message::BlindedMessagePath>,
-       )> {
+       fn release_pending_messages(&self) -> Vec<(AsyncPaymentsMessage, MessageSendInstructions)> {
                vec![]
        }
 }
index ba2fe982d293048e45265610a08c94545b548987..fd5108d5ad7d5d404b60eb351269f051b5e78289 100644 (file)
@@ -428,38 +428,6 @@ pub enum MessageSendInstructions {
        }
 }
 
-/// An [`OnionMessage`] for [`OnionMessenger`] to send.
-///
-/// These are obtained when released from [`OnionMessenger`]'s handlers after which they are
-/// enqueued for sending.
-#[cfg(not(c_bindings))]
-pub struct PendingOnionMessage<T: OnionMessageContents> {
-       /// The message contents to send in an [`OnionMessage`].
-       pub contents: T,
-
-       /// The destination of the message.
-       pub destination: Destination,
-
-       /// A reply path to include in the [`OnionMessage`] for a response.
-       pub reply_path: Option<BlindedMessagePath>,
-}
-
-#[cfg(c_bindings)]
-/// An [`OnionMessage`] for [`OnionMessenger`] to send.
-///
-/// These are obtained when released from [`OnionMessenger`]'s handlers after which they are
-/// enqueued for sending.
-pub type PendingOnionMessage<T> = (T, Destination, Option<BlindedMessagePath>);
-
-pub(crate) fn new_pending_onion_message<T: OnionMessageContents>(
-       contents: T, destination: Destination, reply_path: Option<BlindedMessagePath>
-) -> PendingOnionMessage<T> {
-       #[cfg(not(c_bindings))]
-       return PendingOnionMessage { contents, destination, reply_path };
-       #[cfg(c_bindings)]
-       return (contents, destination, reply_path);
-}
-
 /// A trait defining behavior for routing an [`OnionMessage`].
 pub trait MessageRouter {
        /// Returns a route for sending an [`OnionMessage`] to the given [`Destination`].