diff --git a/sim-cli/src/main.rs b/sim-cli/src/main.rs index 69ae876c..9d544f51 100644 --- a/sim-cli/src/main.rs +++ b/sim-cli/src/main.rs @@ -28,6 +28,10 @@ struct Cli { expected_pmt_amt: Option, #[clap(long, short)] capacity_multiplier: Option, + // DEV-ONLY args, set hide = true so they are not show in help + /// Do not an output file including the simulations results + #[clap(long, short, hide = true, default_value_t = false)] + no_results: bool, } #[tokio::main] @@ -149,6 +153,7 @@ async fn main() -> anyhow::Result<()> { cli.print_batch_size, cli.expected_pmt_amt, cli.capacity_multiplier, + cli.no_results, ); let sim2 = sim.clone(); diff --git a/sim-lib/src/lib.rs b/sim-lib/src/lib.rs index e559edf1..951cb125 100644 --- a/sim-lib/src/lib.rs +++ b/sim-lib/src/lib.rs @@ -334,6 +334,8 @@ pub struct Simulation { /// The number of times that the network sends its total capacity in a month of operation when generating random /// activity. activity_multiplier: f64, + /// Wether we want the simulation not to produce and result file. Useful for developing, defaults to false. + no_results: bool, } const DEFAULT_PRINT_BATCH_SIZE: u32 = 500; @@ -346,6 +348,7 @@ impl Simulation { print_batch_size: Option, expected_payment_amount: Option, activity_multiplier: Option, + no_results: bool, ) -> Self { let (shutdown_trigger, shutdown_listener) = triggered::trigger(); Self { @@ -357,6 +360,7 @@ impl Simulation { print_batch_size: print_batch_size.unwrap_or(DEFAULT_PRINT_BATCH_SIZE), expected_payment_msat: expected_payment_amount.unwrap_or(EXPECTED_PAYMENT_AMOUNT), activity_multiplier: activity_multiplier.unwrap_or(ACTIVITY_MULTIPLIER), + no_results, } } @@ -536,7 +540,6 @@ impl Simulation { tasks: &mut JoinSet<()>, ) { let listener = self.shutdown_listener.clone(); - let print_batch_size = self.print_batch_size; log::debug!("Setting up simulator data collection."); // Create a sender/receiver pair that will be used to report final results of simulation. @@ -552,7 +555,8 @@ impl Simulation { tasks.spawn(consume_simulation_results( results_receiver, listener, - print_batch_size, + self.print_batch_size, + self.no_results, )); log::debug!("Simulator data collection set up."); } @@ -872,10 +876,11 @@ async fn consume_simulation_results( receiver: Receiver<(Payment, PaymentResult)>, listener: Listener, print_batch_size: u32, + no_results: bool, ) { log::debug!("Simulation results consumer started."); - if let Err(e) = write_payment_results(receiver, listener, print_batch_size).await { + if let Err(e) = write_payment_results(receiver, listener, print_batch_size, no_results).await { log::error!("Error while reporting payment results: {:?}.", e); } @@ -886,14 +891,19 @@ async fn write_payment_results( mut receiver: Receiver<(Payment, PaymentResult)>, listener: Listener, print_batch_size: u32, + no_results: bool, ) -> Result<(), SimulationError> { - let mut writer = WriterBuilder::new().from_path(format!( - "simulation_{:?}.csv", - SystemTime::now() - .duration_since(SystemTime::UNIX_EPOCH) - .unwrap() - .as_secs() - ))?; + let mut writer = if no_results { + WriterBuilder::new().from_path("/dev/null")? + } else { + WriterBuilder::new().from_path(format!( + "simulation_{:?}.csv", + SystemTime::now() + .duration_since(SystemTime::UNIX_EPOCH) + .unwrap() + .as_secs() + ))? + }; let mut result_logger = PaymentResultLogger::new();