@@ -3432,8 +3432,7 @@ fn test_reload_mon_update_completion_actions() {
3432
3432
do_test_reload_mon_update_completion_actions ( false ) ;
3433
3433
}
3434
3434
3435
- #[ test]
3436
- fn test_glacial_peer_cant_hang ( ) {
3435
+ fn do_test_glacial_peer_cant_hang ( hold_chan_a : bool ) {
3437
3436
// Test that if a peer manages to send an `update_fulfill_htlc` message without a
3438
3437
// `commitment_signed`, disconnects, then replays the `update_fulfill_htlc` message it doesn't
3439
3438
// result in a channel hang. This was previously broken as the `DuplicateClaim` case wasn't
@@ -3457,13 +3456,19 @@ fn test_glacial_peer_cant_hang() {
3457
3456
expect_payment_claimed ! ( nodes[ 2 ] , payment_hash, 1_000_000 ) ;
3458
3457
3459
3458
let cs_updates = get_htlc_update_msgs ( & nodes[ 2 ] , & nodes[ 1 ] . node . get_our_node_id ( ) ) ;
3459
+ if hold_chan_a {
3460
+ // The first update will be on the A <-> B channel, which we allow to complete.
3461
+ chanmon_cfgs[ 1 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: InProgress ) ;
3462
+ }
3460
3463
nodes[ 1 ] . node . handle_update_fulfill_htlc ( & nodes[ 2 ] . node . get_our_node_id ( ) , & cs_updates. update_fulfill_htlcs [ 0 ] ) ;
3461
-
3462
3464
check_added_monitors ( & nodes[ 1 ] , 1 ) ;
3463
- let bs_updates = get_htlc_update_msgs ( & nodes[ 1 ] , & nodes[ 0 ] . node . get_our_node_id ( ) ) ;
3464
- nodes[ 0 ] . node . handle_update_fulfill_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & bs_updates. update_fulfill_htlcs [ 0 ] ) ;
3465
- commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , bs_updates. commitment_signed, false ) ;
3466
- expect_payment_sent ! ( nodes[ 0 ] , payment_preimage) ;
3465
+
3466
+ if !hold_chan_a {
3467
+ let bs_updates = get_htlc_update_msgs ( & nodes[ 1 ] , & nodes[ 0 ] . node . get_our_node_id ( ) ) ;
3468
+ nodes[ 0 ] . node . handle_update_fulfill_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & bs_updates. update_fulfill_htlcs [ 0 ] ) ;
3469
+ commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , bs_updates. commitment_signed, false ) ;
3470
+ expect_payment_sent ! ( & nodes[ 0 ] , payment_preimage) ;
3471
+ }
3467
3472
3468
3473
nodes[ 1 ] . node . peer_disconnected ( & nodes[ 2 ] . node . get_our_node_id ( ) ) ;
3469
3474
nodes[ 2 ] . node . peer_disconnected ( & nodes[ 1 ] . node . get_our_node_id ( ) ) ;
@@ -3472,7 +3477,26 @@ fn test_glacial_peer_cant_hang() {
3472
3477
reconnect. pending_htlc_claims = ( 1 , 0 ) ;
3473
3478
reconnect_nodes ( reconnect) ;
3474
3479
3475
- expect_payment_forwarded ! ( nodes[ 1 ] , nodes[ 0 ] , nodes[ 2 ] , Some ( 1000 ) , false , false ) ;
3480
+ if !hold_chan_a {
3481
+ expect_payment_forwarded ! ( nodes[ 1 ] , nodes[ 0 ] , nodes[ 2 ] , Some ( 1000 ) , false , false ) ;
3482
+ send_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , 100_000 ) ;
3483
+ } else {
3484
+ assert ! ( nodes[ 1 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
3485
+ assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
3476
3486
3477
- send_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , 100_000 ) ;
3487
+ let ( route, payment_hash_2, _, payment_secret_2) = get_route_and_payment_hash ! ( & nodes[ 1 ] , nodes[ 2 ] , 1_000_000 ) ;
3488
+
3489
+ nodes[ 1 ] . node . send_payment_with_route ( & route, payment_hash_2,
3490
+ RecipientOnionFields :: secret_only ( payment_secret_2) , PaymentId ( payment_hash_2. 0 ) ) . unwrap ( ) ;
3491
+ check_added_monitors ( & nodes[ 1 ] , 0 ) ;
3492
+
3493
+ assert ! ( nodes[ 1 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
3494
+ assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
3495
+ }
3496
+ }
3497
+
3498
+ #[ test]
3499
+ fn test_glacial_peer_cant_hang ( ) {
3500
+ do_test_glacial_peer_cant_hang ( false ) ;
3501
+ do_test_glacial_peer_cant_hang ( true ) ;
3478
3502
}
0 commit comments