@@ -673,6 +673,57 @@ fn three_hop_blinded_path_success() {
673673 claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 4 ] ] , payment_preimage) ;
674674}
675675
676+ #[ test]
677+ fn three_hop_blinded_path_fail ( ) {
678+ let chanmon_cfgs = create_chanmon_cfgs ( 4 ) ;
679+ let node_cfgs = create_node_cfgs ( 4 , & chanmon_cfgs) ;
680+ let node_chanmgrs = create_node_chanmgrs ( 4 , & node_cfgs, & [ None , None , None , None ] ) ;
681+ let mut nodes = create_network ( 4 , & node_cfgs, & node_chanmgrs) ;
682+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
683+ let chan_upd_1_2 = create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) . 0 . contents ;
684+ let chan_upd_2_3 = create_announced_chan_between_nodes_with_value ( & nodes, 2 , 3 , 1_000_000 , 0 ) . 0 . contents ;
685+
686+ let amt_msat = 5000 ;
687+ let ( _, payment_hash, payment_secret) = get_payment_preimage_hash ( & nodes[ 3 ] , Some ( amt_msat) , None ) ;
688+ let route_params = get_blinded_route_parameters ( amt_msat, payment_secret,
689+ nodes. iter ( ) . skip ( 1 ) . map ( |n| n. node . get_our_node_id ( ) ) . collect ( ) ,
690+ & [ & chan_upd_1_2, & chan_upd_2_3] , & chanmon_cfgs[ 3 ] . keys_manager ) ;
691+
692+ nodes[ 0 ] . node . send_payment ( payment_hash, RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( payment_hash. 0 ) , route_params, Retry :: Attempts ( 0 ) ) . unwrap ( ) ;
693+ check_added_monitors ( & nodes[ 0 ] , 1 ) ;
694+ pass_along_route ( & nodes[ 0 ] , & [ & [ & nodes[ 1 ] , & nodes[ 2 ] , & nodes[ 3 ] ] ] , amt_msat, payment_hash, payment_secret) ;
695+
696+ nodes[ 3 ] . node . fail_htlc_backwards ( & payment_hash) ;
697+ expect_pending_htlcs_forwardable_conditions (
698+ nodes[ 3 ] . node . get_and_clear_pending_events ( ) , & [ HTLCDestination :: FailedPayment { payment_hash } ]
699+ ) ;
700+ nodes[ 3 ] . node . process_pending_htlc_forwards ( ) ;
701+ check_added_monitors ! ( nodes[ 3 ] , 1 ) ;
702+
703+ let updates_3_2 = get_htlc_update_msgs ! ( nodes[ 3 ] , nodes[ 2 ] . node. get_our_node_id( ) ) ;
704+ assert_eq ! ( updates_3_2. update_fail_malformed_htlcs. len( ) , 1 ) ;
705+ let update_malformed = & updates_3_2. update_fail_malformed_htlcs [ 0 ] ;
706+ assert_eq ! ( update_malformed. sha256_of_onion, [ 0 ; 32 ] ) ;
707+ assert_eq ! ( update_malformed. failure_code, INVALID_ONION_BLINDING ) ;
708+ nodes[ 2 ] . node . handle_update_fail_malformed_htlc ( & nodes[ 3 ] . node . get_our_node_id ( ) , update_malformed) ;
709+ do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 3 ] , & updates_3_2. commitment_signed , true , false ) ;
710+
711+ let updates_2_1 = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
712+ assert_eq ! ( updates_2_1. update_fail_malformed_htlcs. len( ) , 1 ) ;
713+ let update_malformed = & updates_2_1. update_fail_malformed_htlcs [ 0 ] ;
714+ assert_eq ! ( update_malformed. sha256_of_onion, [ 0 ; 32 ] ) ;
715+ assert_eq ! ( update_malformed. failure_code, INVALID_ONION_BLINDING ) ;
716+ nodes[ 1 ] . node . handle_update_fail_malformed_htlc ( & nodes[ 2 ] . node . get_our_node_id ( ) , update_malformed) ;
717+ do_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 2 ] , & updates_2_1. commitment_signed , true , false ) ;
718+
719+ let updates_1_0 = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
720+ assert_eq ! ( updates_1_0. update_fail_htlcs. len( ) , 1 ) ;
721+ nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & updates_1_0. update_fail_htlcs [ 0 ] ) ;
722+ do_commitment_signed_dance ( & nodes[ 0 ] , & nodes[ 1 ] , & updates_1_0. commitment_signed , false , false ) ;
723+ expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false ,
724+ PaymentFailedConditions :: new ( ) . expected_htlc_error_data ( INVALID_ONION_BLINDING , & [ 0 ; 32 ] ) ) ;
725+ }
726+
676727#[ derive( PartialEq ) ]
677728enum ReceiveCheckFail {
678729 // The recipient fails the payment upon `PaymentClaimable`.
0 commit comments