@@ -162,17 +162,13 @@ impl TestCustomMessageHandler {
162
162
}
163
163
164
164
fn expect_message ( & self , message : TestCustomMessage ) {
165
- self . expectations
166
- . lock ( )
167
- . unwrap ( )
168
- . push_back ( OnHandleCustomMessage { expect : message, include_reply_path : false } ) ;
165
+ let expectation = OnHandleCustomMessage { expect : message, include_reply_path : false } ;
166
+ self . expectations . lock ( ) . unwrap ( ) . push_back ( expectation) ;
169
167
}
170
168
171
169
fn expect_message_and_response ( & self , message : TestCustomMessage ) {
172
- self . expectations
173
- . lock ( )
174
- . unwrap ( )
175
- . push_back ( OnHandleCustomMessage { expect : message, include_reply_path : true } ) ;
170
+ let expectation = OnHandleCustomMessage { expect : message, include_reply_path : true } ;
171
+ self . expectations . lock ( ) . unwrap ( ) . push_back ( expectation) ;
176
172
}
177
173
178
174
fn get_next_expectation ( & self ) -> OnHandleCustomMessage {
@@ -208,12 +204,11 @@ impl CustomOnionMessageHandler for TestCustomMessageHandler {
208
204
}
209
205
210
206
match responder {
211
- Some ( responder) if expectation. include_reply_path => Some ( (
212
- response,
213
- responder. respond_with_reply_path ( MessageContext :: Custom (
214
- context. unwrap_or_else ( Vec :: new) ,
215
- ) ) ,
216
- ) ) ,
207
+ Some ( responder) if expectation. include_reply_path => {
208
+ let context = MessageContext :: Custom ( context. unwrap_or_else ( Vec :: new) ) ;
209
+ let reply = responder. respond_with_reply_path ( context) ;
210
+ Some ( ( response, reply) )
211
+ } ,
217
212
Some ( responder) => Some ( ( response, responder. respond ( ) ) ) ,
218
213
None => None ,
219
214
}
@@ -412,14 +407,9 @@ fn one_blinded_hop() {
412
407
413
408
let secp_ctx = Secp256k1 :: new ( ) ;
414
409
let context = MessageContext :: Custom ( Vec :: new ( ) ) ;
415
- let blinded_path = BlindedMessagePath :: new (
416
- & [ ] ,
417
- nodes[ 1 ] . node_id ,
418
- context,
419
- & * nodes[ 1 ] . entropy_source ,
420
- & secp_ctx,
421
- )
422
- . unwrap ( ) ;
410
+ let entropy = & * nodes[ 1 ] . entropy_source ;
411
+ let blinded_path =
412
+ BlindedMessagePath :: new ( & [ ] , nodes[ 1 ] . node_id , context, entropy, & secp_ctx) . unwrap ( ) ;
423
413
let destination = Destination :: BlindedPath ( blinded_path) ;
424
414
let instructions = MessageSendInstructions :: WithoutReplyPath { destination } ;
425
415
nodes[ 0 ] . messenger . send_onion_message ( test_msg, instructions) . unwrap ( ) ;
@@ -436,14 +426,10 @@ fn two_unblinded_two_blinded() {
436
426
let intermediate_nodes =
437
427
[ MessageForwardNode { node_id : nodes[ 3 ] . node_id , short_channel_id : None } ] ;
438
428
let context = MessageContext :: Custom ( Vec :: new ( ) ) ;
439
- let blinded_path = BlindedMessagePath :: new (
440
- & intermediate_nodes,
441
- nodes[ 4 ] . node_id ,
442
- context,
443
- & * nodes[ 4 ] . entropy_source ,
444
- & secp_ctx,
445
- )
446
- . unwrap ( ) ;
429
+ let entropy = & * nodes[ 4 ] . entropy_source ;
430
+ let blinded_path =
431
+ BlindedMessagePath :: new ( & intermediate_nodes, nodes[ 4 ] . node_id , context, entropy, & secp_ctx)
432
+ . unwrap ( ) ;
447
433
let path = OnionMessagePath {
448
434
intermediate_nodes : vec ! [ nodes[ 1 ] . node_id, nodes[ 2 ] . node_id] ,
449
435
destination : Destination :: BlindedPath ( blinded_path) ,
@@ -466,14 +452,10 @@ fn three_blinded_hops() {
466
452
MessageForwardNode { node_id : nodes[ 2 ] . node_id , short_channel_id : None } ,
467
453
] ;
468
454
let context = MessageContext :: Custom ( Vec :: new ( ) ) ;
469
- let blinded_path = BlindedMessagePath :: new (
470
- & intermediate_nodes,
471
- nodes[ 3 ] . node_id ,
472
- context,
473
- & * nodes[ 3 ] . entropy_source ,
474
- & secp_ctx,
475
- )
476
- . unwrap ( ) ;
455
+ let entropy = & * nodes[ 3 ] . entropy_source ;
456
+ let blinded_path =
457
+ BlindedMessagePath :: new ( & intermediate_nodes, nodes[ 3 ] . node_id , context, entropy, & secp_ctx)
458
+ . unwrap ( ) ;
477
459
let destination = Destination :: BlindedPath ( blinded_path) ;
478
460
let instructions = MessageSendInstructions :: WithoutReplyPath { destination } ;
479
461
@@ -497,14 +479,9 @@ fn async_response_over_one_blinded_hop() {
497
479
// 3. Simulate the creation of a Blinded Reply path provided by Bob.
498
480
let secp_ctx = Secp256k1 :: new ( ) ;
499
481
let context = MessageContext :: Custom ( Vec :: new ( ) ) ;
500
- let reply_path = BlindedMessagePath :: new (
501
- & [ ] ,
502
- nodes[ 1 ] . node_id ,
503
- context,
504
- & * nodes[ 1 ] . entropy_source ,
505
- & secp_ctx,
506
- )
507
- . unwrap ( ) ;
482
+ let entropy = & * nodes[ 1 ] . entropy_source ;
483
+ let reply_path =
484
+ BlindedMessagePath :: new ( & [ ] , nodes[ 1 ] . node_id , context, entropy, & secp_ctx) . unwrap ( ) ;
508
485
509
486
// 4. Create a responder using the reply path for Alice.
510
487
let responder = Some ( Responder :: new ( reply_path) ) ;
@@ -632,14 +609,10 @@ fn we_are_intro_node() {
632
609
MessageForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ,
633
610
] ;
634
611
let context = MessageContext :: Custom ( Vec :: new ( ) ) ;
635
- let blinded_path = BlindedMessagePath :: new (
636
- & intermediate_nodes,
637
- nodes[ 2 ] . node_id ,
638
- context,
639
- & * nodes[ 2 ] . entropy_source ,
640
- & secp_ctx,
641
- )
642
- . unwrap ( ) ;
612
+ let entropy = & * nodes[ 2 ] . entropy_source ;
613
+ let blinded_path =
614
+ BlindedMessagePath :: new ( & intermediate_nodes, nodes[ 2 ] . node_id , context, entropy, & secp_ctx)
615
+ . unwrap ( ) ;
643
616
let destination = Destination :: BlindedPath ( blinded_path) ;
644
617
let instructions = MessageSendInstructions :: WithoutReplyPath { destination } ;
645
618
@@ -651,14 +624,10 @@ fn we_are_intro_node() {
651
624
let intermediate_nodes =
652
625
[ MessageForwardNode { node_id : nodes[ 0 ] . node_id , short_channel_id : None } ] ;
653
626
let context = MessageContext :: Custom ( Vec :: new ( ) ) ;
654
- let blinded_path = BlindedMessagePath :: new (
655
- & intermediate_nodes,
656
- nodes[ 1 ] . node_id ,
657
- context,
658
- & * nodes[ 1 ] . entropy_source ,
659
- & secp_ctx,
660
- )
661
- . unwrap ( ) ;
627
+ let entropy = & * nodes[ 1 ] . entropy_source ;
628
+ let blinded_path =
629
+ BlindedMessagePath :: new ( & intermediate_nodes, nodes[ 1 ] . node_id , context, entropy, & secp_ctx)
630
+ . unwrap ( ) ;
662
631
let destination = Destination :: BlindedPath ( blinded_path) ;
663
632
let instructions = MessageSendInstructions :: WithoutReplyPath { destination } ;
664
633
@@ -678,14 +647,10 @@ fn invalid_blinded_path_error() {
678
647
let intermediate_nodes =
679
648
[ MessageForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ] ;
680
649
let context = MessageContext :: Custom ( Vec :: new ( ) ) ;
681
- let mut blinded_path = BlindedMessagePath :: new (
682
- & intermediate_nodes,
683
- nodes[ 2 ] . node_id ,
684
- context,
685
- & * nodes[ 2 ] . entropy_source ,
686
- & secp_ctx,
687
- )
688
- . unwrap ( ) ;
650
+ let entropy = & * nodes[ 2 ] . entropy_source ;
651
+ let mut blinded_path =
652
+ BlindedMessagePath :: new ( & intermediate_nodes, nodes[ 2 ] . node_id , context, entropy, & secp_ctx)
653
+ . unwrap ( ) ;
689
654
blinded_path. clear_blinded_hops ( ) ;
690
655
let destination = Destination :: BlindedPath ( blinded_path) ;
691
656
let instructions = MessageSendInstructions :: WithoutReplyPath { destination } ;
@@ -711,14 +676,10 @@ fn reply_path() {
711
676
MessageForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ,
712
677
] ;
713
678
let context = MessageContext :: Custom ( Vec :: new ( ) ) ;
714
- let reply_path = BlindedMessagePath :: new (
715
- & intermediate_nodes,
716
- nodes[ 0 ] . node_id ,
717
- context,
718
- & * nodes[ 0 ] . entropy_source ,
719
- & secp_ctx,
720
- )
721
- . unwrap ( ) ;
679
+ let entropy = & * nodes[ 0 ] . entropy_source ;
680
+ let reply_path =
681
+ BlindedMessagePath :: new ( & intermediate_nodes, nodes[ 0 ] . node_id , context, entropy, & secp_ctx)
682
+ . unwrap ( ) ;
722
683
nodes[ 0 ]
723
684
. messenger
724
685
. send_onion_message_using_path ( path, test_msg. clone ( ) , Some ( reply_path) )
@@ -736,28 +697,20 @@ fn reply_path() {
736
697
MessageForwardNode { node_id : nodes[ 2 ] . node_id , short_channel_id : None } ,
737
698
] ;
738
699
let context = MessageContext :: Custom ( Vec :: new ( ) ) ;
739
- let blinded_path = BlindedMessagePath :: new (
740
- & intermediate_nodes,
741
- nodes[ 3 ] . node_id ,
742
- context,
743
- & * nodes[ 3 ] . entropy_source ,
744
- & secp_ctx,
745
- )
746
- . unwrap ( ) ;
700
+ let entropy = & * nodes[ 3 ] . entropy_source ;
701
+ let blinded_path =
702
+ BlindedMessagePath :: new ( & intermediate_nodes, nodes[ 3 ] . node_id , context, entropy, & secp_ctx)
703
+ . unwrap ( ) ;
747
704
let destination = Destination :: BlindedPath ( blinded_path) ;
748
705
let intermediate_nodes = [
749
706
MessageForwardNode { node_id : nodes[ 2 ] . node_id , short_channel_id : None } ,
750
707
MessageForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ,
751
708
] ;
752
709
let context = MessageContext :: Custom ( Vec :: new ( ) ) ;
753
- let reply_path = BlindedMessagePath :: new (
754
- & intermediate_nodes,
755
- nodes[ 0 ] . node_id ,
756
- context,
757
- & * nodes[ 0 ] . entropy_source ,
758
- & secp_ctx,
759
- )
760
- . unwrap ( ) ;
710
+ let entropy = & * nodes[ 0 ] . entropy_source ;
711
+ let reply_path =
712
+ BlindedMessagePath :: new ( & intermediate_nodes, nodes[ 0 ] . node_id , context, entropy, & secp_ctx)
713
+ . unwrap ( ) ;
761
714
let instructions = MessageSendInstructions :: WithSpecifiedReplyPath { destination, reply_path } ;
762
715
763
716
nodes[ 0 ] . messenger . send_onion_message ( test_msg, instructions) . unwrap ( ) ;
@@ -853,14 +806,10 @@ fn requests_peer_connection_for_buffered_messages() {
853
806
let intermediate_nodes =
854
807
[ MessageForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ] ;
855
808
let context = MessageContext :: Custom ( Vec :: new ( ) ) ;
856
- let blinded_path = BlindedMessagePath :: new (
857
- & intermediate_nodes,
858
- nodes[ 2 ] . node_id ,
859
- context,
860
- & * nodes[ 0 ] . entropy_source ,
861
- & secp_ctx,
862
- )
863
- . unwrap ( ) ;
809
+ let entropy = & * nodes[ 0 ] . entropy_source ;
810
+ let blinded_path =
811
+ BlindedMessagePath :: new ( & intermediate_nodes, nodes[ 2 ] . node_id , context, entropy, & secp_ctx)
812
+ . unwrap ( ) ;
864
813
let destination = Destination :: BlindedPath ( blinded_path) ;
865
814
let instructions = MessageSendInstructions :: WithoutReplyPath { destination } ;
866
815
@@ -899,14 +848,10 @@ fn drops_buffered_messages_waiting_for_peer_connection() {
899
848
let intermediate_nodes =
900
849
[ MessageForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ] ;
901
850
let context = MessageContext :: Custom ( Vec :: new ( ) ) ;
902
- let blinded_path = BlindedMessagePath :: new (
903
- & intermediate_nodes,
904
- nodes[ 2 ] . node_id ,
905
- context,
906
- & * nodes[ 0 ] . entropy_source ,
907
- & secp_ctx,
908
- )
909
- . unwrap ( ) ;
851
+ let entropy = & * nodes[ 0 ] . entropy_source ;
852
+ let blinded_path =
853
+ BlindedMessagePath :: new ( & intermediate_nodes, nodes[ 2 ] . node_id , context, entropy, & secp_ctx)
854
+ . unwrap ( ) ;
910
855
let destination = Destination :: BlindedPath ( blinded_path) ;
911
856
let instructions = MessageSendInstructions :: WithoutReplyPath { destination } ;
912
857
@@ -961,14 +906,10 @@ fn intercept_offline_peer_oms() {
961
906
let intermediate_nodes =
962
907
[ MessageForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ] ;
963
908
let context = MessageContext :: Custom ( Vec :: new ( ) ) ;
964
- let blinded_path = BlindedMessagePath :: new (
965
- & intermediate_nodes,
966
- nodes[ 2 ] . node_id ,
967
- context,
968
- & * nodes[ 2 ] . entropy_source ,
969
- & secp_ctx,
970
- )
971
- . unwrap ( ) ;
909
+ let entropy = & * nodes[ 2 ] . entropy_source ;
910
+ let blinded_path =
911
+ BlindedMessagePath :: new ( & intermediate_nodes, nodes[ 2 ] . node_id , context, entropy, & secp_ctx)
912
+ . unwrap ( ) ;
972
913
let destination = Destination :: BlindedPath ( blinded_path) ;
973
914
let instructions = MessageSendInstructions :: WithoutReplyPath { destination } ;
974
915
@@ -990,10 +931,9 @@ fn intercept_offline_peer_oms() {
990
931
991
932
// Ensure that we'll refuse to forward the re-injected OM until after the
992
933
// outbound peer comes back online.
993
- let err = nodes[ 1 ]
994
- . messenger
995
- . forward_onion_message ( onion_message. clone ( ) , & final_node_vec[ 0 ] . node_id )
996
- . unwrap_err ( ) ;
934
+ let next_node_id = & final_node_vec[ 0 ] . node_id ;
935
+ let err =
936
+ nodes[ 1 ] . messenger . forward_onion_message ( onion_message. clone ( ) , next_node_id) . unwrap_err ( ) ;
997
937
assert_eq ! ( err, SendError :: InvalidFirstHop ( final_node_vec[ 0 ] . node_id) ) ;
998
938
999
939
connect_peers ( & nodes[ 1 ] , & final_node_vec[ 0 ] ) ;
@@ -1034,17 +974,12 @@ fn spec_test_vector() {
1034
974
let sender_to_alice_packet: Packet =
1035
975
<Packet as LengthReadable >:: read ( & mut packet_reader) . unwrap ( ) ;
1036
976
let secp_ctx = Secp256k1 :: new ( ) ;
977
+
978
+ let blinding_key_hex = "6363636363636363636363636363636363636363636363636363636363636363" ;
979
+ let blinding_key =
980
+ SecretKey :: from_slice ( & <Vec < u8 > >:: from_hex ( blinding_key_hex) . unwrap ( ) ) . unwrap ( ) ;
1037
981
let sender_to_alice_om = msgs:: OnionMessage {
1038
- blinding_point : PublicKey :: from_secret_key (
1039
- & secp_ctx,
1040
- & SecretKey :: from_slice (
1041
- & <Vec < u8 > >:: from_hex (
1042
- "6363636363636363636363636363636363636363636363636363636363636363" ,
1043
- )
1044
- . unwrap ( ) ,
1045
- )
1046
- . unwrap ( ) ,
1047
- ) ,
982
+ blinding_point : PublicKey :: from_secret_key ( & secp_ctx, & blinding_key) ,
1048
983
onion_routing_packet : sender_to_alice_packet,
1049
984
} ;
1050
985
// The spec test vectors prepend the OM message type (513) to the encoded onion message strings,
0 commit comments