@@ -874,6 +874,7 @@ impl <SP: Deref> PeerState<SP> where SP::Target: SignerProvider {
874
874
return false
875
875
}
876
876
self.channel_by_id.iter().filter(|(_, phase)| matches!(phase, ChannelPhase::Funded(_))).count() == 0
877
+ && self.channel_by_id.iter().filter(|(_, phase)| matches!(phase, ChannelPhase::UnfundedOutboundV1(_))).count() == 0
877
878
&& self.monitor_update_blocked_actions.is_empty()
878
879
&& self.in_flight_monitor_updates.is_empty()
879
880
}
@@ -8730,10 +8731,12 @@ where
8730
8731
}
8731
8732
&mut chan.context
8732
8733
},
8733
- // Unfunded channels will always be removed.
8734
- ChannelPhase::UnfundedOutboundV1(chan) => {
8735
- &mut chan.context
8734
+ // We retain UnfundedOutboundV1 channel for some time in case
8735
+ // peer unexpectedly disconnects, and intends to reconnect again.
8736
+ ChannelPhase::UnfundedOutboundV1(_) => {
8737
+ return true;
8736
8738
},
8739
+ // Unfunded inbound channels will always be removed.
8737
8740
ChannelPhase::UnfundedInboundV1(chan) => {
8738
8741
&mut chan.context
8739
8742
},
@@ -8873,21 +8876,27 @@ where
8873
8876
let peer_state = &mut *peer_state_lock;
8874
8877
let pending_msg_events = &mut peer_state.pending_msg_events;
8875
8878
8876
- peer_state.channel_by_id.iter_mut().filter_map(|(_, phase)|
8877
- if let ChannelPhase::Funded(chan) = phase { Some(chan) } else {
8878
- // Since unfunded channel maps are cleared upon disconnecting a peer, and they're not persisted
8879
- // (so won't be recovered after a crash), they shouldn't exist here and we would never need to
8880
- // worry about closing and removing them.
8879
+ for (_, phase) in peer_state.channel_by_id.iter_mut() {
8880
+ if let ChannelPhase::Funded(chan) = phase {
8881
+ let logger = WithChannelContext::from(&self.logger, &chan.context);
8882
+ pending_msg_events.push(events::MessageSendEvent::SendChannelReestablish {
8883
+ node_id: chan.context.get_counterparty_node_id(),
8884
+ msg: chan.get_channel_reestablish(&&logger),
8885
+ });
8886
+ }
8887
+ else if let ChannelPhase::UnfundedOutboundV1(chan) = phase {
8888
+ pending_msg_events.push(events::MessageSendEvent::SendOpenChannel {
8889
+ node_id: chan.context.get_counterparty_node_id(),
8890
+ msg: chan.get_open_channel(self.chain_hash),
8891
+ });
8892
+ }
8893
+ else {
8894
+ // Since unfunded inbound channel maps are cleared upon disconnecting a peer, and they're not
8895
+ // persisted (so won't be recovered after a crash), they shouldn't exist here and we would never
8896
+ // need to worry about closing and removing them.
8881
8897
debug_assert!(false);
8882
- None
8883
8898
}
8884
- ).for_each(|chan| {
8885
- let logger = WithChannelContext::from(&self.logger, &chan.context);
8886
- pending_msg_events.push(events::MessageSendEvent::SendChannelReestablish {
8887
- node_id: chan.context.get_counterparty_node_id(),
8888
- msg: chan.get_channel_reestablish(&&logger),
8889
- });
8890
- });
8899
+ }
8891
8900
}
8892
8901
8893
8902
return NotifyOption::SkipPersistHandleEvents;
0 commit comments