4141//! blinded paths are used.
4242
4343use bitcoin:: network:: constants:: Network ;
44+ use bitcoin:: secp256k1:: PublicKey ;
4445use core:: time:: Duration ;
4546use crate :: blinded_path:: { BlindedPath , IntroductionNode } ;
4647use crate :: blinded_path:: payment:: { Bolt12OfferContext , Bolt12RefundContext , PaymentContext } ;
@@ -133,6 +134,12 @@ fn announce_node_address<'a, 'b, 'c>(
133134 }
134135}
135136
137+ fn resolve_introduction_node < ' a , ' b , ' c > ( node : & Node < ' a , ' b , ' c > , path : & BlindedPath ) -> PublicKey {
138+ path. public_introduction_node_id ( & node. network_graph . read_only ( ) )
139+ . and_then ( |node_id| node_id. as_pubkey ( ) . ok ( ) )
140+ . unwrap ( )
141+ }
142+
136143fn route_bolt12_payment < ' a , ' b , ' c > (
137144 node : & Node < ' a , ' b , ' c > , path : & [ & Node < ' a , ' b , ' c > ] , invoice : & Bolt12Invoice
138145) {
@@ -273,8 +280,9 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
273280 assert_ne ! ( offer. signing_pubkey( ) , Some ( bob_id) ) ;
274281 assert ! ( !offer. paths( ) . is_empty( ) ) ;
275282 for path in offer. paths ( ) {
276- assert_ne ! ( path. introduction_node, IntroductionNode :: NodeId ( bob_id) ) ;
277- assert_ne ! ( path. introduction_node, IntroductionNode :: NodeId ( charlie_id) ) ;
283+ let introduction_node_id = resolve_introduction_node ( david, & path) ;
284+ assert_ne ! ( introduction_node_id, bob_id) ;
285+ assert_ne ! ( introduction_node_id, charlie_id) ;
278286 }
279287
280288 // Use a one-hop blinded path when Bob is announced and all his peers are Tor-only.
@@ -288,7 +296,8 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
288296 assert_ne ! ( offer. signing_pubkey( ) , Some ( bob_id) ) ;
289297 assert ! ( !offer. paths( ) . is_empty( ) ) ;
290298 for path in offer. paths ( ) {
291- assert_eq ! ( path. introduction_node, IntroductionNode :: NodeId ( bob_id) ) ;
299+ let introduction_node_id = resolve_introduction_node ( david, & path) ;
300+ assert_eq ! ( introduction_node_id, bob_id) ;
292301 }
293302}
294303
@@ -338,7 +347,8 @@ fn prefers_more_connected_nodes_in_blinded_paths() {
338347 assert_ne ! ( offer. signing_pubkey( ) , Some ( bob_id) ) ;
339348 assert ! ( !offer. paths( ) . is_empty( ) ) ;
340349 for path in offer. paths ( ) {
341- assert_eq ! ( path. introduction_node, IntroductionNode :: NodeId ( nodes[ 4 ] . node. get_our_node_id( ) ) ) ;
350+ let introduction_node_id = resolve_introduction_node ( david, & path) ;
351+ assert_eq ! ( introduction_node_id, nodes[ 4 ] . node. get_our_node_id( ) ) ;
342352 }
343353}
344354
@@ -388,7 +398,9 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
388398 assert_ne ! ( offer. signing_pubkey( ) , Some ( alice_id) ) ;
389399 assert ! ( !offer. paths( ) . is_empty( ) ) ;
390400 for path in offer. paths ( ) {
391- assert_eq ! ( path. introduction_node, IntroductionNode :: NodeId ( bob_id) ) ;
401+ let introduction_node_id = resolve_introduction_node ( david, & path) ;
402+ assert_eq ! ( introduction_node_id, bob_id) ;
403+ assert ! ( matches!( path. introduction_node, IntroductionNode :: DirectedShortChannelId ( ..) ) ) ;
392404 }
393405
394406 let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
@@ -415,9 +427,11 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
415427 payer_note_truncated : None ,
416428 } ,
417429 } ) ;
430+ let introduction_node_id = resolve_introduction_node ( alice, & reply_path) ;
418431 assert_eq ! ( invoice_request. amount_msats( ) , None ) ;
419432 assert_ne ! ( invoice_request. payer_id( ) , david_id) ;
420- assert_eq ! ( reply_path. introduction_node, IntroductionNode :: NodeId ( charlie_id) ) ;
433+ assert_eq ! ( introduction_node_id, charlie_id) ;
434+ assert ! ( matches!( reply_path. introduction_node, IntroductionNode :: DirectedShortChannelId ( ..) ) ) ;
421435
422436 let onion_message = alice. onion_messenger . next_onion_message_for_peer ( charlie_id) . unwrap ( ) ;
423437 charlie. onion_messenger . handle_onion_message ( & alice_id, & onion_message) ;
@@ -489,7 +503,9 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
489503 assert_ne ! ( refund. payer_id( ) , david_id) ;
490504 assert ! ( !refund. paths( ) . is_empty( ) ) ;
491505 for path in refund. paths ( ) {
492- assert_eq ! ( path. introduction_node, IntroductionNode :: NodeId ( charlie_id) ) ;
506+ let introduction_node_id = resolve_introduction_node ( alice, & path) ;
507+ assert_eq ! ( introduction_node_id, charlie_id) ;
508+ assert ! ( matches!( path. introduction_node, IntroductionNode :: DirectedShortChannelId ( ..) ) ) ;
493509 }
494510 expect_recent_payment ! ( david, RecentPaymentDetails :: AwaitingInvoice , payment_id) ;
495511
@@ -545,7 +561,9 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
545561 assert_ne ! ( offer. signing_pubkey( ) , Some ( alice_id) ) ;
546562 assert ! ( !offer. paths( ) . is_empty( ) ) ;
547563 for path in offer. paths ( ) {
548- assert_eq ! ( path. introduction_node, IntroductionNode :: NodeId ( alice_id) ) ;
564+ let introduction_node_id = resolve_introduction_node ( bob, & path) ;
565+ assert_eq ! ( introduction_node_id, alice_id) ;
566+ assert ! ( matches!( path. introduction_node, IntroductionNode :: DirectedShortChannelId ( ..) ) ) ;
549567 }
550568
551569 let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
@@ -564,9 +582,11 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
564582 payer_note_truncated : None ,
565583 } ,
566584 } ) ;
585+ let introduction_node_id = resolve_introduction_node ( alice, & reply_path) ;
567586 assert_eq ! ( invoice_request. amount_msats( ) , None ) ;
568587 assert_ne ! ( invoice_request. payer_id( ) , bob_id) ;
569- assert_eq ! ( reply_path. introduction_node, IntroductionNode :: NodeId ( bob_id) ) ;
588+ assert_eq ! ( introduction_node_id, bob_id) ;
589+ assert ! ( matches!( reply_path. introduction_node, IntroductionNode :: DirectedShortChannelId ( ..) ) ) ;
570590
571591 let onion_message = alice. onion_messenger . next_onion_message_for_peer ( bob_id) . unwrap ( ) ;
572592 bob. onion_messenger . handle_onion_message ( & alice_id, & onion_message) ;
@@ -614,7 +634,9 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
614634 assert_ne ! ( refund. payer_id( ) , bob_id) ;
615635 assert ! ( !refund. paths( ) . is_empty( ) ) ;
616636 for path in refund. paths ( ) {
617- assert_eq ! ( path. introduction_node, IntroductionNode :: NodeId ( bob_id) ) ;
637+ let introduction_node_id = resolve_introduction_node ( alice, & path) ;
638+ assert_eq ! ( introduction_node_id, bob_id) ;
639+ assert ! ( matches!( path. introduction_node, IntroductionNode :: DirectedShortChannelId ( ..) ) ) ;
618640 }
619641 expect_recent_payment ! ( bob, RecentPaymentDetails :: AwaitingInvoice , payment_id) ;
620642
0 commit comments