@@ -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 ) ;
@@ -361,11 +392,7 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
361
392
do_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 0 ] , & updates_0_1. commitment_signed , true , true ) ;
362
393
363
394
if intro_fails {
364
- let mut updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
365
- nodes[ 0 ] . node . handle_update_fail_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , & updates. update_fail_htlcs [ 0 ] ) ;
366
- do_commitment_signed_dance ( & nodes[ 0 ] , & nodes[ 1 ] , & updates. commitment_signed , false , false ) ;
367
- expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false ,
368
- PaymentFailedConditions :: new ( ) . expected_htlc_error_data ( INVALID_ONION_BLINDING , & [ 0 ; 32 ] ) ) ;
395
+ fail_blinded_htlc_backwards ( payment_hash, 1 , & [ & nodes[ 0 ] , & nodes[ 1 ] ] ) ;
369
396
return
370
397
}
371
398
@@ -547,13 +574,8 @@ fn do_forward_fail_in_process_pending_htlc_fwds(check: ProcessPendingHTLCsCheck,
547
574
548
575
if intro_fails {
549
576
cause_error ! ( nodes[ 0 ] , nodes[ 1 ] , nodes[ 2 ] , chan_id_1_2, chan_upd_1_2. short_channel_id) ;
550
- let mut updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
551
- nodes[ 0 ] . node . handle_update_fail_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , & updates. update_fail_htlcs [ 0 ] ) ;
552
577
check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
553
- do_commitment_signed_dance ( & nodes[ 0 ] , & nodes[ 1 ] , & updates. commitment_signed , false , false ) ;
554
-
555
- expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false ,
556
- PaymentFailedConditions :: new ( ) . expected_htlc_error_data ( INVALID_ONION_BLINDING , & [ 0 ; 32 ] ) ) ;
578
+ fail_blinded_htlc_backwards ( payment_hash, 1 , & [ & nodes[ 0 ] , & nodes[ 1 ] ] ) ;
557
579
return
558
580
}
559
581
@@ -643,14 +665,8 @@ fn do_blinded_intercept_payment(intercept_node_fails: bool) {
643
665
nodes[ 1 ] . node . fail_intercepted_htlc ( intercept_id) . unwrap ( ) ;
644
666
expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore ! ( nodes[ 1 ] , vec![ HTLCDestination :: UnknownNextHop { requested_forward_scid: intercept_scid } ] ) ;
645
667
nodes[ 1 ] . node . process_pending_htlc_forwards ( ) ;
646
- let update_fail = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
647
668
check_added_monitors ! ( & nodes[ 1 ] , 1 ) ;
648
- assert ! ( update_fail. update_fail_htlcs. len( ) == 1 ) ;
649
- let fail_msg = update_fail. update_fail_htlcs [ 0 ] . clone ( ) ;
650
- nodes[ 0 ] . node . handle_update_fail_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , & fail_msg) ;
651
- commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , update_fail. commitment_signed, false ) ;
652
- expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false ,
653
- PaymentFailedConditions :: new ( ) . expected_htlc_error_data ( INVALID_ONION_BLINDING , & [ 0 ; 32 ] ) ) ;
669
+ fail_blinded_htlc_backwards ( payment_hash, 1 , & [ & nodes[ 0 ] , & nodes[ 1 ] ] ) ;
654
670
return
655
671
}
656
672
@@ -756,29 +772,7 @@ fn three_hop_blinded_path_fail() {
756
772
) ;
757
773
nodes[ 3 ] . node . process_pending_htlc_forwards ( ) ;
758
774
check_added_monitors ! ( nodes[ 3 ] , 1 ) ;
759
-
760
- let updates_3_2 = get_htlc_update_msgs ! ( nodes[ 3 ] , nodes[ 2 ] . node. get_our_node_id( ) ) ;
761
- assert_eq ! ( updates_3_2. update_fail_malformed_htlcs. len( ) , 1 ) ;
762
- let update_malformed = & updates_3_2. update_fail_malformed_htlcs [ 0 ] ;
763
- assert_eq ! ( update_malformed. sha256_of_onion, [ 0 ; 32 ] ) ;
764
- assert_eq ! ( update_malformed. failure_code, INVALID_ONION_BLINDING ) ;
765
- nodes[ 2 ] . node . handle_update_fail_malformed_htlc ( nodes[ 3 ] . node . get_our_node_id ( ) , update_malformed) ;
766
- do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 3 ] , & updates_3_2. commitment_signed , true , false ) ;
767
-
768
- let updates_2_1 = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
769
- assert_eq ! ( updates_2_1. update_fail_malformed_htlcs. len( ) , 1 ) ;
770
- let update_malformed = & updates_2_1. update_fail_malformed_htlcs [ 0 ] ;
771
- assert_eq ! ( update_malformed. sha256_of_onion, [ 0 ; 32 ] ) ;
772
- assert_eq ! ( update_malformed. failure_code, INVALID_ONION_BLINDING ) ;
773
- nodes[ 1 ] . node . handle_update_fail_malformed_htlc ( nodes[ 2 ] . node . get_our_node_id ( ) , update_malformed) ;
774
- do_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 2 ] , & updates_2_1. commitment_signed , true , false ) ;
775
-
776
- let updates_1_0 = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
777
- assert_eq ! ( updates_1_0. update_fail_htlcs. len( ) , 1 ) ;
778
- nodes[ 0 ] . node . handle_update_fail_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , & updates_1_0. update_fail_htlcs [ 0 ] ) ;
779
- do_commitment_signed_dance ( & nodes[ 0 ] , & nodes[ 1 ] , & updates_1_0. commitment_signed , false , false ) ;
780
- expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false ,
781
- PaymentFailedConditions :: new ( ) . expected_htlc_error_data ( INVALID_ONION_BLINDING , & [ 0 ; 32 ] ) ) ;
775
+ fail_blinded_htlc_backwards ( payment_hash, 1 , & [ & nodes[ 0 ] , & nodes[ 1 ] , & nodes[ 2 ] , & nodes[ 3 ] ] ) ;
782
776
}
783
777
784
778
#[ derive( PartialEq ) ]
0 commit comments