@@ -7114,35 +7114,25 @@ where
7114
7114
log_debug ! ( self . logger, "Generating channel_reestablish events for {}" , log_pubkey!( counterparty_node_id) ) ;
7115
7115
7116
7116
let per_peer_state = self . per_peer_state . read ( ) . unwrap ( ) ;
7117
- for ( _cp_id , peer_state_mutex) in per_peer_state. iter ( ) {
7117
+ if let Some ( peer_state_mutex) = per_peer_state. get ( counterparty_node_id ) {
7118
7118
let mut peer_state_lock = peer_state_mutex. lock ( ) . unwrap ( ) ;
7119
7119
let peer_state = & mut * peer_state_lock;
7120
7120
let pending_msg_events = & mut peer_state. pending_msg_events ;
7121
7121
peer_state. outbound_v1_channel_by_id . retain ( |_, chan| {
7122
- if chan. context . get_counterparty_node_id ( ) == * counterparty_node_id {
7123
- // If we created this (outbound) channel while we were disconnected from the
7124
- // peer we probably failed to send the open_channel message, which is now
7125
- // lost. We can't have had anything pending related to this channel, so we just
7126
- // drop it.
7127
- chan. context . have_received_message ( )
7128
- } else { true }
7122
+ // We shouldn't have any pending outbound channels upon reconnect. If one exists,
7123
+ // then we probably tried to open a channel while the peer was disconnected and they
7124
+ // wouldn't have received the corresponding channel open message. We can just force-close
7125
+ // these channels and drop them.
7126
+ log_error ! ( self . logger, "Force-closing channel {}" , log_bytes!( chan. context. channel_id( ) ) ) ;
7127
+ self . issue_channel_close_events ( & chan. context , ClosureReason :: HolderForceClosed ) ;
7128
+ self . finish_force_close_channel ( chan. context . force_shutdown ( false ) ) ;
7129
+ false
7129
7130
} ) ;
7130
7131
peer_state. channel_by_id . iter_mut ( ) . for_each ( |( _, chan) | {
7131
- if chan. context . get_counterparty_node_id ( ) == * counterparty_node_id {
7132
- pending_msg_events. push ( events:: MessageSendEvent :: SendChannelReestablish {
7133
- node_id : chan. context . get_counterparty_node_id ( ) ,
7134
- msg : chan. get_channel_reestablish ( & self . logger ) ,
7135
- } ) ;
7136
- } else {
7137
- if let Some ( msg) = chan. get_signed_channel_announcement ( & self . node_signer , self . genesis_hash . clone ( ) , self . best_block . read ( ) . unwrap ( ) . height ( ) , & self . default_configuration ) {
7138
- if let Ok ( update_msg) = self . get_channel_update_for_broadcast ( chan) {
7139
- pending_msg_events. push ( events:: MessageSendEvent :: SendChannelAnnouncement {
7140
- node_id : * counterparty_node_id,
7141
- msg, update_msg,
7142
- } ) ;
7143
- }
7144
- }
7145
- }
7132
+ pending_msg_events. push ( events:: MessageSendEvent :: SendChannelReestablish {
7133
+ node_id : chan. context . get_counterparty_node_id ( ) ,
7134
+ msg : chan. get_channel_reestablish ( & self . logger ) ,
7135
+ } ) ;
7146
7136
} ) ;
7147
7137
}
7148
7138
//TODO: Also re-broadcast announcement_signatures
0 commit comments