Skip to content

Commit

Permalink
clients: make recommended args toggleable
Browse files Browse the repository at this point in the history
  • Loading branch information
dknopik committed Oct 22, 2024
1 parent 37e5331 commit 764c225
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 39 deletions.
6 changes: 3 additions & 3 deletions lib/src/clients/blobssss.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::clients::Client;
use crate::clients::CommonArgs;
use crate::clients::CommonParams;
use crate::config::shadow::Process;
use crate::node::{NodeInfo, SimulationContext};
use crate::validators::Validator;
Expand All @@ -11,7 +11,7 @@ use std::collections::HashMap;
#[derive(Deserialize, Debug, Clone)]
pub struct Blobssss {
#[serde(flatten)]
pub common: CommonArgs,
pub common: CommonParams,
pub private_key: String,
pub min_per_slot: u8,
pub max_per_slot: u8,
Expand All @@ -34,7 +34,7 @@ impl Client for Blobssss {
self.max_per_slot,
self.private_key,
ctx.el_http_endpoints().iter().join(","),
self.common.extra_args,
self.common.arguments(""),
),
environment: HashMap::default(),
expected_final_state: "running".into(),
Expand Down
10 changes: 4 additions & 6 deletions lib/src/clients/geth.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::clients::CommonArgs;
use crate::clients::CommonParams;
use crate::clients::ENGINE_API_PORT;
use crate::clients::{Client, JSON_RPC_PORT};
use crate::config::shadow::Process;
Expand All @@ -17,7 +17,7 @@ const PORT: &str = "21000";
#[serde(default)]
pub struct Geth {
#[serde(flatten)]
pub common: CommonArgs,
pub common: CommonParams,
}

#[typetag::deserialize(name = "geth")]
Expand Down Expand Up @@ -63,13 +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.extra_args,
self.common.arguments("--syncmode full --ipcdisable"),
),
environment: HashMap::new(),
expected_final_state: "running".into(),
Expand Down
7 changes: 3 additions & 4 deletions lib/src/clients/geth_bootnode.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::clients::CommonArgs;
use crate::clients::CommonParams;
use std::collections::HashMap;
use std::fs::{create_dir, File};
use std::io::Write;
Expand All @@ -17,7 +17,7 @@ const DISC_PORT: u16 = 30305;
#[serde(default)]
pub struct GethBootnode {
#[serde(flatten)]
pub common: CommonArgs,
pub common: CommonParams,
}

#[typetag::deserialize(name = "geth_bootnode")]
Expand Down Expand Up @@ -50,10 +50,9 @@ impl Client for GethBootnode {
path: self.common.executable_or("bootnode"),
args: format!(
"-nodekey \"{key_file}\" \
-verbosity 5 \
-addr :{DISC_PORT} \
-nat extip:{ip} {}",
self.common.extra_args,
self.common.arguments("-verbosity 5"),
),
environment: HashMap::new(),
expected_final_state: "running".into(),
Expand Down
11 changes: 4 additions & 7 deletions lib/src/clients/lighthouse.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::clients::Client;
use crate::clients::CommonArgs;
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};
Expand All @@ -14,14 +14,14 @@ const PORT: &str = "31000";
#[serde(default)]
pub struct Lighthouse {
#[serde(flatten)]
pub common: CommonArgs,
pub common: CommonParams,
pub lower_target_peers: bool,
}

impl Default for Lighthouse {
fn default() -> Self {
Self {
common: CommonArgs::default(),
common: CommonParams::default(),
lower_target_peers: true,
}
}
Expand Down Expand Up @@ -60,16 +60,13 @@ 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 {}",
ctx.metadata_path().to_str().ok_or(Error::NonUTF8Path)?,
ctx.jwt_path().to_str().ok_or(Error::NonUTF8Path)?,
ctx.cl_bootnode_enrs().join(","),
self.common.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));
Expand Down
9 changes: 4 additions & 5 deletions lib/src/clients/lighthouse_bootnode.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::clients::CommonArgs;
use crate::clients::CommonParams;
use log::debug;
use serde::Deserialize;
use std::collections::HashMap;
Expand All @@ -18,14 +18,14 @@ const PORT: &str = "4011";
#[serde(default)]
pub struct LighthouseBootnode {
#[serde(flatten)]
pub common: CommonArgs,
pub common: CommonParams,
pub lcli_executable: CowStr,
}

impl Default for LighthouseBootnode {
fn default() -> Self {
Self {
common: CommonArgs::default(),
common: CommonParams::default(),
lcli_executable: "lcli".into(),
}
}
Expand Down Expand Up @@ -73,11 +73,10 @@ impl Client for LighthouseBootnode {
"--testnet-dir \"{}\" \
boot_node \
--port {PORT} \
--disable-packet-filter \
--network-dir {} {}",
ctx.metadata_path().to_str().ok_or(Error::NonUTF8Path)?,
dir.to_str().ok_or(Error::NonUTF8Path)?,
self.common.extra_args,
self.common.arguments("--disable-packet-filter"),
),
environment: HashMap::new(),
expected_final_state: "running".into(),
Expand Down
9 changes: 5 additions & 4 deletions lib/src/clients/lighthouse_vc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::clients::CommonArgs;
use crate::clients::CommonParams;
use crate::clients::BEACON_API_PORT;
use crate::clients::{Client, ValidatorDemand};
use crate::config::shadow::Process;
Expand All @@ -14,7 +14,7 @@ use std::fs::create_dir;
#[serde(default)]
pub struct LighthouseValidatorClient {
#[serde(flatten)]
pub common: CommonArgs,
pub common: CommonParams,
pub validators: Option<usize>,
}

Expand Down Expand Up @@ -60,10 +60,11 @@ impl Client for LighthouseValidatorClient {
validator_client \
--datadir \"{dir_str}\" \
--beacon-nodes http://localhost:{BEACON_API_PORT} \
--suggested-fee-recipient 0xf97e180c050e5Ab072211Ad2C213Eb5AEE4DF134 \
--init-slashing-protection {}",
ctx.metadata_path().to_str().ok_or(Error::NonUTF8Path)?,
self.common.extra_args,
self.common.arguments(
"--suggested-fee-recipient 0xf97e180c050e5Ab072211Ad2C213Eb5AEE4DF134"
),
),
environment: HashMap::new(),
expected_final_state: "running".into(),
Expand Down
25 changes: 22 additions & 3 deletions lib/src/clients/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,38 @@ pub trait Client: Debug {
}
}

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

impl CommonArgs {
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()
}
}
}
6 changes: 3 additions & 3 deletions lib/src/clients/prometheus.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::clients::Client;
use crate::clients::CommonArgs;
use crate::clients::CommonParams;
use crate::config::shadow::Process;
use crate::node::{NodeInfo, SimulationContext};
use crate::validators::Validator;
Expand All @@ -13,7 +13,7 @@ use std::fs::File;
#[serde(default)]
pub struct Prometheus {
#[serde(flatten)]
common: CommonArgs,
common: CommonParams,
}

#[derive(Serialize)]
Expand Down Expand Up @@ -70,7 +70,7 @@ impl Client for Prometheus {
"--storage.tsdb.path={} --config.file={} {}",
dir.to_str().ok_or(Error::NonUTF8Path)?,
config_file.to_str().ok_or(Error::NonUTF8Path)?,
self.common.extra_args,
self.common.arguments(""),
),
environment: HashMap::default(),
expected_final_state: "running".into(),
Expand Down
7 changes: 3 additions & 4 deletions lib/src/clients/reth.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::clients::CommonArgs;
use crate::clients::CommonParams;
use crate::clients::ENGINE_API_PORT;
use crate::clients::{Client, JSON_RPC_PORT};
use crate::config::shadow::Process;
Expand All @@ -14,7 +14,7 @@ const PORT: &str = "21000";
#[serde(default)]
pub struct Reth {
#[serde(flatten)]
pub common: CommonArgs,
pub common: CommonParams,
}

#[typetag::deserialize(name = "reth")]
Expand Down Expand Up @@ -48,12 +48,11 @@ impl Client for Reth {
--port {PORT} \
--bootnodes {} \
--nat extip:{} \
--ipcdisable \
--log.file.directory {dir} {}",
ctx.jwt_path().to_str().ok_or(Error::NonUTF8Path)?,
ctx.el_bootnode_enodes().join(","),
node.ip(),
self.common.extra_args,
self.common.arguments("--ipcdisable"),
),
environment: HashMap::new(),
expected_final_state: "running".into(),
Expand Down

0 comments on commit 764c225

Please sign in to comment.