@@ -13,10 +13,11 @@ use crate::sign::{EntropySource, SignerProvider};
1313use crate :: chain:: ChannelMonitorUpdateStatus ;
1414use crate :: chain:: transaction:: OutPoint ;
1515use crate :: events:: { MessageSendEvent , HTLCDestination , MessageSendEventsProvider , ClosureReason } ;
16- use crate :: ln:: channelmanager:: { self , PaymentSendFailure , PaymentId , RecipientOnionFields , ChannelShutdownState , ChannelDetails } ;
16+ use crate :: ln:: channelmanager:: { self , PaymentSendFailure , PaymentId , RecipientOnionFields , Retry , ChannelShutdownState , ChannelDetails } ;
1717use crate :: routing:: router:: { PaymentParameters , get_route, RouteParameters } ;
1818use crate :: ln:: msgs;
1919use crate :: ln:: msgs:: { ChannelMessageHandler , ErrorAction } ;
20+ use crate :: ln:: onion_utils:: INVALID_ONION_BLINDING ;
2021use crate :: ln:: script:: ShutdownScript ;
2122use crate :: util:: test_utils;
2223use crate :: util:: test_utils:: OnGetShutdownScriptpubkey ;
@@ -401,6 +402,11 @@ fn updates_shutdown_wait() {
401402
402403#[ test]
403404fn htlc_fail_async_shutdown ( ) {
405+ do_htlc_fail_async_shutdown ( true ) ;
406+ do_htlc_fail_async_shutdown ( false ) ;
407+ }
408+
409+ fn do_htlc_fail_async_shutdown ( blinded_recipient : bool ) {
404410 // Test HTLCs fail if shutdown starts even if messages are delivered out-of-order
405411 let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
406412 let node_cfgs = create_node_cfgs ( 3 , & chanmon_cfgs) ;
@@ -409,9 +415,20 @@ fn htlc_fail_async_shutdown() {
409415 let chan_1 = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
410416 let chan_2 = create_announced_chan_between_nodes ( & nodes, 1 , 2 ) ;
411417
412- let ( route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 2 ] , 100000 ) ;
413- nodes[ 0 ] . node . send_payment_with_route ( & route, our_payment_hash,
414- RecipientOnionFields :: secret_only ( our_payment_secret) , PaymentId ( our_payment_hash. 0 ) ) . unwrap ( ) ;
418+ let amt_msat = 100000 ;
419+ let ( _, our_payment_hash, our_payment_secret) = get_payment_preimage_hash ( & nodes[ 2 ] , Some ( amt_msat) , None ) ;
420+ let route_params = if blinded_recipient {
421+ crate :: ln:: blinded_payment_tests:: get_blinded_route_parameters (
422+ amt_msat, our_payment_secret,
423+ nodes. iter ( ) . skip ( 1 ) . map ( |n| n. node . get_our_node_id ( ) ) . collect ( ) , & [ & chan_2. 0 . contents ] ,
424+ & chanmon_cfgs[ 2 ] . keys_manager )
425+ } else {
426+ RouteParameters :: from_payment_params_and_value (
427+ PaymentParameters :: from_node_id ( nodes[ 2 ] . node . get_our_node_id ( ) , TEST_FINAL_CLTV ) , amt_msat)
428+ } ;
429+ nodes[ 0 ] . node . send_payment ( our_payment_hash,
430+ RecipientOnionFields :: secret_only ( our_payment_secret) ,
431+ PaymentId ( our_payment_hash. 0 ) , route_params, Retry :: Attempts ( 0 ) ) . unwrap ( ) ;
415432 check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
416433 let updates = get_htlc_update_msgs ! ( nodes[ 0 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
417434 assert_eq ! ( updates. update_add_htlcs. len( ) , 1 ) ;
@@ -441,7 +458,12 @@ fn htlc_fail_async_shutdown() {
441458 nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & updates_2. update_fail_htlcs [ 0 ] ) ;
442459 commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , updates_2. commitment_signed, false , true ) ;
443460
444- expect_payment_failed_with_update ! ( nodes[ 0 ] , our_payment_hash, false , chan_2. 0 . contents. short_channel_id, true ) ;
461+ if blinded_recipient {
462+ expect_payment_failed_conditions ( & nodes[ 0 ] , our_payment_hash, false ,
463+ PaymentFailedConditions :: new ( ) . expected_htlc_error_data ( INVALID_ONION_BLINDING , & [ 0 ; 32 ] ) ) ;
464+ } else {
465+ expect_payment_failed_with_update ! ( nodes[ 0 ] , our_payment_hash, false , chan_2. 0 . contents. short_channel_id, true ) ;
466+ }
445467
446468 let msg_events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
447469 assert_eq ! ( msg_events. len( ) , 1 ) ;
0 commit comments