Expose ChannelDetails::channel_shutdown_state#827
Expose ChannelDetails::channel_shutdown_state#827f3r10 wants to merge 1 commit intolightningdevkit:mainfrom
ChannelDetails::channel_shutdown_state#827Conversation
|
👋 Thanks for assigning @tnull as a reviewer! |
src/types.rs
Outdated
| pub config: ChannelConfig, | ||
| /// The current shutdown state of the channel, if any. | ||
| /// | ||
| /// Returns `None` for channels that have not yet started the shutdown process. |
There was a problem hiding this comment.
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.
|
Thanks for looking into this. Could we add assertions for |
|
🔔 1st Reminder Hey @tnull! This PR has been waiting for your review. |
src/types.rs
Outdated
| /// [`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 { |
There was a problem hiding this comment.
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?
30b610c to
32c3eef
Compare
|
🔔 1st Reminder Hey @tnull @Camillarhi! This PR has been waiting for your review. |
1 similar comment
|
🔔 1st Reminder Hey @tnull @Camillarhi! This PR has been waiting for your review. |
tnull
left a comment
There was a problem hiding this comment.
Thanks! Already looks good, just some minor remarks regarding re-exports and test coverage.
src/ffi/types.rs
Outdated
| pub use lightning::chain::channelmonitor::BalanceSource; | ||
| use lightning::events::PaidBolt12Invoice as LdkPaidBolt12Invoice; | ||
| pub use lightning::events::{ClosureReason, PaymentFailureReason}; | ||
| pub use lightning::ln::channel_state::ChannelShutdownState; |
There was a problem hiding this comment.
nit: I believe we don't need this to be pub?
src/types.rs
Outdated
| use lightning::chain::chainmonitor; | ||
| use lightning::impl_writeable_tlv_based; | ||
| use lightning::ln::channel_state::ChannelDetails as LdkChannelDetails; | ||
| pub use lightning::ln::channel_state::ChannelShutdownState; |
There was a problem hiding this comment.
nit: Let's drop the pub here.
src/lib.rs
Outdated
| Wallet, | ||
| }; | ||
| pub use types::{ChannelDetails, CustomTlvRecord, PeerDetails, SyncAndAsyncKVStore, UserChannelId}; | ||
| pub use types::{ |
There was a problem hiding this comment.
nit: Rather than re-exporting via crate::types, lets just add a pub use lightning::ln::channel_state::ChannelShutdownState; line.
src/types.rs
Outdated
| pub config: ChannelConfig, | ||
| /// The current shutdown state of the channel, if any. | ||
| /// | ||
| /// Returns `None` for `ChannelDetails` serialized on LDK versions prior to 0.0.116. |
There was a problem hiding this comment.
As this is in LDK Node context, we should provide compatibility notes based on LDK Node's versions. In this case that would mean LDK Node versions prior to 0.2 (aruably that's so old we could also omit the note altogether).
There was a problem hiding this comment.
I agree, I am going to remove that line
tests/integration_tests_rust.rs
Outdated
| .confirmations, | ||
| Some(0) | ||
| ); | ||
| let client_channel = client_node |
There was a problem hiding this comment.
Could you expand on why the LSPS2 tests in particular do need additional test coverage for channel shutdown?
There was a problem hiding this comment.
you are right, those tests are not necessary. I am going to revert those.
| None | Some(ChannelShutdownState::NotShuttingDown) | ||
| )); | ||
| } | ||
|
|
There was a problem hiding this comment.
Hmm, if we add all these assertions for NotShuttingDown, should we at least also add one later for a case when we are shutting down (i.e., close/force close)?
There was a problem hiding this comment.
I have been trying to test this part, but the problem is that for cooperative close, the shutdown completes very quickly in tests, so by the time we call list_channels() after close_channel(), the channel may already be gone.
In the force close phase, LDK doesn't use the cooperative shutdown state machine for force closes, so the field would still be None/NotShuttingDown right up until the channel disappears.
tests/integration_tests_rust.rs
Outdated
| assert!(channel.channel_value_sats > premine_amount_sat - anchor_reserve_sat - 500); | ||
| assert_eq!(channel.counterparty_node_id, node_b.node_id()); | ||
| assert_eq!(channel.funding_txo.unwrap(), funding_txo); | ||
| assert!(matches!( |
There was a problem hiding this comment.
I think we don't need to add all of these assertions, as the actual behavior should be tested in LDK.
|
🔔 2nd Reminder Hey @Camillarhi! This PR has been waiting for your review. |
|
🔔 3rd Reminder Hey @Camillarhi! This PR has been waiting for your review. |
|
🔔 4th Reminder Hey @Camillarhi! This PR has been waiting for your review. |
|
🔔 5th Reminder Hey @Camillarhi! This PR has been waiting for your review. |
Add a `ChannelShutdownState` enum mirroring LDK's own type, and expose it as an `Option<ChannelShutdownState>` field on `ChannelDetails`.
32c3eef to
3b68c59
Compare
tnull
left a comment
There was a problem hiding this comment.
One comment, otherwise LGTM
Though, IMO, you could further reduce the test changes. Maybe just add one at an opportune place? Asserting on NotShuttingDown over and over again isn't super helpful and just increases clutter.
| 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. |
There was a problem hiding this comment.
Please add a note that this will be None for objects first serialized with LDK Node v0.1.
Summary
Closes #803.
We currently don't expose
ChannelDetails::channel_shutdown_state, so there is no good way for callers to tell whether a channel is actively going through a cooperative shutdown or merely has its peer temporarily disconnected — both situations causeis_usableto becomefalse.This PR adds:
ChannelShutdownStateenum (mirroring LDK's own type) with variantsNotShuttingDown,ShutdownInitiated,ResolvingHTLCs,NegotiatingClosingFee, andShutdownComplete.Option<ChannelShutdownState>field onChannelDetails, populated fromLdkChannelDetails::channel_shutdown_statevia the existingFromconversion.typedef enum ChannelShutdownStateentry in the UniFFI UDL so the field is available to Swift, Kotlin, and Python bindings.ChannelShutdownStatefrom the crate root.