From 29990674ea96f6439481cc8d7730bb8dc5defd54 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 21 Aug 2024 19:10:46 +0000 Subject: [PATCH] 3/3 Use `MessageSendInstructions` instead of `PendingOnionMessage` 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 | 4 +-- lightning/src/onion_message/async_payments.rs | 22 ++----------- lightning/src/onion_message/messenger.rs | 32 ------------------- 3 files changed, 4 insertions(+), 54 deletions(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index b215880c9..855af0d89 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -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> { + fn release_pending_messages(&self) -> Vec<(AsyncPaymentsMessage, MessageSendInstructions)> { Vec::new() } } diff --git a/lightning/src/onion_message/async_payments.rs b/lightning/src/onion_message/async_payments.rs index dcc528305..37e4a5341 100644 --- a/lightning/src/onion_message/async_payments.rs +++ b/lightning/src/onion_message/async_payments.rs @@ -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> { - 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, - )> { + fn release_pending_messages(&self) -> Vec<(AsyncPaymentsMessage, MessageSendInstructions)> { vec![] } } diff --git a/lightning/src/onion_message/messenger.rs b/lightning/src/onion_message/messenger.rs index ba2fe982d..fd5108d5a 100644 --- a/lightning/src/onion_message/messenger.rs +++ b/lightning/src/onion_message/messenger.rs @@ -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 { - /// 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, -} - -#[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, Destination, Option); - -pub(crate) fn new_pending_onion_message( - contents: T, destination: Destination, reply_path: Option -) -> PendingOnionMessage { - #[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`]. -- 2.39.5