From: Jeffrey Czyz Date: Thu, 9 Nov 2023 17:10:23 +0000 (-0600) Subject: Add Event::ConnectionNeeded for onion messages X-Git-Tag: v0.0.119~21^2~11 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=ba2a8221c414c253531a1fd49623bf1c743bad6a;p=rust-lightning Add Event::ConnectionNeeded for onion messages A MessageRouter may be unable to find a complete path to an onion message's destination. This could because no such path exists or any needs on a potential path don't support onion messages. Add an event that indicates a connection with a node is needed in order to send the message. --- diff --git a/lightning/src/events/mod.rs b/lightning/src/events/mod.rs index 4e04a3634..76e5f25c0 100644 --- a/lightning/src/events/mod.rs +++ b/lightning/src/events/mod.rs @@ -530,6 +530,25 @@ pub enum Event { /// serialized prior to LDK version 0.0.117. sender_intended_total_msat: Option, }, + /// Indicates that a peer connection with a node is needed in order to send an [`OnionMessage`]. + /// + /// Typically, this happens when a [`MessageRouter`] is unable to find a complete path to a + /// [`Destination`]. Once a connection is established, any messages buffered by an + /// [`OnionMessageHandler`] may be sent. + /// + /// This event will not be generated for onion message forwards; only for sends including + /// replies. Handlers should connect to the node otherwise any buffered messages may be lost. + /// + /// [`OnionMessage`]: msgs::OnionMessage + /// [`MessageRouter`]: crate::onion_message::MessageRouter + /// [`Destination`]: crate::onion_message::Destination + /// [`OnionMessageHandler`]: crate::ln::msgs::OnionMessageHandler + ConnectionNeeded { + /// The node id for the node needing a connection. + node_id: PublicKey, + /// Sockets for connecting to the node. + addresses: Vec, + }, /// Indicates a request for an invoice failed to yield a response in a reasonable amount of time /// or was explicitly abandoned by [`ChannelManager::abandon_payment`]. This may be for an /// [`InvoiceRequest`] sent for an [`Offer`] or for a [`Refund`] that hasn't been redeemed. @@ -1190,6 +1209,10 @@ impl Writeable for Event { (0, payment_id, required), }) }, + &Event::ConnectionNeeded { .. } => { + 35u8.write(writer)?; + // Never write ConnectionNeeded events as buffered onion messages aren't serialized. + }, // Note that, going forward, all new events must only write data inside of // `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write // data via `write_tlv_fields`. @@ -1200,8 +1223,7 @@ impl Writeable for Event { impl MaybeReadable for Event { fn read(reader: &mut R) -> Result, msgs::DecodeError> { match Readable::read(reader)? { - // Note that we do not write a length-prefixed TLV for FundingGenerationReady events, - // unlike all other events, thus we return immediately here. + // Note that we do not write a length-prefixed TLV for FundingGenerationReady events. 0u8 => Ok(None), 1u8 => { let f = || { @@ -1588,6 +1610,8 @@ impl MaybeReadable for Event { }; f() }, + // Note that we do not write a length-prefixed TLV for ConnectionNeeded events. + 35u8 => Ok(None), // Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue. // Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt // reads.