Skip to content

Commit

Permalink
Merge pull request #5 from dknopik/common-args
Browse files Browse the repository at this point in the history
clients: allow specification of custom CLI args for every client
  • Loading branch information
ppopth authored Oct 27, 2024
2 parents e93dbd3 + 2600e69 commit 59e058b
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 102 deletions.
19 changes: 11 additions & 8 deletions lib/src/clients/blobssss.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
use std::collections::HashMap;
use crate::clients::Client;
use crate::clients::CommonParams;
use crate::config::shadow::Process;
use crate::node::{NodeInfo, SimulationContext};
use crate::validators::Validator;
use crate::Error;
use itertools::Itertools;
use serde::Deserialize;
use std::collections::HashMap;

#[derive(Deserialize, Debug, Clone)]
pub struct Blobssss {
executable: String,
private_key: String,
min_per_slot: u8,
max_per_slot: u8,
start_time: String,
#[serde(flatten)]
pub common: CommonParams,
pub private_key: String,
pub min_per_slot: u8,
pub max_per_slot: u8,
pub start_time: String,
}

#[typetag::deserialize(name = "blobssss")]
Expand All @@ -25,13 +27,14 @@ impl Client for Blobssss {
_validators: &[Validator],
) -> Result<Process, Error> {
Ok(Process {
path: self.executable.clone().into(),
path: self.common.executable_or("blobssss"),
args: format!(
"--min {} --max {} --key {} --rpcs {}",
"--min {} --max {} --key {} --rpcs {} {}",
self.min_per_slot,
self.max_per_slot,
self.private_key,
ctx.el_http_endpoints().iter().join(","),
self.common.arguments(""),
),
environment: HashMap::default(),
expected_final_state: "running".into(),
Expand Down
26 changes: 10 additions & 16 deletions lib/src/clients/geth.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::clients::CommonParams;
use crate::clients::ENGINE_API_PORT;
use crate::clients::{Client, JSON_RPC_PORT};
use crate::config::shadow::Process;
use crate::node::{NodeInfo, SimulationContext};
use crate::utils::log_and_wait;
use crate::validators::Validator;
use crate::CowStr;
use crate::Error;
use log::debug;
use serde::Deserialize;
Expand All @@ -13,18 +13,11 @@ use std::process::Command;

const PORT: &str = "21000";

#[derive(Deserialize, Debug, Clone)]
#[derive(Deserialize, Debug, Clone, Default)]
#[serde(default)]
pub struct Geth {
pub executable: CowStr,
}

impl Default for Geth {
fn default() -> Self {
Self {
executable: "geth".into(),
}
}
#[serde(flatten)]
pub common: CommonParams,
}

#[typetag::deserialize(name = "geth")]
Expand All @@ -41,9 +34,11 @@ impl Client for Geth {
let dir = node.dir().join("geth");
let dir = dir.to_str().ok_or(Error::NonUTF8Path)?;

let executable = self.common.executable_or("geth");

debug!("Calling geth init");
let status = log_and_wait(
Command::new(self.executable.as_ref())
Command::new(executable.as_ref())
.arg("init")
.arg("--datadir")
.arg(dir)
Expand All @@ -56,7 +51,7 @@ impl Client for Geth {
ctx.add_el_http_endpoint(format!("http://{}:{JSON_RPC_PORT}", node.ip()));

Ok(Process {
path: self.executable.clone(),
path: executable,
args: format!(
"--datadir {dir} \
--authrpc.port {ENGINE_API_PORT} \
Expand All @@ -68,12 +63,11 @@ impl Client for Geth {
--port {PORT} \
--bootnodes {} \
--nat extip:{} \
--ipcdisable \
--log.file {dir}/geth.log \
--syncmode full",
--log.file {dir}/geth.log {}",
ctx.jwt_path().to_str().ok_or(Error::NonUTF8Path)?,
ctx.el_bootnode_enodes().join(","),
node.ip(),
self.common.arguments("--syncmode full --ipcdisable"),
),
environment: HashMap::new(),
expected_final_state: "running".into(),
Expand Down
21 changes: 7 additions & 14 deletions lib/src/clients/geth_bootnode.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::clients::CommonParams;
use std::collections::HashMap;
use std::fs::{create_dir, File};
use std::io::Write;
Expand All @@ -8,23 +9,15 @@ use serde::Deserialize;
use crate::clients::{Client, Validator};
use crate::config::shadow::Process;
use crate::node::{NodeInfo, SimulationContext};
use crate::CowStr;
use crate::Error;

const DISC_PORT: u16 = 30305;

#[derive(Deserialize, Debug, Clone)]
#[derive(Deserialize, Debug, Clone, Default)]
#[serde(default)]
pub struct GethBootnode {
pub executable: CowStr,
}

impl Default for GethBootnode {
fn default() -> Self {
Self {
executable: "bootnode".into(),
}
}
#[serde(flatten)]
pub common: CommonParams,
}

#[typetag::deserialize(name = "geth_bootnode")]
Expand Down Expand Up @@ -54,12 +47,12 @@ impl Client for GethBootnode {
ctx.add_el_bootnode_enode(format!("enode://{pub_key}@{ip}:0?discport={DISC_PORT}"));

Ok(Process {
path: self.executable.clone(),
path: self.common.executable_or("bootnode"),
args: format!(
"-nodekey \"{key_file}\" \
-verbosity 5 \
-addr :{DISC_PORT} \
-nat extip:{ip}"
-nat extip:{ip} {}",
self.common.arguments("-verbosity 5"),
),
environment: HashMap::new(),
expected_final_state: "running".into(),
Expand Down
20 changes: 8 additions & 12 deletions lib/src/clients/lighthouse.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::clients::Client;
use crate::clients::CommonParams;
use crate::clients::{BEACON_API_PORT, CL_PROMETHEUS_PORT, ENGINE_API_PORT};
use crate::config::shadow::Process;
use crate::node::{NodeInfo, SimulationContext};
use crate::validators::Validator;
use crate::CowStr;
use crate::Error;
use serde::Deserialize;
use std::collections::HashMap;
Expand All @@ -13,16 +13,15 @@ const PORT: &str = "31000";
#[derive(Deserialize, Debug, Clone)]
#[serde(default)]
pub struct Lighthouse {
pub executable: CowStr,
pub extra_args: String,
#[serde(flatten)]
pub common: CommonParams,
pub lower_target_peers: bool,
}

impl Default for Lighthouse {
fn default() -> Self {
Self {
executable: "lighthouse".into(),
extra_args: String::new(),
common: CommonParams::default(),
lower_target_peers: true,
}
}
Expand Down Expand Up @@ -61,24 +60,21 @@ impl Client for Lighthouse {
--enr-tcp-port {PORT} \
--http \
--http-port {BEACON_API_PORT} \
--disable-quic \
--disable-upnp \
--disable-packet-filter \
--metrics-address 0.0.0.0 \
--metrics-port {CL_PROMETHEUS_PORT} \
--metrics \
{} ",
--metrics {}",
ctx.metadata_path().to_str().ok_or(Error::NonUTF8Path)?,
ctx.jwt_path().to_str().ok_or(Error::NonUTF8Path)?,
ctx.cl_bootnode_enrs().join(","),
self.extra_args,
self.common
.arguments("--disable-quic --disable-upnp --disable-packet-filter"),
);
if self.lower_target_peers && ctx.num_cl_clients() <= 100 {
args.push_str(&format!("--target-peers {}", ctx.num_cl_clients() - 1));
}

Ok(Process {
path: self.executable.clone(),
path: self.common.executable_or("lighthouse"),
args,
environment: HashMap::new(),
expected_final_state: "running".into(),
Expand Down
12 changes: 7 additions & 5 deletions lib/src/clients/lighthouse_bootnode.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::clients::CommonParams;
use log::debug;
use serde::Deserialize;
use std::collections::HashMap;
Expand All @@ -16,14 +17,15 @@ const PORT: &str = "4011";
#[derive(Deserialize, Debug, Clone)]
#[serde(default)]
pub struct LighthouseBootnode {
pub executable: CowStr,
#[serde(flatten)]
pub common: CommonParams,
pub lcli_executable: CowStr,
}

impl Default for LighthouseBootnode {
fn default() -> Self {
Self {
executable: "lighthouse".into(),
common: CommonParams::default(),
lcli_executable: "lcli".into(),
}
}
Expand Down Expand Up @@ -66,15 +68,15 @@ impl Client for LighthouseBootnode {
ctx.add_cl_bootnode_enr(enr);

Ok(Process {
path: self.executable.clone(),
path: self.common.executable_or("lighthouse"),
args: format!(
"--testnet-dir \"{}\" \
boot_node \
--port {PORT} \
--disable-packet-filter \
--network-dir {}",
--network-dir {} {}",
ctx.metadata_path().to_str().ok_or(Error::NonUTF8Path)?,
dir.to_str().ok_or(Error::NonUTF8Path)?,
self.common.arguments("--disable-packet-filter"),
),
environment: HashMap::new(),
expected_final_state: "running".into(),
Expand Down
24 changes: 9 additions & 15 deletions lib/src/clients/lighthouse_vc.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
use crate::clients::CommonParams;
use crate::clients::BEACON_API_PORT;
use crate::clients::{Client, ValidatorDemand};
use crate::config::shadow::Process;
use crate::node::{NodeInfo, SimulationContext};
use crate::validators::Validator;
use crate::CowStr;
use crate::Error;
use serde::Deserialize;
use std::collections::HashMap;
use std::fs;
use std::fs::create_dir;

#[derive(Deserialize, Debug, Clone)]
#[derive(Deserialize, Debug, Clone, Default)]
#[serde(default)]
pub struct LighthouseValidatorClient {
pub executable: CowStr,
#[serde(flatten)]
pub common: CommonParams,
pub validators: Option<usize>,
}

impl Default for LighthouseValidatorClient {
fn default() -> Self {
Self {
executable: "lighthouse".into(),
validators: None,
}
}
}

#[typetag::deserialize(name = "lighthouse_vc")]
impl Client for LighthouseValidatorClient {
fn add_to_node(
Expand Down Expand Up @@ -62,15 +54,17 @@ impl Client for LighthouseValidatorClient {
}

Ok(Process {
path: self.executable.clone(),
path: self.common.executable_or("lighthouse"),
args: format!(
"--testnet-dir \"{}\" \
validator_client \
--datadir \"{dir_str}\" \
--beacon-nodes http://localhost:{BEACON_API_PORT} \
--suggested-fee-recipient 0xf97e180c050e5Ab072211Ad2C213Eb5AEE4DF134 \
--init-slashing-protection",
--init-slashing-protection {}",
ctx.metadata_path().to_str().ok_or(Error::NonUTF8Path)?,
self.common.arguments(
"--suggested-fee-recipient 0xf97e180c050e5Ab072211Ad2C213Eb5AEE4DF134"
),
),
environment: HashMap::new(),
expected_final_state: "running".into(),
Expand Down
38 changes: 38 additions & 0 deletions lib/src/clients/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::config::shadow::Process;
use crate::node::{NodeInfo, SimulationContext};
use crate::validators::Validator;
use crate::CowStr;
use crate::Error;
use serde::Deserialize;
use std::fmt::Debug;

const ENGINE_API_PORT: &str = "21001";
Expand Down Expand Up @@ -49,3 +51,39 @@ pub trait Client: Debug {
false
}
}

#[derive(Deserialize, Debug, Clone)]
#[serde(default)]
pub struct CommonParams {
pub executable: String,
pub extra_args: String,
pub use_recommended_args: bool,
}

impl Default for CommonParams {
fn default() -> Self {
CommonParams {
executable: String::new(),
extra_args: String::new(),
use_recommended_args: true,
}
}
}

impl CommonParams {
pub fn executable_or(&self, default: &'static str) -> CowStr {
if self.executable.is_empty() {
default.into()
} else {
self.executable.clone().into()
}
}

pub fn arguments(&self, recommended: &'static str) -> String {
if self.use_recommended_args && !recommended.is_empty() {
format!("{} {}", recommended, self.extra_args)
} else {
self.extra_args.clone()
}
}
}
Loading

0 comments on commit 59e058b

Please sign in to comment.