Merge pull request #3011 from jkczyz/2024-04-compact-blinded-path-creation
[rust-lightning] / lightning / src / onion_message / functional_tests.rs
index 764a2bdcbdcd198f901e722e388d3d3bcc4e86b6..029038a9fe769cc258088cbac6e9230c6477e827 100644 (file)
@@ -10,6 +10,7 @@
 //! Onion message testing and test utilities live here.
 
 use crate::blinded_path::{BlindedPath, EmptyNodeIdLookUp};
+use crate::blinded_path::message::ForwardNode;
 use crate::events::{Event, EventsProvider};
 use crate::ln::features::{ChannelFeatures, InitFeatures};
 use crate::ln::msgs::{self, DecodeError, OnionMessageHandler};
@@ -327,7 +328,7 @@ fn one_blinded_hop() {
        let test_msg = TestCustomMessage::Response;
 
        let secp_ctx = Secp256k1::new();
-       let blinded_path = BlindedPath::new_for_message(&[nodes[1].node_id], &*nodes[1].entropy_source, &secp_ctx).unwrap();
+       let blinded_path = BlindedPath::new_for_message(&[], nodes[1].node_id, &*nodes[1].entropy_source, &secp_ctx).unwrap();
        let destination = Destination::BlindedPath(blinded_path);
        nodes[0].messenger.send_onion_message(test_msg, destination, None).unwrap();
        nodes[1].custom_message_handler.expect_message(TestCustomMessage::Response);
@@ -340,7 +341,8 @@ fn two_unblinded_two_blinded() {
        let test_msg = TestCustomMessage::Response;
 
        let secp_ctx = Secp256k1::new();
-       let blinded_path = BlindedPath::new_for_message(&[nodes[3].node_id, nodes[4].node_id], &*nodes[4].entropy_source, &secp_ctx).unwrap();
+       let intermediate_nodes = [ForwardNode { node_id: nodes[3].node_id, short_channel_id: None }];
+       let blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[4].node_id, &*nodes[4].entropy_source, &secp_ctx).unwrap();
        let path = OnionMessagePath {
                intermediate_nodes: vec![nodes[1].node_id, nodes[2].node_id],
                destination: Destination::BlindedPath(blinded_path),
@@ -358,7 +360,11 @@ fn three_blinded_hops() {
        let test_msg = TestCustomMessage::Response;
 
        let secp_ctx = Secp256k1::new();
-       let blinded_path = BlindedPath::new_for_message(&[nodes[1].node_id, nodes[2].node_id, nodes[3].node_id], &*nodes[3].entropy_source, &secp_ctx).unwrap();
+       let intermediate_nodes = [
+               ForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
+               ForwardNode { node_id: nodes[2].node_id, short_channel_id: None },
+       ];
+       let blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[3].node_id, &*nodes[3].entropy_source, &secp_ctx).unwrap();
        let destination = Destination::BlindedPath(blinded_path);
 
        nodes[0].messenger.send_onion_message(test_msg, destination, None).unwrap();
@@ -391,7 +397,11 @@ fn we_are_intro_node() {
        let test_msg = TestCustomMessage::Response;
 
        let secp_ctx = Secp256k1::new();
-       let blinded_path = BlindedPath::new_for_message(&[nodes[0].node_id, nodes[1].node_id, nodes[2].node_id], &*nodes[2].entropy_source, &secp_ctx).unwrap();
+       let intermediate_nodes = [
+               ForwardNode { node_id: nodes[0].node_id, short_channel_id: None },
+               ForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
+       ];
+       let blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[2].node_id, &*nodes[2].entropy_source, &secp_ctx).unwrap();
        let destination = Destination::BlindedPath(blinded_path);
 
        nodes[0].messenger.send_onion_message(test_msg.clone(), destination, None).unwrap();
@@ -399,7 +409,8 @@ fn we_are_intro_node() {
        pass_along_path(&nodes);
 
        // Try with a two-hop blinded path where we are the introduction node.
-       let blinded_path = BlindedPath::new_for_message(&[nodes[0].node_id, nodes[1].node_id], &*nodes[1].entropy_source, &secp_ctx).unwrap();
+       let intermediate_nodes = [ForwardNode { node_id: nodes[0].node_id, short_channel_id: None }];
+       let blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[1].node_id, &*nodes[1].entropy_source, &secp_ctx).unwrap();
        let destination = Destination::BlindedPath(blinded_path);
        nodes[0].messenger.send_onion_message(test_msg, destination, None).unwrap();
        nodes[1].custom_message_handler.expect_message(TestCustomMessage::Response);
@@ -414,7 +425,8 @@ fn invalid_blinded_path_error() {
        let test_msg = TestCustomMessage::Response;
 
        let secp_ctx = Secp256k1::new();
-       let mut blinded_path = BlindedPath::new_for_message(&[nodes[1].node_id, nodes[2].node_id], &*nodes[2].entropy_source, &secp_ctx).unwrap();
+       let intermediate_nodes = [ForwardNode { node_id: nodes[1].node_id, short_channel_id: None }];
+       let mut blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[2].node_id, &*nodes[2].entropy_source, &secp_ctx).unwrap();
        blinded_path.blinded_hops.clear();
        let destination = Destination::BlindedPath(blinded_path);
        let err = nodes[0].messenger.send_onion_message(test_msg, destination, None).unwrap_err();
@@ -433,7 +445,11 @@ fn reply_path() {
                destination: Destination::Node(nodes[3].node_id),
                first_node_addresses: None,
        };
-       let reply_path = BlindedPath::new_for_message(&[nodes[2].node_id, nodes[1].node_id, nodes[0].node_id], &*nodes[0].entropy_source, &secp_ctx).unwrap();
+       let intermediate_nodes = [
+               ForwardNode { node_id: nodes[2].node_id, short_channel_id: None },
+               ForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
+       ];
+       let reply_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[0].node_id, &*nodes[0].entropy_source, &secp_ctx).unwrap();
        nodes[0].messenger.send_onion_message_using_path(path, test_msg.clone(), Some(reply_path)).unwrap();
        nodes[3].custom_message_handler.expect_message(TestCustomMessage::Request);
        pass_along_path(&nodes);
@@ -443,9 +459,17 @@ fn reply_path() {
        pass_along_path(&nodes);
 
        // Destination::BlindedPath
-       let blinded_path = BlindedPath::new_for_message(&[nodes[1].node_id, nodes[2].node_id, nodes[3].node_id], &*nodes[3].entropy_source, &secp_ctx).unwrap();
+       let intermediate_nodes = [
+               ForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
+               ForwardNode { node_id: nodes[2].node_id, short_channel_id: None },
+       ];
+       let blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[3].node_id, &*nodes[3].entropy_source, &secp_ctx).unwrap();
        let destination = Destination::BlindedPath(blinded_path);
-       let reply_path = BlindedPath::new_for_message(&[nodes[2].node_id, nodes[1].node_id, nodes[0].node_id], &*nodes[0].entropy_source, &secp_ctx).unwrap();
+       let intermediate_nodes = [
+               ForwardNode { node_id: nodes[2].node_id, short_channel_id: None },
+               ForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
+       ];
+       let reply_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[0].node_id, &*nodes[0].entropy_source, &secp_ctx).unwrap();
 
        nodes[0].messenger.send_onion_message(test_msg, destination, Some(reply_path)).unwrap();
        nodes[3].custom_message_handler.expect_message(TestCustomMessage::Request);
@@ -525,8 +549,9 @@ fn requests_peer_connection_for_buffered_messages() {
        let secp_ctx = Secp256k1::new();
        add_channel_to_graph(&nodes[0], &nodes[1], &secp_ctx, 42);
 
+       let intermediate_nodes = [ForwardNode { node_id: nodes[1].node_id, short_channel_id: None }];
        let blinded_path = BlindedPath::new_for_message(
-               &[nodes[1].node_id, nodes[2].node_id], &*nodes[0].entropy_source, &secp_ctx
+               &intermediate_nodes, nodes[2].node_id, &*nodes[0].entropy_source, &secp_ctx
        ).unwrap();
        let destination = Destination::BlindedPath(blinded_path);
 
@@ -562,8 +587,9 @@ fn drops_buffered_messages_waiting_for_peer_connection() {
        let secp_ctx = Secp256k1::new();
        add_channel_to_graph(&nodes[0], &nodes[1], &secp_ctx, 42);
 
+       let intermediate_nodes = [ForwardNode { node_id: nodes[1].node_id, short_channel_id: None }];
        let blinded_path = BlindedPath::new_for_message(
-               &[nodes[1].node_id, nodes[2].node_id], &*nodes[0].entropy_source, &secp_ctx
+               &intermediate_nodes, nodes[2].node_id, &*nodes[0].entropy_source, &secp_ctx
        ).unwrap();
        let destination = Destination::BlindedPath(blinded_path);
 
@@ -611,8 +637,9 @@ fn intercept_offline_peer_oms() {
 
        let message = TestCustomMessage::Response;
        let secp_ctx = Secp256k1::new();
+       let intermediate_nodes = [ForwardNode { node_id: nodes[1].node_id, short_channel_id: None }];
        let blinded_path = BlindedPath::new_for_message(
-               &[nodes[1].node_id, nodes[2].node_id], &*nodes[2].entropy_source, &secp_ctx
+               &intermediate_nodes, nodes[2].node_id, &*nodes[2].entropy_source, &secp_ctx
        ).unwrap();
        let destination = Destination::BlindedPath(blinded_path);