@@ -11,7 +11,9 @@ use crate::blinded_path::message::{MessageContext, OffersContext};
11
11
use crate :: blinded_path:: payment:: PaymentContext ;
12
12
use crate :: blinded_path:: payment:: { AsyncBolt12OfferContext , BlindedPaymentTlvs } ;
13
13
use crate :: chain:: channelmonitor:: { HTLC_FAIL_BACK_BUFFER , LATENCY_GRACE_PERIOD_BLOCKS } ;
14
- use crate :: events:: { Event , HTLCHandlingFailureType , PaidBolt12Invoice , PaymentFailureReason } ;
14
+ use crate :: events:: {
15
+ Event , HTLCHandlingFailureType , PaidBolt12Invoice , PaymentFailureReason , PaymentPurpose ,
16
+ } ;
15
17
use crate :: ln:: blinded_payment_tests:: { fail_blinded_htlc_backwards, get_blinded_route_parameters} ;
16
18
use crate :: ln:: channelmanager:: { PaymentId , RecipientOnionFields } ;
17
19
use crate :: ln:: functional_test_utils:: * ;
@@ -128,6 +130,25 @@ fn create_static_invoice<T: secp256k1::Signing + secp256k1::Verification>(
128
130
( offer, static_invoice)
129
131
}
130
132
133
+ fn extract_payment_hash ( event : & MessageSendEvent ) -> PaymentHash {
134
+ match event {
135
+ MessageSendEvent :: UpdateHTLCs { ref updates, .. } => {
136
+ updates. update_add_htlcs [ 0 ] . payment_hash
137
+ } ,
138
+ _ => panic ! ( ) ,
139
+ }
140
+ }
141
+
142
+ fn extract_payment_preimage ( event : & Event ) -> PaymentPreimage {
143
+ match event {
144
+ Event :: PaymentClaimable {
145
+ purpose : PaymentPurpose :: Bolt12OfferPayment { payment_preimage, .. } ,
146
+ ..
147
+ } => payment_preimage. unwrap ( ) ,
148
+ _ => panic ! ( ) ,
149
+ }
150
+ }
151
+
131
152
#[ test]
132
153
fn invalid_keysend_payment_secret ( ) {
133
154
let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
@@ -215,6 +236,7 @@ fn static_invoice_unknown_required_features() {
215
236
create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
216
237
create_unannounced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) ;
217
238
239
+ // Manually construct a static invoice so we can set unknown required features.
218
240
let blinded_paths_to_always_online_node = nodes[ 1 ]
219
241
. message_router
220
242
. create_blinded_paths (
@@ -237,6 +259,8 @@ fn static_invoice_unknown_required_features() {
237
259
. build_and_sign ( & secp_ctx)
238
260
. unwrap ( ) ;
239
261
262
+ // Initiate payment to the offer corresponding to the manually-constructed invoice that has
263
+ // unknown required features.
240
264
let amt_msat = 5000 ;
241
265
let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
242
266
let params = RouteParametersConfig :: default ( ) ;
@@ -264,6 +288,8 @@ fn static_invoice_unknown_required_features() {
264
288
)
265
289
. unwrap ( ) ;
266
290
291
+ // Check that paying the static invoice fails as expected with
292
+ // `PaymentFailureReason::UnknownRequiredFeatures`.
267
293
let static_invoice_om = nodes[ 1 ]
268
294
. onion_messenger
269
295
. next_onion_message_for_peer ( nodes[ 0 ] . node . get_our_node_id ( ) )
@@ -404,12 +430,6 @@ fn async_receive_flow_success() {
404
430
create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
405
431
create_unannounced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) ;
406
432
407
- // Set the random bytes so we can predict the payment preimage and hash.
408
- let hardcoded_random_bytes = [ 42 ; 32 ] ;
409
- let keysend_preimage = PaymentPreimage ( hardcoded_random_bytes) ;
410
- let payment_hash: PaymentHash = keysend_preimage. into ( ) ;
411
- * nodes[ 0 ] . keys_manager . override_random_bytes . lock ( ) . unwrap ( ) = Some ( hardcoded_random_bytes) ;
412
-
413
433
let relative_expiry = Duration :: from_secs ( 1000 ) ;
414
434
let ( offer, static_invoice) =
415
435
create_static_invoice ( & nodes[ 1 ] , & nodes[ 2 ] , Some ( relative_expiry) , & secp_ctx) ;
@@ -433,6 +453,7 @@ fn async_receive_flow_success() {
433
453
let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
434
454
assert_eq ! ( events. len( ) , 1 ) ;
435
455
let ev = remove_first_msg_event_to_node ( & nodes[ 1 ] . node . get_our_node_id ( ) , & mut events) ;
456
+ let payment_hash = extract_payment_hash ( & ev) ;
436
457
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
437
458
438
459
// Receiving a duplicate release_htlc message doesn't result in duplicate payment.
@@ -442,9 +463,9 @@ fn async_receive_flow_success() {
442
463
assert ! ( nodes[ 0 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
443
464
444
465
let route: & [ & [ & Node ] ] = & [ & [ & nodes[ 1 ] , & nodes[ 2 ] ] ] ;
445
- let args = PassAlongPathArgs :: new ( & nodes[ 0 ] , route[ 0 ] , amt_msat, payment_hash, ev)
446
- . with_payment_preimage ( keysend_preimage ) ;
447
- do_pass_along_path ( args ) ;
466
+ let args = PassAlongPathArgs :: new ( & nodes[ 0 ] , route[ 0 ] , amt_msat, payment_hash, ev) ;
467
+ let claimable_ev = do_pass_along_path ( args ) . unwrap ( ) ;
468
+ let keysend_preimage = extract_payment_preimage ( & claimable_ev ) ;
448
469
let res =
449
470
claim_payment_along_route ( ClaimAlongRouteArgs :: new ( & nodes[ 0 ] , route, keysend_preimage) ) ;
450
471
assert ! ( res. is_some( ) ) ;
@@ -556,9 +577,6 @@ fn async_receive_mpp() {
556
577
557
578
let ( offer, static_invoice) = create_static_invoice ( & nodes[ 1 ] , & nodes[ 3 ] , None , & secp_ctx) ;
558
579
559
- // In other tests we hardcode the sender's random bytes so we can predict the keysend preimage to
560
- // check later in the test, but that doesn't work for MPP because it causes the session_privs for
561
- // the different MPP parts to not be unique.
562
580
let amt_msat = 15_000_000 ;
563
581
let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
564
582
let params = RouteParametersConfig :: default ( ) ;
@@ -593,8 +611,8 @@ fn async_receive_mpp() {
593
611
let args = PassAlongPathArgs :: new ( & nodes[ 0 ] , expected_route[ 1 ] , amt_msat, payment_hash, ev) ;
594
612
let claimable_ev = do_pass_along_path ( args) . unwrap ( ) ;
595
613
let keysend_preimage = match claimable_ev {
596
- crate :: events :: Event :: PaymentClaimable {
597
- purpose : crate :: events :: PaymentPurpose :: Bolt12OfferPayment { payment_preimage, .. } ,
614
+ Event :: PaymentClaimable {
615
+ purpose : PaymentPurpose :: Bolt12OfferPayment { payment_preimage, .. } ,
598
616
..
599
617
} => payment_preimage. unwrap ( ) ,
600
618
_ => panic ! ( ) ,
@@ -643,13 +661,6 @@ fn amount_doesnt_match_invreq() {
643
661
connect_blocks ( & nodes[ 3 ] , 4 * CHAN_CONFIRM_DEPTH + 1 - nodes[ 3 ] . best_block_info ( ) . 1 ) ;
644
662
645
663
let ( offer, static_invoice) = create_static_invoice ( & nodes[ 1 ] , & nodes[ 3 ] , None , & secp_ctx) ;
646
-
647
- // Set the random bytes so we can predict the payment preimage and hash.
648
- let hardcoded_random_bytes = [ 42 ; 32 ] ;
649
- let keysend_preimage = PaymentPreimage ( hardcoded_random_bytes) ;
650
- let payment_hash: PaymentHash = keysend_preimage. into ( ) ;
651
- * nodes[ 0 ] . keys_manager . override_random_bytes . lock ( ) . unwrap ( ) = Some ( hardcoded_random_bytes) ;
652
-
653
664
let amt_msat = 5000 ;
654
665
let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
655
666
let params = RouteParametersConfig :: default ( ) ;
@@ -696,10 +707,10 @@ fn amount_doesnt_match_invreq() {
696
707
let mut ev = remove_first_msg_event_to_node ( & nodes[ 1 ] . node . get_our_node_id ( ) , & mut events) ;
697
708
assert ! ( matches!(
698
709
ev, MessageSendEvent :: UpdateHTLCs { ref updates, .. } if updates. update_add_htlcs. len( ) == 1 ) ) ;
710
+ let payment_hash = extract_payment_hash ( & ev) ;
699
711
700
712
let route: & [ & [ & Node ] ] = & [ & [ & nodes[ 1 ] , & nodes[ 3 ] ] ] ;
701
713
let args = PassAlongPathArgs :: new ( & nodes[ 0 ] , route[ 0 ] , amt_msat, payment_hash, ev)
702
- . with_payment_preimage ( keysend_preimage)
703
714
. without_claimable_event ( )
704
715
. expect_failure ( HTLCHandlingFailureType :: Receive { payment_hash } ) ;
705
716
do_pass_along_path ( args) ;
@@ -725,9 +736,9 @@ fn amount_doesnt_match_invreq() {
725
736
ev, MessageSendEvent :: UpdateHTLCs { ref updates, .. } if updates. update_add_htlcs. len( ) == 1 ) ) ;
726
737
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
727
738
let route: & [ & [ & Node ] ] = & [ & [ & nodes[ 2 ] , & nodes[ 3 ] ] ] ;
728
- let args = PassAlongPathArgs :: new ( & nodes[ 0 ] , route[ 0 ] , amt_msat, payment_hash, ev)
729
- . with_payment_preimage ( keysend_preimage ) ;
730
- do_pass_along_path ( args ) ;
739
+ let args = PassAlongPathArgs :: new ( & nodes[ 0 ] , route[ 0 ] , amt_msat, payment_hash, ev) ;
740
+ let claimable_ev = do_pass_along_path ( args ) . unwrap ( ) ;
741
+ let keysend_preimage = extract_payment_preimage ( & claimable_ev ) ;
731
742
claim_payment_along_route ( ClaimAlongRouteArgs :: new ( & nodes[ 0 ] , route, keysend_preimage) ) ;
732
743
}
733
744
@@ -882,12 +893,6 @@ fn invalid_async_receive_with_retry<F1, F2>(
882
893
. build_and_sign ( & secp_ctx)
883
894
. unwrap ( ) ;
884
895
885
- // Set the random bytes so we can predict the payment preimage and hash.
886
- let hardcoded_random_bytes = [ 42 ; 32 ] ;
887
- let keysend_preimage = PaymentPreimage ( hardcoded_random_bytes) ;
888
- let payment_hash: PaymentHash = keysend_preimage. into ( ) ;
889
- * nodes[ 0 ] . keys_manager . override_random_bytes . lock ( ) . unwrap ( ) = Some ( hardcoded_random_bytes) ;
890
-
891
896
let params = RouteParametersConfig :: default ( ) ;
892
897
nodes[ 0 ]
893
898
. node
@@ -906,10 +911,10 @@ fn invalid_async_receive_with_retry<F1, F2>(
906
911
let mut ev = remove_first_msg_event_to_node ( & nodes[ 1 ] . node . get_our_node_id ( ) , & mut events) ;
907
912
assert ! ( matches!(
908
913
ev, MessageSendEvent :: UpdateHTLCs { ref updates, .. } if updates. update_add_htlcs. len( ) == 1 ) ) ;
914
+ let payment_hash = extract_payment_hash ( & ev) ;
909
915
910
916
let route: & [ & [ & Node ] ] = & [ & [ & nodes[ 1 ] , & nodes[ 2 ] ] ] ;
911
- let args = PassAlongPathArgs :: new ( & nodes[ 0 ] , route[ 0 ] , amt_msat, payment_hash, ev)
912
- . with_payment_preimage ( keysend_preimage) ;
917
+ let args = PassAlongPathArgs :: new ( & nodes[ 0 ] , route[ 0 ] , amt_msat, payment_hash, ev) ;
913
918
do_pass_along_path ( args) ;
914
919
915
920
// Fail the HTLC backwards to enable us to more easily modify the now-Retryable outbound to test
@@ -935,7 +940,6 @@ fn invalid_async_receive_with_retry<F1, F2>(
935
940
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
936
941
let route: & [ & [ & Node ] ] = & [ & [ & nodes[ 1 ] , & nodes[ 2 ] ] ] ;
937
942
let args = PassAlongPathArgs :: new ( & nodes[ 0 ] , route[ 0 ] , amt_msat, payment_hash, ev)
938
- . with_payment_preimage ( keysend_preimage)
939
943
. without_claimable_event ( )
940
944
. expect_failure ( HTLCHandlingFailureType :: Receive { payment_hash } ) ;
941
945
do_pass_along_path ( args) ;
@@ -949,9 +953,9 @@ fn invalid_async_receive_with_retry<F1, F2>(
949
953
let mut ev = remove_first_msg_event_to_node ( & nodes[ 1 ] . node . get_our_node_id ( ) , & mut events) ;
950
954
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
951
955
let route: & [ & [ & Node ] ] = & [ & [ & nodes[ 1 ] , & nodes[ 2 ] ] ] ;
952
- let args = PassAlongPathArgs :: new ( & nodes[ 0 ] , route[ 0 ] , amt_msat, payment_hash, ev)
953
- . with_payment_preimage ( keysend_preimage ) ;
954
- do_pass_along_path ( args ) ;
956
+ let args = PassAlongPathArgs :: new ( & nodes[ 0 ] , route[ 0 ] , amt_msat, payment_hash, ev) ;
957
+ let claimable_ev = do_pass_along_path ( args ) . unwrap ( ) ;
958
+ let keysend_preimage = extract_payment_preimage ( & claimable_ev ) ;
955
959
claim_payment_along_route ( ClaimAlongRouteArgs :: new ( & nodes[ 0 ] , route, keysend_preimage) ) ;
956
960
}
957
961
@@ -1031,12 +1035,6 @@ fn expired_static_invoice_payment_path() {
1031
1035
connect_blocks ( & nodes[ 1 ] , node_max_height - nodes[ 1 ] . best_block_info ( ) . 1 ) ;
1032
1036
connect_blocks ( & nodes[ 2 ] , node_max_height - nodes[ 2 ] . best_block_info ( ) . 1 ) ;
1033
1037
1034
- // Set the random bytes so we can predict the payment preimage and hash.
1035
- let hardcoded_random_bytes = [ 42 ; 32 ] ;
1036
- let keysend_preimage = PaymentPreimage ( hardcoded_random_bytes) ;
1037
- let payment_hash: PaymentHash = keysend_preimage. into ( ) ;
1038
- * nodes[ 0 ] . keys_manager . override_random_bytes . lock ( ) . unwrap ( ) = Some ( hardcoded_random_bytes) ;
1039
-
1040
1038
// Hardcode the blinded payment path returned by the router so we can expire it via mining blocks.
1041
1039
let ( _, static_invoice_expired_paths) =
1042
1040
create_static_invoice ( & nodes[ 1 ] , & nodes[ 2 ] , None , & secp_ctx) ;
@@ -1097,11 +1095,11 @@ fn expired_static_invoice_payment_path() {
1097
1095
let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
1098
1096
assert_eq ! ( events. len( ) , 1 ) ;
1099
1097
let ev = remove_first_msg_event_to_node ( & nodes[ 1 ] . node . get_our_node_id ( ) , & mut events) ;
1098
+ let payment_hash = extract_payment_hash ( & ev) ;
1100
1099
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
1101
1100
1102
1101
let route: & [ & [ & Node ] ] = & [ & [ & nodes[ 1 ] , & nodes[ 2 ] ] ] ;
1103
1102
let args = PassAlongPathArgs :: new ( & nodes[ 0 ] , route[ 0 ] , amt_msat, payment_hash, ev)
1104
- . with_payment_preimage ( keysend_preimage)
1105
1103
. without_claimable_event ( )
1106
1104
. expect_failure ( HTLCHandlingFailureType :: Receive { payment_hash } ) ;
1107
1105
do_pass_along_path ( args) ;
0 commit comments