@@ -933,6 +933,13 @@ pub(super) struct ReestablishResponses {
933
933
pub shutdown_msg: Option<msgs::Shutdown>,
934
934
}
935
935
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
+
936
943
/// The result of a shutdown that should be handled.
937
944
#[must_use]
938
945
pub(crate) struct ShutdownResult {
@@ -1304,41 +1311,43 @@ impl<SP: Deref> Channel<SP> where
1304
1311
}
1305
1312
}
1306
1313
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>(
1308
1317
&mut self, chain_hash: ChainHash, logger: &L,
1309
- ) -> Option<OpenChannelMessage> where L::Target: Logger {
1318
+ ) -> ReconnectionMsg where L::Target: Logger {
1310
1319
match &mut self.phase {
1311
1320
ChannelPhase::Undefined => unreachable!(),
1312
- ChannelPhase::Funded(_) => None,
1321
+ ChannelPhase::Funded(chan) =>
1322
+ ReconnectionMsg::Reestablish(chan.get_channel_reestablish(logger)),
1313
1323
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 )
1317
1327
},
1318
1328
ChannelPhase::UnfundedInboundV1(_) => {
1319
1329
// Since unfunded inbound channel maps are cleared upon disconnecting a peer,
1320
1330
// they are not persisted and won't be recovered after a crash.
1321
1331
// Therefore, they shouldn't exist at this point.
1322
1332
debug_assert!(false);
1323
- None
1333
+ ReconnectionMsg:: None
1324
1334
},
1325
1335
#[cfg(dual_funding)]
1326
1336
ChannelPhase::UnfundedV2(chan) => {
1327
1337
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
+ ))
1329
1341
} else {
1330
1342
// Since unfunded inbound channel maps are cleared upon disconnecting a peer,
1331
1343
// they are not persisted and won't be recovered after a crash.
1332
1344
// Therefore, they shouldn't exist at this point.
1333
1345
debug_assert!(false);
1334
- None
1346
+ ReconnectionMsg:: None
1335
1347
}
1336
1348
},
1337
1349
#[cfg(not(dual_funding))]
1338
- ChannelPhase::UnfundedV2(_) => {
1339
- debug_assert!(false);
1340
- None
1341
- },
1350
+ ChannelPhase::UnfundedV2(_) => ReconnectionMsg::None,
1342
1351
}
1343
1352
}
1344
1353
@@ -8101,7 +8110,7 @@ impl<SP: Deref> FundedChannel<SP> where
8101
8110
8102
8111
/// May panic if called on a channel that wasn't immediately-previously
8103
8112
/// 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 {
8105
8114
assert!(self.context.channel_state.is_peer_disconnected());
8106
8115
assert_ne!(self.context.cur_counterparty_commitment_transaction_number, INITIAL_COMMITMENT_NUMBER);
8107
8116
// This is generally the first function which gets called on any given channel once we're
0 commit comments