@@ -933,6 +933,13 @@ pub(super) struct ReestablishResponses {
933933 pub shutdown_msg: Option<msgs::Shutdown>,
934934}
935935
936+ /// The first message we send to our peer after connection
937+ pub(super) enum ReconnectionMsg {
938+ Reestablish(msgs::ChannelReestablish),
939+ Open(OpenChannelMessage),
940+ None,
941+ }
942+
936943/// The result of a shutdown that should be handled.
937944#[must_use]
938945pub(crate) struct ShutdownResult {
@@ -1304,41 +1311,43 @@ impl<SP: Deref> Channel<SP> where
13041311 }
13051312 }
13061313
1307- pub fn maybe_get_open_channel<L: Deref>(
1314+ /// Should be called when the peer re-connects, returning an initial message which we should
1315+ /// send our peer to begin the channel reconnection process.
1316+ pub fn peer_connected_get_handshake<L: Deref>(
13081317 &mut self, chain_hash: ChainHash, logger: &L,
1309- ) -> Option<OpenChannelMessage> where L::Target: Logger {
1318+ ) -> ReconnectionMsg where L::Target: Logger {
13101319 match &mut self.phase {
13111320 ChannelPhase::Undefined => unreachable!(),
1312- ChannelPhase::Funded(_) => None,
1321+ ChannelPhase::Funded(chan) =>
1322+ ReconnectionMsg::Reestablish(chan.get_channel_reestablish(logger)),
13131323 ChannelPhase::UnfundedOutboundV1(chan) => {
1314- let logger = WithChannelContext::from(logger, & chan.context, None);
1315- chan.get_open_channel(chain_hash, &&logger )
1316- .map(|msg| OpenChannelMessage::V1(msg) )
1324+ chan.get_open_channel(chain_hash, logger)
1325+ .map(|msg| ReconnectionMsg::Open(OpenChannelMessage::V1(msg)) )
1326+ .unwrap_or(ReconnectionMsg::None )
13171327 },
13181328 ChannelPhase::UnfundedInboundV1(_) => {
13191329 // Since unfunded inbound channel maps are cleared upon disconnecting a peer,
13201330 // they are not persisted and won't be recovered after a crash.
13211331 // Therefore, they shouldn't exist at this point.
13221332 debug_assert!(false);
1323- None
1333+ ReconnectionMsg:: None
13241334 },
13251335 #[cfg(dual_funding)]
13261336 ChannelPhase::UnfundedV2(chan) => {
13271337 if chan.context.is_outbound() {
1328- Some(OpenChannelMessage::V2(chan.get_open_channel_v2(chain_hash)))
1338+ ReconnectionMsg::Open(OpenChannelMessage::V2(
1339+ chan.get_open_channel_v2(chain_hash)
1340+ ))
13291341 } else {
13301342 // Since unfunded inbound channel maps are cleared upon disconnecting a peer,
13311343 // they are not persisted and won't be recovered after a crash.
13321344 // Therefore, they shouldn't exist at this point.
13331345 debug_assert!(false);
1334- None
1346+ ReconnectionMsg:: None
13351347 }
13361348 },
13371349 #[cfg(not(dual_funding))]
1338- ChannelPhase::UnfundedV2(_) => {
1339- debug_assert!(false);
1340- None
1341- },
1350+ ChannelPhase::UnfundedV2(_) => ReconnectionMsg::None,
13421351 }
13431352 }
13441353
@@ -8101,7 +8110,7 @@ impl<SP: Deref> FundedChannel<SP> where
81018110
81028111 /// May panic if called on a channel that wasn't immediately-previously
81038112 /// self.remove_uncommitted_htlcs_and_mark_paused()'d
8104- pub fn get_channel_reestablish<L: Deref>(&mut self, logger: &L) -> msgs::ChannelReestablish where L::Target: Logger {
8113+ fn get_channel_reestablish<L: Deref>(&mut self, logger: &L) -> msgs::ChannelReestablish where L::Target: Logger {
81058114 assert!(self.context.channel_state.is_peer_disconnected());
81068115 assert_ne!(self.context.cur_counterparty_commitment_transaction_number, INITIAL_COMMITMENT_NUMBER);
81078116 // This is generally the first function which gets called on any given channel once we're
0 commit comments