Return correct SendSuccess in OnionMessenger
authorJeffrey Czyz <jkczyz@gmail.com>
Fri, 8 Dec 2023 04:44:58 +0000 (22:44 -0600)
committerJeffrey Czyz <jkczyz@gmail.com>
Fri, 8 Dec 2023 05:44:47 +0000 (23:44 -0600)
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

index a6f11bf6a7d75e07be52442569c42ed87d610870..21a1b302da09b76fa3f73cbc70953fa46919c3c6 100644 (file)
@@ -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))
+                               }
                        },
                }
        }