From: Jeffrey Czyz Date: Fri, 8 Dec 2023 04:44:58 +0000 (-0600) Subject: Return correct SendSuccess in OnionMessenger X-Git-Tag: v0.0.119~20^2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=1c4d3289ff38a8f33ad6e7736992ff3330e9edac;p=rust-lightning 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. --- 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)) + } }, } }