43
43
use bitcoin:: network:: constants:: Network ;
44
44
use core:: time:: Duration ;
45
45
use crate :: blinded_path:: BlindedPath ;
46
+ use crate :: blinded_path:: payment:: PaymentContext ;
46
47
use crate :: events:: { Event , MessageSendEventsProvider , PaymentPurpose } ;
47
48
use crate :: ln:: channelmanager:: { PaymentId , RecentPaymentDetails , Retry , self } ;
48
49
use crate :: ln:: functional_test_utils:: * ;
@@ -151,14 +152,21 @@ fn route_bolt12_payment<'a, 'b, 'c>(
151
152
do_pass_along_path ( args) ;
152
153
}
153
154
154
- fn claim_bolt12_payment < ' a , ' b , ' c > ( node : & Node < ' a , ' b , ' c > , path : & [ & Node < ' a , ' b , ' c > ] ) {
155
+ fn claim_bolt12_payment < ' a , ' b , ' c > (
156
+ node : & Node < ' a , ' b , ' c > , path : & [ & Node < ' a , ' b , ' c > ] , expected_payment_context : PaymentContext
157
+ ) {
155
158
let recipient = & path[ path. len ( ) - 1 ] ;
156
159
match get_event ! ( recipient, Event :: PaymentClaimable ) {
157
160
Event :: PaymentClaimable {
158
161
purpose : PaymentPurpose :: InvoicePayment {
159
- payment_preimage : Some ( payment_preimage) , ..
162
+ payment_preimage : Some ( payment_preimage) ,
163
+ payment_context : Some ( payment_context) ,
164
+ ..
160
165
} , ..
161
- } => claim_payment ( node, path, payment_preimage) ,
166
+ } => {
167
+ assert_eq ! ( payment_context, expected_payment_context) ;
168
+ claim_payment ( node, path, payment_preimage)
169
+ } ,
162
170
_ => panic ! ( ) ,
163
171
} ;
164
172
}
@@ -367,10 +375,12 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
367
375
disconnect_peers ( alice, & [ charlie, david, & nodes[ 4 ] , & nodes[ 5 ] ] ) ;
368
376
disconnect_peers ( david, & [ bob, & nodes[ 4 ] , & nodes[ 5 ] ] ) ;
369
377
370
- let offer = alice. node
371
- . create_offer_builder ( "coffee" . to_string ( ) ) . unwrap ( )
372
- . amount_msats ( 10_000_000 )
373
- . build ( ) . unwrap ( ) ;
378
+ let builder = alice. node
379
+ . create_offer_builder ( "coffee" . to_string ( ) )
380
+ . unwrap ( )
381
+ . amount_msats ( 10_000_000 ) ;
382
+ let payment_context = PaymentContext :: Bolt12Offer { offer_id : builder. offer_id ( ) } ;
383
+ let offer = builder. build ( ) . unwrap ( ) ;
374
384
assert_ne ! ( offer. signing_pubkey( ) , alice_id) ;
375
385
assert ! ( !offer. paths( ) . is_empty( ) ) ;
376
386
for path in offer. paths ( ) {
@@ -414,7 +424,7 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
414
424
route_bolt12_payment ( david, & [ charlie, bob, alice] , & invoice) ;
415
425
expect_recent_payment ! ( david, RecentPaymentDetails :: Pending , payment_id) ;
416
426
417
- claim_bolt12_payment ( david, & [ charlie, bob, alice] ) ;
427
+ claim_bolt12_payment ( david, & [ charlie, bob, alice] , payment_context ) ;
418
428
expect_recent_payment ! ( david, RecentPaymentDetails :: Fulfilled , payment_id) ;
419
429
}
420
430
@@ -473,6 +483,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
473
483
}
474
484
expect_recent_payment ! ( david, RecentPaymentDetails :: AwaitingInvoice , payment_id) ;
475
485
486
+ let payment_context = PaymentContext :: Bolt12Refund { } ;
476
487
let expected_invoice = alice. node . request_refund_payment ( & refund) . unwrap ( ) ;
477
488
478
489
connect_peers ( alice, charlie) ;
@@ -496,7 +507,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
496
507
route_bolt12_payment ( david, & [ charlie, bob, alice] , & invoice) ;
497
508
expect_recent_payment ! ( david, RecentPaymentDetails :: Pending , payment_id) ;
498
509
499
- claim_bolt12_payment ( david, & [ charlie, bob, alice] ) ;
510
+ claim_bolt12_payment ( david, & [ charlie, bob, alice] , payment_context ) ;
500
511
expect_recent_payment ! ( david, RecentPaymentDetails :: Fulfilled , payment_id) ;
501
512
}
502
513
@@ -517,10 +528,11 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
517
528
let bob = & nodes[ 1 ] ;
518
529
let bob_id = bob. node . get_our_node_id ( ) ;
519
530
520
- let offer = alice. node
531
+ let builder = alice. node
521
532
. create_offer_builder ( "coffee" . to_string ( ) ) . unwrap ( )
522
- . amount_msats ( 10_000_000 )
523
- . build ( ) . unwrap ( ) ;
533
+ . amount_msats ( 10_000_000 ) ;
534
+ let payment_context = PaymentContext :: Bolt12Offer { offer_id : builder. offer_id ( ) } ;
535
+ let offer = builder. build ( ) . unwrap ( ) ;
524
536
assert_ne ! ( offer. signing_pubkey( ) , alice_id) ;
525
537
assert ! ( !offer. paths( ) . is_empty( ) ) ;
526
538
for path in offer. paths ( ) {
@@ -553,7 +565,7 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
553
565
route_bolt12_payment ( bob, & [ alice] , & invoice) ;
554
566
expect_recent_payment ! ( bob, RecentPaymentDetails :: Pending , payment_id) ;
555
567
556
- claim_bolt12_payment ( bob, & [ alice] ) ;
568
+ claim_bolt12_payment ( bob, & [ alice] , payment_context ) ;
557
569
expect_recent_payment ! ( bob, RecentPaymentDetails :: Fulfilled , payment_id) ;
558
570
}
559
571
@@ -591,6 +603,7 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
591
603
}
592
604
expect_recent_payment ! ( bob, RecentPaymentDetails :: AwaitingInvoice , payment_id) ;
593
605
606
+ let payment_context = PaymentContext :: Bolt12Refund { } ;
594
607
let expected_invoice = alice. node . request_refund_payment ( & refund) . unwrap ( ) ;
595
608
596
609
let onion_message = alice. onion_messenger . next_onion_message_for_peer ( bob_id) . unwrap ( ) ;
@@ -609,7 +622,7 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
609
622
route_bolt12_payment ( bob, & [ alice] , & invoice) ;
610
623
expect_recent_payment ! ( bob, RecentPaymentDetails :: Pending , payment_id) ;
611
624
612
- claim_bolt12_payment ( bob, & [ alice] ) ;
625
+ claim_bolt12_payment ( bob, & [ alice] , payment_context ) ;
613
626
expect_recent_payment ! ( bob, RecentPaymentDetails :: Fulfilled , payment_id) ;
614
627
}
615
628
@@ -630,11 +643,12 @@ fn pays_for_offer_without_blinded_paths() {
630
643
let bob = & nodes[ 1 ] ;
631
644
let bob_id = bob. node . get_our_node_id ( ) ;
632
645
633
- let offer = alice. node
646
+ let builder = alice. node
634
647
. create_offer_builder ( "coffee" . to_string ( ) ) . unwrap ( )
635
648
. clear_paths ( )
636
- . amount_msats ( 10_000_000 )
637
- . build ( ) . unwrap ( ) ;
649
+ . amount_msats ( 10_000_000 ) ;
650
+ let payment_context = PaymentContext :: Bolt12Offer { offer_id : builder. offer_id ( ) } ;
651
+ let offer = builder. build ( ) . unwrap ( ) ;
638
652
assert_eq ! ( offer. signing_pubkey( ) , alice_id) ;
639
653
assert ! ( offer. paths( ) . is_empty( ) ) ;
640
654
@@ -652,7 +666,7 @@ fn pays_for_offer_without_blinded_paths() {
652
666
route_bolt12_payment ( bob, & [ alice] , & invoice) ;
653
667
expect_recent_payment ! ( bob, RecentPaymentDetails :: Pending , payment_id) ;
654
668
655
- claim_bolt12_payment ( bob, & [ alice] ) ;
669
+ claim_bolt12_payment ( bob, & [ alice] , payment_context ) ;
656
670
expect_recent_payment ! ( bob, RecentPaymentDetails :: Fulfilled , payment_id) ;
657
671
}
658
672
@@ -685,6 +699,7 @@ fn pays_for_refund_without_blinded_paths() {
685
699
assert ! ( refund. paths( ) . is_empty( ) ) ;
686
700
expect_recent_payment ! ( bob, RecentPaymentDetails :: AwaitingInvoice , payment_id) ;
687
701
702
+ let payment_context = PaymentContext :: Bolt12Refund { } ;
688
703
let expected_invoice = alice. node . request_refund_payment ( & refund) . unwrap ( ) ;
689
704
690
705
let onion_message = alice. onion_messenger . next_onion_message_for_peer ( bob_id) . unwrap ( ) ;
@@ -696,7 +711,7 @@ fn pays_for_refund_without_blinded_paths() {
696
711
route_bolt12_payment ( bob, & [ alice] , & invoice) ;
697
712
expect_recent_payment ! ( bob, RecentPaymentDetails :: Pending , payment_id) ;
698
713
699
- claim_bolt12_payment ( bob, & [ alice] ) ;
714
+ claim_bolt12_payment ( bob, & [ alice] , payment_context ) ;
700
715
expect_recent_payment ! ( bob, RecentPaymentDetails :: Fulfilled , payment_id) ;
701
716
}
702
717
@@ -1069,12 +1084,13 @@ fn fails_paying_invoice_more_than_once() {
1069
1084
david. onion_messenger . handle_onion_message ( & charlie_id, & onion_message) ;
1070
1085
1071
1086
// David pays the first invoice
1087
+ let payment_context = PaymentContext :: Bolt12Refund { } ;
1072
1088
let invoice1 = extract_invoice ( david, & onion_message) ;
1073
1089
1074
1090
route_bolt12_payment ( david, & [ charlie, bob, alice] , & invoice1) ;
1075
1091
expect_recent_payment ! ( david, RecentPaymentDetails :: Pending , payment_id) ;
1076
1092
1077
- claim_bolt12_payment ( david, & [ charlie, bob, alice] ) ;
1093
+ claim_bolt12_payment ( david, & [ charlie, bob, alice] , payment_context ) ;
1078
1094
expect_recent_payment ! ( david, RecentPaymentDetails :: Fulfilled , payment_id) ;
1079
1095
1080
1096
disconnect_peers ( alice, & [ charlie] ) ;
0 commit comments