Rename ChannelPhase to Channel

In preparation for hiding ChannelPhase inside a Channel type, rename
ChannelPhase to Channel.
This commit is contained in:
Jeffrey Czyz 2025-01-08 18:49:34 -06:00
parent c55508860f
commit 442b030504
No known key found for this signature in database
GPG Key ID: 912EF12EA67705F5
4 changed files with 106 additions and 106 deletions

View File

@ -1124,9 +1124,9 @@ impl_writeable_tlv_based!(PendingChannelMonitorUpdate, {
(0, update, required),
});
/// The `ChannelPhase` enum describes the current phase in life of a lightning channel with each of
/// The `Channel` enum describes the current phase in life of a lightning channel with each of
/// its variants containing an appropriate channel struct.
pub(super) enum ChannelPhase<SP: Deref> where SP::Target: SignerProvider {
pub(super) enum Channel<SP: Deref> where SP::Target: SignerProvider {
UnfundedOutboundV1(OutboundV1Channel<SP>),
UnfundedInboundV1(InboundV1Channel<SP>),
#[allow(dead_code)] // TODO(dual_funding): Remove once creating V2 channels is enabled.
@ -1134,43 +1134,43 @@ pub(super) enum ChannelPhase<SP: Deref> where SP::Target: SignerProvider {
Funded(FundedChannel<SP>),
}
impl<'a, SP: Deref> ChannelPhase<SP> where
impl<'a, SP: Deref> Channel<SP> where
SP::Target: SignerProvider,
<SP::Target as SignerProvider>::EcdsaSigner: ChannelSigner,
{
pub fn context(&'a self) -> &'a ChannelContext<SP> {
match self {
ChannelPhase::Funded(chan) => &chan.context,
ChannelPhase::UnfundedOutboundV1(chan) => &chan.context,
ChannelPhase::UnfundedInboundV1(chan) => &chan.context,
ChannelPhase::UnfundedV2(chan) => &chan.context,
Channel::Funded(chan) => &chan.context,
Channel::UnfundedOutboundV1(chan) => &chan.context,
Channel::UnfundedInboundV1(chan) => &chan.context,
Channel::UnfundedV2(chan) => &chan.context,
}
}
pub fn context_mut(&'a mut self) -> &'a mut ChannelContext<SP> {
match self {
ChannelPhase::Funded(ref mut chan) => &mut chan.context,
ChannelPhase::UnfundedOutboundV1(ref mut chan) => &mut chan.context,
ChannelPhase::UnfundedInboundV1(ref mut chan) => &mut chan.context,
ChannelPhase::UnfundedV2(ref mut chan) => &mut chan.context,
Channel::Funded(ref mut chan) => &mut chan.context,
Channel::UnfundedOutboundV1(ref mut chan) => &mut chan.context,
Channel::UnfundedInboundV1(ref mut chan) => &mut chan.context,
Channel::UnfundedV2(ref mut chan) => &mut chan.context,
}
}
pub fn unfunded_context_mut(&mut self) -> Option<&mut UnfundedChannelContext> {
match self {
ChannelPhase::Funded(_) => { debug_assert!(false); None },
ChannelPhase::UnfundedOutboundV1(chan) => Some(&mut chan.unfunded_context),
ChannelPhase::UnfundedInboundV1(chan) => Some(&mut chan.unfunded_context),
ChannelPhase::UnfundedV2(chan) => Some(&mut chan.unfunded_context),
Channel::Funded(_) => { debug_assert!(false); None },
Channel::UnfundedOutboundV1(chan) => Some(&mut chan.unfunded_context),
Channel::UnfundedInboundV1(chan) => Some(&mut chan.unfunded_context),
Channel::UnfundedV2(chan) => Some(&mut chan.unfunded_context),
}
}
pub fn is_funded(&self) -> bool {
matches!(self, ChannelPhase::Funded(_))
matches!(self, Channel::Funded(_))
}
pub fn as_funded(&self) -> Option<&FundedChannel<SP>> {
if let ChannelPhase::Funded(channel) = self {
if let Channel::Funded(channel) = self {
Some(channel)
} else {
None
@ -1178,7 +1178,7 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
}
pub fn as_funded_mut(&mut self) -> Option<&mut FundedChannel<SP>> {
if let ChannelPhase::Funded(channel) = self {
if let Channel::Funded(channel) = self {
Some(channel)
} else {
None
@ -1186,7 +1186,7 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
}
pub fn as_unfunded_outbound_v1_mut(&mut self) -> Option<&mut OutboundV1Channel<SP>> {
if let ChannelPhase::UnfundedOutboundV1(channel) = self {
if let Channel::UnfundedOutboundV1(channel) = self {
Some(channel)
} else {
None
@ -1194,11 +1194,11 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
}
pub fn is_unfunded_outbound_v1(&self) -> bool {
matches!(self, ChannelPhase::UnfundedOutboundV1(_))
matches!(self, Channel::UnfundedOutboundV1(_))
}
pub fn into_unfunded_outbound_v1(self) -> Result<OutboundV1Channel<SP>, Self> {
if let ChannelPhase::UnfundedOutboundV1(channel) = self {
if let Channel::UnfundedOutboundV1(channel) = self {
Ok(channel)
} else {
Err(self)
@ -1206,7 +1206,7 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
}
pub fn into_unfunded_inbound_v1(self) -> Result<InboundV1Channel<SP>, Self> {
if let ChannelPhase::UnfundedInboundV1(channel) = self {
if let Channel::UnfundedInboundV1(channel) = self {
Ok(channel)
} else {
Err(self)
@ -1214,7 +1214,7 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
}
pub fn as_unfunded_v2(&self) -> Option<&PendingV2Channel<SP>> {
if let ChannelPhase::UnfundedV2(channel) = self {
if let Channel::UnfundedV2(channel) = self {
Some(channel)
} else {
None
@ -1222,7 +1222,7 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
}
pub fn as_unfunded_v2_mut(&mut self) -> Option<&mut PendingV2Channel<SP>> {
if let ChannelPhase::UnfundedV2(channel) = self {
if let Channel::UnfundedV2(channel) = self {
Some(channel)
} else {
None
@ -1230,7 +1230,7 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
}
pub fn into_unfunded_v2(self) -> Option<PendingV2Channel<SP>> {
if let ChannelPhase::UnfundedV2(channel) = self {
if let Channel::UnfundedV2(channel) = self {
Some(channel)
} else {
None
@ -1241,8 +1241,8 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
&mut self, chain_hash: ChainHash, logger: &L,
) -> Option<SignerResumeUpdates> where L::Target: Logger {
match self {
ChannelPhase::Funded(chan) => Some(chan.signer_maybe_unblocked(logger)),
ChannelPhase::UnfundedOutboundV1(chan) => {
Channel::Funded(chan) => Some(chan.signer_maybe_unblocked(logger)),
Channel::UnfundedOutboundV1(chan) => {
let (open_channel, funding_created) = chan.signer_maybe_unblocked(chain_hash, logger);
Some(SignerResumeUpdates {
commitment_update: None,
@ -1258,7 +1258,7 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
shutdown_result: None,
})
},
ChannelPhase::UnfundedInboundV1(chan) => {
Channel::UnfundedInboundV1(chan) => {
let logger = WithChannelContext::from(logger, &chan.context, None);
let accept_channel = chan.signer_maybe_unblocked(&&logger);
Some(SignerResumeUpdates {
@ -1275,16 +1275,16 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
shutdown_result: None,
})
},
ChannelPhase::UnfundedV2(_) => None,
Channel::UnfundedV2(_) => None,
}
}
pub fn is_resumable(&self) -> bool {
match self {
ChannelPhase::Funded(_) => false,
ChannelPhase::UnfundedOutboundV1(chan) => chan.is_resumable(),
ChannelPhase::UnfundedInboundV1(_) => false,
ChannelPhase::UnfundedV2(_) => false,
Channel::Funded(_) => false,
Channel::UnfundedOutboundV1(chan) => chan.is_resumable(),
Channel::UnfundedInboundV1(_) => false,
Channel::UnfundedV2(_) => false,
}
}
@ -1292,13 +1292,13 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
&mut self, chain_hash: ChainHash, logger: &L,
) -> Option<OpenChannelMessage> where L::Target: Logger {
match self {
ChannelPhase::Funded(_) => None,
ChannelPhase::UnfundedOutboundV1(chan) => {
Channel::Funded(_) => None,
Channel::UnfundedOutboundV1(chan) => {
let logger = WithChannelContext::from(logger, &chan.context, None);
chan.get_open_channel(chain_hash, &&logger)
.map(|msg| OpenChannelMessage::V1(msg))
},
ChannelPhase::UnfundedInboundV1(_) => {
Channel::UnfundedInboundV1(_) => {
// Since unfunded inbound channel maps are cleared upon disconnecting a peer,
// they are not persisted and won't be recovered after a crash.
// Therefore, they shouldn't exist at this point.
@ -1306,7 +1306,7 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
None
},
#[cfg(dual_funding)]
ChannelPhase::UnfundedV2(chan) => {
Channel::UnfundedV2(chan) => {
if chan.context.is_outbound() {
Some(OpenChannelMessage::V2(chan.get_open_channel_v2(chain_hash)))
} else {
@ -1318,7 +1318,7 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
}
},
#[cfg(not(dual_funding))]
ChannelPhase::UnfundedV2(_) => {
Channel::UnfundedV2(_) => {
debug_assert!(false);
None
},
@ -1333,15 +1333,15 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
L::Target: Logger,
{
match self {
ChannelPhase::Funded(_) => Ok(None),
ChannelPhase::UnfundedOutboundV1(chan) => {
Channel::Funded(_) => Ok(None),
Channel::UnfundedOutboundV1(chan) => {
let logger = WithChannelContext::from(logger, &chan.context, None);
chan.maybe_handle_error_without_close(chain_hash, fee_estimator, &&logger)
.map(|msg| Some(OpenChannelMessage::V1(msg)))
},
ChannelPhase::UnfundedInboundV1(_) => Ok(None),
Channel::UnfundedInboundV1(_) => Ok(None),
#[cfg(dual_funding)]
ChannelPhase::UnfundedV2(chan) => {
Channel::UnfundedV2(chan) => {
if chan.context.is_outbound() {
chan.maybe_handle_error_without_close(chain_hash, fee_estimator)
.map(|msg| Some(OpenChannelMessage::V2(msg)))
@ -1350,7 +1350,7 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
}
},
#[cfg(not(dual_funding))]
ChannelPhase::UnfundedV2(_) => {
Channel::UnfundedV2(_) => {
debug_assert!(false);
Ok(None)
},
@ -1358,43 +1358,43 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
}
}
impl<SP: Deref> From<OutboundV1Channel<SP>> for ChannelPhase<SP>
impl<SP: Deref> From<OutboundV1Channel<SP>> for Channel<SP>
where
SP::Target: SignerProvider,
<SP::Target as SignerProvider>::EcdsaSigner: ChannelSigner,
{
fn from(channel: OutboundV1Channel<SP>) -> Self {
ChannelPhase::UnfundedOutboundV1(channel)
Channel::UnfundedOutboundV1(channel)
}
}
impl<SP: Deref> From<InboundV1Channel<SP>> for ChannelPhase<SP>
impl<SP: Deref> From<InboundV1Channel<SP>> for Channel<SP>
where
SP::Target: SignerProvider,
<SP::Target as SignerProvider>::EcdsaSigner: ChannelSigner,
{
fn from(channel: InboundV1Channel<SP>) -> Self {
ChannelPhase::UnfundedInboundV1(channel)
Channel::UnfundedInboundV1(channel)
}
}
impl<SP: Deref> From<PendingV2Channel<SP>> for ChannelPhase<SP>
impl<SP: Deref> From<PendingV2Channel<SP>> for Channel<SP>
where
SP::Target: SignerProvider,
<SP::Target as SignerProvider>::EcdsaSigner: ChannelSigner,
{
fn from(channel: PendingV2Channel<SP>) -> Self {
ChannelPhase::UnfundedV2(channel)
Channel::UnfundedV2(channel)
}
}
impl<SP: Deref> From<FundedChannel<SP>> for ChannelPhase<SP>
impl<SP: Deref> From<FundedChannel<SP>> for Channel<SP>
where
SP::Target: SignerProvider,
<SP::Target as SignerProvider>::EcdsaSigner: ChannelSigner,
{
fn from(channel: FundedChannel<SP>) -> Self {
ChannelPhase::Funded(channel)
Channel::Funded(channel)
}
}

View File

@ -48,7 +48,7 @@ use crate::events::{self, Event, EventHandler, EventsProvider, InboundChannelFun
use crate::ln::inbound_payment;
use crate::ln::types::ChannelId;
use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
use crate::ln::channel::{self, ChannelPhase, ChannelError, ChannelUpdateStatus, FundedChannel, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext};
use crate::ln::channel::{self, Channel, ChannelError, ChannelUpdateStatus, FundedChannel, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext};
#[cfg(any(dual_funding, splicing))]
use crate::ln::channel::PendingV2Channel;
use crate::ln::channel_state::ChannelDetails;
@ -1289,10 +1289,10 @@ impl Readable for Option<RAAMonitorUpdateBlockingAction> {
/// State we hold per-peer.
pub(super) struct PeerState<SP: Deref> where SP::Target: SignerProvider {
/// `channel_id` -> `ChannelPhase`
/// `channel_id` -> `Channel`
///
/// Holds all channels within corresponding `ChannelPhase`s where the peer is the counterparty.
pub(super) channel_by_id: HashMap<ChannelId, ChannelPhase<SP>>,
/// Holds all channels where the peer is the counterparty.
pub(super) channel_by_id: HashMap<ChannelId, Channel<SP>>,
/// `temporary_channel_id` -> `InboundChannelRequest`.
///
/// When manual channel acceptance is enabled, this holds all unaccepted inbound channels where
@ -3219,7 +3219,7 @@ macro_rules! handle_monitor_update_completion {
let mut peer_state = peer_state_mutex.lock().unwrap();
if let Some(chan) = peer_state.channel_by_id
.get_mut(&channel_id)
.and_then(ChannelPhase::as_funded_mut)
.and_then(Channel::as_funded_mut)
{
batch_funding_tx = batch_funding_tx.or_else(|| chan.context.unbroadcasted_funding());
chan.set_batch_ready();
@ -3668,7 +3668,7 @@ where
panic!("RNG is bad???");
}
},
hash_map::Entry::Vacant(entry) => { entry.insert(ChannelPhase::from(channel)); }
hash_map::Entry::Vacant(entry) => { entry.insert(Channel::from(channel)); }
}
if let Some(msg) = res {
@ -3695,7 +3695,7 @@ where
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
let peer_state = &mut *peer_state_lock;
res.extend(peer_state.channel_by_id.iter()
// Only `Channels` in the `ChannelPhase::Funded` phase can be considered funded.
// Only `Channels` in the `Channel::Funded` phase can be considered funded.
.filter_map(|(chan_id, phase)| phase.as_funded().map(|chan| (chan_id, chan)))
.filter(f)
.map(|(_channel_id, channel)| {
@ -4259,7 +4259,7 @@ where
}
let mut peer_state_lock = peer_state_mutex_opt.unwrap().lock().unwrap();
let peer_state = &mut *peer_state_lock;
match peer_state.channel_by_id.get_mut(&channel_id).and_then(ChannelPhase::as_funded_mut) {
match peer_state.channel_by_id.get_mut(&channel_id).and_then(Channel::as_funded_mut) {
None => None,
Some(chan) => Some(callback(chan)),
}
@ -5036,7 +5036,7 @@ where
let peer_state = &mut *peer_state_lock;
let funding_txo;
let (mut chan, msg_opt) = match peer_state.channel_by_id.remove(&temporary_channel_id)
.map(ChannelPhase::into_unfunded_outbound_v1)
.map(Channel::into_unfunded_outbound_v1)
{
Some(Ok(mut chan)) => {
macro_rules! close_chan { ($err: expr, $api_err: expr, $chan: expr) => { {
@ -5116,7 +5116,7 @@ where
return Err(APIError::ChannelUnavailable { err });
}
}
e.insert(ChannelPhase::from(chan));
e.insert(Channel::from(chan));
}
}
Ok(())
@ -5901,7 +5901,7 @@ where
// The channel with the least amount of outbound liquidity will be used to maximize the
// probability of being able to successfully forward a subsequent HTLC.
let maybe_optimal_channel = peer_state.channel_by_id.values_mut()
.filter_map(ChannelPhase::as_funded_mut)
.filter_map(Channel::as_funded_mut)
.filter_map(|chan| {
let balances = chan.context.get_available_balances(&self.fee_estimator);
if outgoing_amt_msat <= balances.next_outbound_htlc_limit_msat &&
@ -5919,7 +5919,7 @@ where
// Fall back to the specified channel to return an appropriate error.
if let Some(chan) = peer_state.channel_by_id
.get_mut(&forward_chan_id)
.and_then(ChannelPhase::as_funded_mut)
.and_then(Channel::as_funded_mut)
{
chan
} else {
@ -5950,7 +5950,7 @@ where
if let Some(chan) = peer_state.channel_by_id
.get_mut(&forward_chan_id)
.and_then(ChannelPhase::as_funded_mut)
.and_then(Channel::as_funded_mut)
{
let failure_code = 0x1000|7;
let data = self.get_htlc_inbound_temp_fail_data(failure_code);
@ -5971,7 +5971,7 @@ where
HTLCForwardInfo::FailHTLC { htlc_id, ref err_packet } => {
if let Some(chan) = peer_state.channel_by_id
.get_mut(&forward_chan_id)
.and_then(ChannelPhase::as_funded_mut)
.and_then(Channel::as_funded_mut)
{
let logger = WithChannelContext::from(&self.logger, &chan.context, None);
log_trace!(logger, "Failing HTLC back to channel with short id {} (backward HTLC ID {}) after delay", short_chan_id, htlc_id);
@ -5984,7 +5984,7 @@ where
HTLCForwardInfo::FailMalformedHTLC { htlc_id, failure_code, sha256_of_onion } => {
if let Some(chan) = peer_state.channel_by_id
.get_mut(&forward_chan_id)
.and_then(ChannelPhase::as_funded_mut)
.and_then(Channel::as_funded_mut)
{
let logger = WithChannelContext::from(&self.logger, &chan.context, None);
log_trace!(logger, "Failing malformed HTLC back to channel with short id {} (backward HTLC ID {}) after delay", short_chan_id, htlc_id);
@ -6003,7 +6003,7 @@ where
if let ChannelError::Ignore(msg) = e {
if let Some(chan) = peer_state.channel_by_id
.get_mut(&forward_chan_id)
.and_then(ChannelPhase::as_funded_mut)
.and_then(Channel::as_funded_mut)
{
let logger = WithChannelContext::from(&self.logger, &chan.context, None);
log_trace!(logger, "Failed to fail HTLC with ID {} backwards to short_id {}: {}", htlc_id, short_chan_id, msg);
@ -6314,7 +6314,7 @@ where
let peer_state = &mut *peer_state_lock;
if let Some(chan) = peer_state.channel_by_id
.get_mut(&channel_id)
.and_then(ChannelPhase::as_funded_mut)
.and_then(Channel::as_funded_mut)
{
handle_monitor_update_completion!(self, peer_state_lock, peer_state, per_peer_state, chan);
} else {
@ -7581,7 +7581,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
if let Some(chan) = peer_state.channel_by_id
.get_mut(channel_id)
.and_then(ChannelPhase::as_funded_mut)
.and_then(Channel::as_funded_mut)
{
if chan.is_awaiting_monitor_update() {
log_trace!(logger, "Channel is open and awaiting update, resuming it");
@ -7689,7 +7689,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
msg,
}
});
(*temporary_channel_id, ChannelPhase::from(channel), message_send_event)
(*temporary_channel_id, Channel::from(channel), message_send_event)
})
},
#[cfg(dual_funding)]
@ -7713,7 +7713,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
node_id: channel.context.get_counterparty_node_id(),
msg: channel.accept_inbound_dual_funded_channel()
};
(channel.context.channel_id(), ChannelPhase::from(channel), Some(message_send_event))
(channel.context.channel_id(), Channel::from(channel), Some(message_send_event))
})
},
}
@ -7977,7 +7977,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
msg,
}
});
(ChannelPhase::from(channel), message_send_event)
(Channel::from(channel), message_send_event)
},
#[cfg(dual_funding)]
OpenChannelMessageRef::V2(msg) => {
@ -7991,7 +7991,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
node_id: *counterparty_node_id,
msg: channel.accept_inbound_dual_funded_channel(),
};
(ChannelPhase::from(channel), Some(message_send_event))
(Channel::from(channel), Some(message_send_event))
},
};
@ -8058,7 +8058,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
let peer_state = &mut *peer_state_lock;
let (mut chan, funding_msg_opt, monitor) =
match peer_state.channel_by_id.remove(&msg.temporary_channel_id)
.map(ChannelPhase::into_unfunded_inbound_v1)
.map(Channel::into_unfunded_inbound_v1)
{
Some(Ok(inbound_chan)) => {
let logger = WithChannelContext::from(&self.logger, &inbound_chan.context, None);
@ -8124,7 +8124,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
});
}
if let Some(chan) = e.insert(ChannelPhase::from(chan)).as_funded_mut() {
if let Some(chan) = e.insert(Channel::from(chan)).as_funded_mut() {
handle_new_monitor_update!(self, persist_state, peer_state_lock, peer_state,
per_peer_state, chan, INITIAL_MONITOR);
} else {
@ -8171,7 +8171,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
// We really should be able to insert here without doing a second
// lookup, but sadly rust stdlib doesn't currently allow keeping
// the original Entry around with the value removed.
let chan = peer_state.channel_by_id.entry(msg.channel_id).or_insert(ChannelPhase::from(chan));
let chan = peer_state.channel_by_id.entry(msg.channel_id).or_insert(Channel::from(chan));
if let Some(chan) = chan.as_funded_mut() {
handle_new_monitor_update!(self, persist_status, peer_state_lock, peer_state, per_peer_state, chan, INITIAL_MONITOR);
} else { unreachable!(); }
@ -8203,7 +8203,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
}
}
fn internal_tx_msg<HandleTxMsgFn: Fn(&mut ChannelPhase<SP>) -> Result<MessageSendEvent, &'static str>>(
fn internal_tx_msg<HandleTxMsgFn: Fn(&mut Channel<SP>) -> Result<MessageSendEvent, &'static str>>(
&self, counterparty_node_id: &PublicKey, channel_id: ChannelId, tx_msg_handler: HandleTxMsgFn
) -> Result<(), MsgHandleErrInternal> {
let per_peer_state = self.per_peer_state.read().unwrap();
@ -8238,7 +8238,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
}
fn internal_tx_add_input(&self, counterparty_node_id: PublicKey, msg: &msgs::TxAddInput) -> Result<(), MsgHandleErrInternal> {
self.internal_tx_msg(&counterparty_node_id, msg.channel_id, |channel_phase: &mut ChannelPhase<SP>| {
self.internal_tx_msg(&counterparty_node_id, msg.channel_id, |channel_phase: &mut Channel<SP>| {
match channel_phase.as_unfunded_v2_mut() {
Some(channel) => {
Ok(channel.tx_add_input(msg).into_msg_send_event(counterparty_node_id))
@ -8249,7 +8249,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
}
fn internal_tx_add_output(&self, counterparty_node_id: PublicKey, msg: &msgs::TxAddOutput) -> Result<(), MsgHandleErrInternal> {
self.internal_tx_msg(&counterparty_node_id, msg.channel_id, |channel_phase: &mut ChannelPhase<SP>| {
self.internal_tx_msg(&counterparty_node_id, msg.channel_id, |channel_phase: &mut Channel<SP>| {
match channel_phase.as_unfunded_v2_mut() {
Some(channel) => {
Ok(channel.tx_add_output(msg).into_msg_send_event(counterparty_node_id))
@ -8260,7 +8260,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
}
fn internal_tx_remove_input(&self, counterparty_node_id: PublicKey, msg: &msgs::TxRemoveInput) -> Result<(), MsgHandleErrInternal> {
self.internal_tx_msg(&counterparty_node_id, msg.channel_id, |channel_phase: &mut ChannelPhase<SP>| {
self.internal_tx_msg(&counterparty_node_id, msg.channel_id, |channel_phase: &mut Channel<SP>| {
match channel_phase.as_unfunded_v2_mut() {
Some(channel) => {
Ok(channel.tx_remove_input(msg).into_msg_send_event(counterparty_node_id))
@ -8271,7 +8271,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
}
fn internal_tx_remove_output(&self, counterparty_node_id: PublicKey, msg: &msgs::TxRemoveOutput) -> Result<(), MsgHandleErrInternal> {
self.internal_tx_msg(&counterparty_node_id, msg.channel_id, |channel_phase: &mut ChannelPhase<SP>| {
self.internal_tx_msg(&counterparty_node_id, msg.channel_id, |channel_phase: &mut Channel<SP>| {
match channel_phase.as_unfunded_v2_mut() {
Some(channel) => {
Ok(channel.tx_remove_output(msg).into_msg_send_event(counterparty_node_id))
@ -8326,7 +8326,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
.into()))
},
}.map_err(|err| MsgHandleErrInternal::send_err_msg_no_close(format!("{}", err), msg.channel_id))?;
peer_state.channel_by_id.insert(channel_id, ChannelPhase::from(channel));
peer_state.channel_by_id.insert(channel_id, Channel::from(channel));
if let Some(funding_ready_for_sig_event) = funding_ready_for_sig_event_opt {
let mut pending_events = self.pending_events.lock().unwrap();
pending_events.push_back((funding_ready_for_sig_event, None));
@ -8417,7 +8417,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
Some(chan) => &mut chan.interactive_tx_constructor,
None => if channel_phase.is_funded() {
// TODO(splicing)/TODO(RBF): We'll also be doing interactive tx construction
// for a "ChannelPhase::Funded" when we want to bump the fee on an interactively
// for a "Channel::Funded" when we want to bump the fee on an interactively
// constructed funding tx or during splicing. For now we send an error as we would
// never ack an RBF attempt or a splice for now:
try_chan_phase_entry!(self, peer_state, Err(ChannelError::Warn(
@ -8631,7 +8631,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
log_info!(WithContext::from(&self.logger, Some(*counterparty_node_id), channel_id, None), "Broadcasting {}", log_tx!(broadcast_tx));
self.tx_broadcaster.broadcast_transactions(&[&broadcast_tx]);
}
if let Some(chan) = chan_option.as_ref().and_then(ChannelPhase::as_funded) {
if let Some(chan) = chan_option.as_ref().and_then(Channel::as_funded) {
if let Ok(update) = self.get_channel_update_for_broadcast(chan) {
let mut pending_broadcast_messages = self.pending_broadcast_messages.lock().unwrap();
pending_broadcast_messages.push(events::MessageSendEvent::BroadcastChannelUpdate {
@ -9454,7 +9454,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
// Returns whether we should remove this channel as it's just been closed.
let unblock_chan = |phase: &mut ChannelPhase<SP>, pending_msg_events: &mut Vec<MessageSendEvent>| -> Option<ShutdownResult> {
let unblock_chan = |phase: &mut Channel<SP>, pending_msg_events: &mut Vec<MessageSendEvent>| -> Option<ShutdownResult> {
let node_id = phase.context().get_counterparty_node_id();
match (phase.signer_maybe_unblocked(self.chain_hash, &self.logger), phase.as_funded()) {
(Some(msgs), Some(chan)) => {
@ -10530,7 +10530,7 @@ where
for (_cp_id, peer_state_mutex) in per_peer_state.iter() {
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
let peer_state = &mut *peer_state_lock;
for chan in peer_state.channel_by_id.values().filter_map(ChannelPhase::as_funded) {
for chan in peer_state.channel_by_id.values().filter_map(Channel::as_funded) {
for (htlc_source, _) in chan.inflight_htlc_sources() {
if let HTLCSource::OutboundRoute { path, .. } = htlc_source {
inflight_htlcs.process_path(path, self.get_our_node_id());
@ -10905,7 +10905,7 @@ where
for (_cp_id, peer_state_mutex) in self.per_peer_state.read().unwrap().iter() {
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
let peer_state = &mut *peer_state_lock;
for chan in peer_state.channel_by_id.values().filter_map(ChannelPhase::as_funded) {
for chan in peer_state.channel_by_id.values().filter_map(Channel::as_funded) {
let txid_opt = chan.context.get_funding_txo();
let height_opt = chan.context.get_funding_tx_confirmation_height();
let hash_opt = chan.context.get_funding_tx_confirmed_in();
@ -11690,7 +11690,7 @@ where
let mut peer_state = peer_state_mutex_opt.unwrap().lock().unwrap();
if let Some(chan) = peer_state.channel_by_id
.get(&msg.channel_id)
.and_then(ChannelPhase::as_funded)
.and_then(Channel::as_funded)
{
if let Some(msg) = chan.get_outbound_shutdown() {
peer_state.pending_msg_events.push(events::MessageSendEvent::SendShutdown {
@ -12721,7 +12721,7 @@ where
number_of_funded_channels += peer_state.channel_by_id
.values()
.filter_map(ChannelPhase::as_funded)
.filter_map(Channel::as_funded)
.filter(|chan| chan.context.is_funding_broadcast())
.count();
}
@ -12733,7 +12733,7 @@ where
let peer_state = &mut *peer_state_lock;
for channel in peer_state.channel_by_id
.values()
.filter_map(ChannelPhase::as_funded)
.filter_map(Channel::as_funded)
.filter(|channel| channel.context.is_funding_broadcast())
{
channel.write(writer)?;
@ -13253,7 +13253,7 @@ where
per_peer_state.entry(channel.context.get_counterparty_node_id())
.or_insert_with(|| Mutex::new(empty_peer_state()))
.get_mut().unwrap()
.channel_by_id.insert(channel.context.channel_id(), ChannelPhase::from(channel));
.channel_by_id.insert(channel.context.channel_id(), Channel::from(channel));
}
} else if channel.is_awaiting_initial_mon_persist() {
// If we were persisted and shut down while the initial ChannelMonitor persistence
@ -14252,7 +14252,7 @@ where
let peer_state = &mut *peer_state_lock;
if let Some(channel) = peer_state.channel_by_id
.get_mut(&previous_channel_id)
.and_then(ChannelPhase::as_funded_mut)
.and_then(Channel::as_funded_mut)
{
let logger = WithChannelContext::from(&channel_manager.logger, &channel.context, Some(payment_hash));
channel.claim_htlc_while_disconnected_dropping_mon_update_legacy(

View File

@ -3605,7 +3605,7 @@ macro_rules! get_channel_value_stat {
($node: expr, $counterparty_node: expr, $channel_id: expr) => {{
let peer_state_lock = $node.node.per_peer_state.read().unwrap();
let chan_lock = peer_state_lock.get(&$counterparty_node.node.get_our_node_id()).unwrap().lock().unwrap();
let chan = chan_lock.channel_by_id.get(&$channel_id).and_then(ChannelPhase::as_funded).unwrap();
let chan = chan_lock.channel_by_id.get(&$channel_id).and_then(Channel::as_funded).unwrap();
chan.get_value_stat()
}}
}

View File

@ -21,7 +21,7 @@ use crate::sign::{ecdsa::EcdsaChannelSigner, EntropySource, OutputSpender, Signe
use crate::events::{Event, FundingInfo, MessageSendEvent, MessageSendEventsProvider, PathFailure, PaymentPurpose, ClosureReason, HTLCDestination, PaymentFailureReason};
use crate::ln::types::ChannelId;
use crate::types::payment::{PaymentPreimage, PaymentSecret, PaymentHash};
use crate::ln::channel::{CONCURRENT_INBOUND_HTLC_FEE_BUFFER, FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE, MIN_AFFORDABLE_HTLC_COUNT, get_holder_selected_channel_reserve_satoshis, OutboundV1Channel, InboundV1Channel, COINBASE_MATURITY, ChannelPhase};
use crate::ln::channel::{CONCURRENT_INBOUND_HTLC_FEE_BUFFER, FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE, MIN_AFFORDABLE_HTLC_COUNT, get_holder_selected_channel_reserve_satoshis, OutboundV1Channel, InboundV1Channel, COINBASE_MATURITY, Channel};
use crate::ln::channelmanager::{self, PaymentId, RAACommitmentOrder, PaymentSendFailure, RecipientOnionFields, BREAKDOWN_TIMEOUT, ENABLE_GOSSIP_TICKS, DISABLE_GOSSIP_TICKS, MIN_CLTV_EXPIRY_DELTA};
use crate::ln::channel::{DISCONNECT_PEER_AWAITING_RESPONSE_TICKS, ChannelError};
use crate::ln::{chan_utils, onion_utils};
@ -216,7 +216,7 @@ fn do_test_counterparty_no_reserve(send_from_initiator: bool) {
let channel_phase = get_channel_ref!(sender_node, counterparty_node, sender_node_per_peer_lock, sender_node_peer_state_lock, temp_channel_id);
match channel_phase {
ChannelPhase::UnfundedInboundV1(_) | ChannelPhase::UnfundedOutboundV1(_) => {
Channel::UnfundedInboundV1(_) | Channel::UnfundedOutboundV1(_) => {
let chan_context = channel_phase.context_mut();
chan_context.holder_selected_channel_reserve_satoshis = 0;
chan_context.holder_max_htlc_value_in_flight_msat = 100_000_000;
@ -734,7 +734,7 @@ fn test_update_fee_that_funder_cannot_afford() {
let (local_revocation_basepoint, local_htlc_basepoint, local_funding) = {
let per_peer_state = nodes[0].node.per_peer_state.read().unwrap();
let chan_lock = per_peer_state.get(&nodes[1].node.get_our_node_id()).unwrap().lock().unwrap();
let local_chan = chan_lock.channel_by_id.get(&chan.2).and_then(ChannelPhase::as_funded).unwrap();
let local_chan = chan_lock.channel_by_id.get(&chan.2).and_then(Channel::as_funded).unwrap();
let chan_signer = local_chan.get_signer();
let pubkeys = chan_signer.as_ref().pubkeys();
(pubkeys.revocation_basepoint, pubkeys.htlc_basepoint,
@ -743,7 +743,7 @@ fn test_update_fee_that_funder_cannot_afford() {
let (remote_delayed_payment_basepoint, remote_htlc_basepoint, remote_point, remote_funding) = {
let per_peer_state = nodes[1].node.per_peer_state.read().unwrap();
let chan_lock = per_peer_state.get(&nodes[0].node.get_our_node_id()).unwrap().lock().unwrap();
let remote_chan = chan_lock.channel_by_id.get(&chan.2).and_then(ChannelPhase::as_funded).unwrap();
let remote_chan = chan_lock.channel_by_id.get(&chan.2).and_then(Channel::as_funded).unwrap();
let chan_signer = remote_chan.get_signer();
let pubkeys = chan_signer.as_ref().pubkeys();
(pubkeys.delayed_payment_basepoint, pubkeys.htlc_basepoint,
@ -758,7 +758,7 @@ fn test_update_fee_that_funder_cannot_afford() {
let res = {
let per_peer_state = nodes[0].node.per_peer_state.read().unwrap();
let local_chan_lock = per_peer_state.get(&nodes[1].node.get_our_node_id()).unwrap().lock().unwrap();
let local_chan = local_chan_lock.channel_by_id.get(&chan.2).and_then(ChannelPhase::as_funded).unwrap();
let local_chan = local_chan_lock.channel_by_id.get(&chan.2).and_then(Channel::as_funded).unwrap();
let local_chan_signer = local_chan.get_signer();
let mut htlcs: Vec<(HTLCOutputInCommitment, ())> = vec![];
let commitment_tx = CommitmentTransaction::new_with_auxiliary_htlc_data(
@ -1464,7 +1464,7 @@ fn test_fee_spike_violation_fails_htlc() {
let (local_revocation_basepoint, local_htlc_basepoint, local_secret, next_local_point, local_funding) = {
let per_peer_state = nodes[0].node.per_peer_state.read().unwrap();
let chan_lock = per_peer_state.get(&nodes[1].node.get_our_node_id()).unwrap().lock().unwrap();
let local_chan = chan_lock.channel_by_id.get(&chan.2).and_then(ChannelPhase::as_funded).unwrap();
let local_chan = chan_lock.channel_by_id.get(&chan.2).and_then(Channel::as_funded).unwrap();
let chan_signer = local_chan.get_signer();
// Make the signer believe we validated another commitment, so we can release the secret
chan_signer.as_ecdsa().unwrap().get_enforcement_state().last_holder_commitment -= 1;
@ -1478,7 +1478,7 @@ fn test_fee_spike_violation_fails_htlc() {
let (remote_delayed_payment_basepoint, remote_htlc_basepoint, remote_point, remote_funding) = {
let per_peer_state = nodes[1].node.per_peer_state.read().unwrap();
let chan_lock = per_peer_state.get(&nodes[0].node.get_our_node_id()).unwrap().lock().unwrap();
let remote_chan = chan_lock.channel_by_id.get(&chan.2).and_then(ChannelPhase::as_funded).unwrap();
let remote_chan = chan_lock.channel_by_id.get(&chan.2).and_then(Channel::as_funded).unwrap();
let chan_signer = remote_chan.get_signer();
let pubkeys = chan_signer.as_ref().pubkeys();
(pubkeys.delayed_payment_basepoint, pubkeys.htlc_basepoint,
@ -1507,7 +1507,7 @@ fn test_fee_spike_violation_fails_htlc() {
let res = {
let per_peer_state = nodes[0].node.per_peer_state.read().unwrap();
let local_chan_lock = per_peer_state.get(&nodes[1].node.get_our_node_id()).unwrap().lock().unwrap();
let local_chan = local_chan_lock.channel_by_id.get(&chan.2).and_then(ChannelPhase::as_funded).unwrap();
let local_chan = local_chan_lock.channel_by_id.get(&chan.2).and_then(Channel::as_funded).unwrap();
let local_chan_signer = local_chan.get_signer();
let commitment_tx = CommitmentTransaction::new_with_auxiliary_htlc_data(
commitment_number,
@ -7774,7 +7774,7 @@ fn test_counterparty_raa_skip_no_crash() {
{
let per_peer_state = nodes[0].node.per_peer_state.read().unwrap();
let mut guard = per_peer_state.get(&nodes[1].node.get_our_node_id()).unwrap().lock().unwrap();
let keys = guard.channel_by_id.get(&channel_id).and_then(ChannelPhase::as_funded).unwrap()
let keys = guard.channel_by_id.get(&channel_id).and_then(Channel::as_funded).unwrap()
.get_signer();
const INITIAL_COMMITMENT_NUMBER: u64 = (1 << 48) - 1;
@ -9221,11 +9221,11 @@ fn test_duplicate_chan_id() {
// try to create another channel. Instead, we drop the channel entirely here (leaving the
// channelmanager in a possibly nonsense state instead).
match a_peer_state.channel_by_id.remove(&open_chan_2_msg.common_fields.temporary_channel_id).unwrap() {
ChannelPhase::UnfundedOutboundV1(mut chan) => {
Channel::UnfundedOutboundV1(mut chan) => {
let logger = test_utils::TestLogger::new();
chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap()
},
_ => panic!("Unexpected ChannelPhase variant"),
_ => panic!("Unexpected Channel variant"),
}.unwrap()
};
check_added_monitors!(nodes[0], 0);
@ -9927,10 +9927,10 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e
let mut node_0_per_peer_lock;
let mut node_0_peer_state_lock;
match get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, temporary_channel_id) {
ChannelPhase::UnfundedOutboundV1(chan) => {
Channel::UnfundedOutboundV1(chan) => {
chan.context.holder_dust_limit_satoshis = 546;
},
_ => panic!("Unexpected ChannelPhase variant"),
_ => panic!("Unexpected Channel variant"),
}
}