@@ -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 {
@@ -1286,7 +1293,8 @@ impl<SP: Deref> Channel<SP> where
12861293 }
12871294
12881295 /// Should be called when the peer is disconnected. Returns true if the channel can be resumed
1289- /// when the peer reconnects. If not, the channel must be immediately closed.
1296+ /// when the peer reconnects (via [`Self::peer_connected_get_handshake`]). If not, the channel
1297+ /// must be immediately closed.
12901298 pub fn peer_disconnected_is_resumable<L: Deref>(&mut self, logger: &L) -> bool where L::Target: Logger {
12911299 match &mut self.phase {
12921300 ChannelPhase::Undefined => unreachable!(),
@@ -1303,41 +1311,43 @@ impl<SP: Deref> Channel<SP> where
13031311 }
13041312 }
13051313
1306- 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>(
13071317 &mut self, chain_hash: ChainHash, logger: &L,
1308- ) -> Option<OpenChannelMessage> where L::Target: Logger {
1318+ ) -> ReconnectionMsg where L::Target: Logger {
13091319 match &mut self.phase {
13101320 ChannelPhase::Undefined => unreachable!(),
1311- ChannelPhase::Funded(_) => None,
1321+ ChannelPhase::Funded(chan) =>
1322+ ReconnectionMsg::Reestablish(chan.get_channel_reestablish(logger)),
13121323 ChannelPhase::UnfundedOutboundV1(chan) => {
1313- let logger = WithChannelContext::from(logger, & chan.context, None);
1314- chan.get_open_channel(chain_hash, &&logger )
1315- .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 )
13161327 },
13171328 ChannelPhase::UnfundedInboundV1(_) => {
13181329 // Since unfunded inbound channel maps are cleared upon disconnecting a peer,
13191330 // they are not persisted and won't be recovered after a crash.
13201331 // Therefore, they shouldn't exist at this point.
13211332 debug_assert!(false);
1322- None
1333+ ReconnectionMsg:: None
13231334 },
13241335 #[cfg(dual_funding)]
13251336 ChannelPhase::UnfundedV2(chan) => {
13261337 if chan.context.is_outbound() {
1327- Some(OpenChannelMessage::V2(chan.get_open_channel_v2(chain_hash)))
1338+ ReconnectionMsg::Open(OpenChannelMessage::V2(
1339+ chan.get_open_channel_v2(chain_hash)
1340+ ))
13281341 } else {
13291342 // Since unfunded inbound channel maps are cleared upon disconnecting a peer,
13301343 // they are not persisted and won't be recovered after a crash.
13311344 // Therefore, they shouldn't exist at this point.
13321345 debug_assert!(false);
1333- None
1346+ ReconnectionMsg:: None
13341347 }
13351348 },
13361349 #[cfg(not(dual_funding))]
1337- ChannelPhase::UnfundedV2(_) => {
1338- debug_assert!(false);
1339- None
1340- },
1350+ ChannelPhase::UnfundedV2(_) => ReconnectionMsg::None,
13411351 }
13421352 }
13431353
@@ -8052,7 +8062,7 @@ impl<SP: Deref> FundedChannel<SP> where
80528062
80538063 /// May panic if called on a channel that wasn't immediately-previously
80548064 /// self.remove_uncommitted_htlcs_and_mark_paused()'d
8055- pub fn get_channel_reestablish<L: Deref>(&mut self, logger: &L) -> msgs::ChannelReestablish where L::Target: Logger {
8065+ fn get_channel_reestablish<L: Deref>(&mut self, logger: &L) -> msgs::ChannelReestablish where L::Target: Logger {
80568066 assert!(self.context.channel_state.is_peer_disconnected());
80578067 assert_ne!(self.context.cur_counterparty_commitment_transaction_number, INITIAL_COMMITMENT_NUMBER);
80588068 // This is generally the first function which gets called on any given channel once we're
0 commit comments