Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ dictionary OutPoint {

typedef dictionary ChannelDetails;

typedef enum ChannelShutdownState;

typedef dictionary PeerDetails;

[Remote]
Expand Down
11 changes: 8 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ pub use lightning;
use lightning::chain::BestBlock;
use lightning::impl_writeable_tlv_based;
use lightning::ln::chan_utils::FUNDING_TRANSACTION_WITNESS_WEIGHT;
use lightning::ln::channel_state::{ChannelDetails as LdkChannelDetails, ChannelShutdownState};
use lightning::ln::channel_state::{
ChannelDetails as LdkChannelDetails, ChannelShutdownState as LdkChannelShutdownState,
};
use lightning::ln::channelmanager::PaymentId;
use lightning::ln::msgs::SocketAddress;
use lightning::routing::gossip::NodeAlias;
Expand Down Expand Up @@ -173,7 +175,10 @@ use types::{
HRNResolver, KeysManager, OnionMessenger, PaymentStore, PeerManager, Router, Scorer, Sweeper,
Wallet,
};
pub use types::{ChannelDetails, CustomTlvRecord, PeerDetails, SyncAndAsyncKVStore, UserChannelId};
pub use types::{
ChannelDetails, ChannelShutdownState, CustomTlvRecord, PeerDetails, SyncAndAsyncKVStore,
UserChannelId,
};
pub use vss_client;

use crate::scoring::setup_background_pathfinding_scores_sync;
Expand Down Expand Up @@ -2021,7 +2026,7 @@ pub(crate) fn total_anchor_channels_reserve_sats(
.filter(|c| {
!anchor_channels_config.trusted_peers_no_reserve.contains(&c.counterparty.node_id)
&& c.channel_shutdown_state
.map_or(true, |s| s != ChannelShutdownState::ShutdownComplete)
.map_or(true, |s| s != LdkChannelShutdownState::ShutdownComplete)
&& c.channel_type
.as_ref()
.map_or(false, |t| t.requires_anchors_zero_fee_htlc_tx())
Expand Down
43 changes: 42 additions & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ use bitcoin::{OutPoint, ScriptBuf};
use bitcoin_payment_instructions::onion_message_resolver::LDKOnionMessageDNSSECHrnResolver;
use lightning::chain::chainmonitor;
use lightning::impl_writeable_tlv_based;
use lightning::ln::channel_state::ChannelDetails as LdkChannelDetails;
use lightning::ln::channel_state::{
ChannelDetails as LdkChannelDetails, ChannelShutdownState as LdkChannelShutdownState,
};
use lightning::ln::msgs::{RoutingMessageHandler, SocketAddress};
use lightning::ln::peer_handler::IgnoringMessageHandler;
use lightning::ln::types::ChannelId;
Expand Down Expand Up @@ -347,6 +349,40 @@ impl fmt::Display for UserChannelId {
}
}

/// The shutdown state of a channel as returned in [`ChannelDetails::channel_shutdown_state`].
///
/// [`ChannelDetails::channel_shutdown_state`]: crate::ChannelDetails::channel_shutdown_state
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
pub enum ChannelShutdownState {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to duplicate this enum here, or could we get away with using the upstream one and only using #[uniffi::remote(Enum)] for uniffi?

/// Channel has not sent or received a shutdown message.
NotShuttingDown,
/// Local node has sent a shutdown message for this channel.
ShutdownInitiated,
/// Shutdown message exchanges have concluded and the channels are in the midst of
/// resolving all existing open HTLCs before closing can continue.
ResolvingHTLCs,
/// All HTLCs have been resolved, nodes are currently negotiating channel close onchain fee rates.
NegotiatingClosingFee,
/// We've successfully negotiated a closing_signed dance. At this point `ChannelManager` is about
/// to drop the channel.
ShutdownComplete,
}

impl From<LdkChannelShutdownState> for ChannelShutdownState {
fn from(value: LdkChannelShutdownState) -> Self {
match value {
LdkChannelShutdownState::NotShuttingDown => ChannelShutdownState::NotShuttingDown,
LdkChannelShutdownState::ShutdownInitiated => ChannelShutdownState::ShutdownInitiated,
LdkChannelShutdownState::ResolvingHTLCs => ChannelShutdownState::ResolvingHTLCs,
LdkChannelShutdownState::NegotiatingClosingFee => {
ChannelShutdownState::NegotiatingClosingFee
},
LdkChannelShutdownState::ShutdownComplete => ChannelShutdownState::ShutdownComplete,
}
}
}

/// Details of a channel as returned by [`Node::list_channels`].
///
/// When a channel is spliced, most fields continue to refer to the original pre-splice channel
Expand Down Expand Up @@ -529,6 +565,10 @@ pub struct ChannelDetails {
pub inbound_htlc_maximum_msat: Option<u64>,
/// Set of configurable parameters that affect channel operation.
pub config: ChannelConfig,
/// The current shutdown state of the channel, if any.
///
/// Returns `None` for channels that have not yet started the shutdown process.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we replace this to accurately reflect what the source from the library says Returns None for ChannelDetails serialized on LDK versions prior to 0.0.116.

pub channel_shutdown_state: Option<ChannelShutdownState>,
}

impl From<LdkChannelDetails> for ChannelDetails {
Expand Down Expand Up @@ -584,6 +624,7 @@ impl From<LdkChannelDetails> for ChannelDetails {
inbound_htlc_maximum_msat: value.inbound_htlc_maximum_msat,
// unwrap safety: `config` is only `None` for LDK objects serialized prior to 0.0.109.
config: value.config.map(|c| c.into()).unwrap(),
channel_shutdown_state: value.channel_shutdown_state.map(|s| s.into()),
}
}
}
Expand Down
Loading