Skip to content

Commit 9acf20e

Browse files
committed
Add uniffi support for probing
1 parent b90f76d commit 9acf20e

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

bindings/ldk_node.udl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ typedef dictionary TorConfig;
1313

1414
typedef interface NodeEntropy;
1515

16+
typedef interface ProbingConfig;
17+
1618
typedef enum WordCount;
1719

1820
[Remote]
@@ -61,6 +63,7 @@ interface Builder {
6163
[Throws=BuildError]
6264
void set_async_payments_role(AsyncPaymentsRole? role);
6365
void set_wallet_recovery_mode();
66+
void set_probing_config(ProbingConfig config);
6467
[Throws=BuildError]
6568
Node build(NodeEntropy node_entropy);
6669
[Throws=BuildError]

src/builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,8 +1111,8 @@ impl ArcedNodeBuilder {
11111111
/// Configures background probing.
11121112
///
11131113
/// See [`ProbingConfig`] for details.
1114-
pub fn set_probing_config(&self, config: ProbingConfig) {
1115-
self.inner.write().unwrap().set_probing_config(config);
1114+
pub fn set_probing_config(&self, config: Arc<ProbingConfig>) {
1115+
self.inner.write().unwrap().set_probing_config((*config).clone());
11161116
}
11171117

11181118
/// Builds a [`Node`] instance with a [`SqliteStore`] backend and according to the options

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
116116
#[cfg(cycle_tests)]
117117
use std::{any::Any, sync::Weak};
118118

119+
#[cfg(feature = "uniffi")]
120+
use crate::probing::ProbingConfig;
119121
pub use balance::{BalanceDetails, LightningBalance, PendingSweepBalance};
120122
pub use bip39;
121123
pub use bitcoin;

src/probing.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub(crate) enum ProbingStrategyKind {
5858
/// [`custom`]: Self::custom
5959
/// [`build`]: ProbingConfigBuilder::build
6060
#[derive(Clone)]
61+
#[cfg_attr(feature = "uniffi", derive(uniffi::Object))]
6162
pub struct ProbingConfig {
6263
pub(crate) kind: ProbingStrategyKind,
6364
pub(crate) interval: Duration,
@@ -108,6 +109,60 @@ impl ProbingConfig {
108109
}
109110
}
110111

112+
#[cfg(feature = "uniffi")]
113+
#[uniffi::export]
114+
impl ProbingConfig {
115+
/// Creates a probing config that probes toward the highest-degree nodes in the graph.
116+
///
117+
/// `top_node_count` controls how many of the most-connected nodes are cycled through.
118+
/// All other parameters are optional and fall back to sensible defaults when `None`.
119+
#[uniffi::constructor]
120+
pub fn new_high_degree(
121+
top_node_count: u64, interval_secs: Option<u64>, max_locked_msat: Option<u64>,
122+
diversity_penalty_msat: Option<u64>, cooldown_secs: Option<u64>,
123+
) -> Self {
124+
let mut builder = Self::high_degree(top_node_count as usize);
125+
if let Some(secs) = interval_secs {
126+
builder = builder.interval(Duration::from_secs(secs));
127+
}
128+
if let Some(msat) = max_locked_msat {
129+
builder = builder.max_locked_msat(msat);
130+
}
131+
if let Some(penalty) = diversity_penalty_msat {
132+
builder = builder.diversity_penalty_msat(penalty);
133+
}
134+
if let Some(secs) = cooldown_secs {
135+
builder = builder.cooldown(Duration::from_secs(secs));
136+
}
137+
builder.build()
138+
}
139+
140+
/// Creates a probing config that probes via random graph walks.
141+
///
142+
/// `max_hops` is the upper bound on the number of hops in a randomly constructed path.
143+
/// All other parameters are optional and fall back to sensible defaults when `None`.
144+
#[uniffi::constructor]
145+
pub fn new_random_walk(
146+
max_hops: u64, interval_secs: Option<u64>, max_locked_msat: Option<u64>,
147+
diversity_penalty_msat: Option<u64>, cooldown_secs: Option<u64>,
148+
) -> Self {
149+
let mut builder = Self::random_walk(max_hops as usize);
150+
if let Some(secs) = interval_secs {
151+
builder = builder.interval(Duration::from_secs(secs));
152+
}
153+
if let Some(msat) = max_locked_msat {
154+
builder = builder.max_locked_msat(msat);
155+
}
156+
if let Some(penalty) = diversity_penalty_msat {
157+
builder = builder.diversity_penalty_msat(penalty);
158+
}
159+
if let Some(secs) = cooldown_secs {
160+
builder = builder.cooldown(Duration::from_secs(secs));
161+
}
162+
builder.build()
163+
}
164+
}
165+
111166
/// Builder for [`ProbingConfig`].
112167
///
113168
/// Created via [`ProbingConfig::high_degree`], [`ProbingConfig::random_walk`], or

0 commit comments

Comments
 (0)