Skip to content

Commit e8bfcf4

Browse files
sangbidachuksys
authored andcommitted
Add pathfinder trait
1 parent 2bdd675 commit e8bfcf4

File tree

3 files changed

+141
-58
lines changed

3 files changed

+141
-58
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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ use log::LevelFilter;
55
use serde::{Deserialize, Serialize};
66
use simln_lib::clock::SimulationClock;
77
use simln_lib::sim_node::{
8+
<<<<<<< HEAD
89
ln_node_from_graph, populate_network_graph, ChannelPolicy, CustomRecords, Interceptor,
910
SimGraph, SimNode, SimulatedChannel,
11+
=======
12+
ln_node_from_graph, populate_network_graph, ChannelPolicy, CustomRecords, Interceptor, PathFinder,
13+
SimGraph, SimulatedChannel,
14+
>>>>>>> 59dbbe6 (Add pathfinder trait)
1015
};
16+
1117
use simln_lib::{
1218
cln, cln::ClnNode, eclair, eclair::EclairNode, lnd, lnd::LndNode, serializers,
1319
ActivityDefinition, Amount, Interval, LightningError, LightningNode, NodeId, NodeInfo,
@@ -241,6 +247,7 @@ struct NodeMapping {
241247
alias_node_map: HashMap<String, NodeInfo>,
242248
}
243249

250+
<<<<<<< HEAD
244251
/// Creates a simulation that will run on an entirely-simulated network defined in `sim_params`,
245252
/// returning the simulation, a validated vector of any defined activities that were specified and
246253
/// a map of all the simulated nodes in the network. Note that if `sim_params::exclude` was set,
@@ -253,11 +260,16 @@ struct NodeMapping {
253260
/// records set by the original sender of payments in their simulated `update_add_htlc`.
254261
pub async fn create_simulation_with_network(
255262
cfg: SimulationCfg,
263+
=======
264+
pub async fn create_simulation_with_network<P: for<'a> PathFinder<'a> + Clone + 'static>(
265+
cli: &Cli,
266+
>>>>>>> 59dbbe6 (Add pathfinder trait)
256267
sim_params: &SimParams,
257268
clock: Arc<SimulationClock>,
258269
tasks: TaskTracker,
259270
interceptors: Vec<Arc<dyn Interceptor>>,
260271
custom_records: CustomRecords,
272+
<<<<<<< HEAD
261273
) -> Result<
262274
(
263275
Simulation<SimulationClock>,
@@ -266,6 +278,11 @@ pub async fn create_simulation_with_network(
266278
),
267279
anyhow::Error,
268280
> {
281+
=======
282+
pathfinder: P,
283+
) -> Result<(Simulation<SimulationClock>, Vec<ActivityDefinition>), anyhow::Error> {
284+
let cfg: SimulationCfg = SimulationCfg::try_from(cli)?;
285+
>>>>>>> 59dbbe6 (Add pathfinder trait)
269286
let SimParams {
270287
nodes: _,
271288
sim_network,
@@ -309,6 +326,7 @@ pub async fn create_simulation_with_network(
309326
.map_err(|e| SimulationError::SimulatedNetworkError(format!("{:?}", e)))?,
310327
);
311328

329+
<<<<<<< HEAD
312330
// We want the full set of nodes in our graph to return to the caller so that they can take
313331
// custom actions on the simulated network. For the nodes we'll pass our simulation, cast them
314332
// to a dyn trait and exclude any nodes that shouldn't be included in random activity
@@ -322,6 +340,10 @@ pub async fn create_simulation_with_network(
322340
nodes_dyn.remove(pk);
323341
}
324342

343+
=======
344+
// Pass the pathfinder to ln_node_from_graph
345+
let nodes = ln_node_from_graph(simulation_graph.clone(), routing_graph, pathfinder).await;
346+
>>>>>>> 59dbbe6 (Add pathfinder trait)
325347
let validated_activities =
326348
get_validated_activities(&nodes_dyn, nodes_info, sim_params.activity.clone()).await?;
327349

@@ -339,6 +361,7 @@ pub async fn create_simulation_with_network(
339361
))
340362
}
341363

364+
342365
/// Parses the cli options provided and creates a simulation to be run, connecting to lightning nodes and validating
343366
/// any activity described in the simulation file.
344367
pub async fn create_simulation(

0 commit comments

Comments
 (0)