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
3 changes: 3 additions & 0 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -148,6 +149,8 @@ typedef interface Liquidity;

typedef interface ForwardingAnalytics;

typedef interface Prober;

[Error]
enum NodeError {
"AlreadyRunning",
Expand Down
6 changes: 0 additions & 6 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1219,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.
///
Expand Down
36 changes: 36 additions & 0 deletions src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,13 @@ impl From<lightning::routing::gossip::NodeInfo> 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<crate::ffi::NodeFeatures>,
/// 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<u8>,
/// Moniker assigned to the node.
/// May be invalid or malicious (eg control chars),
/// should not be exposed to the user.
Expand All @@ -167,9 +171,41 @@ pub struct NodeAnnouncementInfo {
impl From<lightning::routing::gossip::NodeAnnouncementInfo> 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);
}
}
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Arc<Prober>> {
self.prober.clone()
}

/// Retrieve a list of known channels.
pub fn list_channels(&self) -> Vec<ChannelDetails> {
self.channel_manager
Expand Down
1 change: 1 addition & 0 deletions src/payment/forwarding_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChannelPairForwardingStats> {
Expand Down
4 changes: 4 additions & 0 deletions src/probing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChannelManager>,
pub(crate) logger: Arc<Logger>,
Expand All @@ -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 {
Expand All @@ -843,7 +845,9 @@ impl Prober {
})
.sum();
}
}

impl Prober {
pub(crate) fn handle_background_probe_successful(&self, path: &Path, payment_id: PaymentId) {
log_debug!(
self.logger,
Expand Down
Loading