Support NextHop::ShortChannelId in BlindedPath
[rust-lightning] / lightning / src / onion_message / messenger.rs
index 97fcbfd94afa5e4c3ff7c866cd637392050e5cc3..9fd6fd95f95a1ea3cdd82bb3ebaea9b0848f8ed4 100644 (file)
@@ -16,7 +16,7 @@ use bitcoin::hashes::sha256::Hash as Sha256;
 use bitcoin::secp256k1::{self, PublicKey, Scalar, Secp256k1, SecretKey};
 
 use crate::blinded_path::{BlindedPath, IntroductionNode, NextMessageHop, NodeIdLookUp};
-use crate::blinded_path::message::{advance_path_by_one, ForwardTlvs, ReceiveTlvs};
+use crate::blinded_path::message::{advance_path_by_one, ForwardNode, ForwardTlvs, ReceiveTlvs};
 use crate::blinded_path::utils;
 use crate::events::{Event, EventHandler, EventsProvider};
 use crate::sign::{EntropySource, NodeSigner, Recipient};
@@ -71,6 +71,7 @@ pub(super) const MAX_TIMER_TICKS: usize = 2;
 /// # use bitcoin::hashes::hex::FromHex;
 /// # use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey, self};
 /// # use lightning::blinded_path::{BlindedPath, EmptyNodeIdLookUp};
+/// # use lightning::blinded_path::message::ForwardNode;
 /// # use lightning::sign::{EntropySource, KeysManager};
 /// # use lightning::ln::peer_handler::IgnoringMessageHandler;
 /// # use lightning::onion_message::messenger::{Destination, MessageRouter, OnionMessagePath, OnionMessenger};
@@ -145,8 +146,11 @@ pub(super) const MAX_TIMER_TICKS: usize = 2;
 ///
 /// // Create a blinded path to yourself, for someone to send an onion message to.
 /// # let your_node_id = hop_node_id1;
-/// let hops = [hop_node_id3, hop_node_id4, your_node_id];
-/// let blinded_path = BlindedPath::new_for_message(&hops, &keys_manager, &secp_ctx).unwrap();
+/// let hops = [
+///    ForwardNode { node_id: hop_node_id3, short_channel_id: None },
+///    ForwardNode { node_id: hop_node_id4, short_channel_id: None },
+/// ];
+/// let blinded_path = BlindedPath::new_for_message(&hops, your_node_id, &keys_manager, &secp_ctx).unwrap();
 ///
 /// // Send a custom onion message to a blinded path.
 /// let destination = Destination::BlindedPath(blinded_path);
@@ -435,8 +439,12 @@ where
                });
 
                let paths = peer_info.into_iter()
-                       .map(|(pubkey, _, _)| vec![pubkey, recipient])
-                       .map(|node_pks| BlindedPath::new_for_message(&node_pks, &*self.entropy_source, secp_ctx))
+                       .map(|(node_id, _, _)| vec![ForwardNode { node_id, short_channel_id: None }])
+                       .map(|intermediate_nodes| {
+                               BlindedPath::new_for_message(
+                                       &intermediate_nodes, recipient, &*self.entropy_source, secp_ctx
+                               )
+                       })
                        .take(MAX_PATHS)
                        .collect::<Result<Vec<_>, _>>();
 
@@ -923,13 +931,12 @@ where
                &self, contents: T, destination: Destination, reply_path: Option<BlindedPath>,
                log_suffix: fmt::Arguments
        ) -> Result<SendSuccess, SendError> {
-               let mut logger = WithContext::from(&self.logger, None, None);
-               let result = self.find_path(destination)
-                       .and_then(|path| {
-                               let first_hop = path.intermediate_nodes.get(0).map(|p| *p);
-                               logger = WithContext::from(&self.logger, first_hop, None);
-                               self.enqueue_onion_message(path, contents, reply_path, log_suffix)
-                       });
+               let mut logger = WithContext::from(&self.logger, None, None, None);
+               let result = self.find_path(destination).and_then(|path| {
+                       let first_hop = path.intermediate_nodes.get(0).map(|p| *p);
+                       logger = WithContext::from(&self.logger, first_hop, None, None);
+                       self.enqueue_onion_message(path, contents, reply_path, log_suffix)
+               });
 
                match result.as_ref() {
                        Err(SendError::GetNodeIdFailed) => {
@@ -1149,7 +1156,7 @@ where
        CMH::Target: CustomOnionMessageHandler,
 {
        fn handle_onion_message(&self, peer_node_id: &PublicKey, msg: &OnionMessage) {
-               let logger = WithContext::from(&self.logger, Some(*peer_node_id), None);
+               let logger = WithContext::from(&self.logger, Some(*peer_node_id), None, None);
                match self.peel_onion_message(msg) {
                        Ok(PeeledOnion::Receive(message, path_id, reply_path)) => {
                                log_trace!(