@@ -336,8 +336,10 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
336
336
// We need the session priv to construct a bogus onion packet later.
337
337
* nodes[ 0 ] . keys_manager . override_random_bytes . lock ( ) . unwrap ( ) = Some ( [ 3 ; 32 ] ) ;
338
338
create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
339
- let chan_upd_1_2 = create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) . 0 . contents ;
340
- let chan_upd_2_3 = create_announced_chan_between_nodes_with_value ( & nodes, 2 , 3 , 1_000_000 , 0 ) . 0 . contents ;
339
+ let chan_1_2 = create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) ;
340
+ let chan_upd_1_2 = chan_1_2. 0 . contents ;
341
+ let chan_2_3 = create_announced_chan_between_nodes_with_value ( & nodes, 2 , 3 , 1_000_000 , 0 ) ;
342
+ let chan_upd_2_3 = chan_2_3. 0 . contents ;
341
343
342
344
let amt_msat = 5000 ;
343
345
let ( _, payment_hash, payment_secret) = get_payment_preimage_hash ( & nodes[ 3 ] , Some ( amt_msat) , None ) ;
@@ -391,14 +393,27 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
391
393
check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
392
394
do_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 0 ] , & updates_0_1. commitment_signed , true , true ) ;
393
395
396
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
397
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
398
+
394
399
if intro_fails {
395
- fail_blinded_htlc_backwards ( payment_hash, 1 , & [ & nodes[ 0 ] , & nodes[ 1 ] ] ) ;
400
+ let mut updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
401
+ nodes[ 0 ] . node . handle_update_fail_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , & updates. update_fail_htlcs [ 0 ] ) ;
402
+ do_commitment_signed_dance ( & nodes[ 0 ] , & nodes[ 1 ] , & updates. commitment_signed , false , false ) ;
403
+ let failed_destination = match check {
404
+ ForwardCheckFail :: InboundOnionCheck => HTLCDestination :: InvalidOnion ,
405
+ ForwardCheckFail :: ForwardPayloadEncodedAsReceive => HTLCDestination :: FailedPayment { payment_hash } ,
406
+ ForwardCheckFail :: OutboundChannelCheck =>
407
+ HTLCDestination :: NextHopChannel { node_id : Some ( nodes[ 2 ] . node . get_our_node_id ( ) ) , channel_id : chan_1_2. 2 } ,
408
+ } ;
409
+ expect_htlc_handling_failed_destinations ! (
410
+ nodes[ 1 ] . node. get_and_clear_pending_events( ) , & [ failed_destination. clone( ) ]
411
+ ) ;
412
+ expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false ,
413
+ PaymentFailedConditions :: new ( ) . expected_htlc_error_data ( INVALID_ONION_BLINDING , & [ 0 ; 32 ] ) ) ;
396
414
return
397
415
}
398
416
399
- expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
400
- check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
401
-
402
417
let mut updates_1_2 = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 2 ] . node. get_our_node_id( ) ) ;
403
418
let mut update_add = & mut updates_1_2. update_add_htlcs [ 0 ] ;
404
419
@@ -408,6 +423,17 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
408
423
check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
409
424
do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & updates_1_2. commitment_signed , true , true ) ;
410
425
426
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
427
+ let failed_destination = match check {
428
+ ForwardCheckFail :: InboundOnionCheck |ForwardCheckFail :: ForwardPayloadEncodedAsReceive => HTLCDestination :: InvalidOnion ,
429
+ ForwardCheckFail :: OutboundChannelCheck =>
430
+ HTLCDestination :: NextHopChannel { node_id : Some ( nodes[ 3 ] . node . get_our_node_id ( ) ) , channel_id : chan_2_3. 2 } ,
431
+ } ;
432
+ expect_htlc_handling_failed_destinations ! (
433
+ nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ failed_destination. clone( ) ]
434
+ ) ;
435
+ check_added_monitors ! ( nodes[ 2 ] , 1 ) ;
436
+
411
437
let mut updates = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
412
438
let update_malformed = & mut updates. update_fail_malformed_htlcs [ 0 ] ;
413
439
assert_eq ! ( update_malformed. failure_code, INVALID_ONION_BLINDING ) ;
@@ -467,7 +493,10 @@ fn failed_backwards_to_intro_node() {
467
493
nodes[ 2 ] . node . handle_update_add_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
468
494
check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
469
495
do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & payment_event. commitment_msg , true , true ) ;
470
- nodes[ 2 ] . node . process_pending_htlc_forwards ( ) ;
496
+
497
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
498
+ expect_htlc_handling_failed_destinations ! ( nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: InvalidOnion ] ) ;
499
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
471
500
472
501
let mut updates = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
473
502
let mut update_malformed = & mut updates. update_fail_malformed_htlcs [ 0 ] ;
@@ -544,7 +573,7 @@ fn do_forward_fail_in_process_pending_htlc_fwds(check: ProcessPendingHTLCsCheck,
544
573
// intro node will error backwards.
545
574
$curr_node. node. peer_disconnected( $next_node. node. get_our_node_id( ) ) ;
546
575
expect_pending_htlcs_forwardable!( $curr_node) ;
547
- expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore !( $curr_node,
576
+ expect_htlc_handling_failed_destinations !( $curr_node. node . get_and_clear_pending_events ( ) ,
548
577
vec![ HTLCDestination :: NextHopChannel { node_id: Some ( $next_node. node. get_our_node_id( ) ) , channel_id: $failed_chan_id } ] ) ;
549
578
} ,
550
579
ProcessPendingHTLCsCheck :: FwdChannelClosed => {
@@ -560,12 +589,12 @@ fn do_forward_fail_in_process_pending_htlc_fwds(check: ProcessPendingHTLCsCheck,
560
589
crate :: events:: Event :: ChannelClosed { .. } => { } ,
561
590
_ => panic!( "Unexpected event {:?}" , events) ,
562
591
}
592
+ check_closed_broadcast( & $curr_node, 1 , true ) ;
593
+ check_added_monitors!( $curr_node, 1 ) ;
563
594
564
595
$curr_node. node. process_pending_htlc_forwards( ) ;
565
- expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore !( $curr_node,
596
+ expect_htlc_handling_failed_destinations !( $curr_node. node . get_and_clear_pending_events ( ) ,
566
597
vec![ HTLCDestination :: UnknownNextHop { requested_forward_scid: $failed_scid } ] ) ;
567
- check_closed_broadcast( & $curr_node, 1 , true ) ;
568
- check_added_monitors!( $curr_node, 1 ) ;
569
598
$curr_node. node. process_pending_htlc_forwards( ) ;
570
599
} ,
571
600
}
@@ -646,6 +675,7 @@ fn do_blinded_intercept_payment(intercept_node_fails: bool) {
646
675
} ;
647
676
nodes[ 1 ] . node . handle_update_add_htlc ( nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
648
677
commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 0 ] , & payment_event. commitment_msg, false , true ) ;
678
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
649
679
650
680
let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
651
681
assert_eq ! ( events. len( ) , 1 ) ;
@@ -923,13 +953,19 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
923
953
nodes[ 2 ] . node . handle_update_add_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , update_add) ;
924
954
check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
925
955
do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & payment_event_1_2. commitment_msg , true , true ) ;
956
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
957
+ expect_htlc_handling_failed_destinations ! ( nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: InvalidOnion ] ) ;
958
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
926
959
} ,
927
960
ReceiveCheckFail :: ReceiveRequirements => {
928
961
let update_add = & mut payment_event_1_2. msgs [ 0 ] ;
929
962
update_add. amount_msat -= 1 ;
930
963
nodes[ 2 ] . node . handle_update_add_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , update_add) ;
931
964
check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
932
965
do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & payment_event_1_2. commitment_msg , true , true ) ;
966
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
967
+ expect_htlc_handling_failed_destinations ! ( nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: FailedPayment { payment_hash } ] ) ;
968
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
933
969
} ,
934
970
ReceiveCheckFail :: ChannelCheck => {
935
971
nodes[ 2 ] . node . close_channel ( & chan_id_1_2, & nodes[ 1 ] . node . get_our_node_id ( ) ) . unwrap ( ) ;
@@ -943,6 +979,9 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
943
979
944
980
nodes[ 2 ] . node . handle_shutdown ( nodes[ 1 ] . node . get_our_node_id ( ) , & node_1_shutdown) ;
945
981
commitment_signed_dance ! ( nodes[ 2 ] , nodes[ 1 ] , ( ) , false , true , false , false ) ;
982
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
983
+ expect_htlc_handling_failed_destinations ! ( nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: FailedPayment { payment_hash } ] ) ;
984
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
946
985
} ,
947
986
ReceiveCheckFail :: ProcessPendingHTLCsCheck => {
948
987
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 ) ;
@@ -958,6 +997,9 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
958
997
nodes[ 2 ] . node . handle_update_add_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , & payment_event_1_2. msgs [ 0 ] ) ;
959
998
check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
960
999
do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & payment_event_1_2. commitment_msg , true , true ) ;
1000
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
1001
+ expect_htlc_handling_failed_destinations ! ( nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: FailedPayment { payment_hash } ] ) ;
1002
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
961
1003
}
962
1004
}
963
1005
@@ -1158,6 +1200,12 @@ fn min_htlc() {
1158
1200
nodes[ 1 ] . node . handle_update_add_htlc ( nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event_0_1. msgs [ 0 ] ) ;
1159
1201
check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
1160
1202
do_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 0 ] , & payment_event_0_1. commitment_msg , true , true ) ;
1203
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
1204
+ expect_htlc_handling_failed_destinations ! (
1205
+ nodes[ 1 ] . node. get_and_clear_pending_events( ) ,
1206
+ & [ HTLCDestination :: NextHopChannel { node_id: Some ( nodes[ 2 ] . node. get_our_node_id( ) ) , channel_id: chan_1_2. 2 } ]
1207
+ ) ;
1208
+ check_added_monitors ( & nodes[ 1 ] , 1 ) ;
1161
1209
let mut updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
1162
1210
nodes[ 0 ] . node . handle_update_fail_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , & updates. update_fail_htlcs [ 0 ] ) ;
1163
1211
do_commitment_signed_dance ( & nodes[ 0 ] , & nodes[ 1 ] , & updates. commitment_signed , false , false ) ;
@@ -1344,9 +1392,11 @@ fn fails_receive_tlvs_authentication() {
1344
1392
let mut payment_event = SendEvent :: from_event ( ev) ;
1345
1393
1346
1394
nodes[ 1 ] . node . handle_update_add_htlc ( nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
1347
- check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
1348
1395
do_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 0 ] , & payment_event. commitment_msg , true , true ) ;
1396
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
1349
1397
nodes[ 1 ] . node . process_pending_htlc_forwards ( ) ;
1398
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
1399
+ expect_htlc_handling_failed_destinations ! ( nodes[ 1 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: InvalidOnion ] ) ;
1350
1400
1351
1401
let mut update_fail = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
1352
1402
assert ! ( update_fail. update_fail_htlcs. len( ) == 1 ) ;
0 commit comments