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 } ;
@@ -133,6 +134,12 @@ fn announce_node_address<'a, 'b, 'c>(
133
134
}
134
135
}
135
136
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
+
136
143
fn route_bolt12_payment < ' a , ' b , ' c > (
137
144
node : & Node < ' a , ' b , ' c > , path : & [ & Node < ' a , ' b , ' c > ] , invoice : & Bolt12Invoice
138
145
) {
@@ -273,8 +280,9 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
273
280
assert_ne ! ( offer. signing_pubkey( ) , Some ( bob_id) ) ;
274
281
assert ! ( !offer. paths( ) . is_empty( ) ) ;
275
282
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) ;
278
286
}
279
287
280
288
// 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() {
288
296
assert_ne ! ( offer. signing_pubkey( ) , Some ( bob_id) ) ;
289
297
assert ! ( !offer. paths( ) . is_empty( ) ) ;
290
298
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) ;
292
301
}
293
302
}
294
303
@@ -338,7 +347,8 @@ fn prefers_more_connected_nodes_in_blinded_paths() {
338
347
assert_ne ! ( offer. signing_pubkey( ) , Some ( bob_id) ) ;
339
348
assert ! ( !offer. paths( ) . is_empty( ) ) ;
340
349
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( ) ) ;
342
352
}
343
353
}
344
354
@@ -388,7 +398,9 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
388
398
assert_ne ! ( offer. signing_pubkey( ) , Some ( alice_id) ) ;
389
399
assert ! ( !offer. paths( ) . is_empty( ) ) ;
390
400
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 ( ..) ) ) ;
392
404
}
393
405
394
406
let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
@@ -415,9 +427,11 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
415
427
payer_note_truncated : None ,
416
428
} ,
417
429
} ) ;
430
+ let introduction_node_id = resolve_introduction_node ( alice, & reply_path) ;
418
431
assert_eq ! ( invoice_request. amount_msats( ) , None ) ;
419
432
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 ( ..) ) ) ;
421
435
422
436
let onion_message = alice. onion_messenger . next_onion_message_for_peer ( charlie_id) . unwrap ( ) ;
423
437
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() {
489
503
assert_ne ! ( refund. payer_id( ) , david_id) ;
490
504
assert ! ( !refund. paths( ) . is_empty( ) ) ;
491
505
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 ( ..) ) ) ;
493
509
}
494
510
expect_recent_payment ! ( david, RecentPaymentDetails :: AwaitingInvoice , payment_id) ;
495
511
@@ -545,7 +561,9 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
545
561
assert_ne ! ( offer. signing_pubkey( ) , Some ( alice_id) ) ;
546
562
assert ! ( !offer. paths( ) . is_empty( ) ) ;
547
563
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 ( ..) ) ) ;
549
567
}
550
568
551
569
let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
@@ -564,9 +582,11 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
564
582
payer_note_truncated : None ,
565
583
} ,
566
584
} ) ;
585
+ let introduction_node_id = resolve_introduction_node ( alice, & reply_path) ;
567
586
assert_eq ! ( invoice_request. amount_msats( ) , None ) ;
568
587
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 ( ..) ) ) ;
570
590
571
591
let onion_message = alice. onion_messenger . next_onion_message_for_peer ( bob_id) . unwrap ( ) ;
572
592
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() {
614
634
assert_ne ! ( refund. payer_id( ) , bob_id) ;
615
635
assert ! ( !refund. paths( ) . is_empty( ) ) ;
616
636
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 ( ..) ) ) ;
618
640
}
619
641
expect_recent_payment ! ( bob, RecentPaymentDetails :: AwaitingInvoice , payment_id) ;
620
642
0 commit comments