@@ -277,8 +277,10 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
277
277
// We need the session priv to construct a bogus onion packet later.
278
278
* nodes[ 0 ] . keys_manager . override_random_bytes . lock ( ) . unwrap ( ) = Some ( [ 3 ; 32 ] ) ;
279
279
create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
280
- let chan_upd_1_2 = create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) . 0 . contents ;
281
- let chan_upd_2_3 = create_announced_chan_between_nodes_with_value ( & nodes, 2 , 3 , 1_000_000 , 0 ) . 0 . contents ;
280
+ let chan_1_2 = create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) ;
281
+ let chan_upd_1_2 = chan_1_2. 0 . contents ;
282
+ let chan_2_3 = create_announced_chan_between_nodes_with_value ( & nodes, 2 , 3 , 1_000_000 , 0 ) ;
283
+ let chan_upd_2_3 = chan_2_3. 0 . contents ;
282
284
283
285
let amt_msat = 5000 ;
284
286
let ( _, payment_hash, payment_secret) = get_payment_preimage_hash ( & nodes[ 3 ] , Some ( amt_msat) , None ) ;
@@ -330,18 +332,27 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
330
332
check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
331
333
do_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 0 ] , & updates_0_1. commitment_signed , true , true ) ;
332
334
335
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
336
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
337
+
333
338
if intro_fails {
334
339
let mut updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
335
340
nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & updates. update_fail_htlcs [ 0 ] ) ;
336
341
do_commitment_signed_dance ( & nodes[ 0 ] , & nodes[ 1 ] , & updates. commitment_signed , false , false ) ;
342
+ let failed_destination = match check {
343
+ ForwardCheckFail :: InboundOnionCheck => HTLCDestination :: InvalidOnion ,
344
+ ForwardCheckFail :: ForwardPayloadEncodedAsReceive => HTLCDestination :: FailedPayment { payment_hash } ,
345
+ ForwardCheckFail :: OutboundChannelCheck =>
346
+ HTLCDestination :: NextHopChannel { node_id : Some ( nodes[ 2 ] . node . get_our_node_id ( ) ) , channel_id : chan_1_2. 2 } ,
347
+ } ;
348
+ expect_htlc_handling_failed_destinations ! (
349
+ nodes[ 1 ] . node. get_and_clear_pending_events( ) , & [ failed_destination. clone( ) ]
350
+ ) ;
337
351
expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false ,
338
352
PaymentFailedConditions :: new ( ) . expected_htlc_error_data ( INVALID_ONION_BLINDING , & [ 0 ; 32 ] ) ) ;
339
353
return
340
354
}
341
355
342
- expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
343
- check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
344
-
345
356
let mut updates_1_2 = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 2 ] . node. get_our_node_id( ) ) ;
346
357
let mut update_add = & mut updates_1_2. update_add_htlcs [ 0 ] ;
347
358
@@ -351,6 +362,17 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
351
362
check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
352
363
do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & updates_1_2. commitment_signed , true , true ) ;
353
364
365
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
366
+ let failed_destination = match check {
367
+ ForwardCheckFail :: InboundOnionCheck |ForwardCheckFail :: ForwardPayloadEncodedAsReceive => HTLCDestination :: InvalidOnion ,
368
+ ForwardCheckFail :: OutboundChannelCheck =>
369
+ HTLCDestination :: NextHopChannel { node_id : Some ( nodes[ 3 ] . node . get_our_node_id ( ) ) , channel_id : chan_2_3. 2 } ,
370
+ } ;
371
+ expect_htlc_handling_failed_destinations ! (
372
+ nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ failed_destination. clone( ) ]
373
+ ) ;
374
+ check_added_monitors ! ( nodes[ 2 ] , 1 ) ;
375
+
354
376
let mut updates = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
355
377
let update_malformed = & mut updates. update_fail_malformed_htlcs [ 0 ] ;
356
378
assert_eq ! ( update_malformed. failure_code, INVALID_ONION_BLINDING ) ;
@@ -410,7 +432,10 @@ fn failed_backwards_to_intro_node() {
410
432
nodes[ 2 ] . node . handle_update_add_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
411
433
check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
412
434
do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & payment_event. commitment_msg , true , true ) ;
413
- nodes[ 2 ] . node . process_pending_htlc_forwards ( ) ;
435
+
436
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
437
+ expect_htlc_handling_failed_destinations ! ( nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: InvalidOnion ] ) ;
438
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
414
439
415
440
let mut updates = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
416
441
let mut update_malformed = & mut updates. update_fail_malformed_htlcs [ 0 ] ;
@@ -486,7 +511,7 @@ fn do_forward_fail_in_process_pending_htlc_fwds(check: ProcessPendingHTLCsCheck,
486
511
// intro node will error backwards.
487
512
$curr_node. node. peer_disconnected( & $next_node. node. get_our_node_id( ) ) ;
488
513
expect_pending_htlcs_forwardable!( $curr_node) ;
489
- expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore !( $curr_node,
514
+ expect_htlc_handling_failed_destinations !( $curr_node. node . get_and_clear_pending_events ( ) ,
490
515
vec![ HTLCDestination :: NextHopChannel { node_id: Some ( $next_node. node. get_our_node_id( ) ) , channel_id: $failed_chan_id } ] ) ;
491
516
} ,
492
517
ProcessPendingHTLCsCheck :: FwdChannelClosed => {
@@ -502,12 +527,12 @@ fn do_forward_fail_in_process_pending_htlc_fwds(check: ProcessPendingHTLCsCheck,
502
527
crate :: events:: Event :: ChannelClosed { .. } => { } ,
503
528
_ => panic!( "Unexpected event {:?}" , events) ,
504
529
}
530
+ check_closed_broadcast( & $curr_node, 1 , true ) ;
531
+ check_added_monitors!( $curr_node, 1 ) ;
505
532
506
533
$curr_node. node. process_pending_htlc_forwards( ) ;
507
- expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore !( $curr_node,
534
+ expect_htlc_handling_failed_destinations !( $curr_node. node . get_and_clear_pending_events ( ) ,
508
535
vec![ HTLCDestination :: UnknownNextHop { requested_forward_scid: $failed_scid } ] ) ;
509
- check_closed_broadcast( & $curr_node, 1 , true ) ;
510
- check_added_monitors!( $curr_node, 1 ) ;
511
536
$curr_node. node. process_pending_htlc_forwards( ) ;
512
537
} ,
513
538
}
@@ -593,6 +618,7 @@ fn do_blinded_intercept_payment(intercept_node_fails: bool) {
593
618
} ;
594
619
nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
595
620
commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 0 ] , & payment_event. commitment_msg, false , true ) ;
621
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
596
622
597
623
let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
598
624
assert_eq ! ( events. len( ) , 1 ) ;
@@ -894,13 +920,19 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
894
920
nodes[ 2 ] . node . handle_update_add_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , update_add) ;
895
921
check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
896
922
do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & payment_event_1_2. commitment_msg , true , true ) ;
923
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
924
+ expect_htlc_handling_failed_destinations ! ( nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: InvalidOnion ] ) ;
925
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
897
926
} ,
898
927
ReceiveCheckFail :: ReceiveRequirements => {
899
928
let update_add = & mut payment_event_1_2. msgs [ 0 ] ;
900
929
update_add. amount_msat -= 1 ;
901
930
nodes[ 2 ] . node . handle_update_add_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , update_add) ;
902
931
check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
903
932
do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & payment_event_1_2. commitment_msg , true , true ) ;
933
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
934
+ expect_htlc_handling_failed_destinations ! ( nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: FailedPayment { payment_hash } ] ) ;
935
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
904
936
} ,
905
937
ReceiveCheckFail :: ChannelCheck => {
906
938
nodes[ 2 ] . node . close_channel ( & chan_id_1_2, & nodes[ 1 ] . node . get_our_node_id ( ) ) . unwrap ( ) ;
@@ -914,6 +946,9 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
914
946
915
947
nodes[ 2 ] . node . handle_shutdown ( & nodes[ 1 ] . node . get_our_node_id ( ) , & node_1_shutdown) ;
916
948
commitment_signed_dance ! ( nodes[ 2 ] , nodes[ 1 ] , ( ) , false , true , false , false ) ;
949
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
950
+ expect_htlc_handling_failed_destinations ! ( nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: FailedPayment { payment_hash } ] ) ;
951
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
917
952
} ,
918
953
ReceiveCheckFail :: ProcessPendingHTLCsCheck => {
919
954
assert_eq ! ( payment_event_1_2. msgs[ 0 ] . cltv_expiry, nodes[ 0 ] . best_block_info( ) . 1 + 1 + excess_final_cltv_delta_opt. unwrap( ) as u32 + TEST_FINAL_CLTV ) ;
@@ -929,6 +964,9 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
929
964
nodes[ 2 ] . node . handle_update_add_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & payment_event_1_2. msgs [ 0 ] ) ;
930
965
check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
931
966
do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & payment_event_1_2. commitment_msg , true , true ) ;
967
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
968
+ expect_htlc_handling_failed_destinations ! ( nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: FailedPayment { payment_hash } ] ) ;
969
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
932
970
}
933
971
}
934
972
@@ -1129,6 +1167,12 @@ fn min_htlc() {
1129
1167
nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event_0_1. msgs [ 0 ] ) ;
1130
1168
check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
1131
1169
do_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 0 ] , & payment_event_0_1. commitment_msg , true , true ) ;
1170
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
1171
+ expect_htlc_handling_failed_destinations ! (
1172
+ nodes[ 1 ] . node. get_and_clear_pending_events( ) ,
1173
+ & [ HTLCDestination :: NextHopChannel { node_id: Some ( nodes[ 2 ] . node. get_our_node_id( ) ) , channel_id: chan_1_2. 2 } ]
1174
+ ) ;
1175
+ check_added_monitors ( & nodes[ 1 ] , 1 ) ;
1132
1176
let mut updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
1133
1177
nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & updates. update_fail_htlcs [ 0 ] ) ;
1134
1178
do_commitment_signed_dance ( & nodes[ 0 ] , & nodes[ 1 ] , & updates. commitment_signed , false , false ) ;
0 commit comments