Skip to content

Commit 30b610c

Browse files
committed
Expose ChannelDetails::channel_shutdown_state
Add a `ChannelShutdownState` enum mirroring LDK's own type, and expose it as an `Option<ChannelShutdownState>` field on `ChannelDetails`.
1 parent b0e159a commit 30b610c

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

bindings/ldk_node.udl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ dictionary OutPoint {
316316

317317
typedef dictionary ChannelDetails;
318318

319+
typedef enum ChannelShutdownState;
320+
319321
typedef dictionary PeerDetails;
320322

321323
[Remote]

src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ pub use lightning;
145145
use lightning::chain::BestBlock;
146146
use lightning::impl_writeable_tlv_based;
147147
use lightning::ln::chan_utils::FUNDING_TRANSACTION_WITNESS_WEIGHT;
148-
use lightning::ln::channel_state::{ChannelDetails as LdkChannelDetails, ChannelShutdownState};
148+
use lightning::ln::channel_state::{
149+
ChannelDetails as LdkChannelDetails, ChannelShutdownState as LdkChannelShutdownState,
150+
};
149151
use lightning::ln::channelmanager::PaymentId;
150152
use lightning::ln::msgs::SocketAddress;
151153
use lightning::routing::gossip::NodeAlias;
@@ -173,7 +175,10 @@ use types::{
173175
HRNResolver, KeysManager, OnionMessenger, PaymentStore, PeerManager, Router, Scorer, Sweeper,
174176
Wallet,
175177
};
176-
pub use types::{ChannelDetails, CustomTlvRecord, PeerDetails, SyncAndAsyncKVStore, UserChannelId};
178+
pub use types::{
179+
ChannelDetails, ChannelShutdownState, CustomTlvRecord, PeerDetails, SyncAndAsyncKVStore,
180+
UserChannelId,
181+
};
177182
pub use vss_client;
178183

179184
use crate::scoring::setup_background_pathfinding_scores_sync;
@@ -2021,7 +2026,7 @@ pub(crate) fn total_anchor_channels_reserve_sats(
20212026
.filter(|c| {
20222027
!anchor_channels_config.trusted_peers_no_reserve.contains(&c.counterparty.node_id)
20232028
&& c.channel_shutdown_state
2024-
.map_or(true, |s| s != ChannelShutdownState::ShutdownComplete)
2029+
.map_or(true, |s| s != LdkChannelShutdownState::ShutdownComplete)
20252030
&& c.channel_type
20262031
.as_ref()
20272032
.map_or(false, |t| t.requires_anchors_zero_fee_htlc_tx())

src/types.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use bitcoin::{OutPoint, ScriptBuf};
1515
use bitcoin_payment_instructions::onion_message_resolver::LDKOnionMessageDNSSECHrnResolver;
1616
use lightning::chain::chainmonitor;
1717
use lightning::impl_writeable_tlv_based;
18-
use lightning::ln::channel_state::ChannelDetails as LdkChannelDetails;
18+
use lightning::ln::channel_state::{
19+
ChannelDetails as LdkChannelDetails, ChannelShutdownState as LdkChannelShutdownState,
20+
};
1921
use lightning::ln::msgs::{RoutingMessageHandler, SocketAddress};
2022
use lightning::ln::peer_handler::IgnoringMessageHandler;
2123
use lightning::ln::types::ChannelId;
@@ -347,6 +349,40 @@ impl fmt::Display for UserChannelId {
347349
}
348350
}
349351

352+
/// The shutdown state of a channel as returned in [`ChannelDetails::channel_shutdown_state`].
353+
///
354+
/// [`ChannelDetails::channel_shutdown_state`]: crate::ChannelDetails::channel_shutdown_state
355+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
356+
#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
357+
pub enum ChannelShutdownState {
358+
/// Channel has not sent or received a shutdown message.
359+
NotShuttingDown,
360+
/// Local node has sent a shutdown message for this channel.
361+
ShutdownInitiated,
362+
/// Shutdown message exchanges have concluded and the channels are in the midst of
363+
/// resolving all existing open HTLCs before closing can continue.
364+
ResolvingHTLCs,
365+
/// All HTLCs have been resolved, nodes are currently negotiating channel close onchain fee rates.
366+
NegotiatingClosingFee,
367+
/// We've successfully negotiated a closing_signed dance. At this point `ChannelManager` is about
368+
/// to drop the channel.
369+
ShutdownComplete,
370+
}
371+
372+
impl From<LdkChannelShutdownState> for ChannelShutdownState {
373+
fn from(value: LdkChannelShutdownState) -> Self {
374+
match value {
375+
LdkChannelShutdownState::NotShuttingDown => ChannelShutdownState::NotShuttingDown,
376+
LdkChannelShutdownState::ShutdownInitiated => ChannelShutdownState::ShutdownInitiated,
377+
LdkChannelShutdownState::ResolvingHTLCs => ChannelShutdownState::ResolvingHTLCs,
378+
LdkChannelShutdownState::NegotiatingClosingFee => {
379+
ChannelShutdownState::NegotiatingClosingFee
380+
},
381+
LdkChannelShutdownState::ShutdownComplete => ChannelShutdownState::ShutdownComplete,
382+
}
383+
}
384+
}
385+
350386
/// Details of a channel as returned by [`Node::list_channels`].
351387
///
352388
/// When a channel is spliced, most fields continue to refer to the original pre-splice channel
@@ -529,6 +565,10 @@ pub struct ChannelDetails {
529565
pub inbound_htlc_maximum_msat: Option<u64>,
530566
/// Set of configurable parameters that affect channel operation.
531567
pub config: ChannelConfig,
568+
/// The current shutdown state of the channel, if any.
569+
///
570+
/// Returns `None` for channels that have not yet started the shutdown process.
571+
pub channel_shutdown_state: Option<ChannelShutdownState>,
532572
}
533573

534574
impl From<LdkChannelDetails> for ChannelDetails {
@@ -584,6 +624,7 @@ impl From<LdkChannelDetails> for ChannelDetails {
584624
inbound_htlc_maximum_msat: value.inbound_htlc_maximum_msat,
585625
// unwrap safety: `config` is only `None` for LDK objects serialized prior to 0.0.109.
586626
config: value.config.map(|c| c.into()).unwrap(),
627+
channel_shutdown_state: value.channel_shutdown_state.map(|s| s.into()),
587628
}
588629
}
589630
}

0 commit comments

Comments
 (0)