Expose ChannelCounterparty and ReserveType in ChannelDetails#841
Expose ChannelCounterparty and ReserveType in ChannelDetails#841enigbe wants to merge 3 commits into
Conversation
|
👋 I see @tnull was un-assigned. |
This fixup moves node feature exposure from freestanding APIs to NodeStatus, as suggested in review. Rather than exposing init_features(), channel_features(), bolt11_invoice_features(), and node_features() as separate public methods on Node, this embeds NodeFeatures in the NodeStatus struct returned by Node::status(). Additionally, channel and invoice features at node level are confusing. Users would expect negotiated per-peer/channel/invoice features, not what the node generally supports. Access to negotiated features are addressed in lightningdevkit#841
tnull
left a comment
There was a problem hiding this comment.
Thanks! Looks pretty good, have a few initial comments.
33a36bd to
63f32ab
Compare
tnull
left a comment
There was a problem hiding this comment.
One comment, otherwise looks good. Feel free to squash (also the new fixup)
63f32ab to
56d86f7
Compare
|
Squashed all fix-ups. |
56d86f7 to
77dcbc4
Compare
fe4597a to
eb7f021
Compare
86e9936 to
863d5e7
Compare
863d5e7 to
b5736f1
Compare
|
🔔 1st Reminder Hey @tnull! This PR has been waiting for your review. |
|
🔔 2nd Reminder Hey @tnull! This PR has been waiting for your review. |
|
🔔 3rd Reminder Hey @tnull! This PR has been waiting for your review. |
tnull
left a comment
There was a problem hiding this comment.
Looks good I think. One nit.
tnull
left a comment
There was a problem hiding this comment.
This needs a minor rebase by now.
d67aaa8 to
fdbd4ff
Compare
|
Thanks for the review @tnull. I've rebased and also simplified the documentation on |
| /// to better separate parameters. | ||
| #[derive(Clone, Debug, PartialEq)] | ||
| #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] | ||
| pub struct ChannelCounterparty { |
There was a problem hiding this comment.
This needs to be re-exported via a pub use in src/ffi/types.rs.
There was a problem hiding this comment.
Why does this need to be re-exported in src/ffi/types.rs? We don't do this for other uniffi::Records. Do you mean src/lib.rs? If it's the latter, I've re-exported in the fix-up commit.
aa631a4 to
b4dcc99
Compare
b4dcc99 to
3b06d8e
Compare
| pub(crate) inner: LdkInitFeatures, | ||
| } | ||
|
|
||
| impl InitFeatures { |
There was a problem hiding this comment.
This seems to be missing #[uniffi::export]?
There was a problem hiding this comment.
This has been added.
There was a problem hiding this comment.
No, the one you added is also fine to keep, but we'll also need to add uniffi::export to the impl block, as otherwise the methods won't be available in bindings.
There was a problem hiding this comment.
That's right. I've added this and extended the coverage in the python test to check the now-exposed methods. I noticed NodeFeatures had the same issue, so I fixed and covered that as well.
| pub(crate) fn from_ldk( | ||
| value: LdkChannelDetails, anchor_channels_config: Option<&AnchorChannelsConfig>, | ||
| ) -> Self { | ||
| let reserve_type = |
There was a problem hiding this comment.
Hmm, the LDK docs on channel_type say: "None until negotiation completes and the channel type is finalized."
This means we'll erroneously report all channels as Legacy util the negotiation is fully done, no? Probably will need to make this an optional field, too, or have a state for 'not ready' or similar?
There was a problem hiding this comment.
Leaning more towards making it optional. Also, I updated the documentation to highlight this.
84095d9 to
2613151
Compare
We previously flattened ChannelCounterparty fields into ChannelDetails as individual counterparty_* fields, and InitFeatures was entirely omitted. This made it impossible for consumers to access per-peer feature flags, and awkward to access counterparty forwarding information without navigating the flattened field names. This commit replaces the flattened fields with a structured ChannelCounterparty type that mirrors LDK's ChannelCounterparty, exposing InitFeatures and CounterpartyForwardingInfo that were previously inaccessible. We keep outbound_htlc_minimum_msat optional because it is unavailable before receiving OpenChannel or AcceptChannel, and re-export ChannelCounterparty so Rust consumers can name the type.
We expose the reserve type of each channel through a new ReserveType enum on ChannelDetails. This tells users whether a channel uses adaptive anchor reserves, has no reserve due to a trusted peer, or is a legacy pre-anchor channel. The reserve type is derived at query time in list_channels by checking the channel's type features against trusted_peers_no_reserve. We replace the From<LdkChannelDetails> implementation with an explicit from_ldk method that takes the anchor channels config. Additionally, we document the rationale behind selecting adaptive reserve type in the unlikely event the anchor channels config was previously set and then later removed.
We add requires_* counterparts for every supports_* method on InitFeatures, completing the BOLT 9 feature flag coverage for FFI consumers. We export the existing feature helper methods for both InitFeatures and NodeFeatures through UniFFI. NodeFeatures had the same missing export path as InitFeatures and was noticed while addressing the InitFeatures FFI exposure. Additionally, we extend the Python full-cycle test to cover node features and init features on their real runtime paths.
2613151 to
fee7a73
Compare
What this PR does
In #305, we needed a way to expose channel type and the channel reserve without leaking implementation details not useful to users. The related discussion in #141 proposed a
ReserveTypeabstraction that bakes in both in a user-relevant way. This PR introduces the said enumeration toChannelDetailswith the following variants:Legacy: signifying pre-anchor channel types where on-chain fees paying for broadcast transactions following channel closure were pre-determinedTrustedPeersNoReserve: for anchor type channels with trusted peersAdaptive: indicating anchor channel with adaptive reserve, reflecting dynamic best-effort attempt at fee-bumping.(see @jkczyz's suggestion)
We modify the
ChannelDetailsconstructor to accept an optional anchor channels config to address the challenge of users cross-referencing the channel details and config to determine if counterparties are trusted.Additionally, following recommendation in #810 about negotiated features, this PR exposes per-peer
InitFeatures, and as a consequence, modifiesChannelDetailsby replacing the flattenedcounterparty_*withChannelCounterpartythat encapsulates them and mirror LDK's.Issue Addressed
Closes #305.
Builds on discussions and recommendations from #141 and #810.