10
10
//! Onion message testing and test utilities live here.
11
11
12
12
use crate :: blinded_path:: { BlindedPath , EmptyNodeIdLookUp } ;
13
+ use crate :: blinded_path:: message:: ForwardNode ;
13
14
use crate :: events:: { Event , EventsProvider } ;
14
15
use crate :: ln:: features:: { ChannelFeatures , InitFeatures } ;
15
16
use crate :: ln:: msgs:: { self , DecodeError , OnionMessageHandler } ;
@@ -327,7 +328,7 @@ fn one_blinded_hop() {
327
328
let test_msg = TestCustomMessage :: Response ;
328
329
329
330
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 ( ) ;
331
332
let destination = Destination :: BlindedPath ( blinded_path) ;
332
333
nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, None ) . unwrap ( ) ;
333
334
nodes[ 1 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
@@ -340,7 +341,8 @@ fn two_unblinded_two_blinded() {
340
341
let test_msg = TestCustomMessage :: Response ;
341
342
342
343
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 ( ) ;
344
346
let path = OnionMessagePath {
345
347
intermediate_nodes : vec ! [ nodes[ 1 ] . node_id, nodes[ 2 ] . node_id] ,
346
348
destination : Destination :: BlindedPath ( blinded_path) ,
@@ -358,7 +360,11 @@ fn three_blinded_hops() {
358
360
let test_msg = TestCustomMessage :: Response ;
359
361
360
362
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 ( ) ;
362
368
let destination = Destination :: BlindedPath ( blinded_path) ;
363
369
364
370
nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, None ) . unwrap ( ) ;
@@ -391,15 +397,20 @@ fn we_are_intro_node() {
391
397
let test_msg = TestCustomMessage :: Response ;
392
398
393
399
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 ( ) ;
395
405
let destination = Destination :: BlindedPath ( blinded_path) ;
396
406
397
407
nodes[ 0 ] . messenger . send_onion_message ( test_msg. clone ( ) , destination, None ) . unwrap ( ) ;
398
408
nodes[ 2 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
399
409
pass_along_path ( & nodes) ;
400
410
401
411
// 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 ( ) ;
403
414
let destination = Destination :: BlindedPath ( blinded_path) ;
404
415
nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, None ) . unwrap ( ) ;
405
416
nodes[ 1 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
@@ -414,7 +425,8 @@ fn invalid_blinded_path_error() {
414
425
let test_msg = TestCustomMessage :: Response ;
415
426
416
427
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 ( ) ;
418
430
blinded_path. blinded_hops . clear ( ) ;
419
431
let destination = Destination :: BlindedPath ( blinded_path) ;
420
432
let err = nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, None ) . unwrap_err ( ) ;
@@ -433,7 +445,11 @@ fn reply_path() {
433
445
destination : Destination :: Node ( nodes[ 3 ] . node_id ) ,
434
446
first_node_addresses : None ,
435
447
} ;
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 ( ) ;
437
453
nodes[ 0 ] . messenger . send_onion_message_using_path ( path, test_msg. clone ( ) , Some ( reply_path) ) . unwrap ( ) ;
438
454
nodes[ 3 ] . custom_message_handler . expect_message ( TestCustomMessage :: Request ) ;
439
455
pass_along_path ( & nodes) ;
@@ -443,9 +459,17 @@ fn reply_path() {
443
459
pass_along_path ( & nodes) ;
444
460
445
461
// 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 ( ) ;
447
467
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 ( ) ;
449
473
450
474
nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, Some ( reply_path) ) . unwrap ( ) ;
451
475
nodes[ 3 ] . custom_message_handler . expect_message ( TestCustomMessage :: Request ) ;
@@ -525,8 +549,9 @@ fn requests_peer_connection_for_buffered_messages() {
525
549
let secp_ctx = Secp256k1 :: new ( ) ;
526
550
add_channel_to_graph ( & nodes[ 0 ] , & nodes[ 1 ] , & secp_ctx, 42 ) ;
527
551
552
+ let intermediate_nodes = [ ForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ] ;
528
553
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
530
555
) . unwrap ( ) ;
531
556
let destination = Destination :: BlindedPath ( blinded_path) ;
532
557
@@ -562,8 +587,9 @@ fn drops_buffered_messages_waiting_for_peer_connection() {
562
587
let secp_ctx = Secp256k1 :: new ( ) ;
563
588
add_channel_to_graph ( & nodes[ 0 ] , & nodes[ 1 ] , & secp_ctx, 42 ) ;
564
589
590
+ let intermediate_nodes = [ ForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ] ;
565
591
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
567
593
) . unwrap ( ) ;
568
594
let destination = Destination :: BlindedPath ( blinded_path) ;
569
595
@@ -611,8 +637,9 @@ fn intercept_offline_peer_oms() {
611
637
612
638
let message = TestCustomMessage :: Response ;
613
639
let secp_ctx = Secp256k1 :: new ( ) ;
640
+ let intermediate_nodes = [ ForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ] ;
614
641
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
616
643
) . unwrap ( ) ;
617
644
let destination = Destination :: BlindedPath ( blinded_path) ;
618
645
0 commit comments