Skip to content

Commit ddee928

Browse files
committed
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.
1 parent 8412e83 commit ddee928

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lightning/src/onion_message/messenger.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ pub enum SendSuccess {
313313
/// The message was buffered and will be sent once it is processed by
314314
/// [`OnionMessageHandler::next_onion_message_for_peer`].
315315
Buffered,
316+
/// The message was buffered and will be sent once the node is connected as a peer and it is
317+
/// processed by [`OnionMessageHandler::next_onion_message_for_peer`].
318+
BufferedAwaitingConnection(PublicKey),
316319
}
317320

318321
/// Errors that may occur when [sending an onion message].
@@ -328,8 +331,6 @@ pub enum SendError {
328331
/// The provided [`Destination`] was an invalid [`BlindedPath`] due to not having any blinded
329332
/// hops.
330333
TooFewBlindedHops,
331-
/// Our next-hop peer was offline or does not support onion message forwarding.
332-
InvalidFirstHop,
333334
/// A path from the sender to the destination could not be found by the [`MessageRouter`].
334335
PathNotFound,
335336
/// Onion message contents must have a TLV type >= 64.
@@ -612,6 +613,12 @@ where
612613
Ok(SendSuccess::Buffered) => {
613614
log_trace!(self.logger, "Buffered onion message {}", log_suffix);
614615
},
616+
Ok(SendSuccess::BufferedAwaitingConnection(node_id)) => {
617+
log_trace!(
618+
self.logger, "Buffered onion message waiting on peer connection {}: {:?}",
619+
log_suffix, node_id
620+
);
621+
},
615622
}
616623

617624
result
@@ -649,7 +656,11 @@ where
649656
}
650657

651658
match message_buffers.entry(first_node_id) {
652-
hash_map::Entry::Vacant(_) => Err(SendError::InvalidFirstHop),
659+
hash_map::Entry::Vacant(e) => {
660+
e.insert(OnionMessageBuffer::PendingConnection(VecDeque::new()))
661+
.enqueue_message(onion_message);
662+
Ok(SendSuccess::BufferedAwaitingConnection(first_node_id))
663+
},
653664
hash_map::Entry::Occupied(mut e) => {
654665
e.get_mut().enqueue_message(onion_message);
655666
Ok(SendSuccess::Buffered)

0 commit comments

Comments
 (0)