Skip to content

Commit 6d0ed09

Browse files
committed
Introduce new code changes properly handling this new behavior
- Do not remove channel immediately when peer_disconnect, instead removed it after some time if peer doesn't reconnect soon (handled in previous commit). - Do not mark per ok_to_remove if we have some OutboundV1Channels too. - Rebroadcast SendOpenChannel for outboundV1Channel when peer reconnects.
1 parent 3b56f5c commit 6d0ed09

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ impl <SP: Deref> PeerState<SP> where SP::Target: SignerProvider {
874874
return false
875875
}
876876
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
877878
&& self.monitor_update_blocked_actions.is_empty()
878879
&& self.in_flight_monitor_updates.is_empty()
879880
}
@@ -8730,10 +8731,12 @@ where
87308731
}
87318732
&mut chan.context
87328733
},
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;
87368738
},
8739+
// Unfunded inbound channels will always be removed.
87378740
ChannelPhase::UnfundedInboundV1(chan) => {
87388741
&mut chan.context
87398742
},
@@ -8873,21 +8876,27 @@ where
88738876
let peer_state = &mut *peer_state_lock;
88748877
let pending_msg_events = &mut peer_state.pending_msg_events;
88758878

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.
88818897
debug_assert!(false);
8882-
None
88838898
}
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+
}
88918900
}
88928901

88938902
return NotifyOption::SkipPersistHandleEvents;

0 commit comments

Comments
 (0)