@@ -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
}
@@ -8734,10 +8735,12 @@ where
8734
8735
}
8735
8736
&mut chan.context
8736
8737
},
8737
- // Unfunded channels will always be removed.
8738
- ChannelPhase::UnfundedOutboundV1(chan) => {
8739
- &mut chan.context
8738
+ // We retain UnfundedOutboundV1 channel for some time in case
8739
+ // peer unexpectedly disconnects, and intends to reconnect again.
8740
+ ChannelPhase::UnfundedOutboundV1(_) => {
8741
+ return true;
8740
8742
},
8743
+ // Unfunded inbound channels will always be removed.
8741
8744
ChannelPhase::UnfundedInboundV1(chan) => {
8742
8745
&mut chan.context
8743
8746
},
@@ -8877,21 +8880,27 @@ where
8877
8880
let peer_state = &mut *peer_state_lock;
8878
8881
let pending_msg_events = &mut peer_state.pending_msg_events;
8879
8882
8880
- peer_state.channel_by_id.iter_mut().filter_map(|(_, phase)|
8881
- if let ChannelPhase::Funded(chan) = phase { Some(chan) } else {
8882
- // Since unfunded channel maps are cleared upon disconnecting a peer, and they're not persisted
8883
- // (so won't be recovered after a crash), they shouldn't exist here and we would never need to
8884
- // worry about closing and removing them.
8883
+ for (_, phase) in peer_state.channel_by_id.iter_mut() {
8884
+ if let ChannelPhase::Funded(chan) = phase {
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
+ }
8891
+ else if let ChannelPhase::UnfundedOutboundV1(chan) = phase {
8892
+ pending_msg_events.push(events::MessageSendEvent::SendOpenChannel {
8893
+ node_id: chan.context.get_counterparty_node_id(),
8894
+ msg: chan.get_open_channel(self.chain_hash),
8895
+ });
8896
+ }
8897
+ else {
8898
+ // Since unfunded inbound channel maps are cleared upon disconnecting a peer, and they're not
8899
+ // persisted (so won't be recovered after a crash), they shouldn't exist here and we would never
8900
+ // need to worry about closing and removing them.
8885
8901
debug_assert!(false);
8886
- None
8887
8902
}
8888
- ).for_each(|chan| {
8889
- let logger = WithChannelContext::from(&self.logger, &chan.context);
8890
- pending_msg_events.push(events::MessageSendEvent::SendChannelReestablish {
8891
- node_id: chan.context.get_counterparty_node_id(),
8892
- msg: chan.get_channel_reestablish(&&logger),
8893
- });
8894
- });
8903
+ }
8895
8904
}
8896
8905
8897
8906
return NotifyOption::SkipPersistHandleEvents;
0 commit comments