@@ -7144,7 +7144,13 @@ where
7144
7144
// peer we probably failed to send the open_channel message, which is now
7145
7145
// lost. We can't have had anything pending related to this channel, so we just
7146
7146
// drop it.
7147
- chan. context . have_received_message ( )
7147
+ let retain = chan. context . have_received_message ( ) ;
7148
+ if !retain {
7149
+ log_error ! ( self . logger, "Force-closing channel {}" , log_bytes!( chan. context. channel_id( ) ) ) ;
7150
+ self . issue_channel_close_events ( & chan. context , ClosureReason :: HolderForceClosed ) ;
7151
+ self . finish_force_close_channel ( chan. context . force_shutdown ( false ) ) ;
7152
+ }
7153
+ retain
7148
7154
} else { true }
7149
7155
} ) ;
7150
7156
peer_state. channel_by_id . iter_mut ( ) . for_each ( |( _, chan) | {
@@ -9394,6 +9400,33 @@ mod tests {
9394
9400
}
9395
9401
}
9396
9402
9403
+ #[ test]
9404
+ fn test_outbound_channels_created_when_disconnected_removed_on_peer_connected ( ) {
9405
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
9406
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
9407
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
9408
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
9409
+
9410
+ let temporary_channel_id = nodes[ 0 ] . node . create_channel ( nodes[ 1 ] . node . get_our_node_id ( ) , 1_000_000 , 500_000_000 , 42 , None ) . unwrap ( ) ;
9411
+
9412
+ {
9413
+ let per_peer_state = nodes[ 0 ] . node . per_peer_state . read ( ) . unwrap ( ) ;
9414
+ let peer_state_mutex = per_peer_state. get ( & nodes[ 1 ] . node . get_our_node_id ( ) ) . unwrap ( ) ;
9415
+ let mut peer_state = peer_state_mutex. lock ( ) . unwrap ( ) ;
9416
+ peer_state. is_connected = false ;
9417
+ }
9418
+
9419
+ let open_channel = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendOpenChannel , nodes[ 1 ] . node. get_our_node_id( ) ) ;
9420
+ assert_eq ! ( open_channel. temporary_channel_id, temporary_channel_id) ;
9421
+
9422
+ nodes[ 0 ] . node . peer_connected ( & nodes[ 1 ] . node . get_our_node_id ( ) , & msgs:: Init {
9423
+ features : nodes[ 0 ] . node . init_features ( ) , networks : None , remote_network_address : None
9424
+ } , true ) . unwrap ( ) ;
9425
+
9426
+ check_closed_event ( & nodes[ 0 ] , 1 , ClosureReason :: HolderForceClosed , false ) ;
9427
+ let chan_closed_events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
9428
+ }
9429
+
9397
9430
#[ test]
9398
9431
fn test_drop_disconnected_peers_when_removing_channels ( ) {
9399
9432
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
0 commit comments