Skip to content

Commit 1780ce4

Browse files
committed
Hide ChannelPhase::Funded behind as_funded method
Exposing ChannelPhase in ChannelManager has led to verbose match statements, which need to be modified each time a ChannelPhase is added. Making ChannelPhase an implementation detail of Channel would help avoid this. As a step in this direction, introduce ChannelPhase::as_funded and ChannelPhase::as_funded_mut for use in ChannelManager when a Channel (to be later renamed FundedChannel) is needed.
1 parent d6637d7 commit 1780ce4

File tree

5 files changed

+150
-126
lines changed

5 files changed

+150
-126
lines changed

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::chain::transaction::OutPoint;
2020
use crate::chain::{ChannelMonitorUpdateStatus, Listen, Watch};
2121
use crate::events::{Event, MessageSendEvent, MessageSendEventsProvider, PaymentPurpose, ClosureReason, HTLCDestination};
2222
use crate::ln::channelmanager::{RAACommitmentOrder, PaymentSendFailure, PaymentId, RecipientOnionFields};
23-
use crate::ln::channel::{AnnouncementSigsState, ChannelPhase};
23+
use crate::ln::channel::AnnouncementSigsState;
2424
use crate::ln::msgs;
2525
use crate::ln::types::ChannelId;
2626
use crate::ln::msgs::{ChannelMessageHandler, RoutingMessageHandler};
@@ -98,7 +98,7 @@ fn test_monitor_and_persister_update_fail() {
9898
{
9999
let mut node_0_per_peer_lock;
100100
let mut node_0_peer_state_lock;
101-
if let ChannelPhase::Funded(ref mut channel) = get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, chan.2) {
101+
if let Some(channel) = get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, chan.2).as_funded_mut() {
102102
if let Ok(Some(update)) = channel.commitment_signed(&updates.commitment_signed, &node_cfgs[0].logger) {
103103
// Check that the persister returns InProgress (and will never actually complete)
104104
// as the monitor update errors.

lightning/src/ln/channel.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,22 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
11521152
ChannelPhase::UnfundedV2(ref mut chan) => &mut chan.context,
11531153
}
11541154
}
1155+
1156+
pub fn as_funded(&self) -> Option<&Channel<SP>> {
1157+
if let ChannelPhase::Funded(channel) = self {
1158+
Some(channel)
1159+
} else {
1160+
None
1161+
}
1162+
}
1163+
1164+
pub fn as_funded_mut(&mut self) -> Option<&mut Channel<SP>> {
1165+
if let ChannelPhase::Funded(channel) = self {
1166+
Some(channel)
1167+
} else {
1168+
None
1169+
}
1170+
}
11551171
}
11561172

11571173
/// Contains all state common to unfunded inbound/outbound channels.

0 commit comments

Comments
 (0)