@@ -2369,3 +2369,66 @@ fn test_reconnect_dup_htlc_claims() {
2369
2369
do_test_reconnect_dup_htlc_claims ( HTLCStatusAtDupClaim :: HoldingCell , true ) ;
2370
2370
do_test_reconnect_dup_htlc_claims ( HTLCStatusAtDupClaim :: Cleared , true ) ;
2371
2371
}
2372
+
2373
+ #[ test]
2374
+ fn test_temporary_error_during_shutdown ( ) {
2375
+ // Test that temporary failures when updating the monitor's shutdown script do not prevent
2376
+ // cooperative close.
2377
+ let mut config = test_default_channel_config ( ) ;
2378
+ config. channel_options . commit_upfront_shutdown_pubkey = false ;
2379
+
2380
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
2381
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
2382
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ Some ( config) , Some ( config) ] ) ;
2383
+ let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
2384
+
2385
+ let ( _, _, channel_id, funding_tx) = create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
2386
+
2387
+ * nodes[ 0 ] . chain_monitor . update_ret . lock ( ) . unwrap ( ) = Some ( Err ( ChannelMonitorUpdateErr :: TemporaryFailure ) ) ;
2388
+ * nodes[ 1 ] . chain_monitor . update_ret . lock ( ) . unwrap ( ) = Some ( Err ( ChannelMonitorUpdateErr :: TemporaryFailure ) ) ;
2389
+ close_channel ( & nodes[ 0 ] , & nodes[ 1 ] , & channel_id, funding_tx, false ) ;
2390
+ check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
2391
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
2392
+ }
2393
+
2394
+ #[ test]
2395
+ fn test_permanent_error_during_sending_shutdown ( ) {
2396
+ // Test that permanent failures when updating the monitor's shutdown script result in a force
2397
+ // close when initiating a cooperative close.
2398
+ let mut config = test_default_channel_config ( ) ;
2399
+ config. channel_options . commit_upfront_shutdown_pubkey = false ;
2400
+
2401
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
2402
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
2403
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ Some ( config) , None ] ) ;
2404
+ let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
2405
+
2406
+ let channel_id = create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) . 2 ;
2407
+ * nodes[ 0 ] . chain_monitor . update_ret . lock ( ) . unwrap ( ) = Some ( Err ( ChannelMonitorUpdateErr :: PermanentFailure ) ) ;
2408
+
2409
+ assert ! ( nodes[ 0 ] . node. close_channel( & channel_id) . is_ok( ) ) ;
2410
+ check_closed_broadcast ! ( nodes[ 0 ] , true ) ;
2411
+ check_added_monitors ! ( nodes[ 0 ] , 2 ) ;
2412
+ }
2413
+
2414
+ #[ test]
2415
+ fn test_permanent_error_during_handling_shutdown ( ) {
2416
+ // Test that permanent failures when updating the monitor's shutdown script result in a force
2417
+ // close when handling a cooperative close.
2418
+ let mut config = test_default_channel_config ( ) ;
2419
+ config. channel_options . commit_upfront_shutdown_pubkey = false ;
2420
+
2421
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
2422
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
2423
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , Some ( config) ] ) ;
2424
+ let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
2425
+
2426
+ let channel_id = create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) . 2 ;
2427
+ * nodes[ 1 ] . chain_monitor . update_ret . lock ( ) . unwrap ( ) = Some ( Err ( ChannelMonitorUpdateErr :: PermanentFailure ) ) ;
2428
+
2429
+ assert ! ( nodes[ 0 ] . node. close_channel( & channel_id) . is_ok( ) ) ;
2430
+ let shutdown = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendShutdown , nodes[ 1 ] . node. get_our_node_id( ) ) ;
2431
+ nodes[ 1 ] . node . handle_shutdown ( & nodes[ 0 ] . node . get_our_node_id ( ) , & InitFeatures :: known ( ) , & shutdown) ;
2432
+ check_closed_broadcast ! ( nodes[ 1 ] , true ) ;
2433
+ check_added_monitors ! ( nodes[ 1 ] , 2 ) ;
2434
+ }
0 commit comments