@@ -105,6 +105,37 @@ pub fn get_blinded_route_parameters(
105
105
)
106
106
}
107
107
108
+ pub fn fail_blinded_htlc_backwards (
109
+ payment_hash : PaymentHash , intro_node_idx : usize , nodes : & [ & Node ] ,
110
+ ) {
111
+ for i in ( 0 ..nodes. len ( ) ) . rev ( ) {
112
+ match i {
113
+ 0 => {
114
+ let mut payment_failed_conditions = PaymentFailedConditions :: new ( )
115
+ . expected_htlc_error_data ( INVALID_ONION_BLINDING , & [ 0 ; 32 ] ) ;
116
+ expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false , payment_failed_conditions) ;
117
+ } ,
118
+ i if i <= intro_node_idx => {
119
+ let unblinded_node_updates = get_htlc_update_msgs ! ( nodes[ i] , nodes[ i-1 ] . node. get_our_node_id( ) ) ;
120
+ assert_eq ! ( unblinded_node_updates. update_fail_htlcs. len( ) , 1 ) ;
121
+ nodes[ i-1 ] . node . handle_update_fail_htlc (
122
+ nodes[ i] . node . get_our_node_id ( ) , & unblinded_node_updates. update_fail_htlcs [ i-1 ]
123
+ ) ;
124
+ do_commitment_signed_dance ( & nodes[ i-1 ] , & nodes[ i] , & unblinded_node_updates. commitment_signed , false , false ) ;
125
+ } ,
126
+ _ => {
127
+ let blinded_node_updates = get_htlc_update_msgs ! ( nodes[ i] , nodes[ i-1 ] . node. get_our_node_id( ) ) ;
128
+ assert_eq ! ( blinded_node_updates. update_fail_malformed_htlcs. len( ) , 1 ) ;
129
+ let update_malformed = & blinded_node_updates. update_fail_malformed_htlcs [ 0 ] ;
130
+ assert_eq ! ( update_malformed. sha256_of_onion, [ 0 ; 32 ] ) ;
131
+ assert_eq ! ( update_malformed. failure_code, INVALID_ONION_BLINDING ) ;
132
+ nodes[ i-1 ] . node . handle_update_fail_malformed_htlc ( nodes[ i] . node . get_our_node_id ( ) , update_malformed) ;
133
+ do_commitment_signed_dance ( & nodes[ i-1 ] , & nodes[ i] , & blinded_node_updates. commitment_signed , true , false ) ;
134
+ }
135
+ }
136
+ }
137
+ }
138
+
108
139
#[ test]
109
140
fn one_hop_blinded_path ( ) {
110
141
do_one_hop_blinded_path ( true ) ;
@@ -572,13 +603,8 @@ fn do_forward_fail_in_process_pending_htlc_fwds(check: ProcessPendingHTLCsCheck,
572
603
573
604
if intro_fails {
574
605
cause_error ! ( nodes[ 0 ] , nodes[ 1 ] , nodes[ 2 ] , chan_id_1_2, chan_upd_1_2. short_channel_id) ;
575
- let mut updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
576
- nodes[ 0 ] . node . handle_update_fail_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , & updates. update_fail_htlcs [ 0 ] ) ;
577
606
check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
578
- do_commitment_signed_dance ( & nodes[ 0 ] , & nodes[ 1 ] , & updates. commitment_signed , false , false ) ;
579
-
580
- expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false ,
581
- PaymentFailedConditions :: new ( ) . expected_htlc_error_data ( INVALID_ONION_BLINDING , & [ 0 ; 32 ] ) ) ;
607
+ fail_blinded_htlc_backwards ( payment_hash, 1 , & [ & nodes[ 0 ] , & nodes[ 1 ] ] ) ;
582
608
return
583
609
}
584
610
@@ -669,14 +695,8 @@ fn do_blinded_intercept_payment(intercept_node_fails: bool) {
669
695
nodes[ 1 ] . node . fail_intercepted_htlc ( intercept_id) . unwrap ( ) ;
670
696
expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore ! ( nodes[ 1 ] , vec![ HTLCDestination :: UnknownNextHop { requested_forward_scid: intercept_scid } ] ) ;
671
697
nodes[ 1 ] . node . process_pending_htlc_forwards ( ) ;
672
- let update_fail = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
673
698
check_added_monitors ! ( & nodes[ 1 ] , 1 ) ;
674
- assert ! ( update_fail. update_fail_htlcs. len( ) == 1 ) ;
675
- let fail_msg = update_fail. update_fail_htlcs [ 0 ] . clone ( ) ;
676
- nodes[ 0 ] . node . handle_update_fail_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , & fail_msg) ;
677
- commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , update_fail. commitment_signed, false ) ;
678
- expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false ,
679
- PaymentFailedConditions :: new ( ) . expected_htlc_error_data ( INVALID_ONION_BLINDING , & [ 0 ; 32 ] ) ) ;
699
+ fail_blinded_htlc_backwards ( payment_hash, 1 , & [ & nodes[ 0 ] , & nodes[ 1 ] ] ) ;
680
700
return
681
701
}
682
702
@@ -782,29 +802,7 @@ fn three_hop_blinded_path_fail() {
782
802
) ;
783
803
nodes[ 3 ] . node . process_pending_htlc_forwards ( ) ;
784
804
check_added_monitors ! ( nodes[ 3 ] , 1 ) ;
785
-
786
- let updates_3_2 = get_htlc_update_msgs ! ( nodes[ 3 ] , nodes[ 2 ] . node. get_our_node_id( ) ) ;
787
- assert_eq ! ( updates_3_2. update_fail_malformed_htlcs. len( ) , 1 ) ;
788
- let update_malformed = & updates_3_2. update_fail_malformed_htlcs [ 0 ] ;
789
- assert_eq ! ( update_malformed. sha256_of_onion, [ 0 ; 32 ] ) ;
790
- assert_eq ! ( update_malformed. failure_code, INVALID_ONION_BLINDING ) ;
791
- nodes[ 2 ] . node . handle_update_fail_malformed_htlc ( nodes[ 3 ] . node . get_our_node_id ( ) , update_malformed) ;
792
- do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 3 ] , & updates_3_2. commitment_signed , true , false ) ;
793
-
794
- let updates_2_1 = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
795
- assert_eq ! ( updates_2_1. update_fail_malformed_htlcs. len( ) , 1 ) ;
796
- let update_malformed = & updates_2_1. update_fail_malformed_htlcs [ 0 ] ;
797
- assert_eq ! ( update_malformed. sha256_of_onion, [ 0 ; 32 ] ) ;
798
- assert_eq ! ( update_malformed. failure_code, INVALID_ONION_BLINDING ) ;
799
- nodes[ 1 ] . node . handle_update_fail_malformed_htlc ( nodes[ 2 ] . node . get_our_node_id ( ) , update_malformed) ;
800
- do_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 2 ] , & updates_2_1. commitment_signed , true , false ) ;
801
-
802
- let updates_1_0 = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
803
- assert_eq ! ( updates_1_0. update_fail_htlcs. len( ) , 1 ) ;
804
- nodes[ 0 ] . node . handle_update_fail_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , & updates_1_0. update_fail_htlcs [ 0 ] ) ;
805
- do_commitment_signed_dance ( & nodes[ 0 ] , & nodes[ 1 ] , & updates_1_0. commitment_signed , false , false ) ;
806
- expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false ,
807
- PaymentFailedConditions :: new ( ) . expected_htlc_error_data ( INVALID_ONION_BLINDING , & [ 0 ; 32 ] ) ) ;
805
+ fail_blinded_htlc_backwards ( payment_hash, 1 , & [ & nodes[ 0 ] , & nodes[ 1 ] , & nodes[ 2 ] , & nodes[ 3 ] ] ) ;
808
806
}
809
807
810
808
#[ derive( PartialEq ) ]
0 commit comments