From 764c2254300e75c516a97d43dba2f7135798b248 Mon Sep 17 00:00:00 2001 From: Daniel Knopik Date: Tue, 22 Oct 2024 18:45:37 +0200 Subject: [PATCH] clients: make recommended args toggleable --- lib/src/clients/blobssss.rs | 6 +++--- lib/src/clients/geth.rs | 10 ++++------ lib/src/clients/geth_bootnode.rs | 7 +++---- lib/src/clients/lighthouse.rs | 11 ++++------- lib/src/clients/lighthouse_bootnode.rs | 9 ++++----- lib/src/clients/lighthouse_vc.rs | 9 +++++---- lib/src/clients/mod.rs | 25 ++++++++++++++++++++++--- lib/src/clients/prometheus.rs | 6 +++--- lib/src/clients/reth.rs | 7 +++---- 9 files changed, 51 insertions(+), 39 deletions(-) diff --git a/lib/src/clients/blobssss.rs b/lib/src/clients/blobssss.rs index 255d466..9dc6b83 100644 --- a/lib/src/clients/blobssss.rs +++ b/lib/src/clients/blobssss.rs @@ -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; @@ -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, @@ -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(), diff --git a/lib/src/clients/geth.rs b/lib/src/clients/geth.rs index d6098af..96bd052 100644 --- a/lib/src/clients/geth.rs +++ b/lib/src/clients/geth.rs @@ -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; @@ -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")] @@ -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(), diff --git a/lib/src/clients/geth_bootnode.rs b/lib/src/clients/geth_bootnode.rs index b35bfb2..21f0872 100644 --- a/lib/src/clients/geth_bootnode.rs +++ b/lib/src/clients/geth_bootnode.rs @@ -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; @@ -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")] @@ -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(), diff --git a/lib/src/clients/lighthouse.rs b/lib/src/clients/lighthouse.rs index accfe5a..55e75e5 100644 --- a/lib/src/clients/lighthouse.rs +++ b/lib/src/clients/lighthouse.rs @@ -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}; @@ -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, } } @@ -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)); diff --git a/lib/src/clients/lighthouse_bootnode.rs b/lib/src/clients/lighthouse_bootnode.rs index 309ac28..0f52de5 100644 --- a/lib/src/clients/lighthouse_bootnode.rs +++ b/lib/src/clients/lighthouse_bootnode.rs @@ -1,4 +1,4 @@ -use crate::clients::CommonArgs; +use crate::clients::CommonParams; use log::debug; use serde::Deserialize; use std::collections::HashMap; @@ -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(), } } @@ -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(), diff --git a/lib/src/clients/lighthouse_vc.rs b/lib/src/clients/lighthouse_vc.rs index 0ee96e2..18e8231 100644 --- a/lib/src/clients/lighthouse_vc.rs +++ b/lib/src/clients/lighthouse_vc.rs @@ -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; @@ -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, } @@ -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(), diff --git a/lib/src/clients/mod.rs b/lib/src/clients/mod.rs index 1780090..751c7f5 100644 --- a/lib/src/clients/mod.rs +++ b/lib/src/clients/mod.rs @@ -52,14 +52,25 @@ 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() @@ -67,4 +78,12 @@ impl CommonArgs { 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() + } + } } diff --git a/lib/src/clients/prometheus.rs b/lib/src/clients/prometheus.rs index f5b8cbb..a8c9e40 100644 --- a/lib/src/clients/prometheus.rs +++ b/lib/src/clients/prometheus.rs @@ -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; @@ -13,7 +13,7 @@ use std::fs::File; #[serde(default)] pub struct Prometheus { #[serde(flatten)] - common: CommonArgs, + common: CommonParams, } #[derive(Serialize)] @@ -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(), diff --git a/lib/src/clients/reth.rs b/lib/src/clients/reth.rs index 3572192..3a96b34 100644 --- a/lib/src/clients/reth.rs +++ b/lib/src/clients/reth.rs @@ -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; @@ -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")] @@ -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(),