@@ -424,26 +424,32 @@ enum ProcessPendingHTLCsCheck {
424
424
425
425
#[ test]
426
426
fn forward_fail_in_process_pending_htlc_fwds ( ) {
427
- do_forward_fail_in_process_pending_htlc_fwds ( ProcessPendingHTLCsCheck :: FwdPeerDisconnected ) ;
428
- do_forward_fail_in_process_pending_htlc_fwds ( ProcessPendingHTLCsCheck :: FwdChannelClosed ) ;
427
+ do_forward_fail_in_process_pending_htlc_fwds ( ProcessPendingHTLCsCheck :: FwdPeerDisconnected , true ) ;
428
+ do_forward_fail_in_process_pending_htlc_fwds ( ProcessPendingHTLCsCheck :: FwdPeerDisconnected , false ) ;
429
+ do_forward_fail_in_process_pending_htlc_fwds ( ProcessPendingHTLCsCheck :: FwdChannelClosed , true ) ;
430
+ do_forward_fail_in_process_pending_htlc_fwds ( ProcessPendingHTLCsCheck :: FwdChannelClosed , false ) ;
429
431
}
430
- fn do_forward_fail_in_process_pending_htlc_fwds ( check : ProcessPendingHTLCsCheck ) {
432
+ fn do_forward_fail_in_process_pending_htlc_fwds ( check : ProcessPendingHTLCsCheck , intro_fails : bool ) {
431
433
// Ensure the intro node will error backwards properly if the HTLC fails in
432
434
// process_pending_htlc_forwards.
433
- let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
434
- let node_cfgs = create_node_cfgs ( 3 , & chanmon_cfgs) ;
435
- let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & [ None , None , None ] ) ;
436
- let mut nodes = create_network ( 3 , & node_cfgs, & node_chanmgrs) ;
435
+ let chanmon_cfgs = create_chanmon_cfgs ( 4 ) ;
436
+ let node_cfgs = create_node_cfgs ( 4 , & chanmon_cfgs) ;
437
+ let node_chanmgrs = create_node_chanmgrs ( 4 , & node_cfgs, & [ None , None , None , None ] ) ;
438
+ let mut nodes = create_network ( 4 , & node_cfgs, & node_chanmgrs) ;
437
439
create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
438
440
let ( chan_upd_1_2, chan_id_1_2) = {
439
441
let chan = create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) ;
440
442
( chan. 0 . contents , chan. 2 )
441
443
} ;
444
+ let ( chan_upd_2_3, chan_id_2_3) = {
445
+ let chan = create_announced_chan_between_nodes_with_value ( & nodes, 2 , 3 , 1_000_000 , 0 ) ;
446
+ ( chan. 0 . contents , chan. 2 )
447
+ } ;
442
448
443
449
let amt_msat = 5000 ;
444
450
let ( _, payment_hash, payment_secret) = get_payment_preimage_hash ( & nodes[ 2 ] , Some ( amt_msat) , None ) ;
445
451
let route_params = get_blinded_route_parameters ( amt_msat, payment_secret,
446
- nodes. iter ( ) . skip ( 1 ) . map ( |n| n. node . get_our_node_id ( ) ) . collect ( ) , & [ & chan_upd_1_2] ,
452
+ nodes. iter ( ) . skip ( 1 ) . map ( |n| n. node . get_our_node_id ( ) ) . collect ( ) , & [ & chan_upd_1_2, & chan_upd_2_3 ] ,
447
453
& chanmon_cfgs[ 2 ] . keys_manager ) ;
448
454
449
455
nodes[ 0 ] . node . send_payment ( payment_hash, RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( payment_hash. 0 ) , route_params, Retry :: Attempts ( 0 ) ) . unwrap ( ) ;
@@ -494,12 +500,44 @@ fn do_forward_fail_in_process_pending_htlc_fwds(check: ProcessPendingHTLCsCheck)
494
500
}
495
501
}
496
502
497
- cause_error ! ( nodes[ 0 ] , nodes[ 1 ] , nodes[ 2 ] , chan_id_1_2, chan_upd_1_2. short_channel_id) ;
503
+ if intro_fails {
504
+ cause_error ! ( nodes[ 0 ] , nodes[ 1 ] , nodes[ 2 ] , chan_id_1_2, chan_upd_1_2. short_channel_id) ;
505
+ let mut updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
506
+ nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & updates. update_fail_htlcs [ 0 ] ) ;
507
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
508
+ do_commitment_signed_dance ( & nodes[ 0 ] , & nodes[ 1 ] , & updates. commitment_signed , false , false ) ;
509
+
510
+ expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false ,
511
+ PaymentFailedConditions :: new ( ) . expected_htlc_error_data ( INVALID_ONION_BLINDING , & [ 0 ; 32 ] ) ) ;
512
+ return
513
+ }
514
+
515
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
516
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
517
+
518
+ let mut updates_1_2 = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 2 ] . node. get_our_node_id( ) ) ;
519
+ let mut update_add = & mut updates_1_2. update_add_htlcs [ 0 ] ;
520
+ nodes[ 2 ] . node . handle_update_add_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & update_add) ;
521
+ check_added_monitors ! ( nodes[ 2 ] , 0 ) ;
522
+ do_commitment_signed_dance ( & nodes[ 2 ] , & nodes[ 1 ] , & updates_1_2. commitment_signed , true , true ) ;
523
+
524
+ cause_error ! ( nodes[ 1 ] , nodes[ 2 ] , nodes[ 3 ] , chan_id_2_3, chan_upd_2_3. short_channel_id) ;
525
+ check_added_monitors ! ( nodes[ 2 ] , 1 ) ;
526
+
527
+ let mut updates = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
528
+ let update_malformed = & mut updates. update_fail_malformed_htlcs [ 0 ] ;
529
+ assert_eq ! ( update_malformed. failure_code, INVALID_ONION_BLINDING ) ;
530
+ assert_eq ! ( update_malformed. sha256_of_onion, [ 0 ; 32 ] ) ;
531
+
532
+ // Ensure the intro node will properly blind the error if its downstream node failed to do so.
533
+ update_malformed. sha256_of_onion = [ 1 ; 32 ] ;
534
+ update_malformed. failure_code = INVALID_ONION_BLINDING ^ 1 ;
535
+ nodes[ 1 ] . node . handle_update_fail_malformed_htlc ( & nodes[ 2 ] . node . get_our_node_id ( ) , update_malformed) ;
536
+ do_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 2 ] , & updates. commitment_signed , true , false ) ;
537
+
498
538
let mut updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
499
539
nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & updates. update_fail_htlcs [ 0 ] ) ;
500
- check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
501
540
do_commitment_signed_dance ( & nodes[ 0 ] , & nodes[ 1 ] , & updates. commitment_signed , false , false ) ;
502
-
503
541
expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false ,
504
542
PaymentFailedConditions :: new ( ) . expected_htlc_error_data ( INVALID_ONION_BLINDING , & [ 0 ; 32 ] ) ) ;
505
543
}
0 commit comments