Merge branch 'unstable' into vc-fallback

This commit is contained in:
Mac L
2024-06-05 16:20:15 +10:00
309 changed files with 9719 additions and 11817 deletions

View File

@@ -27,15 +27,32 @@ const SUGGESTED_FEE_RECIPIENT: [u8; 20] =
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1];
pub fn run_basic_sim(matches: &ArgMatches) -> Result<(), String> {
let node_count = value_t!(matches, "nodes", usize).expect("Missing nodes default");
let proposer_nodes =
value_t!(matches, "proposer-nodes", usize).expect("Missing proposer-nodes default");
let validators_per_node = value_t!(matches, "validators-per-node", usize)
.expect("Missing validators-per-node default");
let speed_up_factor =
value_t!(matches, "speed-up-factor", u64).expect("Missing speed-up-factor default");
let log_level = value_t!(matches, "debug-level", String).expect("Missing default log-level");
let continue_after_checks = matches.is_present("continue-after-checks");
let node_count = matches
.get_one::<String>("nodes")
.expect("missing nodes default")
.parse::<usize>()
.expect("missing nodes default");
let proposer_nodes = matches
.get_one::<String>("proposer-nodes")
.unwrap_or(&String::from("0"))
.parse::<usize>()
.unwrap_or(0);
println!("PROPOSER-NODES: {}", proposer_nodes);
let validators_per_node = matches
.get_one::<String>("validators-per-node")
.expect("missing validators-per-node default")
.parse::<usize>()
.expect("missing validators-per-node default");
let speed_up_factor = matches
.get_one::<String>("speed-up-factor")
.expect("missing speed-up-factor default")
.parse::<u64>()
.expect("missing speed-up-factor default");
let log_level = matches
.get_one::<String>("debug-level")
.expect("missing debug-level");
let continue_after_checks = matches.get_flag("continue-after-checks");
println!("Basic Simulator:");
println!(" nodes: {}", node_count);
@@ -64,7 +81,7 @@ pub fn run_basic_sim(matches: &ArgMatches) -> Result<(), String> {
.initialize_logger(LoggerConfig {
path: None,
debug_level: log_level.clone(),
logfile_debug_level: log_level,
logfile_debug_level: log_level.clone(),
log_format: None,
logfile_format: None,
log_color: false,

View File

@@ -1,12 +1,12 @@
use clap::{App, Arg, SubCommand};
use clap::{crate_version, Arg, ArgAction, Command};
pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
App::new("simulator")
pub fn cli_app() -> Command {
Command::new("simulator")
.version(crate_version!())
.author("Sigma Prime <contact@sigmaprime.io>")
.about("Options for interacting with simulator")
.subcommand(
SubCommand::with_name("basic-sim")
Command::new("basic-sim")
.about(
"Runs a Beacon Chain simulation with `n` beacon node and validator clients, \
each with `v` validators. \
@@ -16,55 +16,55 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
exit immediately.",
)
.arg(
Arg::with_name("nodes")
.short("n")
Arg::new("nodes")
.short('n')
.long("nodes")
.takes_value(true)
.action(ArgAction::Set)
.default_value("3")
.help("Number of beacon nodes"),
)
.arg(
Arg::with_name("proposer-nodes")
.short("p")
Arg::new("proposer-nodes")
.short('p')
.long("proposer-nodes")
.takes_value(true)
.action(ArgAction::Set)
.default_value("3")
.help("Number of proposer-only beacon nodes"),
)
.arg(
Arg::with_name("validators-per-node")
.short("v")
Arg::new("validators-per-node")
.short('v')
.long("validators-per-node")
.takes_value(true)
.action(ArgAction::Set)
.default_value("20")
.help("Number of validators"),
)
.arg(
Arg::with_name("speed-up-factor")
.short("s")
Arg::new("speed-up-factor")
.short('s')
.long("speed-up-factor")
.takes_value(true)
.action(ArgAction::Set)
.default_value("3")
.help("Speed up factor. Please use a divisor of 12."),
)
.arg(
Arg::with_name("debug-level")
.short("d")
Arg::new("debug-level")
.short('d')
.long("debug-level")
.takes_value(true)
.action(ArgAction::Set)
.default_value("debug")
.help("Set the severity level of the logs."),
)
.arg(
Arg::with_name("continue-after-checks")
.short("c")
Arg::new("continue-after-checks")
.short('c')
.long("continue_after_checks")
.takes_value(false)
.action(ArgAction::SetTrue)
.help("Continue after checks (default false)"),
),
)
.subcommand(
SubCommand::with_name("fallback-sim")
Command::new("fallback-sim")
.about(
"Runs a Beacon Chain simulation with `c` validator clients where each VC is \
connected to `b` beacon nodes with `v` validators. \
@@ -76,50 +76,50 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
Otherwise, the simulation will exit and an error will be reported.",
)
.arg(
Arg::with_name("vc-count")
.short("c")
Arg::new("vc-count")
.short('c')
.long("vc-count")
.takes_value(true)
.action(ArgAction::Set)
.default_value("3")
.help("Number of validator clients."),
)
.arg(
Arg::with_name("bns-per-vc")
.short("b")
Arg::new("bns-per-vc")
.short('b')
.long("bns-per-vc")
.takes_value(true)
.action(ArgAction::Set)
.default_value("2")
.help("Number of beacon nodes per validator client."),
)
.arg(
Arg::with_name("validators-per-vc")
.short("v")
Arg::new("validators-per-vc")
.short('v')
.long("validators-per-vc")
.takes_value(true)
.action(ArgAction::Set)
.default_value("20")
.help("Number of validators per client."),
)
.arg(
Arg::with_name("speed-up-factor")
.short("s")
Arg::new("speed-up-factor")
.short('s')
.long("speed-up-factor")
.takes_value(true)
.action(ArgAction::Set)
.default_value("3")
.help("Speed up factor. Please use a divisor of 12."),
)
.arg(
Arg::with_name("debug-level")
.short("d")
Arg::new("debug-level")
.short('d')
.long("debug-level")
.takes_value(true)
.action(ArgAction::Set)
.default_value("debug")
.help("Set the severity level of the logs."),
)
.arg(
Arg::with_name("continue-after-checks")
.short("c")
Arg::new("continue-after-checks")
.short('c')
.long("continue_after_checks")
.takes_value(false)
.action(ArgAction::SetTrue)
.help("Continue after checks (default false)"),
),
)

View File

@@ -34,15 +34,36 @@ const SUGGESTED_FEE_RECIPIENT: [u8; 20] =
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1];
pub fn run_fallback_sim(matches: &ArgMatches) -> Result<(), String> {
let vc_count = value_t!(matches, "vc-count", usize).expect("Missing validator-count default");
let validators_per_vc =
value_t!(matches, "validators-per-vc", usize).expect("Missing validators-per-vc default");
let bns_per_vc = value_t!(matches, "bns-per-vc", usize).expect("Missing bns-per-vc default");
let vc_count = matches
.get_one::<String>("vc-count")
.expect("missing vc-count default")
.parse::<usize>()
.expect("missing vc-count default");
let validators_per_vc = matches
.get_one::<String>("validators-per-vc")
.expect("missing validators-per-vc default")
.parse::<usize>()
.expect("missing validators-per-vc default");
let bns_per_vc = matches
.get_one::<String>("bns-per-vc")
.expect("missing bns-per-vc default")
.parse::<usize>()
.expect("missing bns-per-vc default");
assert!(bns_per_vc > 1);
let speed_up_factor =
value_t!(matches, "speed-up-factor", u64).expect("Missing speed-up-factor default");
let log_level = value_t!(matches, "debug-level", String).expect("Missing default log-level");
let continue_after_checks = matches.is_present("continue-after-checks");
let speed_up_factor = matches
.get_one::<String>("speed-up-factor")
.expect("missing speed-up-factor default")
.parse::<u64>()
.expect("missing speed-up-factor default");
let log_level = matches
.get_one::<String>("debug-level")
.expect("missing debug-level default");
let continue_after_checks = matches.get_flag("continue-after-checks");
println!("Fallback Simulator:");
println!(" vc-count: {}", vc_count);
@@ -70,7 +91,7 @@ pub fn run_fallback_sim(matches: &ArgMatches) -> Result<(), String> {
.initialize_logger(LoggerConfig {
path: None,
debug_level: log_level.clone(),
logfile_debug_level: log_level,
logfile_debug_level: log_level.clone(),
log_format: None,
logfile_format: None,
log_color: false,

View File

@@ -11,7 +11,6 @@
//! easy-to-find files and stdout only contained info from the simulation.
//!
#[macro_use]
extern crate clap;
mod basic_sim;
@@ -34,14 +33,14 @@ fn main() {
let matches = cli_app().get_matches();
match matches.subcommand() {
("basic-sim", Some(matches)) => match basic_sim::run_basic_sim(matches) {
Some(("basic-sim", matches)) => match basic_sim::run_basic_sim(matches) {
Ok(()) => println!("Simulation exited successfully"),
Err(e) => {
eprintln!("Simulation exited with error: {}", e);
std::process::exit(1)
}
},
("fallback-sim", Some(matches)) => match fallback_sim::run_fallback_sim(matches) {
Some(("fallback-sim", matches)) => match fallback_sim::run_fallback_sim(matches) {
Ok(()) => println!("Simulation exited successfully"),
Err(e) => {
eprintln!("Simulation exited with error: {}", e);