@@ -274,8 +274,10 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
274
274
// We need the session priv to construct a bogus onion packet later.
275
275
* nodes[ 0 ] . keys_manager . override_random_bytes . lock ( ) . unwrap ( ) = Some ( [ 3 ; 32 ] ) ;
276
276
create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
277
- let chan_upd_1_2 = create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) . 0 . contents ;
278
- let chan_upd_2_3 = create_announced_chan_between_nodes_with_value ( & nodes, 2 , 3 , 1_000_000 , 0 ) . 0 . contents ;
277
+ let chan_1_2 = create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) ;
278
+ let chan_upd_1_2 = chan_1_2. 0 . contents ;
279
+ let chan_2_3 = create_announced_chan_between_nodes_with_value ( & nodes, 2 , 3 , 1_000_000 , 0 ) ;
280
+ let chan_upd_2_3 = chan_2_3. 0 . contents ;
279
281
280
282
let amt_msat = 5000 ;
281
283
let ( _, payment_hash, payment_secret) = get_payment_preimage_hash ( & nodes[ 3 ] , Some ( amt_msat) , None ) ;
@@ -327,18 +329,27 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
327
329
check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
328
330
do_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 0 ] , & updates_0_1. commitment_signed , true , true ) ;
329
331
332
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
333
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
334
+
330
335
if intro_fails {
331
336
let mut updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
332
337
nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & updates. update_fail_htlcs [ 0 ] ) ;
333
338
do_commitment_signed_dance ( & nodes[ 0 ] , & nodes[ 1 ] , & updates. commitment_signed , false , false ) ;
339
+ let failed_destination = match check {
340
+ ForwardCheckFail :: InboundOnionCheck => HTLCDestination :: InvalidOnion ,
341
+ ForwardCheckFail :: ForwardPayloadEncodedAsReceive => HTLCDestination :: FailedPayment { payment_hash } ,
342
+ ForwardCheckFail :: OutboundChannelCheck =>
343
+ HTLCDestination :: NextHopChannel { node_id : Some ( nodes[ 2 ] . node . get_our_node_id ( ) ) , channel_id : chan_1_2. 2 } ,
344
+ } ;
345
+ expect_htlc_handling_failed_destinations ! (
346
+ nodes[ 1 ] . node. get_and_clear_pending_events( ) , & [ failed_destination. clone( ) ]
347
+ ) ;
334
348
expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false ,
335
349
PaymentFailedConditions :: new ( ) . expected_htlc_error_data ( INVALID_ONION_BLINDING , & [ 0 ; 32 ] ) ) ;
336
350
return
337
351
}
338
352
339
- expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
340
- check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
341
-
342
353
let mut updates_1_2 = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 2 ] . node. get_our_node_id( ) ) ;
343
354
let mut update_add = & mut updates_1_2. update_add_htlcs [ 0 ] ;
344
355
@@ -348,6 +359,17 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
348
359
check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
349
360
do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & updates_1_2. commitment_signed , true , true ) ;
350
361
362
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
363
+ let failed_destination = match check {
364
+ ForwardCheckFail :: InboundOnionCheck |ForwardCheckFail :: ForwardPayloadEncodedAsReceive => HTLCDestination :: InvalidOnion ,
365
+ ForwardCheckFail :: OutboundChannelCheck =>
366
+ HTLCDestination :: NextHopChannel { node_id : Some ( nodes[ 3 ] . node . get_our_node_id ( ) ) , channel_id : chan_2_3. 2 } ,
367
+ } ;
368
+ expect_htlc_handling_failed_destinations ! (
369
+ nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ failed_destination. clone( ) ]
370
+ ) ;
371
+ check_added_monitors ! ( nodes[ 2 ] , 1 ) ;
372
+
351
373
let mut updates = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
352
374
let update_malformed = & mut updates. update_fail_malformed_htlcs [ 0 ] ;
353
375
assert_eq ! ( update_malformed. failure_code, INVALID_ONION_BLINDING ) ;
@@ -407,7 +429,10 @@ fn failed_backwards_to_intro_node() {
407
429
nodes[ 2 ] . node . handle_update_add_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
408
430
check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
409
431
do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & payment_event. commitment_msg , true , true ) ;
410
- nodes[ 2 ] . node . process_pending_htlc_forwards ( ) ;
432
+
433
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
434
+ expect_htlc_handling_failed_destinations ! ( nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: InvalidOnion ] ) ;
435
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
411
436
412
437
let mut updates = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
413
438
let mut update_malformed = & mut updates. update_fail_malformed_htlcs [ 0 ] ;
@@ -483,7 +508,7 @@ fn do_forward_fail_in_process_pending_htlc_fwds(check: ProcessPendingHTLCsCheck,
483
508
// intro node will error backwards.
484
509
$curr_node. node. peer_disconnected( & $next_node. node. get_our_node_id( ) ) ;
485
510
expect_pending_htlcs_forwardable!( $curr_node) ;
486
- expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore !( $curr_node,
511
+ expect_htlc_handling_failed_destinations !( $curr_node. node . get_and_clear_pending_events ( ) ,
487
512
vec![ HTLCDestination :: NextHopChannel { node_id: Some ( $next_node. node. get_our_node_id( ) ) , channel_id: $failed_chan_id } ] ) ;
488
513
} ,
489
514
ProcessPendingHTLCsCheck :: FwdChannelClosed => {
@@ -499,12 +524,12 @@ fn do_forward_fail_in_process_pending_htlc_fwds(check: ProcessPendingHTLCsCheck,
499
524
crate :: events:: Event :: ChannelClosed { .. } => { } ,
500
525
_ => panic!( "Unexpected event {:?}" , events) ,
501
526
}
527
+ check_closed_broadcast( & $curr_node, 1 , true ) ;
528
+ check_added_monitors!( $curr_node, 1 ) ;
502
529
503
530
$curr_node. node. process_pending_htlc_forwards( ) ;
504
- expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore !( $curr_node,
531
+ expect_htlc_handling_failed_destinations !( $curr_node. node . get_and_clear_pending_events ( ) ,
505
532
vec![ HTLCDestination :: UnknownNextHop { requested_forward_scid: $failed_scid } ] ) ;
506
- check_closed_broadcast( & $curr_node, 1 , true ) ;
507
- check_added_monitors!( $curr_node, 1 ) ;
508
533
$curr_node. node. process_pending_htlc_forwards( ) ;
509
534
} ,
510
535
}
@@ -590,6 +615,7 @@ fn do_blinded_intercept_payment(intercept_node_fails: bool) {
590
615
} ;
591
616
nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
592
617
commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 0 ] , & payment_event. commitment_msg, false , true ) ;
618
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
593
619
594
620
let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
595
621
assert_eq ! ( events. len( ) , 1 ) ;
@@ -891,13 +917,19 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
891
917
nodes[ 2 ] . node . handle_update_add_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , update_add) ;
892
918
check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
893
919
do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & payment_event_1_2. commitment_msg , true , true ) ;
920
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
921
+ expect_htlc_handling_failed_destinations ! ( nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: InvalidOnion ] ) ;
922
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
894
923
} ,
895
924
ReceiveCheckFail :: ReceiveRequirements => {
896
925
let update_add = & mut payment_event_1_2. msgs [ 0 ] ;
897
926
update_add. amount_msat -= 1 ;
898
927
nodes[ 2 ] . node . handle_update_add_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , update_add) ;
899
928
check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
900
929
do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & payment_event_1_2. commitment_msg , true , true ) ;
930
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
931
+ expect_htlc_handling_failed_destinations ! ( nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: FailedPayment { payment_hash } ] ) ;
932
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
901
933
} ,
902
934
ReceiveCheckFail :: ChannelCheck => {
903
935
nodes[ 2 ] . node . close_channel ( & chan_id_1_2, & nodes[ 1 ] . node . get_our_node_id ( ) ) . unwrap ( ) ;
@@ -911,6 +943,9 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
911
943
912
944
nodes[ 2 ] . node . handle_shutdown ( & nodes[ 1 ] . node . get_our_node_id ( ) , & node_1_shutdown) ;
913
945
commitment_signed_dance ! ( nodes[ 2 ] , nodes[ 1 ] , ( ) , false , true , false , false ) ;
946
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
947
+ expect_htlc_handling_failed_destinations ! ( nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: FailedPayment { payment_hash } ] ) ;
948
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
914
949
} ,
915
950
ReceiveCheckFail :: ProcessPendingHTLCsCheck => {
916
951
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 ) ;
@@ -926,6 +961,9 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
926
961
nodes[ 2 ] . node . handle_update_add_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & payment_event_1_2. msgs [ 0 ] ) ;
927
962
check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
928
963
do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & payment_event_1_2. commitment_msg , true , true ) ;
964
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
965
+ expect_htlc_handling_failed_destinations ! ( nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: FailedPayment { payment_hash } ] ) ;
966
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
929
967
}
930
968
}
931
969
@@ -1126,6 +1164,12 @@ fn min_htlc() {
1126
1164
nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event_0_1. msgs [ 0 ] ) ;
1127
1165
check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
1128
1166
do_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 0 ] , & payment_event_0_1. commitment_msg , true , true ) ;
1167
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
1168
+ expect_htlc_handling_failed_destinations ! (
1169
+ nodes[ 1 ] . node. get_and_clear_pending_events( ) ,
1170
+ & [ HTLCDestination :: NextHopChannel { node_id: Some ( nodes[ 2 ] . node. get_our_node_id( ) ) , channel_id: chan_1_2. 2 } ]
1171
+ ) ;
1172
+ check_added_monitors ( & nodes[ 1 ] , 1 ) ;
1129
1173
let mut updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
1130
1174
nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & updates. update_fail_htlcs [ 0 ] ) ;
1131
1175
do_commitment_signed_dance ( & nodes[ 0 ] , & nodes[ 1 ] , & updates. commitment_signed , false , false ) ;
0 commit comments