Skip to content

Commit c43b325

Browse files
committed
f - validate latency in cli and make u32
1 parent d1b7247 commit c43b325

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

sim-cli/src/main.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::sync::Arc;
33
use clap::Parser;
44
use log::LevelFilter;
55
use sim_cli::parsing::{create_simulation, create_simulation_with_network, parse_sim_params, Cli};
6-
use simln_lib::{interceptors::LatencyIntercepor, sim_node::Interceptor};
6+
use simln_lib::{latency_interceptor::LatencyIntercepor, sim_node::Interceptor};
77
use simple_logger::SimpleLogger;
88
use tokio_util::task::TaskTracker;
99

@@ -32,8 +32,9 @@ async fn main() -> anyhow::Result<()> {
3232
let (sim, validated_activities) = if sim_params.sim_network.is_empty() {
3333
create_simulation(&cli, &sim_params, tasks.clone()).await?
3434
} else {
35-
let interceptors = if let Some(l) = cli.latency_ms {
36-
vec![Arc::new(LatencyIntercepor::new_poisson(l)?) as Arc<dyn Interceptor>]
35+
let latency = cli.latency_ms.unwrap_or(0);
36+
let interceptors = if latency > 0 {
37+
vec![Arc::new(LatencyIntercepor::new_poisson(latency as f32)?) as Arc<dyn Interceptor>]
3738
} else {
3839
vec![]
3940
};

sim-cli/src/parsing.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ pub struct Cli {
8888
/// simulated nodes.
8989
#[clap(long)]
9090
pub speedup_clock: Option<u16>,
91-
/// Latency to optionally introduce for simulated nodes.
91+
/// Latency to optionally introduce for payments in a simulated network expressed in
92+
/// milliseconds.
9293
#[clap(long)]
93-
pub latency_ms: Option<f32>,
94+
pub latency_ms: Option<u32>,
9495
}
9596

9697
impl Cli {
@@ -116,6 +117,12 @@ impl Cli {
116117
));
117118
}
118119

120+
if !sim_params.nodes.is_empty() && self.latency_ms.is_some() {
121+
return Err(anyhow!(
122+
"Latency for payments is only allowed when running on a simulated network"
123+
));
124+
}
125+
119126
Ok(())
120127
}
121128
}

0 commit comments

Comments
 (0)