Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sim-cli: Improves CLI docs so help has a more friendly report #145

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions sim-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,37 @@ use sim_lib::{
};
use simple_logger::SimpleLogger;

/// The default expected payment amount for the simulation, around ~$10 at the time of writing.
pub const 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;

/// Default batch size to flush result data to disk
const DEFAULT_PRINT_BATCH_SIZE: u32 = 500;

#[derive(Parser)]
#[command(version, about)]
struct Cli {
/// Path to the simulation file to be used by the simulator
#[clap(index = 1)]
sim_file: PathBuf,
/// Total time the simulator will be running
#[clap(long, short)]
total_time: Option<u32>,
/// Number of activity results to batch together before printing to csv file
#[clap(long, short)]
print_batch_size: Option<u32>,
#[clap(long, short, default_value = "info")]
/// Number of activity results to batch together before printing to csv file [min: 1]
#[clap(long, short, default_value_t = DEFAULT_PRINT_BATCH_SIZE, value_parser = clap::builder::RangedU64ValueParser::<u32>::new().range(1..u32::MAX as u64))]
print_batch_size: u32,
/// Level of verbosity of the messages displayed by the simulator.
/// Possible values: [off, error, warn, info, debug, trace]
#[clap(long, short, verbatim_doc_comment, default_value = "info")]
log_level: LevelFilter,
#[clap(long, short)]
expected_pmt_amt: Option<u64>,
#[clap(long, short)]
capacity_multiplier: Option<f64>,
/// Expected payment amount for the random activity generator
#[clap(long, short, default_value_t = EXPECTED_PAYMENT_AMOUNT)]
expected_pmt_amt: u64,
/// Multiplier of the overall network capacity used by the random activity generator
#[clap(long, short, default_value_t = ACTIVITY_MULTIPLIER)]
sr-gi marked this conversation as resolved.
Show resolved Hide resolved
capacity_multiplier: f64,
}

#[tokio::main]
Expand Down
20 changes: 6 additions & 14 deletions sim-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ pub mod lnd;
mod random_activity;
mod serializers;

/// The default expected payment amount for the simulation, around ~$10 at the time of writing.
pub const 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;

#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum NodeConnection {
#[serde(alias = "lnd", alias = "Lnd")]
Expand Down Expand Up @@ -336,16 +330,14 @@ pub struct Simulation {
activity_multiplier: f64,
}

const DEFAULT_PRINT_BATCH_SIZE: u32 = 500;

impl Simulation {
pub fn new(
nodes: HashMap<PublicKey, Arc<Mutex<dyn LightningNode + Send>>>,
activity: Vec<ActivityDefinition>,
total_time: Option<u32>,
print_batch_size: Option<u32>,
expected_payment_amount: Option<u64>,
activity_multiplier: Option<f64>,
print_batch_size: u32,
expected_payment_msat: u64,
activity_multiplier: f64,
) -> Self {
let (shutdown_trigger, shutdown_listener) = triggered::trigger();
Self {
Expand All @@ -354,9 +346,9 @@ impl Simulation {
shutdown_trigger,
shutdown_listener,
total_time: total_time.map(|x| Duration::from_secs(x as u64)),
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),
print_batch_size,
expected_payment_msat,
activity_multiplier,
}
}

Expand Down