From 1c4d3289ff38a8f33ad6e7736992ff3330e9edac Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Thu, 7 Dec 2023 22:44:58 -0600 Subject: [PATCH] Return correct SendSuccess in OnionMessenger When enqueuing a message for a node already awaiting a connection, BufferedAwaitingConnection should be returned when a node is not yet connected as a peer. However, it was only returned when the first message was enqueued. Any messages enqueued after but before a connection was established incorrectly returned Buffered. --- lightning/src/onion_message/messenger.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lightning/src/onion_message/messenger.rs b/lightning/src/onion_message/messenger.rs index a6f11bf6a..21a1b302d 100644 --- a/lightning/src/onion_message/messenger.rs +++ b/lightning/src/onion_message/messenger.rs @@ -223,6 +223,13 @@ impl OnionMessageRecipient { *self = OnionMessageRecipient::ConnectedPeer(new_pending_messages); } } + + fn is_connected(&self) -> bool { + match self { + OnionMessageRecipient::ConnectedPeer(..) => true, + OnionMessageRecipient::PendingConnection(..) => false, + } + } } /// An [`OnionMessage`] for [`OnionMessenger`] to send. @@ -729,7 +736,11 @@ where }, hash_map::Entry::Occupied(mut e) => { e.get_mut().enqueue_message(onion_message); - Ok(SendSuccess::Buffered) + if e.get().is_connected() { + Ok(SendSuccess::Buffered) + } else { + Ok(SendSuccess::BufferedAwaitingConnection(first_node_id)) + } }, } } -- 2.39.5