@@ -219,12 +219,12 @@ fn extract_invoice_request<'a, 'b, 'c>(
219219	} 
220220} 
221221
222- fn  extract_invoice < ' a ,  ' b ,  ' c > ( node :  & Node < ' a ,  ' b ,  ' c > ,  message :  & OnionMessage )  -> ( Bolt12Invoice ,  Option < BlindedMessagePath > )  { 
222+ fn  extract_invoice < ' a ,  ' b ,  ' c > ( node :  & Node < ' a ,  ' b ,  ' c > ,  message :  & OnionMessage )  -> ( Bolt12Invoice ,  BlindedMessagePath )  { 
223223	match  node. onion_messenger . peel_onion_message ( message)  { 
224224		Ok ( PeeledOnion :: Receive ( message,  _,  reply_path) )  => match  message { 
225225			ParsedOnionMessageContents :: Offers ( offers_message)  => match  offers_message { 
226226				OffersMessage :: InvoiceRequest ( invoice_request)  => panic ! ( "Unexpected invoice_request: {:?}" ,  invoice_request) , 
227- 				OffersMessage :: Invoice ( invoice)  => ( invoice,  reply_path) , 
227+ 				OffersMessage :: Invoice ( invoice)  => ( invoice,  reply_path. unwrap ( ) ) , 
228228				#[ cfg( async_payments) ]  
229229				OffersMessage :: StaticInvoice ( invoice)  => panic ! ( "Unexpected static invoice: {:?}" ,  invoice) , 
230230				OffersMessage :: InvoiceError ( error)  => panic ! ( "Unexpected invoice_error: {:?}" ,  error) , 
@@ -580,13 +580,22 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
580580	let  onion_message = charlie. onion_messenger . next_onion_message_for_peer ( david_id) . unwrap ( ) ; 
581581	david. onion_messenger . handle_onion_message ( & charlie_id,  & onion_message) ; 
582582
583- 	let  ( invoice,  _ )  = extract_invoice ( david,  & onion_message) ; 
583+ 	let  ( invoice,  reply_path )  = extract_invoice ( david,  & onion_message) ; 
584584	assert_eq ! ( invoice. amount_msats( ) ,  10_000_000 ) ; 
585585	assert_ne ! ( invoice. signing_pubkey( ) ,  alice_id) ; 
586586	assert ! ( !invoice. payment_paths( ) . is_empty( ) ) ; 
587587	for  path in  invoice. payment_paths ( )  { 
588588		assert_eq ! ( path. introduction_node( ) ,  & IntroductionNode :: NodeId ( bob_id) ) ; 
589589	} 
590+ 	// Both Bob and Charlie have an equal number of channels and need to be connected 
591+ 	// to Alice when she's handling the message. Therefore, either Bob or Charlie could 
592+ 	// serve as the introduction node for the reply path back to Alice. 
593+ 	assert ! ( 
594+ 		matches!( 
595+ 			reply_path. introduction_node( ) , 
596+ 			& IntroductionNode :: NodeId ( node_id)  if  node_id == bob_id || node_id == charlie_id, 
597+ 		) 
598+ 	) ; 
590599
591600	route_bolt12_payment ( david,  & [ charlie,  bob,  alice] ,  & invoice) ; 
592601	expect_recent_payment ! ( david,  RecentPaymentDetails :: Pending ,  payment_id) ; 
@@ -659,7 +668,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
659668	let  onion_message = charlie. onion_messenger . next_onion_message_for_peer ( david_id) . unwrap ( ) ; 
660669	david. onion_messenger . handle_onion_message ( & charlie_id,  & onion_message) ; 
661670
662- 	let  ( invoice,  _ )  = extract_invoice ( david,  & onion_message) ; 
671+ 	let  ( invoice,  reply_path )  = extract_invoice ( david,  & onion_message) ; 
663672	assert_eq ! ( invoice,  expected_invoice) ; 
664673
665674	assert_eq ! ( invoice. amount_msats( ) ,  10_000_000 ) ; 
@@ -668,6 +677,8 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
668677	for  path in  invoice. payment_paths ( )  { 
669678		assert_eq ! ( path. introduction_node( ) ,  & IntroductionNode :: NodeId ( bob_id) ) ; 
670679	} 
680+ 	assert_eq ! ( reply_path. introduction_node( ) ,  & IntroductionNode :: NodeId ( bob_id) ) ; 
681+ 
671682
672683	route_bolt12_payment ( david,  & [ charlie,  bob,  alice] ,  & invoice) ; 
673684	expect_recent_payment ! ( david,  RecentPaymentDetails :: Pending ,  payment_id) ; 
@@ -726,13 +737,14 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
726737	let  onion_message = alice. onion_messenger . next_onion_message_for_peer ( bob_id) . unwrap ( ) ; 
727738	bob. onion_messenger . handle_onion_message ( & alice_id,  & onion_message) ; 
728739
729- 	let  ( invoice,  _ )  = extract_invoice ( bob,  & onion_message) ; 
740+ 	let  ( invoice,  reply_path )  = extract_invoice ( bob,  & onion_message) ; 
730741	assert_eq ! ( invoice. amount_msats( ) ,  10_000_000 ) ; 
731742	assert_ne ! ( invoice. signing_pubkey( ) ,  alice_id) ; 
732743	assert ! ( !invoice. payment_paths( ) . is_empty( ) ) ; 
733744	for  path in  invoice. payment_paths ( )  { 
734745		assert_eq ! ( path. introduction_node( ) ,  & IntroductionNode :: NodeId ( alice_id) ) ; 
735746	} 
747+ 	assert_eq ! ( reply_path. introduction_node( ) ,  & IntroductionNode :: NodeId ( alice_id) ) ; 
736748
737749	route_bolt12_payment ( bob,  & [ alice] ,  & invoice) ; 
738750	expect_recent_payment ! ( bob,  RecentPaymentDetails :: Pending ,  payment_id) ; 
@@ -779,7 +791,7 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
779791	let  onion_message = alice. onion_messenger . next_onion_message_for_peer ( bob_id) . unwrap ( ) ; 
780792	bob. onion_messenger . handle_onion_message ( & alice_id,  & onion_message) ; 
781793
782- 	let  ( invoice,  _ )  = extract_invoice ( bob,  & onion_message) ; 
794+ 	let  ( invoice,  reply_path )  = extract_invoice ( bob,  & onion_message) ; 
783795	assert_eq ! ( invoice,  expected_invoice) ; 
784796
785797	assert_eq ! ( invoice. amount_msats( ) ,  10_000_000 ) ; 
@@ -788,6 +800,7 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
788800	for  path in  invoice. payment_paths ( )  { 
789801		assert_eq ! ( path. introduction_node( ) ,  & IntroductionNode :: NodeId ( alice_id) ) ; 
790802	} 
803+ 	assert_eq ! ( reply_path. introduction_node( ) ,  & IntroductionNode :: NodeId ( alice_id) ) ; 
791804
792805	route_bolt12_payment ( bob,  & [ alice] ,  & invoice) ; 
793806	expect_recent_payment ! ( bob,  RecentPaymentDetails :: Pending ,  payment_id) ; 
@@ -1044,7 +1057,7 @@ fn send_invoice_for_refund_with_distinct_reply_path() {
10441057	let  onion_message = bob. onion_messenger . next_onion_message_for_peer ( alice_id) . unwrap ( ) ; 
10451058
10461059	let  ( _,  reply_path)  = extract_invoice ( alice,  & onion_message) ; 
1047- 	assert_eq ! ( reply_path. unwrap ( ) . introduction_node( ) ,  & IntroductionNode :: NodeId ( charlie_id) ) ; 
1060+ 	assert_eq ! ( reply_path. introduction_node( ) ,  & IntroductionNode :: NodeId ( charlie_id) ) ; 
10481061
10491062	// Send, extract and verify the second Invoice Request message 
10501063	let  onion_message = david. onion_messenger . next_onion_message_for_peer ( bob_id) . unwrap ( ) ; 
@@ -1053,7 +1066,7 @@ fn send_invoice_for_refund_with_distinct_reply_path() {
10531066	let  onion_message = bob. onion_messenger . next_onion_message_for_peer ( alice_id) . unwrap ( ) ; 
10541067
10551068	let  ( _,  reply_path)  = extract_invoice ( alice,  & onion_message) ; 
1056- 	assert_eq ! ( reply_path. unwrap ( ) . introduction_node( ) ,  & IntroductionNode :: NodeId ( nodes[ 6 ] . node. get_our_node_id( ) ) ) ; 
1069+ 	assert_eq ! ( reply_path. introduction_node( ) ,  & IntroductionNode :: NodeId ( nodes[ 6 ] . node. get_our_node_id( ) ) ) ; 
10571070} 
10581071
10591072/// Checks that a deferred invoice can be paid asynchronously from an Event::InvoiceReceived. 
@@ -1190,12 +1203,13 @@ fn creates_offer_with_blinded_path_using_unannounced_introduction_node() {
11901203	let  onion_message = alice. onion_messenger . next_onion_message_for_peer ( bob_id) . unwrap ( ) ; 
11911204	bob. onion_messenger . handle_onion_message ( & alice_id,  & onion_message) ; 
11921205
1193- 	let  ( invoice,  _ )  = extract_invoice ( bob,  & onion_message) ; 
1206+ 	let  ( invoice,  reply_path )  = extract_invoice ( bob,  & onion_message) ; 
11941207	assert_ne ! ( invoice. signing_pubkey( ) ,  alice_id) ; 
11951208	assert ! ( !invoice. payment_paths( ) . is_empty( ) ) ; 
11961209	for  path in  invoice. payment_paths ( )  { 
11971210		assert_eq ! ( path. introduction_node( ) ,  & IntroductionNode :: NodeId ( bob_id) ) ; 
11981211	} 
1212+ 	assert_eq ! ( reply_path. introduction_node( ) ,  & IntroductionNode :: NodeId ( bob_id) ) ; 
11991213
12001214	route_bolt12_payment ( bob,  & [ alice] ,  & invoice) ; 
12011215	expect_recent_payment ! ( bob,  RecentPaymentDetails :: Pending ,  payment_id) ; 
@@ -1239,7 +1253,7 @@ fn creates_refund_with_blinded_path_using_unannounced_introduction_node() {
12391253
12401254	let  onion_message = alice. onion_messenger . next_onion_message_for_peer ( bob_id) . unwrap ( ) ; 
12411255
1242- 	let  ( invoice,  _ )  = extract_invoice ( bob,  & onion_message) ; 
1256+ 	let  ( invoice,  _reply_path )  = extract_invoice ( bob,  & onion_message) ; 
12431257	assert_eq ! ( invoice,  expected_invoice) ; 
12441258	assert_ne ! ( invoice. signing_pubkey( ) ,  alice_id) ; 
12451259	assert ! ( !invoice. payment_paths( ) . is_empty( ) ) ; 
0 commit comments