1010//! Onion message testing and test utilities live here.
1111
1212use crate :: blinded_path:: { BlindedPath , EmptyNodeIdLookUp } ;
13+ use crate :: blinded_path:: message:: ForwardNode ;
1314use crate :: events:: { Event , EventsProvider } ;
1415use crate :: ln:: features:: { ChannelFeatures , InitFeatures } ;
1516use crate :: ln:: msgs:: { self , DecodeError , OnionMessageHandler } ;
@@ -327,7 +328,7 @@ fn one_blinded_hop() {
327328 let test_msg = TestCustomMessage :: Response ;
328329
329330 let secp_ctx = Secp256k1 :: new ( ) ;
330- let blinded_path = BlindedPath :: new_for_message ( & [ nodes[ 1 ] . node_id ] , & * nodes[ 1 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
331+ let blinded_path = BlindedPath :: new_for_message ( & [ ] , nodes[ 1 ] . node_id , & * nodes[ 1 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
331332 let destination = Destination :: BlindedPath ( blinded_path) ;
332333 nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, None ) . unwrap ( ) ;
333334 nodes[ 1 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
@@ -340,7 +341,8 @@ fn two_unblinded_two_blinded() {
340341 let test_msg = TestCustomMessage :: Response ;
341342
342343 let secp_ctx = Secp256k1 :: new ( ) ;
343- let blinded_path = BlindedPath :: new_for_message ( & [ nodes[ 3 ] . node_id , nodes[ 4 ] . node_id ] , & * nodes[ 4 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
344+ let intermediate_nodes = [ ForwardNode { node_id : nodes[ 3 ] . node_id , short_channel_id : None } ] ;
345+ let blinded_path = BlindedPath :: new_for_message ( & intermediate_nodes, nodes[ 4 ] . node_id , & * nodes[ 4 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
344346 let path = OnionMessagePath {
345347 intermediate_nodes : vec ! [ nodes[ 1 ] . node_id, nodes[ 2 ] . node_id] ,
346348 destination : Destination :: BlindedPath ( blinded_path) ,
@@ -358,7 +360,11 @@ fn three_blinded_hops() {
358360 let test_msg = TestCustomMessage :: Response ;
359361
360362 let secp_ctx = Secp256k1 :: new ( ) ;
361- 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 ( ) ;
363+ let intermediate_nodes = [
364+ ForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ,
365+ ForwardNode { node_id : nodes[ 2 ] . node_id , short_channel_id : None } ,
366+ ] ;
367+ let blinded_path = BlindedPath :: new_for_message ( & intermediate_nodes, nodes[ 3 ] . node_id , & * nodes[ 3 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
362368 let destination = Destination :: BlindedPath ( blinded_path) ;
363369
364370 nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, None ) . unwrap ( ) ;
@@ -391,15 +397,20 @@ fn we_are_intro_node() {
391397 let test_msg = TestCustomMessage :: Response ;
392398
393399 let secp_ctx = Secp256k1 :: new ( ) ;
394- 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 ( ) ;
400+ let intermediate_nodes = [
401+ ForwardNode { node_id : nodes[ 0 ] . node_id , short_channel_id : None } ,
402+ ForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ,
403+ ] ;
404+ let blinded_path = BlindedPath :: new_for_message ( & intermediate_nodes, nodes[ 2 ] . node_id , & * nodes[ 2 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
395405 let destination = Destination :: BlindedPath ( blinded_path) ;
396406
397407 nodes[ 0 ] . messenger . send_onion_message ( test_msg. clone ( ) , destination, None ) . unwrap ( ) ;
398408 nodes[ 2 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
399409 pass_along_path ( & nodes) ;
400410
401411 // Try with a two-hop blinded path where we are the introduction node.
402- let blinded_path = BlindedPath :: new_for_message ( & [ nodes[ 0 ] . node_id , nodes[ 1 ] . node_id ] , & * nodes[ 1 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
412+ let intermediate_nodes = [ ForwardNode { node_id : nodes[ 0 ] . node_id , short_channel_id : None } ] ;
413+ let blinded_path = BlindedPath :: new_for_message ( & intermediate_nodes, nodes[ 1 ] . node_id , & * nodes[ 1 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
403414 let destination = Destination :: BlindedPath ( blinded_path) ;
404415 nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, None ) . unwrap ( ) ;
405416 nodes[ 1 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
@@ -414,7 +425,8 @@ fn invalid_blinded_path_error() {
414425 let test_msg = TestCustomMessage :: Response ;
415426
416427 let secp_ctx = Secp256k1 :: new ( ) ;
417- let mut blinded_path = BlindedPath :: new_for_message ( & [ nodes[ 1 ] . node_id , nodes[ 2 ] . node_id ] , & * nodes[ 2 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
428+ let intermediate_nodes = [ ForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ] ;
429+ let mut blinded_path = BlindedPath :: new_for_message ( & intermediate_nodes, nodes[ 2 ] . node_id , & * nodes[ 2 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
418430 blinded_path. blinded_hops . clear ( ) ;
419431 let destination = Destination :: BlindedPath ( blinded_path) ;
420432 let err = nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, None ) . unwrap_err ( ) ;
@@ -433,7 +445,11 @@ fn reply_path() {
433445 destination : Destination :: Node ( nodes[ 3 ] . node_id ) ,
434446 first_node_addresses : None ,
435447 } ;
436- 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 ( ) ;
448+ let intermediate_nodes = [
449+ ForwardNode { node_id : nodes[ 2 ] . node_id , short_channel_id : None } ,
450+ ForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ,
451+ ] ;
452+ let reply_path = BlindedPath :: new_for_message ( & intermediate_nodes, nodes[ 0 ] . node_id , & * nodes[ 0 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
437453 nodes[ 0 ] . messenger . send_onion_message_using_path ( path, test_msg. clone ( ) , Some ( reply_path) ) . unwrap ( ) ;
438454 nodes[ 3 ] . custom_message_handler . expect_message ( TestCustomMessage :: Request ) ;
439455 pass_along_path ( & nodes) ;
@@ -443,9 +459,17 @@ fn reply_path() {
443459 pass_along_path ( & nodes) ;
444460
445461 // Destination::BlindedPath
446- 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 ( ) ;
462+ let intermediate_nodes = [
463+ ForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ,
464+ ForwardNode { node_id : nodes[ 2 ] . node_id , short_channel_id : None } ,
465+ ] ;
466+ let blinded_path = BlindedPath :: new_for_message ( & intermediate_nodes, nodes[ 3 ] . node_id , & * nodes[ 3 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
447467 let destination = Destination :: BlindedPath ( blinded_path) ;
448- 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 ( ) ;
468+ let intermediate_nodes = [
469+ ForwardNode { node_id : nodes[ 2 ] . node_id , short_channel_id : None } ,
470+ ForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ,
471+ ] ;
472+ let reply_path = BlindedPath :: new_for_message ( & intermediate_nodes, nodes[ 0 ] . node_id , & * nodes[ 0 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
449473
450474 nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, Some ( reply_path) ) . unwrap ( ) ;
451475 nodes[ 3 ] . custom_message_handler . expect_message ( TestCustomMessage :: Request ) ;
@@ -525,8 +549,9 @@ fn requests_peer_connection_for_buffered_messages() {
525549 let secp_ctx = Secp256k1 :: new ( ) ;
526550 add_channel_to_graph ( & nodes[ 0 ] , & nodes[ 1 ] , & secp_ctx, 42 ) ;
527551
552+ let intermediate_nodes = [ ForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ] ;
528553 let blinded_path = BlindedPath :: new_for_message (
529- & [ nodes [ 1 ] . node_id , nodes[ 2 ] . node_id ] , & * nodes[ 0 ] . entropy_source , & secp_ctx
554+ & intermediate_nodes , nodes[ 2 ] . node_id , & * nodes[ 0 ] . entropy_source , & secp_ctx
530555 ) . unwrap ( ) ;
531556 let destination = Destination :: BlindedPath ( blinded_path) ;
532557
@@ -562,8 +587,9 @@ fn drops_buffered_messages_waiting_for_peer_connection() {
562587 let secp_ctx = Secp256k1 :: new ( ) ;
563588 add_channel_to_graph ( & nodes[ 0 ] , & nodes[ 1 ] , & secp_ctx, 42 ) ;
564589
590+ let intermediate_nodes = [ ForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ] ;
565591 let blinded_path = BlindedPath :: new_for_message (
566- & [ nodes [ 1 ] . node_id , nodes[ 2 ] . node_id ] , & * nodes[ 0 ] . entropy_source , & secp_ctx
592+ & intermediate_nodes , nodes[ 2 ] . node_id , & * nodes[ 0 ] . entropy_source , & secp_ctx
567593 ) . unwrap ( ) ;
568594 let destination = Destination :: BlindedPath ( blinded_path) ;
569595
@@ -611,8 +637,9 @@ fn intercept_offline_peer_oms() {
611637
612638 let message = TestCustomMessage :: Response ;
613639 let secp_ctx = Secp256k1 :: new ( ) ;
640+ let intermediate_nodes = [ ForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ] ;
614641 let blinded_path = BlindedPath :: new_for_message (
615- & [ nodes [ 1 ] . node_id , nodes[ 2 ] . node_id ] , & * nodes[ 2 ] . entropy_source , & secp_ctx
642+ & intermediate_nodes , nodes[ 2 ] . node_id , & * nodes[ 2 ] . entropy_source , & secp_ctx
616643 ) . unwrap ( ) ;
617644 let destination = Destination :: BlindedPath ( blinded_path) ;
618645
0 commit comments