Skip to content

Commit

Permalink
Merge pull request #207 from carlaKC/206-refactorclidefaults
Browse files Browse the repository at this point in the history
refactor/trivial: sim-cli fixups and SimulationCfg rebase regression
  • Loading branch information
carlaKC authored Nov 20, 2024
2 parents d8c165d + 4d7c28d commit 351563d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
19 changes: 9 additions & 10 deletions sim-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
use bitcoin::secp256k1::PublicKey;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
use tokio::sync::Mutex;

use anyhow::anyhow;
use bitcoin::secp256k1::PublicKey;
use clap::builder::TypedValueParser;
use clap::Parser;
use log::LevelFilter;
Expand All @@ -13,6 +8,10 @@ use simln_lib::{
NodeId, SimParams, Simulation, SimulationCfg, WriteResults,
};
use simple_logger::SimpleLogger;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
use tokio::sync::Mutex;

/// The default directory where the simulation files are stored and where the results will be written to.
pub const DEFAULT_DATA_DIR: &str = ".";
Expand All @@ -21,10 +20,10 @@ pub const DEFAULT_DATA_DIR: &str = ".";
pub const DEFAULT_SIM_FILE: &str = "sim.json";

/// The default expected payment amount for the simulation, around ~$10 at the time of writing.
pub const EXPECTED_PAYMENT_AMOUNT: u64 = 3_800_000;
pub const DEFAULT_EXPECTED_PAYMENT_AMOUNT: u64 = 3_800_000;

/// The number of times over each node in the network sends its total deployed capacity in a calendar month.
pub const ACTIVITY_MULTIPLIER: f64 = 2.0;
pub const DEFAULT_ACTIVITY_MULTIPLIER: f64 = 2.0;

/// Default batch size to flush result data to disk
const DEFAULT_PRINT_BATCH_SIZE: u32 = 500;
Expand Down Expand Up @@ -66,10 +65,10 @@ struct Cli {
#[clap(long, short, verbatim_doc_comment, default_value = "info")]
log_level: LevelFilter,
/// Expected payment amount for the random activity generator
#[clap(long, short, default_value_t = EXPECTED_PAYMENT_AMOUNT, value_parser = clap::builder::RangedU64ValueParser::<u64>::new().range(1..u64::MAX))]
#[clap(long, short, default_value_t = DEFAULT_EXPECTED_PAYMENT_AMOUNT, value_parser = clap::builder::RangedU64ValueParser::<u64>::new().range(1..u64::MAX))]
expected_pmt_amt: u64,
/// Multiplier of the overall network capacity used by the random activity generator
#[clap(long, short, default_value_t = ACTIVITY_MULTIPLIER, value_parser = clap::builder::StringValueParser::new().try_map(deserialize_f64_greater_than_zero))]
#[clap(long, short, default_value_t = DEFAULT_ACTIVITY_MULTIPLIER, value_parser = clap::builder::StringValueParser::new().try_map(deserialize_f64_greater_than_zero))]
capacity_multiplier: f64,
/// Do not create an output file containing the simulations results
#[clap(long, default_value_t = false)]
Expand Down
12 changes: 6 additions & 6 deletions simln-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,6 @@ pub struct SimulationCfg {
write_results: Option<WriteResults>,
/// Random number generator created from fixed seed.
seeded_rng: MutRng,
/// Results logger that holds the simulation statistics.
results: Arc<Mutex<PaymentResultLogger>>,
}

impl SimulationCfg {
Expand All @@ -506,7 +504,6 @@ impl SimulationCfg {
activity_multiplier,
write_results,
seeded_rng: MutRng::new(seed),
results: Arc::new(Mutex::new(PaymentResultLogger::new())),
}
}
}
Expand All @@ -519,6 +516,8 @@ pub struct Simulation {
nodes: HashMap<PublicKey, Arc<Mutex<dyn LightningNode>>>,
/// The activity that are to be executed on the node.
activity: Vec<ActivityDefinition>,
/// Results logger that holds the simulation statistics.
results: Arc<Mutex<PaymentResultLogger>>,
/// High level triggers used to manage simulation tasks and shutdown.
shutdown_trigger: Trigger,
shutdown_listener: Listener,
Expand Down Expand Up @@ -553,6 +552,7 @@ impl Simulation {
cfg,
nodes,
activity,
results: Arc::new(Mutex::new(PaymentResultLogger::new())),
shutdown_trigger,
shutdown_listener,
}
Expand Down Expand Up @@ -760,11 +760,11 @@ impl Simulation {
}

pub async fn get_total_payments(&self) -> u64 {
self.cfg.results.lock().await.total_attempts()
self.results.lock().await.total_attempts()
}

pub async fn get_success_rate(&self) -> f64 {
self.cfg.results.lock().await.success_rate()
self.results.lock().await.success_rate()
}

/// run_data_collection starts the tasks required for the simulation to report of the results of the activity that
Expand Down Expand Up @@ -798,7 +798,7 @@ impl Simulation {
}
});

let result_logger = self.cfg.results.clone();
let result_logger = self.results.clone();

let result_logger_clone = result_logger.clone();
let result_logger_listener = listener.clone();
Expand Down

0 comments on commit 351563d

Please sign in to comment.