Skip to content

Commit 4055c8b

Browse files
committed
Add ChannelPhase::Intermediate variant
When attempting a ChannelPhase transition, the variant-specific channel struct needs to be taken by self in order to move its ChannelContext into the struct for the new phase. Add a variant for an intermediate state, allowing such actions.
1 parent 2b9687f commit 4055c8b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lightning/src/ln/channel.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,7 @@ pub(super) struct Channel<SP: Deref> where SP::Target: SignerProvider {
11331133
/// The `ChannelPhase` enum describes the current phase in life of a lightning channel with each of
11341134
/// its variants containing an appropriate channel struct.
11351135
enum ChannelPhase<SP: Deref> where SP::Target: SignerProvider {
1136+
Intermediate,
11361137
UnfundedOutboundV1(OutboundV1Channel<SP>),
11371138
UnfundedInboundV1(InboundV1Channel<SP>),
11381139
#[allow(dead_code)] // TODO(dual_funding): Remove once creating V2 channels is enabled.
@@ -1146,6 +1147,7 @@ impl<SP: Deref> Channel<SP> where
11461147
{
11471148
pub fn context(&self) -> &ChannelContext<SP> {
11481149
match &self.phase {
1150+
ChannelPhase::Intermediate => unreachable!(),
11491151
ChannelPhase::Funded(chan) => &chan.context,
11501152
ChannelPhase::UnfundedOutboundV1(chan) => &chan.context,
11511153
ChannelPhase::UnfundedInboundV1(chan) => &chan.context,
@@ -1155,6 +1157,7 @@ impl<SP: Deref> Channel<SP> where
11551157

11561158
pub fn context_mut(&mut self) -> &mut ChannelContext<SP> {
11571159
match &mut self.phase {
1160+
ChannelPhase::Intermediate => unreachable!(),
11581161
ChannelPhase::Funded(chan) => &mut chan.context,
11591162
ChannelPhase::UnfundedOutboundV1(chan) => &mut chan.context,
11601163
ChannelPhase::UnfundedInboundV1(chan) => &mut chan.context,
@@ -1164,6 +1167,7 @@ impl<SP: Deref> Channel<SP> where
11641167

11651168
pub fn unfunded_context_mut(&mut self) -> Option<&mut UnfundedChannelContext> {
11661169
match &mut self.phase {
1170+
ChannelPhase::Intermediate => unreachable!(),
11671171
ChannelPhase::Funded(_) => { debug_assert!(false); None },
11681172
ChannelPhase::UnfundedOutboundV1(chan) => Some(&mut chan.unfunded_context),
11691173
ChannelPhase::UnfundedInboundV1(chan) => Some(&mut chan.unfunded_context),
@@ -1252,6 +1256,7 @@ impl<SP: Deref> Channel<SP> where
12521256
&mut self, chain_hash: ChainHash, logger: &L,
12531257
) -> Option<SignerResumeUpdates> where L::Target: Logger {
12541258
match &mut self.phase {
1259+
ChannelPhase::Intermediate => unreachable!(),
12551260
ChannelPhase::Funded(chan) => Some(chan.signer_maybe_unblocked(logger)),
12561261
ChannelPhase::UnfundedOutboundV1(chan) => {
12571262
let (open_channel, funding_created) = chan.signer_maybe_unblocked(chain_hash, logger);
@@ -1292,6 +1297,7 @@ impl<SP: Deref> Channel<SP> where
12921297

12931298
pub fn is_resumable(&self) -> bool {
12941299
match &self.phase {
1300+
ChannelPhase::Intermediate => unreachable!(),
12951301
ChannelPhase::Funded(_) => false,
12961302
ChannelPhase::UnfundedOutboundV1(chan) => chan.is_resumable(),
12971303
ChannelPhase::UnfundedInboundV1(_) => false,
@@ -1303,6 +1309,7 @@ impl<SP: Deref> Channel<SP> where
13031309
&mut self, chain_hash: ChainHash, logger: &L,
13041310
) -> Option<OpenChannelMessage> where L::Target: Logger {
13051311
match &mut self.phase {
1312+
ChannelPhase::Intermediate => unreachable!(),
13061313
ChannelPhase::Funded(_) => None,
13071314
ChannelPhase::UnfundedOutboundV1(chan) => {
13081315
let logger = WithChannelContext::from(logger, &chan.context, None);
@@ -1344,6 +1351,7 @@ impl<SP: Deref> Channel<SP> where
13441351
L::Target: Logger,
13451352
{
13461353
match &mut self.phase {
1354+
ChannelPhase::Intermediate => unreachable!(),
13471355
ChannelPhase::Funded(_) => Ok(None),
13481356
ChannelPhase::UnfundedOutboundV1(chan) => {
13491357
let logger = WithChannelContext::from(logger, &chan.context, None);

0 commit comments

Comments
 (0)