Skip to content

Commit 200de80

Browse files
committed
Add uniffi support of probing
1 parent c31f1ce commit 200de80

File tree

3 files changed

+41
-16
lines changed

3 files changed

+41
-16
lines changed

src/builder.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,11 +1207,36 @@ impl ArcedNodeBuilder {
12071207
self.inner.write().unwrap().set_wallet_recovery_mode();
12081208
}
12091209

1210-
/// Configures a probing strategy for background channel probing.
1210+
/// Configures background probing toward the highest-degree nodes in the network graph.
1211+
pub fn set_high_degree_probing_strategy(&self, top_n: usize) {
1212+
self.inner.write().unwrap().set_high_degree_probing_strategy(top_n);
1213+
}
1214+
1215+
/// Configures background probing via random graph walks of up to `max_hops` hops.
1216+
pub fn set_random_probing_strategy(&self, max_hops: usize) {
1217+
self.inner.write().unwrap().set_random_probing_strategy(max_hops);
1218+
}
1219+
1220+
/// Configures a custom probing strategy for background channel probing.
12111221
pub fn set_custom_probing_strategy(&self, strategy: Arc<dyn probing::ProbingStrategy>) {
12121222
self.inner.write().unwrap().set_custom_probing_strategy(strategy);
12131223
}
12141224

1225+
/// Overrides the interval between probe attempts.
1226+
pub fn set_probing_interval(&self, interval: Duration) {
1227+
self.inner.write().unwrap().set_probing_interval(interval);
1228+
}
1229+
1230+
/// Overrides the maximum millisatoshis that may be locked in in-flight probes at any time.
1231+
pub fn set_max_probe_locked_msat(&self, max_msat: u64) {
1232+
self.inner.write().unwrap().set_max_probe_locked_msat(max_msat);
1233+
}
1234+
1235+
/// Sets the probing diversity penalty applied by the probabilistic scorer.
1236+
pub fn set_probing_diversity_penalty_msat(&self, penalty_msat: u64) {
1237+
self.inner.write().unwrap().set_probing_diversity_penalty_msat(penalty_msat);
1238+
}
1239+
12151240
/// Builds a [`Node`] instance with a [`SqliteStore`] backend and according to the options
12161241
/// previously configured.
12171242
pub fn build(&self, node_entropy: Arc<NodeEntropy>) -> Result<Arc<Node>, BuildError> {

tests/common/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,9 @@ pub(crate) fn random_config(anchor_channels: bool) -> TestConfig {
316316
}
317317

318318
#[cfg(feature = "uniffi")]
319-
type TestNode = Arc<Node>;
319+
pub(crate) type TestNode = Arc<Node>;
320320
#[cfg(not(feature = "uniffi"))]
321-
type TestNode = Node;
321+
pub(crate) type TestNode = Node;
322322

323323
#[derive(Clone)]
324324
pub(crate) enum TestChainSource<'a> {

tests/probing_tests.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ use lightning_invoice::{Bolt11InvoiceDescription, Description};
2626
use common::{
2727
expect_channel_ready_event, expect_event, generate_blocks_and_wait, open_channel,
2828
open_channel_no_electrum_wait, premine_and_distribute_funds, random_config,
29-
setup_bitcoind_and_electrsd, setup_node, TestChainSource, TestProbingConfig,
29+
setup_bitcoind_and_electrsd, setup_node, TestChainSource, TestNode, TestProbingConfig,
3030
TestProbingStrategy,
3131
};
3232

3333
use ldk_node::bitcoin::secp256k1::PublicKey;
3434
use ldk_node::bitcoin::Amount;
35-
use ldk_node::{Event, Node, Probe, ProbingStrategy};
35+
use ldk_node::{Event, Probe, ProbingStrategy};
3636

3737
use rand::rngs::StdRng;
3838
use rand::{Rng, SeedableRng};
@@ -100,21 +100,21 @@ fn probing_config(
100100

101101
fn build_node_fixed_dest_probing(
102102
chain_source: &TestChainSource<'_>, destination_node_id: PublicKey,
103-
) -> Node {
103+
) -> TestNode {
104104
let mut config = random_config(false);
105105
let strategy = FixedDestStrategy::new(destination_node_id, PROBE_AMOUNT_MSAT);
106106
config.probing = probing_config(TestProbingStrategy::Custom(strategy), PROBE_AMOUNT_MSAT, None);
107107
setup_node(chain_source, config)
108108
}
109109

110-
fn build_node_random_probing(chain_source: &TestChainSource<'_>, max_hops: usize) -> Node {
110+
fn build_node_random_probing(chain_source: &TestChainSource<'_>, max_hops: usize) -> TestNode {
111111
let mut config = config_with_label("Random");
112112
config.probing =
113113
probing_config(TestProbingStrategy::Random { max_hops }, MAX_LOCKED_MSAT, None);
114114
setup_node(chain_source, config)
115115
}
116116

117-
fn build_node_highdegree_probing(chain_source: &TestChainSource<'_>, top_n: usize) -> Node {
117+
fn build_node_highdegree_probing(chain_source: &TestChainSource<'_>, top_n: usize) -> TestNode {
118118
let mut config = config_with_label("HiDeg");
119119
config.probing =
120120
probing_config(TestProbingStrategy::HighDegree { top_n }, MAX_LOCKED_MSAT, None);
@@ -123,7 +123,7 @@ fn build_node_highdegree_probing(chain_source: &TestChainSource<'_>, top_n: usiz
123123

124124
fn build_node_z_highdegree_probing(
125125
chain_source: &TestChainSource<'_>, top_n: usize, diversity_penalty_msat: u64,
126-
) -> Node {
126+
) -> TestNode {
127127
let mut config = config_with_label("HiDeg+P");
128128
config.probing = probing_config(
129129
TestProbingStrategy::HighDegree { top_n },
@@ -134,7 +134,7 @@ fn build_node_z_highdegree_probing(
134134
}
135135

136136
// helpers, formatting
137-
fn node_label(node: &Node) -> String {
137+
fn node_label(node: &TestNode) -> String {
138138
node.node_alias()
139139
.map(|alias| {
140140
let end = alias.0.iter().position(|&b| b == 0).unwrap_or(32);
@@ -143,7 +143,7 @@ fn node_label(node: &Node) -> String {
143143
.unwrap_or_else(|| format!("{:.8}", node.node_id()))
144144
}
145145

146-
fn print_topology(all_nodes: &[&Node]) {
146+
fn print_topology(all_nodes: &[&TestNode]) {
147147
let labels: HashMap<PublicKey, String> =
148148
all_nodes.iter().map(|n| (n.node_id(), node_label(n))).collect();
149149
let label_of = |pk: PublicKey| labels.get(&pk).cloned().unwrap_or_else(|| format!("{:.8}", pk));
@@ -195,7 +195,7 @@ fn fmt_est(est: Option<(u64, u64)>) -> String {
195195
}
196196
}
197197

198-
fn print_probing_perfomance(observers: &[&Node], all_nodes: &[&Node]) {
198+
fn print_probing_perfomance(observers: &[&TestNode], all_nodes: &[&TestNode]) {
199199
let labels: HashMap<PublicKey, String> =
200200
all_nodes.iter().chain(observers.iter()).map(|n| (n.node_id(), node_label(n))).collect();
201201
let label_of = |pk: PublicKey| {
@@ -443,7 +443,7 @@ async fn probing_strategies_perfomance() {
443443
let utxos_per_node = num_nodes;
444444
let utxo_per_channel = Amount::from_sat(channel_capacity_sat + 50_000);
445445

446-
let mut nodes: Vec<Node> = Vec::new();
446+
let mut nodes: Vec<TestNode> = Vec::new();
447447
for i in 0..num_nodes {
448448
let label = char::from(b'B' + i as u8).to_string();
449449
let mut config = random_config(false);
@@ -467,7 +467,7 @@ async fn probing_strategies_perfomance() {
467467
let channels_per_nodes: Vec<usize> =
468468
(0..num_nodes).map(|_| rng.random_range(1..=channels_per_node)).collect();
469469

470-
let observer_nodes: [&Node; 4] = [&node_a, &node_y, &node_z, &node_x];
470+
let observer_nodes: [&TestNode; 4] = [&node_a, &node_y, &node_z, &node_x];
471471

472472
let mut addresses = Vec::new();
473473
for node in observer_nodes {
@@ -489,7 +489,7 @@ async fn probing_strategies_perfomance() {
489489
node.sync_wallets().unwrap();
490490
}
491491

492-
fn drain_events(node: &Node) {
492+
fn drain_events(node: &TestNode) {
493493
while let Some(_) = node.next_event() {
494494
node.event_handled().unwrap();
495495
}
@@ -523,7 +523,7 @@ async fn probing_strategies_perfomance() {
523523
node_map.insert(node.node_id(), i);
524524
}
525525

526-
let all_nodes: Vec<&Node> = nodes.iter().chain(observer_nodes).collect();
526+
let all_nodes: Vec<&TestNode> = nodes.iter().chain(observer_nodes).collect();
527527

528528
print_topology(&all_nodes);
529529

0 commit comments

Comments
 (0)