Skip to content

Commit

Permalink
lighthouse: adjust target peers to reduce likelihood of discovery loop
Browse files Browse the repository at this point in the history
  • Loading branch information
dknopik committed Oct 10, 2024
1 parent d1f1aca commit b3f5035
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 47 deletions.
2 changes: 1 addition & 1 deletion ethshadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
//! ```

use clap::{arg, command, value_parser};
use color_eyre::eyre::WrapErr;
use color_eyre::Result;
use ethshadow::generate;
use std::env;
use std::fs::File;
use std::os::unix::prelude::CommandExt;
use std::path::PathBuf;
use color_eyre::eyre::WrapErr;

fn main() -> Result<()> {
let mut matches = command!() // requires `cargo` feature
Expand Down
6 changes: 4 additions & 2 deletions lib/src/clients/geth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::clients::ENGINE_API_PORT;
use crate::clients::{Client, JSON_RPC_PORT};
use crate::config::shadow::Process;
use crate::error::Error;
use crate::node::{Node, SimulationContext};
use crate::node::{NodeInfo, SimulationContext};
use crate::validators::Validator;
use crate::CowStr;
use serde::Deserialize;
Expand All @@ -29,7 +29,7 @@ impl Default for Geth {
impl Client for Geth {
fn add_to_node(
&self,
node: &Node,
node: &NodeInfo,
ctx: &mut SimulationContext,
_validators: &[Validator],
) -> Result<Process, Error> {
Expand Down Expand Up @@ -78,4 +78,6 @@ impl Client for Geth {
start_time: "5s".into(),
})
}

fn is_el_client(&self) -> bool { true }
}
4 changes: 2 additions & 2 deletions lib/src/clients/geth_bootnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde::Deserialize;
use crate::clients::{Client, Validator};
use crate::config::shadow::Process;
use crate::error::Error;
use crate::node::{Node, SimulationContext};
use crate::node::{NodeInfo, SimulationContext};
use crate::CowStr;

const DISC_PORT: u16 = 30305;
Expand All @@ -31,7 +31,7 @@ impl Default for GethBootnode {
impl Client for GethBootnode {
fn add_to_node(
&self,
node: &Node,
node: &NodeInfo,
ctx: &mut SimulationContext,
_validators: &[Validator],
) -> Result<Process, Error> {
Expand Down
34 changes: 22 additions & 12 deletions lib/src/clients/lighthouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::clients::Client;
use crate::clients::{BEACON_API_PORT, CL_PROMETHEUS_PORT, ENGINE_API_PORT};
use crate::config::shadow::Process;
use crate::error::Error;
use crate::node::{Node, SimulationContext};
use crate::node::{NodeInfo, SimulationContext};
use crate::validators::Validator;
use crate::CowStr;
use serde::Deserialize;
Expand All @@ -15,13 +15,15 @@ const PORT: &str = "31000";
pub struct Lighthouse {
pub executable: CowStr,
pub extra_args: String,
pub lower_target_peers: bool,
}

impl Default for Lighthouse {
fn default() -> Self {
Self {
executable: "lighthouse".into(),
extra_args: "".into(),
lower_target_peers: true,
}
}
}
Expand All @@ -30,7 +32,7 @@ impl Default for Lighthouse {
impl Client for Lighthouse {
fn add_to_node<'a>(
&self,
node: &Node<'a>,
node: &NodeInfo<'a>,
ctx: &mut SimulationContext<'a>,
_validators: &[Validator],
) -> Result<Process, Error> {
Expand All @@ -46,10 +48,8 @@ impl Client for Lighthouse {
format!("{ip}:{CL_PROMETHEUS_PORT}"),
);

Ok(Process {
path: self.executable.clone(),
args: format!(
"--testnet-dir \"{}\" \
let mut args = format!(
"--testnet-dir \"{}\" \
beacon_node \
--datadir \"{dir}\" \
--execution-endpoint http://localhost:{ENGINE_API_PORT} \
Expand All @@ -66,15 +66,25 @@ impl Client for Lighthouse {
--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.extra_args,
),
--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,
);
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(),
args,
environment: HashMap::new(),
expected_final_state: "running".into(),
start_time: "5s".into(),
})
}

fn is_cl_client(&self) -> bool { true }
}
4 changes: 2 additions & 2 deletions lib/src/clients/lighthouse_bootnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::Deserialize;
use crate::clients::{Client, Validator};
use crate::config::shadow::Process;
use crate::error::Error;
use crate::node::{Node, SimulationContext};
use crate::node::{NodeInfo, SimulationContext};
use crate::{genesis, CowStr};

const PORT: &str = "4011";
Expand All @@ -32,7 +32,7 @@ impl Default for LighthouseBootnode {
impl Client for LighthouseBootnode {
fn add_to_node(
&self,
node: &Node,
node: &NodeInfo,
ctx: &mut SimulationContext,
_validators: &[Validator],
) -> Result<Process, Error> {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/clients/lighthouse_vc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::clients::BEACON_API_PORT;
use crate::clients::{Client, ValidatorDemand};
use crate::config::shadow::Process;
use crate::error::Error;
use crate::node::{Node, SimulationContext};
use crate::node::{NodeInfo, SimulationContext};
use crate::validators::Validator;
use crate::CowStr;
use serde::Deserialize;
Expand Down Expand Up @@ -30,7 +30,7 @@ impl Default for LighthouseValidatorClient {
impl Client for LighthouseValidatorClient {
fn add_to_node(
&self,
node: &Node,
node: &NodeInfo,
ctx: &mut SimulationContext,
validators: &[Validator],
) -> Result<Process, Error> {
Expand Down
7 changes: 5 additions & 2 deletions lib/src/clients/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::config::shadow::Process;
use crate::error::Error;
use crate::node::{Node, SimulationContext};
use crate::node::{NodeInfo, SimulationContext};
use crate::validators::Validator;
use std::fmt::Debug;

Expand Down Expand Up @@ -33,12 +33,15 @@ pub enum ValidatorDemand {
pub trait Client: Debug {
fn add_to_node<'a>(
&self,
node: &Node<'a>,
node: &NodeInfo<'a>,
ctx: &mut SimulationContext<'a>,
validators: &[Validator],
) -> Result<Process, Error>;

fn validator_demand(&self) -> ValidatorDemand {
ValidatorDemand::None
}

fn is_cl_client(&self) -> bool { false }
fn is_el_client(&self) -> bool { false }
}
4 changes: 2 additions & 2 deletions lib/src/clients/prometheus.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::clients::Client;
use crate::config::shadow::Process;
use crate::error::Error;
use crate::node::{Node, SimulationContext};
use crate::node::{NodeInfo, SimulationContext};
use crate::validators::Validator;
use crate::CowStr;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -45,7 +45,7 @@ struct StaticConfig<'a> {
impl Client for Prometheus {
fn add_to_node(
&self,
node: &Node,
node: &NodeInfo,
ctx: &mut SimulationContext,
_validators: &[Validator],
) -> Result<Process, Error> {
Expand Down
6 changes: 4 additions & 2 deletions lib/src/clients/reth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::clients::ENGINE_API_PORT;
use crate::clients::{Client, JSON_RPC_PORT};
use crate::config::shadow::Process;
use crate::error::Error;
use crate::node::{Node, SimulationContext};
use crate::node::{NodeInfo, SimulationContext};
use crate::validators::Validator;
use crate::CowStr;
use serde::Deserialize;
Expand All @@ -28,7 +28,7 @@ impl Default for Reth {
impl Client for Reth {
fn add_to_node(
&self,
node: &Node,
node: &NodeInfo,
ctx: &mut SimulationContext,
_validators: &[Validator],
) -> Result<Process, Error> {
Expand Down Expand Up @@ -66,4 +66,6 @@ impl Client for Reth {
start_time: "5s".into(),
})
}

fn is_el_client(&self) -> bool { true }
}
4 changes: 2 additions & 2 deletions lib/src/clients/simple_blob_spammer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::clients::Client;
use crate::config::shadow::Process;
use crate::error::Error;
use crate::node::{Node, SimulationContext};
use crate::node::{NodeInfo, SimulationContext};
use crate::validators::Validator;
use itertools::Itertools;
use serde::Deserialize;
Expand All @@ -19,7 +19,7 @@ pub struct SimpleBlobSpammer {
impl Client for SimpleBlobSpammer {
fn add_to_node(
&self,
_node: &Node,
_node: &NodeInfo,
ctx: &mut SimulationContext,
_validators: &[Validator],
) -> Result<Process, Error> {
Expand Down
12 changes: 2 additions & 10 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,12 @@ pub fn generate<T: TryInto<FullConfig, Error = Error>>(

let mut node_manager = NodeManager::new(
output_path.clone(),
&nodes,
&mut shadow_config,
network_graph,
validators,
);
for node in nodes {
for _ in 0..node.count {
node_manager.gen_node(
node.tag.unwrap_or(""),
&node.clients,
node.location,
node.reliability,
)?;
}
}
node_manager.generate_nodes()?;

// write modified shadow.yaml to disk
output_path.push("shadow.yaml");
Expand Down
Loading

0 comments on commit b3f5035

Please sign in to comment.