From: Jeffrey Czyz Date: Tue, 7 Nov 2023 14:17:46 +0000 (-0600) Subject: Buffer onion messages requiring a connection X-Git-Tag: v0.0.119~21^2~15 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;ds=sidebyside;h=ddee9289dce52065bcc0e8bf8ea3fcedd342627a;p=rust-lightning Buffer onion messages requiring a connection MessageRouter::find_path returns a path to use when sending an onion message. If the first node on the path is not connected or does not support onion messages, sending will fail with InvalidFirstHop. Instead of failing outright, buffer the message for later sending once the first node is a connected peer. --- diff --git a/lightning/src/onion_message/messenger.rs b/lightning/src/onion_message/messenger.rs index 8d98e284e..c84cfc120 100644 --- a/lightning/src/onion_message/messenger.rs +++ b/lightning/src/onion_message/messenger.rs @@ -313,6 +313,9 @@ pub enum SendSuccess { /// The message was buffered and will be sent once it is processed by /// [`OnionMessageHandler::next_onion_message_for_peer`]. Buffered, + /// The message was buffered and will be sent once the node is connected as a peer and it is + /// processed by [`OnionMessageHandler::next_onion_message_for_peer`]. + BufferedAwaitingConnection(PublicKey), } /// Errors that may occur when [sending an onion message]. @@ -328,8 +331,6 @@ pub enum SendError { /// The provided [`Destination`] was an invalid [`BlindedPath`] due to not having any blinded /// hops. TooFewBlindedHops, - /// Our next-hop peer was offline or does not support onion message forwarding. - InvalidFirstHop, /// A path from the sender to the destination could not be found by the [`MessageRouter`]. PathNotFound, /// Onion message contents must have a TLV type >= 64. @@ -612,6 +613,12 @@ where Ok(SendSuccess::Buffered) => { log_trace!(self.logger, "Buffered onion message {}", log_suffix); }, + Ok(SendSuccess::BufferedAwaitingConnection(node_id)) => { + log_trace!( + self.logger, "Buffered onion message waiting on peer connection {}: {:?}", + log_suffix, node_id + ); + }, } result @@ -649,7 +656,11 @@ where } match message_buffers.entry(first_node_id) { - hash_map::Entry::Vacant(_) => Err(SendError::InvalidFirstHop), + hash_map::Entry::Vacant(e) => { + e.insert(OnionMessageBuffer::PendingConnection(VecDeque::new())) + .enqueue_message(onion_message); + Ok(SendSuccess::BufferedAwaitingConnection(first_node_id)) + }, hash_map::Entry::Occupied(mut e) => { e.get_mut().enqueue_message(onion_message); Ok(SendSuccess::Buffered)