@@ -305,8 +305,10 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
305
305
// We need the session priv to construct a bogus onion packet later.
306
306
* nodes[ 0 ] . keys_manager . override_random_bytes . lock ( ) . unwrap ( ) = Some ( [ 3 ; 32 ] ) ;
307
307
create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
308
- let chan_upd_1_2 = create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) . 0 . contents ;
309
- let chan_upd_2_3 = create_announced_chan_between_nodes_with_value ( & nodes, 2 , 3 , 1_000_000 , 0 ) . 0 . contents ;
308
+ let chan_1_2 = create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) ;
309
+ let chan_upd_1_2 = chan_1_2. 0 . contents ;
310
+ let chan_2_3 = create_announced_chan_between_nodes_with_value ( & nodes, 2 , 3 , 1_000_000 , 0 ) ;
311
+ let chan_upd_2_3 = chan_2_3. 0 . contents ;
310
312
311
313
let amt_msat = 5000 ;
312
314
let ( _, payment_hash, payment_secret) = get_payment_preimage_hash ( & nodes[ 3 ] , Some ( amt_msat) , None ) ;
@@ -360,18 +362,27 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
360
362
check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
361
363
do_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 0 ] , & updates_0_1. commitment_signed , true , true ) ;
362
364
365
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
366
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
367
+
363
368
if intro_fails {
364
369
let mut updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
365
370
nodes[ 0 ] . node . handle_update_fail_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , & updates. update_fail_htlcs [ 0 ] ) ;
366
371
do_commitment_signed_dance ( & nodes[ 0 ] , & nodes[ 1 ] , & updates. commitment_signed , false , false ) ;
372
+ let failed_destination = match check {
373
+ ForwardCheckFail :: InboundOnionCheck => HTLCDestination :: InvalidOnion ,
374
+ ForwardCheckFail :: ForwardPayloadEncodedAsReceive => HTLCDestination :: FailedPayment { payment_hash } ,
375
+ ForwardCheckFail :: OutboundChannelCheck =>
376
+ HTLCDestination :: NextHopChannel { node_id : Some ( nodes[ 2 ] . node . get_our_node_id ( ) ) , channel_id : chan_1_2. 2 } ,
377
+ } ;
378
+ expect_htlc_handling_failed_destinations ! (
379
+ nodes[ 1 ] . node. get_and_clear_pending_events( ) , & [ failed_destination. clone( ) ]
380
+ ) ;
367
381
expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false ,
368
382
PaymentFailedConditions :: new ( ) . expected_htlc_error_data ( INVALID_ONION_BLINDING , & [ 0 ; 32 ] ) ) ;
369
383
return
370
384
}
371
385
372
- expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
373
- check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
374
-
375
386
let mut updates_1_2 = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 2 ] . node. get_our_node_id( ) ) ;
376
387
let mut update_add = & mut updates_1_2. update_add_htlcs [ 0 ] ;
377
388
@@ -381,6 +392,17 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
381
392
check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
382
393
do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & updates_1_2. commitment_signed , true , true ) ;
383
394
395
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
396
+ let failed_destination = match check {
397
+ ForwardCheckFail :: InboundOnionCheck |ForwardCheckFail :: ForwardPayloadEncodedAsReceive => HTLCDestination :: InvalidOnion ,
398
+ ForwardCheckFail :: OutboundChannelCheck =>
399
+ HTLCDestination :: NextHopChannel { node_id : Some ( nodes[ 3 ] . node . get_our_node_id ( ) ) , channel_id : chan_2_3. 2 } ,
400
+ } ;
401
+ expect_htlc_handling_failed_destinations ! (
402
+ nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ failed_destination. clone( ) ]
403
+ ) ;
404
+ check_added_monitors ! ( nodes[ 2 ] , 1 ) ;
405
+
384
406
let mut updates = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
385
407
let update_malformed = & mut updates. update_fail_malformed_htlcs [ 0 ] ;
386
408
assert_eq ! ( update_malformed. failure_code, INVALID_ONION_BLINDING ) ;
@@ -440,7 +462,10 @@ fn failed_backwards_to_intro_node() {
440
462
nodes[ 2 ] . node . handle_update_add_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
441
463
check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
442
464
do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & payment_event. commitment_msg , true , true ) ;
443
- nodes[ 2 ] . node . process_pending_htlc_forwards ( ) ;
465
+
466
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
467
+ expect_htlc_handling_failed_destinations ! ( nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: InvalidOnion ] ) ;
468
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
444
469
445
470
let mut updates = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
446
471
let mut update_malformed = & mut updates. update_fail_malformed_htlcs [ 0 ] ;
@@ -517,7 +542,7 @@ fn do_forward_fail_in_process_pending_htlc_fwds(check: ProcessPendingHTLCsCheck,
517
542
// intro node will error backwards.
518
543
$curr_node. node. peer_disconnected( $next_node. node. get_our_node_id( ) ) ;
519
544
expect_pending_htlcs_forwardable!( $curr_node) ;
520
- expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore !( $curr_node,
545
+ expect_htlc_handling_failed_destinations !( $curr_node. node . get_and_clear_pending_events ( ) ,
521
546
vec![ HTLCDestination :: NextHopChannel { node_id: Some ( $next_node. node. get_our_node_id( ) ) , channel_id: $failed_chan_id } ] ) ;
522
547
} ,
523
548
ProcessPendingHTLCsCheck :: FwdChannelClosed => {
@@ -533,12 +558,12 @@ fn do_forward_fail_in_process_pending_htlc_fwds(check: ProcessPendingHTLCsCheck,
533
558
crate :: events:: Event :: ChannelClosed { .. } => { } ,
534
559
_ => panic!( "Unexpected event {:?}" , events) ,
535
560
}
561
+ check_closed_broadcast( & $curr_node, 1 , true ) ;
562
+ check_added_monitors!( $curr_node, 1 ) ;
536
563
537
564
$curr_node. node. process_pending_htlc_forwards( ) ;
538
- expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore !( $curr_node,
565
+ expect_htlc_handling_failed_destinations !( $curr_node. node . get_and_clear_pending_events ( ) ,
539
566
vec![ HTLCDestination :: UnknownNextHop { requested_forward_scid: $failed_scid } ] ) ;
540
- check_closed_broadcast( & $curr_node, 1 , true ) ;
541
- check_added_monitors!( $curr_node, 1 ) ;
542
567
$curr_node. node. process_pending_htlc_forwards( ) ;
543
568
} ,
544
569
}
@@ -624,6 +649,7 @@ fn do_blinded_intercept_payment(intercept_node_fails: bool) {
624
649
} ;
625
650
nodes[ 1 ] . node . handle_update_add_htlc ( nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
626
651
commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 0 ] , & payment_event. commitment_msg, false , true ) ;
652
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
627
653
628
654
let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
629
655
assert_eq ! ( events. len( ) , 1 ) ;
@@ -929,13 +955,19 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
929
955
nodes[ 2 ] . node . handle_update_add_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , update_add) ;
930
956
check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
931
957
do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & payment_event_1_2. commitment_msg , true , true ) ;
958
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
959
+ expect_htlc_handling_failed_destinations ! ( nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: InvalidOnion ] ) ;
960
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
932
961
} ,
933
962
ReceiveCheckFail :: ReceiveRequirements => {
934
963
let update_add = & mut payment_event_1_2. msgs [ 0 ] ;
935
964
update_add. amount_msat -= 1 ;
936
965
nodes[ 2 ] . node . handle_update_add_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , update_add) ;
937
966
check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
938
967
do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & payment_event_1_2. commitment_msg , true , true ) ;
968
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
969
+ expect_htlc_handling_failed_destinations ! ( nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: FailedPayment { payment_hash } ] ) ;
970
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
939
971
} ,
940
972
ReceiveCheckFail :: ChannelCheck => {
941
973
nodes[ 2 ] . node . close_channel ( & chan_id_1_2, & nodes[ 1 ] . node . get_our_node_id ( ) ) . unwrap ( ) ;
@@ -949,6 +981,9 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
949
981
950
982
nodes[ 2 ] . node . handle_shutdown ( nodes[ 1 ] . node . get_our_node_id ( ) , & node_1_shutdown) ;
951
983
commitment_signed_dance ! ( nodes[ 2 ] , nodes[ 1 ] , ( ) , false , true , false , false ) ;
984
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
985
+ expect_htlc_handling_failed_destinations ! ( nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: FailedPayment { payment_hash } ] ) ;
986
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
952
987
} ,
953
988
ReceiveCheckFail :: ProcessPendingHTLCsCheck => {
954
989
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 ) ;
@@ -964,6 +999,9 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
964
999
nodes[ 2 ] . node . handle_update_add_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , & payment_event_1_2. msgs [ 0 ] ) ;
965
1000
check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
966
1001
do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & payment_event_1_2. commitment_msg , true , true ) ;
1002
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
1003
+ expect_htlc_handling_failed_destinations ! ( nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: FailedPayment { payment_hash } ] ) ;
1004
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
967
1005
}
968
1006
}
969
1007
@@ -1164,6 +1202,12 @@ fn min_htlc() {
1164
1202
nodes[ 1 ] . node . handle_update_add_htlc ( nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event_0_1. msgs [ 0 ] ) ;
1165
1203
check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
1166
1204
do_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 0 ] , & payment_event_0_1. commitment_msg , true , true ) ;
1205
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
1206
+ expect_htlc_handling_failed_destinations ! (
1207
+ nodes[ 1 ] . node. get_and_clear_pending_events( ) ,
1208
+ & [ HTLCDestination :: NextHopChannel { node_id: Some ( nodes[ 2 ] . node. get_our_node_id( ) ) , channel_id: chan_1_2. 2 } ]
1209
+ ) ;
1210
+ check_added_monitors ( & nodes[ 1 ] , 1 ) ;
1167
1211
let mut updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
1168
1212
nodes[ 0 ] . node . handle_update_fail_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , & updates. update_fail_htlcs [ 0 ] ) ;
1169
1213
do_commitment_signed_dance ( & nodes[ 0 ] , & nodes[ 1 ] , & updates. commitment_signed , false , false ) ;
@@ -1350,9 +1394,11 @@ fn fails_receive_tlvs_authentication() {
1350
1394
let mut payment_event = SendEvent :: from_event ( ev) ;
1351
1395
1352
1396
nodes[ 1 ] . node . handle_update_add_htlc ( nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
1353
- check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
1354
1397
do_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 0 ] , & payment_event. commitment_msg , true , true ) ;
1398
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
1355
1399
nodes[ 1 ] . node . process_pending_htlc_forwards ( ) ;
1400
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
1401
+ expect_htlc_handling_failed_destinations ! ( nodes[ 1 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: InvalidOnion ] ) ;
1356
1402
1357
1403
let mut update_fail = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
1358
1404
assert ! ( update_fail. update_fail_htlcs. len( ) == 1 ) ;
0 commit comments