@@ -309,8 +309,10 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
309
309
// We need the session priv to construct a bogus onion packet later.
310
310
* nodes[ 0 ] . keys_manager . override_random_bytes . lock ( ) . unwrap ( ) = Some ( [ 3 ; 32 ] ) ;
311
311
create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
312
- let chan_upd_1_2 = create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) . 0 . contents ;
313
- let chan_upd_2_3 = create_announced_chan_between_nodes_with_value ( & nodes, 2 , 3 , 1_000_000 , 0 ) . 0 . contents ;
312
+ let chan_1_2 = create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) ;
313
+ let chan_upd_1_2 = chan_1_2. 0 . contents ;
314
+ let chan_2_3 = create_announced_chan_between_nodes_with_value ( & nodes, 2 , 3 , 1_000_000 , 0 ) ;
315
+ let chan_upd_2_3 = chan_2_3. 0 . contents ;
314
316
315
317
let amt_msat = 5000 ;
316
318
let ( _, payment_hash, payment_secret) = get_payment_preimage_hash ( & nodes[ 3 ] , Some ( amt_msat) , None ) ;
@@ -364,18 +366,27 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
364
366
check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
365
367
do_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 0 ] , & updates_0_1. commitment_signed , true , true ) ;
366
368
369
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
370
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
371
+
367
372
if intro_fails {
368
373
let mut updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
369
374
nodes[ 0 ] . node . handle_update_fail_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , & updates. update_fail_htlcs [ 0 ] ) ;
370
375
do_commitment_signed_dance ( & nodes[ 0 ] , & nodes[ 1 ] , & updates. commitment_signed , false , false ) ;
376
+ let failed_destination = match check {
377
+ ForwardCheckFail :: InboundOnionCheck => HTLCDestination :: InvalidOnion ,
378
+ ForwardCheckFail :: ForwardPayloadEncodedAsReceive => HTLCDestination :: FailedPayment { payment_hash } ,
379
+ ForwardCheckFail :: OutboundChannelCheck =>
380
+ HTLCDestination :: NextHopChannel { node_id : Some ( nodes[ 2 ] . node . get_our_node_id ( ) ) , channel_id : chan_1_2. 2 } ,
381
+ } ;
382
+ expect_htlc_handling_failed_destinations ! (
383
+ nodes[ 1 ] . node. get_and_clear_pending_events( ) , & [ failed_destination. clone( ) ]
384
+ ) ;
371
385
expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false ,
372
386
PaymentFailedConditions :: new ( ) . expected_htlc_error_data ( INVALID_ONION_BLINDING , & [ 0 ; 32 ] ) ) ;
373
387
return
374
388
}
375
389
376
- expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
377
- check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
378
-
379
390
let mut updates_1_2 = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 2 ] . node. get_our_node_id( ) ) ;
380
391
let mut update_add = & mut updates_1_2. update_add_htlcs [ 0 ] ;
381
392
@@ -385,6 +396,17 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
385
396
check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
386
397
do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & updates_1_2. commitment_signed , true , true ) ;
387
398
399
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
400
+ let failed_destination = match check {
401
+ ForwardCheckFail :: InboundOnionCheck |ForwardCheckFail :: ForwardPayloadEncodedAsReceive => HTLCDestination :: InvalidOnion ,
402
+ ForwardCheckFail :: OutboundChannelCheck =>
403
+ HTLCDestination :: NextHopChannel { node_id : Some ( nodes[ 3 ] . node . get_our_node_id ( ) ) , channel_id : chan_2_3. 2 } ,
404
+ } ;
405
+ expect_htlc_handling_failed_destinations ! (
406
+ nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ failed_destination. clone( ) ]
407
+ ) ;
408
+ check_added_monitors ! ( nodes[ 2 ] , 1 ) ;
409
+
388
410
let mut updates = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
389
411
let update_malformed = & mut updates. update_fail_malformed_htlcs [ 0 ] ;
390
412
assert_eq ! ( update_malformed. failure_code, INVALID_ONION_BLINDING ) ;
@@ -444,7 +466,10 @@ fn failed_backwards_to_intro_node() {
444
466
nodes[ 2 ] . node . handle_update_add_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
445
467
check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
446
468
do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & payment_event. commitment_msg , true , true ) ;
447
- nodes[ 2 ] . node . process_pending_htlc_forwards ( ) ;
469
+
470
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
471
+ expect_htlc_handling_failed_destinations ! ( nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: InvalidOnion ] ) ;
472
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
448
473
449
474
let mut updates = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
450
475
let mut update_malformed = & mut updates. update_fail_malformed_htlcs [ 0 ] ;
@@ -521,7 +546,7 @@ fn do_forward_fail_in_process_pending_htlc_fwds(check: ProcessPendingHTLCsCheck,
521
546
// intro node will error backwards.
522
547
$curr_node. node. peer_disconnected( $next_node. node. get_our_node_id( ) ) ;
523
548
expect_pending_htlcs_forwardable!( $curr_node) ;
524
- expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore !( $curr_node,
549
+ expect_htlc_handling_failed_destinations !( $curr_node. node . get_and_clear_pending_events ( ) ,
525
550
vec![ HTLCDestination :: NextHopChannel { node_id: Some ( $next_node. node. get_our_node_id( ) ) , channel_id: $failed_chan_id } ] ) ;
526
551
} ,
527
552
ProcessPendingHTLCsCheck :: FwdChannelClosed => {
@@ -537,12 +562,12 @@ fn do_forward_fail_in_process_pending_htlc_fwds(check: ProcessPendingHTLCsCheck,
537
562
crate :: events:: Event :: ChannelClosed { .. } => { } ,
538
563
_ => panic!( "Unexpected event {:?}" , events) ,
539
564
}
565
+ check_closed_broadcast( & $curr_node, 1 , true ) ;
566
+ check_added_monitors!( $curr_node, 1 ) ;
540
567
541
568
$curr_node. node. process_pending_htlc_forwards( ) ;
542
- expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore !( $curr_node,
569
+ expect_htlc_handling_failed_destinations !( $curr_node. node . get_and_clear_pending_events ( ) ,
543
570
vec![ HTLCDestination :: UnknownNextHop { requested_forward_scid: $failed_scid } ] ) ;
544
- check_closed_broadcast( & $curr_node, 1 , true ) ;
545
- check_added_monitors!( $curr_node, 1 ) ;
546
571
$curr_node. node. process_pending_htlc_forwards( ) ;
547
572
} ,
548
573
}
@@ -628,6 +653,7 @@ fn do_blinded_intercept_payment(intercept_node_fails: bool) {
628
653
} ;
629
654
nodes[ 1 ] . node . handle_update_add_htlc ( nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
630
655
commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 0 ] , & payment_event. commitment_msg, false , true ) ;
656
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
631
657
632
658
let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
633
659
assert_eq ! ( events. len( ) , 1 ) ;
@@ -933,13 +959,19 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
933
959
nodes[ 2 ] . node . handle_update_add_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , update_add) ;
934
960
check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
935
961
do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & payment_event_1_2. commitment_msg , true , true ) ;
962
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
963
+ expect_htlc_handling_failed_destinations ! ( nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: InvalidOnion ] ) ;
964
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
936
965
} ,
937
966
ReceiveCheckFail :: ReceiveRequirements => {
938
967
let update_add = & mut payment_event_1_2. msgs [ 0 ] ;
939
968
update_add. amount_msat -= 1 ;
940
969
nodes[ 2 ] . node . handle_update_add_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , update_add) ;
941
970
check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
942
971
do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & payment_event_1_2. commitment_msg , true , true ) ;
972
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
973
+ expect_htlc_handling_failed_destinations ! ( nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: FailedPayment { payment_hash } ] ) ;
974
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
943
975
} ,
944
976
ReceiveCheckFail :: ChannelCheck => {
945
977
nodes[ 2 ] . node . close_channel ( & chan_id_1_2, & nodes[ 1 ] . node . get_our_node_id ( ) ) . unwrap ( ) ;
@@ -953,6 +985,9 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
953
985
954
986
nodes[ 2 ] . node . handle_shutdown ( nodes[ 1 ] . node . get_our_node_id ( ) , & node_1_shutdown) ;
955
987
commitment_signed_dance ! ( nodes[ 2 ] , nodes[ 1 ] , ( ) , false , true , false , false ) ;
988
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
989
+ expect_htlc_handling_failed_destinations ! ( nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: FailedPayment { payment_hash } ] ) ;
990
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
956
991
} ,
957
992
ReceiveCheckFail :: ProcessPendingHTLCsCheck => {
958
993
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 ) ;
@@ -968,6 +1003,9 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
968
1003
nodes[ 2 ] . node . handle_update_add_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , & payment_event_1_2. msgs [ 0 ] ) ;
969
1004
check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
970
1005
do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & payment_event_1_2. commitment_msg , true , true ) ;
1006
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
1007
+ expect_htlc_handling_failed_destinations ! ( nodes[ 2 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: FailedPayment { payment_hash } ] ) ;
1008
+ check_added_monitors ( & nodes[ 2 ] , 1 ) ;
971
1009
}
972
1010
}
973
1011
@@ -1168,6 +1206,12 @@ fn min_htlc() {
1168
1206
nodes[ 1 ] . node . handle_update_add_htlc ( nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event_0_1. msgs [ 0 ] ) ;
1169
1207
check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
1170
1208
do_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 0 ] , & payment_event_0_1. commitment_msg , true , true ) ;
1209
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
1210
+ expect_htlc_handling_failed_destinations ! (
1211
+ nodes[ 1 ] . node. get_and_clear_pending_events( ) ,
1212
+ & [ HTLCDestination :: NextHopChannel { node_id: Some ( nodes[ 2 ] . node. get_our_node_id( ) ) , channel_id: chan_1_2. 2 } ]
1213
+ ) ;
1214
+ check_added_monitors ( & nodes[ 1 ] , 1 ) ;
1171
1215
let mut updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
1172
1216
nodes[ 0 ] . node . handle_update_fail_htlc ( nodes[ 1 ] . node . get_our_node_id ( ) , & updates. update_fail_htlcs [ 0 ] ) ;
1173
1217
do_commitment_signed_dance ( & nodes[ 0 ] , & nodes[ 1 ] , & updates. commitment_signed , false , false ) ;
@@ -1497,9 +1541,11 @@ fn fails_receive_tlvs_authentication() {
1497
1541
let mut payment_event = SendEvent :: from_event ( ev) ;
1498
1542
1499
1543
nodes[ 1 ] . node . handle_update_add_htlc ( nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
1500
- check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
1501
1544
do_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 0 ] , & payment_event. commitment_msg , true , true ) ;
1545
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
1502
1546
nodes[ 1 ] . node . process_pending_htlc_forwards ( ) ;
1547
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
1548
+ expect_htlc_handling_failed_destinations ! ( nodes[ 1 ] . node. get_and_clear_pending_events( ) , & [ HTLCDestination :: InvalidOnion ] ) ;
1503
1549
1504
1550
let mut update_fail = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
1505
1551
assert ! ( update_fail. update_fail_htlcs. len( ) == 1 ) ;
0 commit comments