Skip to content

Commit 9ee673c

Browse files
committed
Implement From<Channel> for ChannelPhase
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, define a conversion from Channel (to be renamed FundedChannel) to ChannelPhase (to be renamed Channel).
1 parent 48b93b8 commit 9ee673c

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lightning/src/ln/channel.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,16 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
13581358
}
13591359
}
13601360

1361+
impl<SP: Deref> From<Channel<SP>> for ChannelPhase<SP>
1362+
where
1363+
SP::Target: SignerProvider,
1364+
<SP::Target as SignerProvider>::EcdsaSigner: ChannelSigner,
1365+
{
1366+
fn from(channel: Channel<SP>) -> Self {
1367+
ChannelPhase::Funded(channel)
1368+
}
1369+
}
1370+
13611371
/// Contains all state common to unfunded inbound/outbound channels.
13621372
pub(super) struct UnfundedChannelContext {
13631373
/// A counter tracking how many ticks have elapsed since this unfunded channel was

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8124,7 +8124,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
81248124
});
81258125
}
81268126

8127-
if let Some(chan) = e.insert(ChannelPhase::Funded(chan)).as_funded_mut() {
8127+
if let Some(chan) = e.insert(ChannelPhase::from(chan)).as_funded_mut() {
81288128
handle_new_monitor_update!(self, persist_state, peer_state_lock, peer_state,
81298129
per_peer_state, chan, INITIAL_MONITOR);
81308130
} else {
@@ -8171,7 +8171,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
81718171
// We really should be able to insert here without doing a second
81728172
// lookup, but sadly rust stdlib doesn't currently allow keeping
81738173
// the original Entry around with the value removed.
8174-
let chan = peer_state.channel_by_id.entry(msg.channel_id).or_insert(ChannelPhase::Funded(chan));
8174+
let chan = peer_state.channel_by_id.entry(msg.channel_id).or_insert(ChannelPhase::from(chan));
81758175
if let Some(chan) = chan.as_funded_mut() {
81768176
handle_new_monitor_update!(self, persist_status, peer_state_lock, peer_state, per_peer_state, chan, INITIAL_MONITOR);
81778177
} else { unreachable!(); }
@@ -8326,7 +8326,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
83268326
.into()))
83278327
},
83288328
}.map_err(|err| MsgHandleErrInternal::send_err_msg_no_close(format!("{}", err), msg.channel_id))?;
8329-
peer_state.channel_by_id.insert(channel_id, ChannelPhase::Funded(channel));
8329+
peer_state.channel_by_id.insert(channel_id, ChannelPhase::from(channel));
83308330
if let Some(funding_ready_for_sig_event) = funding_ready_for_sig_event_opt {
83318331
let mut pending_events = self.pending_events.lock().unwrap();
83328332
pending_events.push_back((funding_ready_for_sig_event, None));
@@ -13253,7 +13253,7 @@ where
1325313253
per_peer_state.entry(channel.context.get_counterparty_node_id())
1325413254
.or_insert_with(|| Mutex::new(empty_peer_state()))
1325513255
.get_mut().unwrap()
13256-
.channel_by_id.insert(channel.context.channel_id(), ChannelPhase::Funded(channel));
13256+
.channel_by_id.insert(channel.context.channel_id(), ChannelPhase::from(channel));
1325713257
}
1325813258
} else if channel.is_awaiting_initial_mon_persist() {
1325913259
// If we were persisted and shut down while the initial ChannelMonitor persistence

0 commit comments

Comments
 (0)