Skip to content

Commit cc3cb24

Browse files
committed
sim-cli: surface CLI option to run sim network with speedup
1 parent cee45a8 commit cc3cb24

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

sim-cli/src/parsing.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ pub struct Cli {
8484
/// Seed to run random activity generator deterministically
8585
#[clap(long, short)]
8686
pub fix_seed: Option<u64>,
87+
/// A multiplier to wall time to speed up the simulation's clock. Only available when when running on a network of
88+
/// simulated nodes.
89+
#[clap(long, short)]
90+
pub speedup_clock: Option<u16>,
8791
}
8892

8993
impl Cli {
@@ -103,6 +107,12 @@ impl Cli {
103107
nodes or sim_graph to run with simulated nodes"
104108
));
105109
}
110+
if !sim_params.nodes.is_empty() && self.speedup_clock.is_some() {
111+
return Err(anyhow!(
112+
"Clock speedup is only allowed when running on a simulated network"
113+
));
114+
}
115+
106116
Ok(())
107117
}
108118
}
@@ -229,11 +239,13 @@ pub async fn create_simulation_with_network(
229239
.map_err(|e| SimulationError::SimulatedNetworkError(format!("{:?}", e)))?,
230240
));
231241

242+
let clock = Arc::new(SimulationClock::new(cli.speedup_clock.unwrap_or(1))?);
243+
232244
// Copy all simulated channels into a read-only routing graph, allowing to pathfind for
233245
// individual payments without locking th simulation graph (this is a duplication of the channels,
234246
// but the performance tradeoff is worthwhile for concurrent pathfinding).
235247
let routing_graph = Arc::new(
236-
populate_network_graph(channels)
248+
populate_network_graph(channels, clock.clone())
237249
.map_err(|e| SimulationError::SimulatedNetworkError(format!("{:?}", e)))?,
238250
);
239251

@@ -246,7 +258,7 @@ pub async fn create_simulation_with_network(
246258
cfg,
247259
nodes,
248260
tasks,
249-
Arc::new(SimulationClock::new(1)?),
261+
clock,
250262
shutdown_trigger,
251263
shutdown_listener,
252264
),
@@ -279,6 +291,8 @@ pub async fn create_simulation(
279291
cfg,
280292
clients,
281293
tasks,
294+
// When running on a real network, the underlying node may use wall time so we always use a clock with no
295+
// speedup.
282296
Arc::new(SimulationClock::new(1)?),
283297
shutdown_trigger,
284298
shutdown_listener,

0 commit comments

Comments
 (0)