12
12
use crate :: sign:: { EntropySource , SignerProvider } ;
13
13
use crate :: chain:: transaction:: OutPoint ;
14
14
use crate :: events:: { MessageSendEvent , MessageSendEventsProvider , ClosureReason } ;
15
- use crate :: ln:: channelmanager:: { self , PaymentSendFailure , PaymentId , RecipientOnionFields , ChannelShutdownState , ChannelDetails } ;
15
+ use crate :: ln:: channelmanager:: { self , PaymentSendFailure , PaymentId , RecipientOnionFields , Retry , ChannelShutdownState , ChannelDetails } ;
16
16
use crate :: routing:: router:: { PaymentParameters , get_route, RouteParameters } ;
17
17
use crate :: ln:: msgs;
18
18
use crate :: ln:: msgs:: { ChannelMessageHandler , ErrorAction } ;
19
+ use crate :: ln:: onion_utils:: INVALID_ONION_BLINDING ;
19
20
use crate :: ln:: script:: ShutdownScript ;
20
21
use crate :: util:: test_utils;
21
22
use crate :: util:: test_utils:: OnGetShutdownScriptpubkey ;
@@ -400,6 +401,11 @@ fn updates_shutdown_wait() {
400
401
401
402
#[ test]
402
403
fn htlc_fail_async_shutdown ( ) {
404
+ do_htlc_fail_async_shutdown ( true ) ;
405
+ do_htlc_fail_async_shutdown ( false ) ;
406
+ }
407
+
408
+ fn do_htlc_fail_async_shutdown ( blinded_recipient : bool ) {
403
409
// Test HTLCs fail if shutdown starts even if messages are delivered out-of-order
404
410
let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
405
411
let node_cfgs = create_node_cfgs ( 3 , & chanmon_cfgs) ;
@@ -408,9 +414,20 @@ fn htlc_fail_async_shutdown() {
408
414
let chan_1 = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
409
415
let chan_2 = create_announced_chan_between_nodes ( & nodes, 1 , 2 ) ;
410
416
411
- let ( route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 2 ] , 100000 ) ;
412
- nodes[ 0 ] . node . send_payment_with_route ( & route, our_payment_hash,
413
- RecipientOnionFields :: secret_only ( our_payment_secret) , PaymentId ( our_payment_hash. 0 ) ) . unwrap ( ) ;
417
+ let amt_msat = 100000 ;
418
+ let ( _, our_payment_hash, our_payment_secret) = get_payment_preimage_hash ( & nodes[ 2 ] , Some ( amt_msat) , None ) ;
419
+ let route_params = if blinded_recipient {
420
+ crate :: ln:: blinded_payment_tests:: get_blinded_route_parameters (
421
+ amt_msat, our_payment_secret,
422
+ nodes. iter ( ) . skip ( 1 ) . map ( |n| n. node . get_our_node_id ( ) ) . collect ( ) , & [ & chan_2. 0 . contents ] ,
423
+ & chanmon_cfgs[ 2 ] . keys_manager )
424
+ } else {
425
+ RouteParameters :: from_payment_params_and_value (
426
+ PaymentParameters :: from_node_id ( nodes[ 2 ] . node . get_our_node_id ( ) , TEST_FINAL_CLTV ) , amt_msat)
427
+ } ;
428
+ nodes[ 0 ] . node . send_payment ( our_payment_hash,
429
+ RecipientOnionFields :: secret_only ( our_payment_secret) ,
430
+ PaymentId ( our_payment_hash. 0 ) , route_params, Retry :: Attempts ( 0 ) ) . unwrap ( ) ;
414
431
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
415
432
let updates = get_htlc_update_msgs ! ( nodes[ 0 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
416
433
assert_eq ! ( updates. update_add_htlcs. len( ) , 1 ) ;
@@ -440,7 +457,12 @@ fn htlc_fail_async_shutdown() {
440
457
nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & updates_2. update_fail_htlcs [ 0 ] ) ;
441
458
commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , updates_2. commitment_signed, false , true ) ;
442
459
443
- expect_payment_failed_with_update ! ( nodes[ 0 ] , our_payment_hash, false , chan_2. 0 . contents. short_channel_id, true ) ;
460
+ if blinded_recipient {
461
+ expect_payment_failed_conditions ( & nodes[ 0 ] , our_payment_hash, false ,
462
+ PaymentFailedConditions :: new ( ) . expected_htlc_error_data ( INVALID_ONION_BLINDING , & [ 0 ; 32 ] ) ) ;
463
+ } else {
464
+ expect_payment_failed_with_update ! ( nodes[ 0 ] , our_payment_hash, false , chan_2. 0 . contents. short_channel_id, true ) ;
465
+ }
444
466
445
467
let msg_events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
446
468
assert_eq ! ( msg_events. len( ) , 1 ) ;
0 commit comments