@@ -3410,20 +3410,22 @@ fn test_inbound_reload_without_init_mon() {
3410
3410
do_test_inbound_reload_without_init_mon ( false , false ) ;
3411
3411
}
3412
3412
3413
- #[ test]
3414
- fn test_blocked_chan_preimage_release ( ) {
3413
+ fn do_test_blocked_chan_preimage_release ( completion_mode : u8 ) {
3415
3414
// Test that even if a channel's `ChannelMonitorUpdate` flow is blocked waiting on an event to
3416
3415
// be handled HTLC preimage `ChannelMonitorUpdate`s will still go out.
3417
3416
let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
3418
3417
let node_cfgs = create_node_cfgs ( 3 , & chanmon_cfgs) ;
3418
+ let persister;
3419
+ let new_chain_mon;
3419
3420
let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & [ None , None , None ] ) ;
3421
+ let nodes_1_reload;
3420
3422
let mut nodes = create_network ( 3 , & node_cfgs, & node_chanmgrs) ;
3421
3423
3422
3424
let node_a_id = nodes[ 0 ] . node . get_our_node_id ( ) ;
3423
3425
let node_b_id = nodes[ 1 ] . node . get_our_node_id ( ) ;
3424
3426
let node_c_id = nodes[ 2 ] . node . get_our_node_id ( ) ;
3425
3427
3426
- create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
3428
+ let chan_id_1 = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) . 2 ;
3427
3429
let chan_id_2 = create_announced_chan_between_nodes ( & nodes, 1 , 2 ) . 2 ;
3428
3430
3429
3431
send_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , 5_000_000 ) ;
@@ -3456,29 +3458,63 @@ fn test_blocked_chan_preimage_release() {
3456
3458
expect_payment_claimed ! ( nodes[ 0 ] , payment_hash_2, 1_000_000 ) ;
3457
3459
3458
3460
let as_htlc_fulfill_updates = get_htlc_update_msgs ! ( nodes[ 0 ] , node_b_id) ;
3461
+ if completion_mode != 0 {
3462
+ // We use to incorrectly handle monitor update completion in cases where we completed a
3463
+ // monitor update async or after reload. We test both based on the `completion_mode`.
3464
+ chanmon_cfgs[ 1 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: InProgress ) ;
3465
+ }
3459
3466
nodes[ 1 ]
3460
3467
. node
3461
3468
. handle_update_fulfill_htlc ( node_a_id, & as_htlc_fulfill_updates. update_fulfill_htlcs [ 0 ] ) ;
3462
3469
check_added_monitors ( & nodes[ 1 ] , 1 ) ; // We generate only a preimage monitor update
3463
3470
assert ! ( get_monitor!( nodes[ 1 ] , chan_id_2) . get_stored_preimages( ) . contains_key( & payment_hash_2) ) ;
3464
3471
assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
3472
+ if completion_mode == 1 {
3473
+ let node_ser = nodes[ 1 ] . node . encode ( ) ;
3474
+ let chan_mon_0 = get_monitor ! ( nodes[ 1 ] , chan_id_1) . encode ( ) ;
3475
+ let chan_mon_1 = get_monitor ! ( nodes[ 1 ] , chan_id_2) . encode ( ) ;
3476
+
3477
+ let mons = & [ & chan_mon_0[ ..] , & chan_mon_1[ ..] ] ;
3478
+ reload_node ! ( nodes[ 1 ] , & node_ser, mons, persister, new_chain_mon, nodes_1_reload) ;
3479
+
3480
+ nodes[ 0 ] . node . peer_disconnected ( node_b_id) ;
3481
+ nodes[ 2 ] . node . peer_disconnected ( node_b_id) ;
3482
+
3483
+ let mut a_b_reconnect = ReconnectArgs :: new ( & nodes[ 0 ] , & nodes[ 1 ] ) ;
3484
+ a_b_reconnect. pending_htlc_claims . 1 = 1 ;
3485
+ // Note that we will expect no final RAA monitor update in
3486
+ // `commitment_signed_dance_through_cp_raa` during the reconnect, matching the below case.
3487
+ reconnect_nodes ( a_b_reconnect) ;
3488
+ reconnect_nodes ( ReconnectArgs :: new ( & nodes[ 2 ] , & nodes[ 1 ] ) ) ;
3489
+ } else if completion_mode == 2 {
3490
+ let ( latest_update, _) = get_latest_mon_update_id ( & nodes[ 1 ] , chan_id_2) ;
3491
+ nodes[ 1 ]
3492
+ . chain_monitor
3493
+ . chain_monitor
3494
+ . channel_monitor_updated ( chan_id_2, latest_update)
3495
+ . unwrap ( ) ;
3496
+ }
3465
3497
3466
3498
// Finish the CS dance between nodes[0] and nodes[1]. Note that until the event handling, the
3467
3499
// update_fulfill_htlc + CS is held, even though the preimage is already on disk for the
3468
3500
// channel.
3469
- nodes[ 1 ]
3470
- . node
3471
- . handle_commitment_signed_batch_test ( node_a_id, & as_htlc_fulfill_updates. commitment_signed ) ;
3472
- check_added_monitors ( & nodes[ 1 ] , 1 ) ;
3473
- let ( a, raa) = do_main_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 0 ] , false ) ;
3474
- assert ! ( a. is_none( ) ) ;
3501
+ // Note that in completion_mode 1 we completed the CS dance in `reconnect_nodes` above.
3502
+ if completion_mode != 1 {
3503
+ nodes[ 1 ] . node . handle_commitment_signed_batch_test (
3504
+ node_a_id,
3505
+ & as_htlc_fulfill_updates. commitment_signed ,
3506
+ ) ;
3507
+ check_added_monitors ( & nodes[ 1 ] , 1 ) ;
3508
+ let ( a, raa) = do_main_commitment_signed_dance ( & nodes[ 1 ] , & nodes[ 0 ] , false ) ;
3509
+ assert ! ( a. is_none( ) ) ;
3475
3510
3476
- nodes[ 1 ] . node . handle_revoke_and_ack ( node_a_id, & raa) ;
3477
- check_added_monitors ( & nodes[ 1 ] , 0 ) ;
3478
- assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
3511
+ nodes[ 1 ] . node . handle_revoke_and_ack ( node_a_id, & raa) ;
3512
+ check_added_monitors ( & nodes[ 1 ] , 0 ) ;
3513
+ assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
3514
+ }
3479
3515
3480
3516
let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
3481
- assert_eq ! ( events. len( ) , 3 ) ;
3517
+ assert_eq ! ( events. len( ) , 3 , "{events:?}" ) ;
3482
3518
if let Event :: PaymentSent { .. } = events[ 0 ] {
3483
3519
} else {
3484
3520
panic ! ( ) ;
@@ -3508,6 +3544,13 @@ fn test_blocked_chan_preimage_release() {
3508
3544
expect_payment_sent ( & nodes[ 2 ] , payment_preimage_2, None , true , true ) ;
3509
3545
}
3510
3546
3547
+ #[ test]
3548
+ fn test_blocked_chan_preimage_release ( ) {
3549
+ do_test_blocked_chan_preimage_release ( 0 ) ;
3550
+ do_test_blocked_chan_preimage_release ( 1 ) ;
3551
+ do_test_blocked_chan_preimage_release ( 2 ) ;
3552
+ }
3553
+
3511
3554
fn do_test_inverted_mon_completion_order (
3512
3555
with_latest_manager : bool , complete_bc_commitment_dance : bool ,
3513
3556
) {
0 commit comments