From de54ff061f804a4fd11a176240174208275d8131 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Thu, 19 Nov 2026 10:23:17 +0100 Subject: [PATCH 1/7] Expose Esplora headers setter in bindings `Builder::set_chain_source_esplora_with_headers` was only available to Rust users, so bindings users had no way to authenticate against an Esplora server that requires custom request headers. Export the method via UniFFI alongside the plain Esplora setter, as all of its arguments are already representable in the bindings. Co-Authored-By: HAL 9000 --- src/builder.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index a8cba83db3..28104cf1ae 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -1079,10 +1079,7 @@ impl Builder { ) { self.inner.write().expect("lock").set_chain_source_esplora(server_url, sync_config); } -} -#[cfg(all(feature = "uniffi", feature = "chain-esplora"))] -impl ArcedNodeBuilder { /// Configures the [`Node`] instance to source its chain data from the given Esplora server. /// /// The given `headers` will be included in all requests to the Esplora server, typically used for From 9ccdfcd8920e6e12c9953e70b3429c36616cc044 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Thu, 19 Nov 2026 10:24:13 +0100 Subject: [PATCH 2/7] Expose LSPS2 service setup in bindings `Builder::enable_liquidity_provider` was only available to Rust users, even though `LSPS2ServiceConfig` is already a UniFFI record. Bindings users could therefore construct the service configuration but had no way to hand it to the builder. Export the method via UniFFI next to the other liquidity setter. Co-Authored-By: HAL 9000 --- src/builder.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index 28104cf1ae..6c05dfbfea 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -1216,10 +1216,7 @@ impl Builder { trust_peer_0conf, ); } -} -#[cfg(feature = "uniffi")] -impl ArcedNodeBuilder { /// Configures the [`Node`] instance to provide an [LSPS2] service, issuing just-in-time /// channels to clients. /// From d68c6596210ad4bbb31adf8af292819f49a9e9b6 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Thu, 19 Nov 2026 10:25:17 +0100 Subject: [PATCH 3/7] Expose channel-pair stats aggregation in bindings `aggregate_channel_pair_stats` was only available to Rust users, so bindings users could list channel-pair forwarding buckets but had to reimplement the aggregation into cumulative totals themselves. Export it as a free function via UniFFI. Co-Authored-By: HAL 9000 --- src/payment/forwarding_store.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/payment/forwarding_store.rs b/src/payment/forwarding_store.rs index 86b7c814b8..f42ba89302 100644 --- a/src/payment/forwarding_store.rs +++ b/src/payment/forwarding_store.rs @@ -863,6 +863,7 @@ async fn aggregate_expired_forwarded_payments_at( /// [`bucket_start_timestamp`]: crate::payment::ChannelPairForwardingStats::bucket_start_timestamp /// [`bucket_size_secs`]: crate::payment::ChannelPairForwardingStats::bucket_size_secs /// [`aggregated_at_timestamp`]: crate::payment::ChannelPairForwardingStats::aggregated_at_timestamp +#[cfg_attr(feature = "uniffi", uniffi::export)] pub fn aggregate_channel_pair_stats( buckets: &[ChannelPairForwardingStats], ) -> Option { From 995f78eaf5506658998e07995bed984f70873685 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Thu, 19 Nov 2026 10:28:08 +0100 Subject: [PATCH 4/7] Expose the prober in bindings `Node::prober` and `Prober::locked_msat` were only available to Rust users, so bindings users could configure background probing but had no way to observe how much liquidity is locked in in-flight probes. Make `Prober` a UniFFI object and export `locked_msat`, along with getters for the probing interval and the locked amount limit, which Rust users can read from the public fields. As bindings can't hold a borrowed reference, `Node::prober` hands out a shared handle when building with UniFFI. Co-Authored-By: HAL 9000 --- bindings/ldk_node.udl | 3 +++ src/lib.rs | 7 +++++++ src/probing.rs | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/bindings/ldk_node.udl b/bindings/ldk_node.udl index febc94d91c..337e1c132b 100644 --- a/bindings/ldk_node.udl +++ b/bindings/ldk_node.udl @@ -73,6 +73,7 @@ interface Node { OnchainPayment onchain_payment(); Liquidity liquidity(); ForwardingAnalytics forwarding_analytics(); + Prober? prober(); [Throws=NodeError] void lnurl_auth(string lnurl); [Throws=NodeError] @@ -148,6 +149,8 @@ typedef interface Liquidity; typedef interface ForwardingAnalytics; +typedef interface Prober; + [Error] enum NodeError { "AlreadyRunning", diff --git a/src/lib.rs b/src/lib.rs index 97a179c95f..612940084c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1389,10 +1389,17 @@ impl Node { } /// Returns a reference to the [`Prober`], or `None` if no probing strategy is configured. + #[cfg(not(feature = "uniffi"))] pub fn prober(&self) -> Option<&Prober> { self.prober.as_deref() } + /// Returns the [`Prober`], or `None` if no probing strategy is configured. + #[cfg(feature = "uniffi")] + pub fn prober(&self) -> Option> { + self.prober.clone() + } + /// Retrieve a list of known channels. pub fn list_channels(&self) -> Vec { self.channel_manager diff --git a/src/probing.rs b/src/probing.rs index 42beda5301..0b434b05a0 100644 --- a/src/probing.rs +++ b/src/probing.rs @@ -806,6 +806,7 @@ impl ProbingStrategy for RandomWalkStrategy { } /// Periodically dispatches probes according to a [`ProbingStrategy`]. +#[cfg_attr(feature = "uniffi", derive(uniffi::Object))] pub struct Prober { pub(crate) channel_manager: Arc, pub(crate) logger: Arc, @@ -825,6 +826,7 @@ fn fmt_path(path: &lightning::routing::router::Path) -> String { .join(" -> ") } +#[cfg_attr(feature = "uniffi", uniffi::export)] impl Prober { /// Returns the total millisatoshis currently locked in in-flight probes. pub fn locked_msat(&self) -> u64 { @@ -843,7 +845,23 @@ impl Prober { }) .sum(); } +} + +#[cfg(feature = "uniffi")] +#[uniffi::export] +impl Prober { + /// Returns how often a probe attempt is fired. + pub fn interval(&self) -> Duration { + self.interval + } + /// Returns the maximum total millisatoshis that may be locked in in-flight probes at any time. + pub fn max_locked_msat(&self) -> u64 { + self.max_locked_msat + } +} + +impl Prober { pub(crate) fn handle_background_probe_successful(&self, path: &Path, payment_id: PaymentId) { log_debug!( self.logger, From 140831b7fb483bf57191d9a93a3447c3a83df13a Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Thu, 19 Nov 2026 10:30:27 +0100 Subject: [PATCH 5/7] Expose node features and color in bindings The bindings' `NodeAnnouncementInfo` dropped the announced feature bits and the node color when converting from LDK's type, so bindings users querying the network graph saw less than Rust users do. Carry both fields over, reusing the existing `NodeFeatures` object for the feature bits and passing the color as its three raw bytes. Co-Authored-By: HAL 9000 --- src/graph.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/graph.rs b/src/graph.rs index a83318609f..6b1b8f5a15 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -152,9 +152,13 @@ impl From for NodeInfo { #[cfg(feature = "uniffi")] #[derive(Clone, Debug, PartialEq, Eq, uniffi::Record)] pub struct NodeAnnouncementInfo { + /// Protocol features the node announced support for. + pub features: Arc, /// When the last known update to the node state was issued. /// Value is opaque, as set in the announcement. pub last_update: u32, + /// Color assigned to the node, as three bytes holding the red, green, and blue components. + pub rgb: Vec, /// Moniker assigned to the node. /// May be invalid or malicious (eg control chars), /// should not be exposed to the user. @@ -167,9 +171,41 @@ pub struct NodeAnnouncementInfo { impl From for NodeAnnouncementInfo { fn from(value: lightning::routing::gossip::NodeAnnouncementInfo) -> Self { Self { + features: Arc::new(value.features().clone().into()), last_update: value.last_update(), + rgb: value.rgb().to_vec(), alias: value.alias().to_string(), addresses: value.addresses().iter().cloned().collect(), } } } + +#[cfg(all(test, feature = "uniffi"))] +mod tests { + use lightning::routing::gossip::{ + NodeAlias, NodeAnnouncementDetails, NodeAnnouncementInfo as LdkNodeAnnouncementInfo, + }; + use lightning_types::features::NodeFeatures as LdkNodeFeatures; + + use super::NodeAnnouncementInfo; + + #[test] + fn node_announcement_info_conversion_keeps_features_and_rgb() { + let mut features = LdkNodeFeatures::empty(); + features.set_keysend_optional(); + let rgb = [1, 2, 3]; + let ldk_info = LdkNodeAnnouncementInfo::Local(NodeAnnouncementDetails { + features: features.clone(), + last_update: 42, + rgb, + alias: NodeAlias([0; 32]), + addresses: Vec::new(), + }); + + let info: NodeAnnouncementInfo = ldk_info.into(); + + assert_eq!(info.features.inner, features); + assert_eq!(info.rgb, rgb.to_vec()); + assert_eq!(info.last_update, 42); + } +} From 0a635c7bea6c6f89e26d06d6521f0d355c55e15a Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Mon, 23 Nov 2026 10:22:26 +0100 Subject: [PATCH 6/7] Expose `Network::Testnet4` in bindings The bindings' `Network` enum lacked `Testnet4`, so bindings users couldn't configure a node for it. Moreover, returning it to bindings, e.g., when inspecting the chains of a Testnet4 offer, would panic as UniFFI doesn't know how to convert unlisted variants. Add the missing variant to the bindings' enum. Co-Authored-By: HAL 9000 --- bindings/ldk_node.udl | 1 + src/ffi/types.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/bindings/ldk_node.udl b/bindings/ldk_node.udl index 337e1c132b..2344451b64 100644 --- a/bindings/ldk_node.udl +++ b/bindings/ldk_node.udl @@ -305,6 +305,7 @@ enum LSPS1PaymentState { enum Network { "Bitcoin", "Testnet", + "Testnet4", "Signet", "Regtest", }; diff --git a/src/ffi/types.rs b/src/ffi/types.rs index 9957dcd043..a8b4e440e1 100644 --- a/src/ffi/types.rs +++ b/src/ffi/types.rs @@ -2727,6 +2727,23 @@ mod tests { (ldk_invoice, wrapped_invoice) } + #[test] + fn all_networks_roundtrip_through_ffi() { + use uniffi::{Lift, Lower}; + + for network in [ + Network::Bitcoin, + Network::Testnet, + Network::Testnet4, + Network::Signet, + Network::Regtest, + ] { + let lowered = >::lower(network); + let lifted = >::try_lift(lowered).unwrap(); + assert_eq!(lifted, network); + } + } + #[test] fn test_channel_type_feature_accessors() { let mut optional = LdkChannelTypeFeatures::empty(); From ee1e33fd0689474ff4a29e4ac5b8f756c8f21759 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Mon, 23 Nov 2026 10:25:11 +0100 Subject: [PATCH 7/7] Expose channel features in bindings The bindings' `ChannelInfo` dropped the feature bits of the channel announcement when converting from LDK's type, so bindings users querying the network graph saw less than Rust users do. Carry the field over via a new `ChannelFeatures` object. As no channel features are currently defined, it only offers access to the raw bytes. It avoids the wire encoding's length prefix so that the bytes can be used to reconstruct the object. Co-Authored-By: HAL 9000 --- src/ffi/types.rs | 30 ++++++++++++++++++++++++++++-- src/graph.rs | 39 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/src/ffi/types.rs b/src/ffi/types.rs index a8b4e440e1..d237adda03 100644 --- a/src/ffi/types.rs +++ b/src/ffi/types.rs @@ -53,8 +53,8 @@ pub use lightning_liquidity::lsps1::msgs::{ LSPS1ChannelInfo, LSPS1OrderId, LSPS1OrderParams, LSPS1PaymentState, }; use lightning_types::features::{ - ChannelTypeFeatures as LdkChannelTypeFeatures, InitFeatures as LdkInitFeatures, - NodeFeatures as LdkNodeFeatures, + ChannelFeatures as LdkChannelFeatures, ChannelTypeFeatures as LdkChannelTypeFeatures, + InitFeatures as LdkInitFeatures, NodeFeatures as LdkNodeFeatures, }; pub use lightning_types::payment::{PaymentHash, PaymentPreimage, PaymentSecret}; pub use lightning_types::string::UntrustedString; @@ -2257,6 +2257,32 @@ impl From for NodeFeatures { } } +#[derive(Debug, Clone, PartialEq, Eq, uniffi::Object)] +#[uniffi::export(Debug, Eq)] +pub struct ChannelFeatures { + pub(crate) inner: LdkChannelFeatures, +} + +#[uniffi::export] +impl ChannelFeatures { + /// Constructs channel features from big-endian BOLT 9 encoded bytes. + #[uniffi::constructor] + pub fn from_bytes(bytes: &[u8]) -> Self { + Self { inner: LdkChannelFeatures::from_be_bytes(bytes.to_vec()) } + } + + /// Returns the BOLT 9 big-endian encoded representation of these features. + pub fn to_bytes(&self) -> Vec { + self.inner.le_flags().iter().rev().copied().collect() + } +} + +impl From for ChannelFeatures { + fn from(features: LdkChannelFeatures) -> Self { + Self { inner: features } + } +} + #[derive(Debug, Clone, PartialEq, Eq, uniffi::Object)] #[uniffi::export(Debug, Eq)] pub struct ChannelTypeFeatures { diff --git a/src/graph.rs b/src/graph.rs index 6b1b8f5a15..51c0172540 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -62,6 +62,8 @@ impl NetworkGraph { #[cfg(feature = "uniffi")] #[derive(Clone, Debug, PartialEq, Eq, uniffi::Record)] pub struct ChannelInfo { + /// Protocol features of a channel communicated during its announcement. + pub features: Arc, /// Source node of the first direction of a channel pub node_one: NodeId, /// Details about the first direction of a channel @@ -78,6 +80,7 @@ pub struct ChannelInfo { impl From for ChannelInfo { fn from(value: lightning::routing::gossip::ChannelInfo) -> Self { Self { + features: Arc::new(value.features.into()), node_one: value.node_one, one_to_two: value.one_to_two.map(|u| u.into()), node_two: value.node_two, @@ -182,12 +185,42 @@ impl From for NodeAnnouncement #[cfg(all(test, feature = "uniffi"))] mod tests { + use std::sync::Arc; + + use bitcoin::Network; use lightning::routing::gossip::{ - NodeAlias, NodeAnnouncementDetails, NodeAnnouncementInfo as LdkNodeAnnouncementInfo, + NodeAlias, NodeAnnouncementDetails, NodeAnnouncementInfo as LdkNodeAnnouncementInfo, NodeId, + }; + use lightning_types::features::{ + ChannelFeatures as LdkChannelFeatures, NodeFeatures as LdkNodeFeatures, }; - use lightning_types::features::NodeFeatures as LdkNodeFeatures; - use super::NodeAnnouncementInfo; + use super::{NetworkGraph, NodeAnnouncementInfo}; + use crate::ffi::ChannelFeatures; + use crate::logger::Logger; + use crate::types::Graph; + + #[test] + fn channel_info_conversion_keeps_features() { + let graph = Arc::new(Graph::new(Network::Regtest, Arc::new(Logger::new_log_facade()))); + let features = LdkChannelFeatures::from_be_bytes(vec![0x02, 0x00]); + graph + .add_channel_from_partial_announcement( + 42, + None, + 0, + features.clone(), + NodeId::from_slice(&[2; 33]).unwrap(), + NodeId::from_slice(&[3; 33]).unwrap(), + ) + .unwrap(); + + let info = NetworkGraph::new(graph).channel(42).unwrap(); + + assert_eq!(info.features.inner, features); + assert_eq!(info.features.to_bytes(), vec![0x02, 0x00]); + assert_eq!(ChannelFeatures::from_bytes(&info.features.to_bytes()), *info.features); + } #[test] fn node_announcement_info_conversion_keeps_features_and_rgb() {