Skip to content

Commit 85d68d9

Browse files
committed
Introduce ChannelPhase enum
We introduce the `ChannelPhase` enum which will contain the different channel structs wrapped by each of its variants so that we can place these within a single `channel_by_id` map in `peer_state` in the following commits. This will reduce the number of map lookup operations we need to do in `ChannelManager`'s various methods. It will also make certain channel counting logic easier to reason about with less risk of forgetting to modify logic when new channels structs are introduced for V2 channel establishment.
1 parent 9b13862 commit 85d68d9

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

lightning/src/ln/channel.rs

+26
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,32 @@ impl_writeable_tlv_based!(PendingChannelMonitorUpdate, {
601601
(0, update, required),
602602
});
603603

604+
/// The `ChannelPhase` enum describes the current phase in life of a lightning channel with each of
605+
/// its variants containing an appropriate channel struct.
606+
pub(super) enum ChannelPhase<Signer: ChannelSigner> {
607+
UnfundedOutboundV1(OutboundV1Channel<Signer>),
608+
UnfundedInboundV1(InboundV1Channel<Signer>),
609+
Funded(Channel<Signer>),
610+
}
611+
612+
impl<'a, Signer: ChannelSigner> ChannelPhase<Signer> {
613+
pub fn context(&'a self) -> &'a ChannelContext<Signer> {
614+
match self {
615+
ChannelPhase::Funded(chan) => &chan.context,
616+
ChannelPhase::UnfundedOutboundV1(chan) => &chan.context,
617+
ChannelPhase::UnfundedInboundV1(chan) => &chan.context,
618+
}
619+
}
620+
621+
pub fn context_mut(&'a mut self) -> &'a mut ChannelContext<Signer> {
622+
match self {
623+
ChannelPhase::Funded(ref mut chan) => &mut chan.context,
624+
ChannelPhase::UnfundedOutboundV1(ref mut chan) => &mut chan.context,
625+
ChannelPhase::UnfundedInboundV1(ref mut chan) => &mut chan.context,
626+
}
627+
}
628+
}
629+
604630
/// Contains all state common to unfunded inbound/outbound channels.
605631
pub(super) struct UnfundedChannelContext {
606632
/// A counter tracking how many ticks have elapsed since this unfunded channel was

0 commit comments

Comments
 (0)