@@ -162,17 +162,13 @@ impl TestCustomMessageHandler {
162162 }
163163
164164 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) ;
169167 }
170168
171169 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) ;
176172 }
177173
178174 fn get_next_expectation ( & self ) -> OnHandleCustomMessage {
@@ -208,12 +204,11 @@ impl CustomOnionMessageHandler for TestCustomMessageHandler {
208204 }
209205
210206 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+ } ,
217212 Some ( responder) => Some ( ( response, responder. respond ( ) ) ) ,
218213 None => None ,
219214 }
@@ -412,14 +407,9 @@ fn one_blinded_hop() {
412407
413408 let secp_ctx = Secp256k1 :: new ( ) ;
414409 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 ( ) ;
423413 let destination = Destination :: BlindedPath ( blinded_path) ;
424414 let instructions = MessageSendInstructions :: WithoutReplyPath { destination } ;
425415 nodes[ 0 ] . messenger . send_onion_message ( test_msg, instructions) . unwrap ( ) ;
@@ -436,14 +426,10 @@ fn two_unblinded_two_blinded() {
436426 let intermediate_nodes =
437427 [ MessageForwardNode { node_id : nodes[ 3 ] . node_id , short_channel_id : None } ] ;
438428 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 ( ) ;
447433 let path = OnionMessagePath {
448434 intermediate_nodes : vec ! [ nodes[ 1 ] . node_id, nodes[ 2 ] . node_id] ,
449435 destination : Destination :: BlindedPath ( blinded_path) ,
@@ -466,14 +452,10 @@ fn three_blinded_hops() {
466452 MessageForwardNode { node_id : nodes[ 2 ] . node_id , short_channel_id : None } ,
467453 ] ;
468454 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 ( ) ;
477459 let destination = Destination :: BlindedPath ( blinded_path) ;
478460 let instructions = MessageSendInstructions :: WithoutReplyPath { destination } ;
479461
@@ -497,14 +479,9 @@ fn async_response_over_one_blinded_hop() {
497479 // 3. Simulate the creation of a Blinded Reply path provided by Bob.
498480 let secp_ctx = Secp256k1 :: new ( ) ;
499481 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 ( ) ;
508485
509486 // 4. Create a responder using the reply path for Alice.
510487 let responder = Some ( Responder :: new ( reply_path) ) ;
@@ -632,14 +609,10 @@ fn we_are_intro_node() {
632609 MessageForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ,
633610 ] ;
634611 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 ( ) ;
643616 let destination = Destination :: BlindedPath ( blinded_path) ;
644617 let instructions = MessageSendInstructions :: WithoutReplyPath { destination } ;
645618
@@ -651,14 +624,10 @@ fn we_are_intro_node() {
651624 let intermediate_nodes =
652625 [ MessageForwardNode { node_id : nodes[ 0 ] . node_id , short_channel_id : None } ] ;
653626 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 ( ) ;
662631 let destination = Destination :: BlindedPath ( blinded_path) ;
663632 let instructions = MessageSendInstructions :: WithoutReplyPath { destination } ;
664633
@@ -678,14 +647,10 @@ fn invalid_blinded_path_error() {
678647 let intermediate_nodes =
679648 [ MessageForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ] ;
680649 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 ( ) ;
689654 blinded_path. clear_blinded_hops ( ) ;
690655 let destination = Destination :: BlindedPath ( blinded_path) ;
691656 let instructions = MessageSendInstructions :: WithoutReplyPath { destination } ;
@@ -711,14 +676,10 @@ fn reply_path() {
711676 MessageForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ,
712677 ] ;
713678 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 ( ) ;
722683 nodes[ 0 ]
723684 . messenger
724685 . send_onion_message_using_path ( path, test_msg. clone ( ) , Some ( reply_path) )
@@ -736,28 +697,20 @@ fn reply_path() {
736697 MessageForwardNode { node_id : nodes[ 2 ] . node_id , short_channel_id : None } ,
737698 ] ;
738699 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 ( ) ;
747704 let destination = Destination :: BlindedPath ( blinded_path) ;
748705 let intermediate_nodes = [
749706 MessageForwardNode { node_id : nodes[ 2 ] . node_id , short_channel_id : None } ,
750707 MessageForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ,
751708 ] ;
752709 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 ( ) ;
761714 let instructions = MessageSendInstructions :: WithSpecifiedReplyPath { destination, reply_path } ;
762715
763716 nodes[ 0 ] . messenger . send_onion_message ( test_msg, instructions) . unwrap ( ) ;
@@ -853,14 +806,10 @@ fn requests_peer_connection_for_buffered_messages() {
853806 let intermediate_nodes =
854807 [ MessageForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ] ;
855808 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 ( ) ;
864813 let destination = Destination :: BlindedPath ( blinded_path) ;
865814 let instructions = MessageSendInstructions :: WithoutReplyPath { destination } ;
866815
@@ -899,14 +848,10 @@ fn drops_buffered_messages_waiting_for_peer_connection() {
899848 let intermediate_nodes =
900849 [ MessageForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ] ;
901850 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 ( ) ;
910855 let destination = Destination :: BlindedPath ( blinded_path) ;
911856 let instructions = MessageSendInstructions :: WithoutReplyPath { destination } ;
912857
@@ -961,14 +906,10 @@ fn intercept_offline_peer_oms() {
961906 let intermediate_nodes =
962907 [ MessageForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ] ;
963908 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 ( ) ;
972913 let destination = Destination :: BlindedPath ( blinded_path) ;
973914 let instructions = MessageSendInstructions :: WithoutReplyPath { destination } ;
974915
@@ -990,10 +931,9 @@ fn intercept_offline_peer_oms() {
990931
991932 // Ensure that we'll refuse to forward the re-injected OM until after the
992933 // 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 ( ) ;
997937 assert_eq ! ( err, SendError :: InvalidFirstHop ( final_node_vec[ 0 ] . node_id) ) ;
998938
999939 connect_peers ( & nodes[ 1 ] , & final_node_vec[ 0 ] ) ;
@@ -1034,17 +974,12 @@ fn spec_test_vector() {
1034974 let sender_to_alice_packet: Packet =
1035975 <Packet as LengthReadable >:: read ( & mut packet_reader) . unwrap ( ) ;
1036976 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 ( ) ;
1037981 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) ,
1048983 onion_routing_packet : sender_to_alice_packet,
1049984 } ;
1050985 // The spec test vectors prepend the OM message type (513) to the encoded onion message strings,
0 commit comments