@@ -96,6 +96,7 @@ fn run_onion_failure_test<F1, F2>(
9696// 3: final node fails backward (but tamper onion payloads from node0)
9797// 100: trigger error in the intermediate node and tamper returning fail_htlc
9898// 200: trigger error in the final node and tamper returning fail_htlc
99+ // 201: trigger error in the final node and delay
99100fn run_onion_failure_test_with_fail_intercept < F1 , F2 , F3 > (
100101 _name : & str , test_case : u8 , nodes : & Vec < Node > , route : & Route , payment_hash : & PaymentHash ,
101102 payment_secret : & PaymentSecret , mut callback_msg : F1 , mut callback_fail : F2 ,
@@ -160,11 +161,11 @@ fn run_onion_failure_test_with_fail_intercept<F1, F2, F3>(
160161 assert ! ( fail_len + malformed_len == 1 && ( fail_len == 1 || malformed_len == 1 ) ) ;
161162 update_1_0
162163 } ,
163- 1 | 2 | 3 | 200 => {
164+ 1 | 2 | 3 | 200 | 201 => {
164165 // final node failure; forwarding to 2
165166 assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
166167 // forwarding on 1
167- if test_case != 200 {
168+ if test_case != 200 && test_case != 201 {
168169 callback_node ( ) ;
169170 }
170171 expect_htlc_forward ! ( & nodes[ 1 ] ) ;
@@ -182,29 +183,41 @@ fn run_onion_failure_test_with_fail_intercept<F1, F2, F3>(
182183 nodes[ 2 ] . node . handle_update_add_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , & update_add_1) ;
183184 commitment_signed_dance ! ( nodes[ 2 ] , nodes[ 1 ] , update_1. commitment_signed, false , true ) ;
184185
185- if test_case == 2 || test_case == 200 {
186- expect_htlc_forward ! ( & nodes[ 2 ] ) ;
187- expect_event ! ( & nodes[ 2 ] , Event :: PaymentClaimable ) ;
188- callback_node ( ) ;
189- expect_pending_htlcs_forwardable_and_htlc_handling_failed ! (
190- nodes[ 2 ] ,
191- vec![ HTLCHandlingFailureType :: Receive { payment_hash: payment_hash. clone( ) } ]
192- ) ;
193- } else if test_case == 1 || test_case == 3 {
194- expect_htlc_forward ! ( & nodes[ 2 ] ) ;
195- expect_htlc_handling_failed_destinations ! (
196- nodes[ 2 ] . node. get_and_clear_pending_events( ) ,
197- vec![ expected_failure_type. clone( ) . unwrap( ) ]
198- ) ;
186+ match test_case {
187+ 2 | 200 | 201 => {
188+ expect_htlc_forward ! ( & nodes[ 2 ] ) ;
189+ expect_event ! ( & nodes[ 2 ] , Event :: PaymentClaimable ) ;
190+ callback_node ( ) ;
191+ expect_pending_htlcs_forwardable_and_htlc_handling_failed ! (
192+ nodes[ 2 ] ,
193+ vec![ HTLCHandlingFailureType :: Receive {
194+ payment_hash: payment_hash. clone( )
195+ } ]
196+ ) ;
197+ } ,
198+ 1 | 3 => {
199+ expect_htlc_forward ! ( & nodes[ 2 ] ) ;
200+ expect_htlc_handling_failed_destinations ! (
201+ nodes[ 2 ] . node. get_and_clear_pending_events( ) ,
202+ vec![ expected_failure_type. clone( ) . unwrap( ) ]
203+ ) ;
204+ } ,
205+ _ => { } ,
199206 }
200207 check_added_monitors ! ( & nodes[ 2 ] , 1 ) ;
201208
202209 let update_2_1 = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
203210 assert ! ( update_2_1. update_fail_htlcs. len( ) == 1 ) ;
204211
205212 let mut fail_msg = update_2_1. update_fail_htlcs [ 0 ] . clone ( ) ;
206- if test_case == 200 {
207- callback_fail ( & mut fail_msg) ;
213+ match test_case {
214+ // Trigger error in the final node and tamper returning fail_htlc.
215+ 200 => callback_fail ( & mut fail_msg) ,
216+ // Trigger error in the final node and delay.
217+ 201 => {
218+ std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 200 ) ) ;
219+ } ,
220+ _ => { } ,
208221 }
209222
210223 // 2 => 1
@@ -242,9 +255,17 @@ fn run_onion_failure_test_with_fail_intercept<F1, F2, F3>(
242255 ref short_channel_id,
243256 ref error_code,
244257 failure : PathFailure :: OnPath { ref network_update } ,
258+ ref hold_times,
245259 ..
246260 } = & events[ 0 ]
247261 {
262+ // When resolution is delayed, we expect that to show up in the hold times. Hold times are only reported in std.
263+ if test_case == 201 {
264+ #[ cfg( feature = "std" ) ]
265+ assert ! ( hold_times. iter( ) . any( |ht| * ht > 0 ) ) ;
266+ #[ cfg( not( feature = "std" ) ) ]
267+ assert ! ( hold_times. iter( ) . all( |ht| * ht == 0 ) ) ;
268+ }
248269 assert_eq ! ( * payment_failed_permanently, !expected_retryable) ;
249270 assert_eq ! ( error_code. is_none( ) , expected_error_reason. is_none( ) ) ;
250271 if let Some ( expected_reason) = expected_error_reason {
@@ -1491,6 +1512,23 @@ fn test_onion_failure() {
14911512 Some ( channels[ 1 ] . 0 . contents . short_channel_id ) ,
14921513 None ,
14931514 ) ;
1515+ run_onion_failure_test (
1516+ "delayed_fail" ,
1517+ 201 ,
1518+ & nodes,
1519+ & route,
1520+ & payment_hash,
1521+ & payment_secret,
1522+ |_| { } ,
1523+ || {
1524+ nodes[ 2 ] . node . fail_htlc_backwards ( & payment_hash) ;
1525+ } ,
1526+ false ,
1527+ Some ( LocalHTLCFailureReason :: IncorrectPaymentDetails ) ,
1528+ None ,
1529+ None ,
1530+ None ,
1531+ ) ;
14941532}
14951533
14961534#[ test]
0 commit comments