@@ -3402,8 +3402,7 @@ fn test_durable_preimages_on_closed_channel() {
3402
3402
do_test_durable_preimages_on_closed_channel ( false , false , false ) ;
3403
3403
}
3404
3404
3405
- #[ test]
3406
- fn test_reload_mon_update_completion_actions ( ) {
3405
+ fn do_test_reload_mon_update_completion_actions ( close_during_reload : bool ) {
3407
3406
// Test that if a `ChannelMonitorUpdate` completes but a `ChannelManager` isn't serialized
3408
3407
// before restart we run the monitor update completion action on startup.
3409
3408
let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
@@ -3462,12 +3461,32 @@ fn test_reload_mon_update_completion_actions() {
3462
3461
let manager_b = nodes[ 1 ] . node . encode ( ) ;
3463
3462
reload_node ! ( nodes[ 1 ] , & manager_b, & [ & mon_ab, & mon_bc] , persister, new_chain_monitor, nodes_1_deserialized) ;
3464
3463
3464
+ if close_during_reload {
3465
+ // Test that we still free the B<->C channel if the A<->B channel closed while we reloaded
3466
+ // (as learned about during the on-reload block connection).
3467
+ nodes[ 0 ] . node . force_close_broadcasting_latest_txn ( & chan_id_ab, & nodes[ 1 ] . node . get_our_node_id ( ) ) . unwrap ( ) ;
3468
+ check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
3469
+ check_closed_broadcast ! ( nodes[ 0 ] , true ) ;
3470
+ check_closed_event ( & nodes[ 0 ] , 1 , ClosureReason :: HolderForceClosed , false ) ;
3471
+ let as_closing_tx = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . split_off ( 0 ) ;
3472
+ mine_transaction_without_checks ( & nodes[ 1 ] , & as_closing_tx[ 0 ] ) ;
3473
+ }
3474
+
3465
3475
let bc_update_id = nodes[ 1 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) . get ( & chan_id_bc) . unwrap ( ) . 2 ;
3466
- expect_payment_forwarded ! ( nodes[ 1 ] , nodes[ 0 ] , nodes[ 2 ] , Some ( 1000 ) , false , false ) ;
3476
+ let mut events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
3477
+ assert_eq ! ( events. len( ) , if close_during_reload { 2 } else { 1 } ) ;
3478
+ expect_payment_forwarded ( events. pop ( ) . unwrap ( ) , & nodes[ 1 ] , & nodes[ 0 ] , & nodes[ 2 ] , Some ( 1000 ) , close_during_reload, false ) ;
3479
+ if close_during_reload {
3480
+ match events[ 0 ] {
3481
+ Event :: ChannelClosed { .. } => { } ,
3482
+ _ => panic ! ( ) ,
3483
+ }
3484
+ check_closed_broadcast ! ( nodes[ 1 ] , true ) ;
3485
+ }
3467
3486
3468
3487
// Once we run event processing the monitor should free, check that it was indeed the B<->C
3469
3488
// channel which was updated.
3470
- check_added_monitors ( & nodes[ 1 ] , 1 ) ;
3489
+ check_added_monitors ( & nodes[ 1 ] , if close_during_reload { 2 } else { 1 } ) ;
3471
3490
let post_ev_bc_update_id = nodes[ 1 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) . get ( & chan_id_bc) . unwrap ( ) . 2 ;
3472
3491
assert ! ( bc_update_id != post_ev_bc_update_id) ;
3473
3492
@@ -3477,3 +3496,9 @@ fn test_reload_mon_update_completion_actions() {
3477
3496
reconnect_nodes ( & nodes[ 1 ] , & nodes[ 2 ] , ( false , false ) , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( false , false ) ) ;
3478
3497
send_payment ( & nodes[ 1 ] , & [ & nodes[ 2 ] ] , 100_000 ) ;
3479
3498
}
3499
+
3500
+ #[ test]
3501
+ fn test_reload_mon_update_completion_actions ( ) {
3502
+ do_test_reload_mon_update_completion_actions ( true ) ;
3503
+ do_test_reload_mon_update_completion_actions ( false ) ;
3504
+ }
0 commit comments