Skip to content

Commit de92e1f

Browse files
authored
Merge pull request #283 from elnosh/cfg-changes
pass cfg to `create_simulation_with_network`
2 parents 0f75d43 + 4ef48de commit de92e1f

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

sim-cli/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use sim_cli::parsing::{create_simulation, create_simulation_with_network, parse_
66
use simln_lib::{
77
latency_interceptor::LatencyIntercepor,
88
sim_node::{CustomRecords, Interceptor},
9+
SimulationCfg,
910
};
1011
use simple_logger::SimpleLogger;
1112
use tokio_util::task::TaskTracker;
@@ -41,9 +42,11 @@ async fn main() -> anyhow::Result<()> {
4142
} else {
4243
vec![]
4344
};
45+
let sim_cfg: SimulationCfg = SimulationCfg::try_from(&cli)?;
4446
create_simulation_with_network(
45-
&cli,
47+
sim_cfg,
4648
&sim_params,
49+
cli.speedup_clock.unwrap_or(1),
4750
tasks.clone(),
4851
interceptors,
4952
CustomRecords::default(),

sim-cli/src/parsing.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl Cli {
145145
#[derive(Debug, Serialize, Deserialize, Clone)]
146146
pub struct SimParams {
147147
#[serde(default)]
148-
nodes: Vec<NodeConnection>,
148+
pub nodes: Vec<NodeConnection>,
149149
#[serde(default)]
150150
pub sim_network: Vec<NetworkParser>,
151151
#[serde(default)]
@@ -242,13 +242,13 @@ struct NodeMapping {
242242
}
243243

244244
pub async fn create_simulation_with_network(
245-
cli: &Cli,
245+
cfg: SimulationCfg,
246246
sim_params: &SimParams,
247+
clock_speedup: u16,
247248
tasks: TaskTracker,
248249
interceptors: Vec<Arc<dyn Interceptor>>,
249250
custom_records: CustomRecords,
250251
) -> Result<(Simulation<SimulationClock>, Vec<ActivityDefinition>), anyhow::Error> {
251-
let cfg: SimulationCfg = SimulationCfg::try_from(cli)?;
252252
let SimParams {
253253
nodes: _,
254254
sim_network,
@@ -284,7 +284,7 @@ pub async fn create_simulation_with_network(
284284
.map_err(|e| SimulationError::SimulatedNetworkError(format!("{:?}", e)))?,
285285
));
286286

287-
let clock = Arc::new(SimulationClock::new(cli.speedup_clock.unwrap_or(1))?);
287+
let clock = Arc::new(SimulationClock::new(clock_speedup)?);
288288

289289
// Copy all simulated channels into a read-only routing graph, allowing to pathfind for
290290
// individual payments without locking th simulation graph (this is a duplication of the channels,

simln-lib/src/clock.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ impl SimulationClock {
6161
})
6262
}
6363

64+
/// Returns the instant that the simulation clock was started at.
65+
pub fn get_start_instant(&self) -> Instant {
66+
self.start_instant
67+
}
68+
69+
/// Returns the speedup multiplier applied to time.
70+
pub fn get_speedup_multiplier(&self) -> u16 {
71+
self.speedup_multiplier
72+
}
73+
6474
/// Calculates the current simulation time based on the current wall clock time.
6575
///
6676
/// Separated for testing purposes so that we can fix the current wall clock time and elapsed interval.

0 commit comments

Comments
 (0)