Skip to content

Commit 351563d

Browse files
authored
Merge pull request #207 from carlaKC/206-refactorclidefaults
refactor/trivial: sim-cli fixups and SimulationCfg rebase regression
2 parents d8c165d + 4d7c28d commit 351563d

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

sim-cli/src/main.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
use bitcoin::secp256k1::PublicKey;
2-
use std::collections::HashMap;
3-
use std::path::PathBuf;
4-
use std::sync::Arc;
5-
use tokio::sync::Mutex;
6-
71
use anyhow::anyhow;
2+
use bitcoin::secp256k1::PublicKey;
83
use clap::builder::TypedValueParser;
94
use clap::Parser;
105
use log::LevelFilter;
@@ -13,6 +8,10 @@ use simln_lib::{
138
NodeId, SimParams, Simulation, SimulationCfg, WriteResults,
149
};
1510
use simple_logger::SimpleLogger;
11+
use std::collections::HashMap;
12+
use std::path::PathBuf;
13+
use std::sync::Arc;
14+
use tokio::sync::Mutex;
1615

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

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

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

2928
/// Default batch size to flush result data to disk
3029
const DEFAULT_PRINT_BATCH_SIZE: u32 = 500;
@@ -66,10 +65,10 @@ struct Cli {
6665
#[clap(long, short, verbatim_doc_comment, default_value = "info")]
6766
log_level: LevelFilter,
6867
/// Expected payment amount for the random activity generator
69-
#[clap(long, short, default_value_t = EXPECTED_PAYMENT_AMOUNT, value_parser = clap::builder::RangedU64ValueParser::<u64>::new().range(1..u64::MAX))]
68+
#[clap(long, short, default_value_t = DEFAULT_EXPECTED_PAYMENT_AMOUNT, value_parser = clap::builder::RangedU64ValueParser::<u64>::new().range(1..u64::MAX))]
7069
expected_pmt_amt: u64,
7170
/// Multiplier of the overall network capacity used by the random activity generator
72-
#[clap(long, short, default_value_t = ACTIVITY_MULTIPLIER, value_parser = clap::builder::StringValueParser::new().try_map(deserialize_f64_greater_than_zero))]
71+
#[clap(long, short, default_value_t = DEFAULT_ACTIVITY_MULTIPLIER, value_parser = clap::builder::StringValueParser::new().try_map(deserialize_f64_greater_than_zero))]
7372
capacity_multiplier: f64,
7473
/// Do not create an output file containing the simulations results
7574
#[clap(long, default_value_t = false)]

simln-lib/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,6 @@ pub struct SimulationCfg {
488488
write_results: Option<WriteResults>,
489489
/// Random number generator created from fixed seed.
490490
seeded_rng: MutRng,
491-
/// Results logger that holds the simulation statistics.
492-
results: Arc<Mutex<PaymentResultLogger>>,
493491
}
494492

495493
impl SimulationCfg {
@@ -506,7 +504,6 @@ impl SimulationCfg {
506504
activity_multiplier,
507505
write_results,
508506
seeded_rng: MutRng::new(seed),
509-
results: Arc::new(Mutex::new(PaymentResultLogger::new())),
510507
}
511508
}
512509
}
@@ -519,6 +516,8 @@ pub struct Simulation {
519516
nodes: HashMap<PublicKey, Arc<Mutex<dyn LightningNode>>>,
520517
/// The activity that are to be executed on the node.
521518
activity: Vec<ActivityDefinition>,
519+
/// Results logger that holds the simulation statistics.
520+
results: Arc<Mutex<PaymentResultLogger>>,
522521
/// High level triggers used to manage simulation tasks and shutdown.
523522
shutdown_trigger: Trigger,
524523
shutdown_listener: Listener,
@@ -553,6 +552,7 @@ impl Simulation {
553552
cfg,
554553
nodes,
555554
activity,
555+
results: Arc::new(Mutex::new(PaymentResultLogger::new())),
556556
shutdown_trigger,
557557
shutdown_listener,
558558
}
@@ -760,11 +760,11 @@ impl Simulation {
760760
}
761761

762762
pub async fn get_total_payments(&self) -> u64 {
763-
self.cfg.results.lock().await.total_attempts()
763+
self.results.lock().await.total_attempts()
764764
}
765765

766766
pub async fn get_success_rate(&self) -> f64 {
767-
self.cfg.results.lock().await.success_rate()
767+
self.results.lock().await.success_rate()
768768
}
769769

770770
/// run_data_collection starts the tasks required for the simulation to report of the results of the activity that
@@ -798,7 +798,7 @@ impl Simulation {
798798
}
799799
});
800800

801-
let result_logger = self.cfg.results.clone();
801+
let result_logger = self.results.clone();
802802

803803
let result_logger_clone = result_logger.clone();
804804
let result_logger_listener = listener.clone();

0 commit comments

Comments
 (0)