@@ -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 {
@@ -1286,7 +1293,8 @@ impl<SP: Deref> Channel<SP> where
1286
1293
}
1287
1294
1288
1295
/// 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.
1290
1298
pub fn peer_disconnected_is_resumable<L: Deref>(&mut self, logger: &L) -> bool where L::Target: Logger {
1291
1299
match &mut self.phase {
1292
1300
ChannelPhase::Undefined => unreachable!(),
@@ -1303,41 +1311,43 @@ impl<SP: Deref> Channel<SP> where
1303
1311
}
1304
1312
}
1305
1313
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>(
1307
1317
&mut self, chain_hash: ChainHash, logger: &L,
1308
- ) -> Option<OpenChannelMessage> where L::Target: Logger {
1318
+ ) -> ReconnectionMsg where L::Target: Logger {
1309
1319
match &mut self.phase {
1310
1320
ChannelPhase::Undefined => unreachable!(),
1311
- ChannelPhase::Funded(_) => None,
1321
+ ChannelPhase::Funded(chan) =>
1322
+ ReconnectionMsg::Reestablish(chan.get_channel_reestablish(logger)),
1312
1323
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 )
1316
1327
},
1317
1328
ChannelPhase::UnfundedInboundV1(_) => {
1318
1329
// Since unfunded inbound channel maps are cleared upon disconnecting a peer,
1319
1330
// they are not persisted and won't be recovered after a crash.
1320
1331
// Therefore, they shouldn't exist at this point.
1321
1332
debug_assert!(false);
1322
- None
1333
+ ReconnectionMsg:: None
1323
1334
},
1324
1335
#[cfg(dual_funding)]
1325
1336
ChannelPhase::UnfundedV2(chan) => {
1326
1337
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
+ ))
1328
1341
} else {
1329
1342
// Since unfunded inbound channel maps are cleared upon disconnecting a peer,
1330
1343
// they are not persisted and won't be recovered after a crash.
1331
1344
// Therefore, they shouldn't exist at this point.
1332
1345
debug_assert!(false);
1333
- None
1346
+ ReconnectionMsg:: None
1334
1347
}
1335
1348
},
1336
1349
#[cfg(not(dual_funding))]
1337
- ChannelPhase::UnfundedV2(_) => {
1338
- debug_assert!(false);
1339
- None
1340
- },
1350
+ ChannelPhase::UnfundedV2(_) => ReconnectionMsg::None,
1341
1351
}
1342
1352
}
1343
1353
@@ -8100,7 +8110,7 @@ impl<SP: Deref> FundedChannel<SP> where
8100
8110
8101
8111
/// May panic if called on a channel that wasn't immediately-previously
8102
8112
/// self.remove_uncommitted_htlcs_and_mark_paused()'d
8103
- 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 {
8104
8114
assert!(self.context.channel_state.is_peer_disconnected());
8105
8115
assert_ne!(self.context.cur_counterparty_commitment_transaction_number, INITIAL_COMMITMENT_NUMBER);
8106
8116
// This is generally the first function which gets called on any given channel once we're
0 commit comments