@@ -2246,6 +2246,7 @@ where
2246
2246
for ( _cp_id, peer_state_mutex) in per_peer_state. iter ( ) {
2247
2247
let mut peer_state_lock = peer_state_mutex. lock ( ) . unwrap ( ) ;
2248
2248
let peer_state = & mut * peer_state_lock;
2249
+ // Only `Channels` in the channel_by_id map can be considered funded.
2249
2250
for ( _channel_id, channel) in peer_state. channel_by_id . iter ( ) . filter ( f) {
2250
2251
let details = ChannelDetails :: from_channel_context ( & channel. context , best_block_height,
2251
2252
peer_state. latest_features . clone ( ) , & self . fee_estimator ) ;
@@ -2314,11 +2315,15 @@ where
2314
2315
let mut peer_state_lock = peer_state_mutex. lock ( ) . unwrap ( ) ;
2315
2316
let peer_state = & mut * peer_state_lock;
2316
2317
let features = & peer_state. latest_features ;
2318
+ let chan_context_to_details = |context| {
2319
+ ChannelDetails :: from_channel_context ( context, best_block_height, features. clone ( ) , & self . fee_estimator )
2320
+ } ;
2317
2321
return peer_state. channel_by_id
2318
2322
. iter ( )
2319
- . map ( |( _, channel) |
2320
- ChannelDetails :: from_channel_context ( & channel. context , best_block_height,
2321
- features. clone ( ) , & self . fee_estimator ) )
2323
+ . map ( |( _, channel) | & channel. context )
2324
+ . chain ( peer_state. outbound_v1_channel_by_id . iter ( ) . map ( |( _, channel) | & channel. context ) )
2325
+ . chain ( peer_state. inbound_v1_channel_by_id . iter ( ) . map ( |( _, channel) | & channel. context ) )
2326
+ . map ( chan_context_to_details)
2322
2327
. collect ( ) ;
2323
2328
}
2324
2329
vec ! [ ]
@@ -7214,37 +7219,20 @@ where
7214
7219
log_debug ! ( self . logger, "Generating channel_reestablish events for {}" , log_pubkey!( counterparty_node_id) ) ;
7215
7220
7216
7221
let per_peer_state = self . per_peer_state . read ( ) . unwrap ( ) ;
7217
- for ( _cp_id , peer_state_mutex) in per_peer_state. iter ( ) {
7222
+ if let Some ( peer_state_mutex) = per_peer_state. get ( counterparty_node_id ) {
7218
7223
let mut peer_state_lock = peer_state_mutex. lock ( ) . unwrap ( ) ;
7219
7224
let peer_state = & mut * peer_state_lock;
7220
7225
let pending_msg_events = & mut peer_state. pending_msg_events ;
7221
- peer_state. channel_by_id . retain ( |_, chan| {
7222
- let retain = if chan. context . get_counterparty_node_id ( ) == * counterparty_node_id {
7223
- if !chan. context . have_received_message ( ) {
7224
- // If we created this (outbound) channel while we were disconnected from the
7225
- // peer we probably failed to send the open_channel message, which is now
7226
- // lost. We can't have had anything pending related to this channel, so we just
7227
- // drop it.
7228
- false
7229
- } else {
7230
- pending_msg_events. push ( events:: MessageSendEvent :: SendChannelReestablish {
7231
- node_id : chan. context . get_counterparty_node_id ( ) ,
7232
- msg : chan. get_channel_reestablish ( & self . logger ) ,
7233
- } ) ;
7234
- true
7235
- }
7236
- } else { true } ;
7237
- if retain && chan. context . get_counterparty_node_id ( ) != * counterparty_node_id {
7238
- 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 ) {
7239
- if let Ok ( update_msg) = self . get_channel_update_for_broadcast ( chan) {
7240
- pending_msg_events. push ( events:: MessageSendEvent :: SendChannelAnnouncement {
7241
- node_id : * counterparty_node_id,
7242
- msg, update_msg,
7243
- } ) ;
7244
- }
7245
- }
7246
- }
7247
- retain
7226
+
7227
+ // Since unfunded channel maps are cleared upon disconnecting a peer, and they're not persisted
7228
+ // (so won't be recovered after a crash) we don't need to bother closing unfunded channels and
7229
+ // clearing their maps here. Instead we can just send queue channel_reestablish messages for
7230
+ // channels in the channel_by_id map.
7231
+ peer_state. channel_by_id . iter_mut ( ) . for_each ( |( _, chan) | {
7232
+ pending_msg_events. push ( events:: MessageSendEvent :: SendChannelReestablish {
7233
+ node_id : chan. context . get_counterparty_node_id ( ) ,
7234
+ msg : chan. get_channel_reestablish ( & self . logger ) ,
7235
+ } ) ;
7248
7236
} ) ;
7249
7237
}
7250
7238
//TODO: Also re-broadcast announcement_signatures
0 commit comments