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 } ;
@@ -280,7 +281,7 @@ fn one_blinded_hop() {
280
281
let test_msg = TestCustomMessage :: Response ;
281
282
282
283
let secp_ctx = Secp256k1 :: new ( ) ;
283
- let blinded_path = BlindedPath :: new_for_message ( & [ nodes[ 1 ] . node_id ] , & * nodes[ 1 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
284
+ let blinded_path = BlindedPath :: new_for_message ( & [ ] , nodes[ 1 ] . node_id , & * nodes[ 1 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
284
285
let destination = Destination :: BlindedPath ( blinded_path) ;
285
286
nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, None ) . unwrap ( ) ;
286
287
nodes[ 1 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
@@ -293,7 +294,8 @@ fn two_unblinded_two_blinded() {
293
294
let test_msg = TestCustomMessage :: Response ;
294
295
295
296
let secp_ctx = Secp256k1 :: new ( ) ;
296
- let blinded_path = BlindedPath :: new_for_message ( & [ nodes[ 3 ] . node_id , nodes[ 4 ] . node_id ] , & * nodes[ 4 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
297
+ let intermediate_nodes = [ ForwardNode { node_id : nodes[ 3 ] . node_id , short_channel_id : None } ] ;
298
+ let blinded_path = BlindedPath :: new_for_message ( & intermediate_nodes, nodes[ 4 ] . node_id , & * nodes[ 4 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
297
299
let path = OnionMessagePath {
298
300
intermediate_nodes : vec ! [ nodes[ 1 ] . node_id, nodes[ 2 ] . node_id] ,
299
301
destination : Destination :: BlindedPath ( blinded_path) ,
@@ -311,7 +313,11 @@ fn three_blinded_hops() {
311
313
let test_msg = TestCustomMessage :: Response ;
312
314
313
315
let secp_ctx = Secp256k1 :: new ( ) ;
314
- 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 ( ) ;
316
+ let intermediate_nodes = [
317
+ ForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ,
318
+ ForwardNode { node_id : nodes[ 2 ] . node_id , short_channel_id : None } ,
319
+ ] ;
320
+ let blinded_path = BlindedPath :: new_for_message ( & intermediate_nodes, nodes[ 3 ] . node_id , & * nodes[ 3 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
315
321
let destination = Destination :: BlindedPath ( blinded_path) ;
316
322
317
323
nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, None ) . unwrap ( ) ;
@@ -344,15 +350,20 @@ fn we_are_intro_node() {
344
350
let test_msg = TestCustomMessage :: Response ;
345
351
346
352
let secp_ctx = Secp256k1 :: new ( ) ;
347
- 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 ( ) ;
353
+ let intermediate_nodes = [
354
+ ForwardNode { node_id : nodes[ 0 ] . node_id , short_channel_id : None } ,
355
+ ForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ,
356
+ ] ;
357
+ let blinded_path = BlindedPath :: new_for_message ( & intermediate_nodes, nodes[ 2 ] . node_id , & * nodes[ 2 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
348
358
let destination = Destination :: BlindedPath ( blinded_path) ;
349
359
350
360
nodes[ 0 ] . messenger . send_onion_message ( test_msg. clone ( ) , destination, None ) . unwrap ( ) ;
351
361
nodes[ 2 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
352
362
pass_along_path ( & nodes) ;
353
363
354
364
// Try with a two-hop blinded path where we are the introduction node.
355
- let blinded_path = BlindedPath :: new_for_message ( & [ nodes[ 0 ] . node_id , nodes[ 1 ] . node_id ] , & * nodes[ 1 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
365
+ let intermediate_nodes = [ ForwardNode { node_id : nodes[ 0 ] . node_id , short_channel_id : None } ] ;
366
+ let blinded_path = BlindedPath :: new_for_message ( & intermediate_nodes, nodes[ 1 ] . node_id , & * nodes[ 1 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
356
367
let destination = Destination :: BlindedPath ( blinded_path) ;
357
368
nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, None ) . unwrap ( ) ;
358
369
nodes[ 1 ] . custom_message_handler . expect_message ( TestCustomMessage :: Response ) ;
@@ -368,7 +379,8 @@ fn invalid_blinded_path_error() {
368
379
369
380
// 0 hops
370
381
let secp_ctx = Secp256k1 :: new ( ) ;
371
- let mut blinded_path = BlindedPath :: new_for_message ( & [ nodes[ 1 ] . node_id , nodes[ 2 ] . node_id ] , & * nodes[ 2 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
382
+ let intermediate_nodes = [ ForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ] ;
383
+ let mut blinded_path = BlindedPath :: new_for_message ( & intermediate_nodes, nodes[ 2 ] . node_id , & * nodes[ 2 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
372
384
blinded_path. blinded_hops . clear ( ) ;
373
385
let destination = Destination :: BlindedPath ( blinded_path) ;
374
386
let err = nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, None ) . unwrap_err ( ) ;
@@ -387,7 +399,11 @@ fn reply_path() {
387
399
destination : Destination :: Node ( nodes[ 3 ] . node_id ) ,
388
400
first_node_addresses : None ,
389
401
} ;
390
- 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 ( ) ;
402
+ let intermediate_nodes = [
403
+ ForwardNode { node_id : nodes[ 2 ] . node_id , short_channel_id : None } ,
404
+ ForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ,
405
+ ] ;
406
+ let reply_path = BlindedPath :: new_for_message ( & intermediate_nodes, nodes[ 0 ] . node_id , & * nodes[ 0 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
391
407
nodes[ 0 ] . messenger . send_onion_message_using_path ( path, test_msg. clone ( ) , Some ( reply_path) ) . unwrap ( ) ;
392
408
nodes[ 3 ] . custom_message_handler . expect_message ( TestCustomMessage :: Request ) ;
393
409
pass_along_path ( & nodes) ;
@@ -397,9 +413,17 @@ fn reply_path() {
397
413
pass_along_path ( & nodes) ;
398
414
399
415
// Destination::BlindedPath
400
- 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 ( ) ;
416
+ let intermediate_nodes = [
417
+ ForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ,
418
+ ForwardNode { node_id : nodes[ 2 ] . node_id , short_channel_id : None } ,
419
+ ] ;
420
+ let blinded_path = BlindedPath :: new_for_message ( & intermediate_nodes, nodes[ 3 ] . node_id , & * nodes[ 3 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
401
421
let destination = Destination :: BlindedPath ( blinded_path) ;
402
- 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 ( ) ;
422
+ let intermediate_nodes = [
423
+ ForwardNode { node_id : nodes[ 2 ] . node_id , short_channel_id : None } ,
424
+ ForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ,
425
+ ] ;
426
+ let reply_path = BlindedPath :: new_for_message ( & intermediate_nodes, nodes[ 0 ] . node_id , & * nodes[ 0 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
403
427
404
428
nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, Some ( reply_path) ) . unwrap ( ) ;
405
429
nodes[ 3 ] . custom_message_handler . expect_message ( TestCustomMessage :: Request ) ;
@@ -476,8 +500,9 @@ fn requests_peer_connection_for_buffered_messages() {
476
500
let secp_ctx = Secp256k1 :: new ( ) ;
477
501
add_channel_to_graph ( & nodes[ 0 ] , & nodes[ 1 ] , & secp_ctx, 42 ) ;
478
502
503
+ let intermediate_nodes = [ ForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ] ;
479
504
let blinded_path = BlindedPath :: new_for_message (
480
- & [ nodes [ 1 ] . node_id , nodes[ 2 ] . node_id ] , & * nodes[ 0 ] . entropy_source , & secp_ctx
505
+ & intermediate_nodes , nodes[ 2 ] . node_id , & * nodes[ 0 ] . entropy_source , & secp_ctx
481
506
) . unwrap ( ) ;
482
507
let destination = Destination :: BlindedPath ( blinded_path) ;
483
508
@@ -513,8 +538,9 @@ fn drops_buffered_messages_waiting_for_peer_connection() {
513
538
let secp_ctx = Secp256k1 :: new ( ) ;
514
539
add_channel_to_graph ( & nodes[ 0 ] , & nodes[ 1 ] , & secp_ctx, 42 ) ;
515
540
541
+ let intermediate_nodes = [ ForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ] ;
516
542
let blinded_path = BlindedPath :: new_for_message (
517
- & [ nodes [ 1 ] . node_id , nodes[ 2 ] . node_id ] , & * nodes[ 0 ] . entropy_source , & secp_ctx
543
+ & intermediate_nodes , nodes[ 2 ] . node_id , & * nodes[ 0 ] . entropy_source , & secp_ctx
518
544
) . unwrap ( ) ;
519
545
let destination = Destination :: BlindedPath ( blinded_path) ;
520
546
0 commit comments