41
41
//! blinded paths are used.
42
42
43
43
use bitcoin:: network:: constants:: Network ;
44
+ use bitcoin:: secp256k1:: PublicKey ;
44
45
use core:: time:: Duration ;
45
46
use crate :: blinded_path:: { BlindedPath , IntroductionNode } ;
46
47
use crate :: blinded_path:: payment:: { Bolt12OfferContext , Bolt12RefundContext , PaymentContext } ;
@@ -134,6 +135,12 @@ fn announce_node_address<'a, 'b, 'c>(
134
135
}
135
136
}
136
137
138
+ fn resolve_introduction_node < ' a , ' b , ' c > ( node : & Node < ' a , ' b , ' c > , path : & BlindedPath ) -> PublicKey {
139
+ path. public_introduction_node_id ( & node. network_graph . read_only ( ) )
140
+ . and_then ( |node_id| node_id. as_pubkey ( ) . ok ( ) )
141
+ . unwrap ( )
142
+ }
143
+
137
144
fn route_bolt12_payment < ' a , ' b , ' c > (
138
145
node : & Node < ' a , ' b , ' c > , path : & [ & Node < ' a , ' b , ' c > ] , invoice : & Bolt12Invoice
139
146
) {
@@ -274,8 +281,9 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
274
281
assert_ne ! ( offer. signing_pubkey( ) , bob_id) ;
275
282
assert ! ( !offer. paths( ) . is_empty( ) ) ;
276
283
for path in offer. paths ( ) {
277
- assert_ne ! ( path. introduction_node, IntroductionNode :: NodeId ( bob_id) ) ;
278
- assert_ne ! ( path. introduction_node, IntroductionNode :: NodeId ( charlie_id) ) ;
284
+ let introduction_node_id = resolve_introduction_node ( david, & path) ;
285
+ assert_ne ! ( introduction_node_id, bob_id) ;
286
+ assert_ne ! ( introduction_node_id, charlie_id) ;
279
287
}
280
288
281
289
// Use a one-hop blinded path when Bob is announced and all his peers are Tor-only.
@@ -289,7 +297,8 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
289
297
assert_ne ! ( offer. signing_pubkey( ) , bob_id) ;
290
298
assert ! ( !offer. paths( ) . is_empty( ) ) ;
291
299
for path in offer. paths ( ) {
292
- assert_eq ! ( path. introduction_node, IntroductionNode :: NodeId ( bob_id) ) ;
300
+ let introduction_node_id = resolve_introduction_node ( david, & path) ;
301
+ assert_eq ! ( introduction_node_id, bob_id) ;
293
302
}
294
303
}
295
304
@@ -339,7 +348,8 @@ fn prefers_more_connected_nodes_in_blinded_paths() {
339
348
assert_ne ! ( offer. signing_pubkey( ) , bob_id) ;
340
349
assert ! ( !offer. paths( ) . is_empty( ) ) ;
341
350
for path in offer. paths ( ) {
342
- assert_eq ! ( path. introduction_node, IntroductionNode :: NodeId ( nodes[ 4 ] . node. get_our_node_id( ) ) ) ;
351
+ let introduction_node_id = resolve_introduction_node ( david, & path) ;
352
+ assert_eq ! ( introduction_node_id, nodes[ 4 ] . node. get_our_node_id( ) ) ;
343
353
}
344
354
}
345
355
@@ -389,7 +399,9 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
389
399
assert_ne ! ( offer. signing_pubkey( ) , alice_id) ;
390
400
assert ! ( !offer. paths( ) . is_empty( ) ) ;
391
401
for path in offer. paths ( ) {
392
- assert_eq ! ( path. introduction_node, IntroductionNode :: NodeId ( bob_id) ) ;
402
+ let introduction_node_id = resolve_introduction_node ( david, & path) ;
403
+ assert_eq ! ( introduction_node_id, bob_id) ;
404
+ assert ! ( matches!( path. introduction_node, IntroductionNode :: DirectedShortChannelId ( ..) ) ) ;
393
405
}
394
406
395
407
let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
@@ -418,9 +430,11 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
418
430
payer_note_truncated : None ,
419
431
} ,
420
432
} ) ;
433
+ let introduction_node_id = resolve_introduction_node ( alice, & reply_path) ;
421
434
assert_eq ! ( invoice_request. amount_msats( ) , None ) ;
422
435
assert_ne ! ( invoice_request. payer_id( ) , david_id) ;
423
- assert_eq ! ( reply_path. introduction_node, IntroductionNode :: NodeId ( charlie_id) ) ;
436
+ assert_eq ! ( introduction_node_id, charlie_id) ;
437
+ assert ! ( matches!( reply_path. introduction_node, IntroductionNode :: DirectedShortChannelId ( ..) ) ) ;
424
438
425
439
let onion_message = alice. onion_messenger . next_onion_message_for_peer ( charlie_id) . unwrap ( ) ;
426
440
charlie. onion_messenger . handle_onion_message ( & alice_id, & onion_message) ;
@@ -494,7 +508,9 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
494
508
assert_ne ! ( refund. payer_id( ) , david_id) ;
495
509
assert ! ( !refund. paths( ) . is_empty( ) ) ;
496
510
for path in refund. paths ( ) {
497
- assert_eq ! ( path. introduction_node, IntroductionNode :: NodeId ( charlie_id) ) ;
511
+ let introduction_node_id = resolve_introduction_node ( alice, & path) ;
512
+ assert_eq ! ( introduction_node_id, charlie_id) ;
513
+ assert ! ( matches!( path. introduction_node, IntroductionNode :: DirectedShortChannelId ( ..) ) ) ;
498
514
}
499
515
expect_recent_payment ! ( david, RecentPaymentDetails :: AwaitingInvoice , payment_id) ;
500
516
@@ -550,7 +566,9 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
550
566
assert_ne ! ( offer. signing_pubkey( ) , alice_id) ;
551
567
assert ! ( !offer. paths( ) . is_empty( ) ) ;
552
568
for path in offer. paths ( ) {
553
- assert_eq ! ( path. introduction_node, IntroductionNode :: NodeId ( alice_id) ) ;
569
+ let introduction_node_id = resolve_introduction_node ( bob, & path) ;
570
+ assert_eq ! ( introduction_node_id, alice_id) ;
571
+ assert ! ( matches!( path. introduction_node, IntroductionNode :: DirectedShortChannelId ( ..) ) ) ;
554
572
}
555
573
556
574
let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
@@ -571,9 +589,11 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
571
589
payer_note_truncated : None ,
572
590
} ,
573
591
} ) ;
592
+ let introduction_node_id = resolve_introduction_node ( alice, & reply_path) ;
574
593
assert_eq ! ( invoice_request. amount_msats( ) , None ) ;
575
594
assert_ne ! ( invoice_request. payer_id( ) , bob_id) ;
576
- assert_eq ! ( reply_path. introduction_node, IntroductionNode :: NodeId ( bob_id) ) ;
595
+ assert_eq ! ( introduction_node_id, bob_id) ;
596
+ assert ! ( matches!( reply_path. introduction_node, IntroductionNode :: DirectedShortChannelId ( ..) ) ) ;
577
597
578
598
let onion_message = alice. onion_messenger . next_onion_message_for_peer ( bob_id) . unwrap ( ) ;
579
599
bob. onion_messenger . handle_onion_message ( & alice_id, & onion_message) ;
@@ -623,7 +643,9 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
623
643
assert_ne ! ( refund. payer_id( ) , bob_id) ;
624
644
assert ! ( !refund. paths( ) . is_empty( ) ) ;
625
645
for path in refund. paths ( ) {
626
- assert_eq ! ( path. introduction_node, IntroductionNode :: NodeId ( bob_id) ) ;
646
+ let introduction_node_id = resolve_introduction_node ( alice, & path) ;
647
+ assert_eq ! ( introduction_node_id, bob_id) ;
648
+ assert ! ( matches!( path. introduction_node, IntroductionNode :: DirectedShortChannelId ( ..) ) ) ;
627
649
}
628
650
expect_recent_payment ! ( bob, RecentPaymentDetails :: AwaitingInvoice , payment_id) ;
629
651
0 commit comments