Skip to content

Commit 4a74f9f

Browse files
sangbidachuksys
authored andcommitted
simln-lib/feat: Add Pathfinder trait
1 parent 2bdd675 commit 4a74f9f

File tree

3 files changed

+120
-90
lines changed

3 files changed

+120
-90
lines changed

sim-cli/src/main.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ use simln_lib::{
1212
use simple_logger::SimpleLogger;
1313
use tokio_util::task::TaskTracker;
1414

15+
// Import the pathfinder types
16+
use simln_lib::sim_node::DefaultPathFinder;
17+
1518
#[tokio::main]
1619
async fn main() -> anyhow::Result<()> {
1720
// Enable tracing if building in developer mode.
@@ -33,6 +36,9 @@ async fn main() -> anyhow::Result<()> {
3336
cli.validate(&sim_params)?;
3437

3538
let tasks = TaskTracker::new();
39+
40+
// Create the pathfinder instance
41+
let pathfinder = DefaultPathFinder;
3642

3743
let (sim, validated_activities) = if sim_params.sim_network.is_empty() {
3844
create_simulation(&cli, &sim_params, tasks.clone()).await?
@@ -51,6 +57,7 @@ async fn main() -> anyhow::Result<()> {
5157
clock,
5258
tasks.clone(),
5359
interceptors,
60+
pathfinder,
5461
CustomRecords::default(),
5562
)
5663
.await?;
@@ -66,4 +73,4 @@ async fn main() -> anyhow::Result<()> {
6673
sim.run(&validated_activities).await?;
6774

6875
Ok(())
69-
}
76+
}

sim-cli/src/parsing.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ use serde::{Deserialize, Serialize};
66
use simln_lib::clock::SimulationClock;
77
use simln_lib::sim_node::{
88
ln_node_from_graph, populate_network_graph, ChannelPolicy, CustomRecords, Interceptor,
9-
SimGraph, SimNode, SimulatedChannel,
9+
PathFinder, SimGraph, SimulatedChannel,
1010
};
11+
1112
use simln_lib::{
1213
cln, cln::ClnNode, eclair, eclair::EclairNode, lnd, lnd::LndNode, serializers,
1314
ActivityDefinition, Amount, Interval, LightningError, LightningNode, NodeId, NodeInfo,
@@ -258,6 +259,7 @@ pub async fn create_simulation_with_network(
258259
tasks: TaskTracker,
259260
interceptors: Vec<Arc<dyn Interceptor>>,
260261
custom_records: CustomRecords,
262+
pathfinder: P,
261263
) -> Result<
262264
(
263265
Simulation<SimulationClock>,
@@ -308,20 +310,18 @@ pub async fn create_simulation_with_network(
308310
populate_network_graph(channels, clock.clone())
309311
.map_err(|e| SimulationError::SimulatedNetworkError(format!("{:?}", e)))?,
310312
);
311-
312313
// We want the full set of nodes in our graph to return to the caller so that they can take
313314
// custom actions on the simulated network. For the nodes we'll pass our simulation, cast them
314315
// to a dyn trait and exclude any nodes that shouldn't be included in random activity
315316
// generation.
316-
let nodes = ln_node_from_graph(simulation_graph.clone(), routing_graph, clock.clone()).await?;
317+
let nodes = ln_node_from_graph(simulation_graph.clone(), routing_graph, clock.clone(), pathfinder).await?;
317318
let mut nodes_dyn: HashMap<_, Arc<Mutex<dyn LightningNode>>> = nodes
318319
.iter()
319320
.map(|(pk, node)| (*pk, Arc::clone(node) as Arc<Mutex<dyn LightningNode>>))
320321
.collect();
321322
for pk in exclude {
322323
nodes_dyn.remove(pk);
323324
}
324-
325325
let validated_activities =
326326
get_validated_activities(&nodes_dyn, nodes_info, sim_params.activity.clone()).await?;
327327

@@ -339,6 +339,7 @@ pub async fn create_simulation_with_network(
339339
))
340340
}
341341

342+
342343
/// Parses the cli options provided and creates a simulation to be run, connecting to lightning nodes and validating
343344
/// any activity described in the simulation file.
344345
pub async fn create_simulation(

0 commit comments

Comments
 (0)