Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,4 @@ cli
ENR
UPnP
Golang
stdin
16 changes: 14 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"anchor/client",
"anchor/common/api_types",
"anchor/common/bls_lagrange",
"anchor/common/global_config",
"anchor/common/operator_key",
"anchor/common/qbft",
"anchor/common/ssv_network_config",
Expand All @@ -17,6 +18,7 @@ members = [
"anchor/http_metrics",
"anchor/keygen",
"anchor/keysplit",
"anchor/logging",
"anchor/message_receiver",
"anchor/message_sender",
"anchor/message_validator",
Expand All @@ -42,6 +44,7 @@ client = { path = "anchor/client" }
database = { path = "anchor/database" }
duties_tracker = { path = "anchor/duties_tracker" }
eth = { path = "anchor/eth" }
global_config = { path = "anchor/common/global_config" }
http_api = { path = "anchor/http_api" }
http_metrics = { path = "anchor/http_metrics" }
keygen = { path = "anchor/keygen" }
Expand Down
2 changes: 2 additions & 0 deletions anchor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ clap = { workspace = true }
client = { workspace = true }
dirs = { workspace = true }
futures = { workspace = true }
global_config = { workspace = true }
keygen = { workspace = true }
keysplit = { workspace = true }
logging = { workspace = true }
metrics = { workspace = true }
serde = { workspace = true }
ssv_network_config = { workspace = true }
strum = { workspace = true }
task_executor = { workspace = true }
tokio = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions anchor/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ eth = { workspace = true }
eth2 = { workspace = true }
ethereum_hashing = "0.7.0"
fdlimit = "0.3"
global_config = { workspace = true }
http_api = { workspace = true }
http_metrics = { workspace = true }
hyper = { workspace = true }
Expand Down
41 changes: 3 additions & 38 deletions anchor/client/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use clap::{
builder::{ArgAction, ArgPredicate, styling::*},
};
use ethereum_hashing::have_sha_extensions;
use logging::LoggingFlags;
use serde::{Deserialize, Serialize};
use logging::FileLoggingFlags;
use version::VERSION;

pub static SHORT_VERSION: LazyLock<String> = LazyLock::new(|| VERSION.replace("Anchor/", ""));
Expand Down Expand Up @@ -48,7 +47,7 @@ fn build_profile_name() -> &'static str {
.unwrap_or("unknown")
}

#[derive(Parser, Clone, Deserialize, Serialize, Debug)]
#[derive(Parser, Clone, Debug)]
#[clap(
name = "ssv",
about = "SSV Validator client. Maintained by Sigma Prime.",
Expand All @@ -62,40 +61,6 @@ fn build_profile_name() -> &'static str {
display_order = 0,
)]
pub struct Node {
#[clap(
long,
short = 'd',
global = true,
value_name = "DIR",
help = "Used to specify a custom root data directory for lighthouse keys and databases. \
Defaults to $HOME/.lighthouse/{network} where network is the value of the `network` flag \
Note: Users should specify separate custom datadirs for different networks.",
display_order = 0
)]
pub datadir: Option<PathBuf>,

#[clap(
long,
short = 't',
global = true,
value_name = "DIR",
help = "Path to directory containing eth2_testnet specs.",
display_order = 0
)]
pub testnet_dir: Option<PathBuf>,

#[clap(
long,
global = true,
value_name = "NETWORK",
value_parser = vec!["holesky", "hoodi"],
conflicts_with = "testnet_dir",
help = "Name of the chain Anchor will validate. Mainnet is not supported.",
display_order = 0,
default_value = crate::config::DEFAULT_HARDCODED_NETWORK,
)]
pub network: String,

#[clap(
long,
global = true,
Expand Down Expand Up @@ -572,7 +537,7 @@ pub struct Node {
pub disable_gossipsub_topic_scoring: bool,

#[clap(flatten)]
pub logging_flags: LoggingFlags,
pub logging_flags: FileLoggingFlags,
}

pub fn get_color_style() -> Styles {
Expand Down
73 changes: 11 additions & 62 deletions anchor/client/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// use crate::{http_api, http_metrics};
// use clap_utils::{flags::DISABLE_MALLOC_TUNING_FLAG, parse_optional, parse_required};

use std::{fs, net::IpAddr, path::PathBuf};
use std::{net::IpAddr, path::PathBuf};

use global_config::GlobalConfig;
use multiaddr::{Multiaddr, Protocol};
use network::{DEFAULT_DISC_PORT, DEFAULT_TCP_PORT, ListenAddr, ListenAddress};
use sensitive_url::SensitiveUrl;
use ssv_network_config::SsvNetworkConfig;
use ssv_types::OperatorId;
use tracing::{error, warn};

Expand All @@ -15,20 +15,12 @@ use crate::cli::Node;
pub const DEFAULT_BEACON_NODE: &str = "http://localhost:5052/";
pub const DEFAULT_EXECUTION_NODE: &str = "http://localhost:8545/";
pub const DEFAULT_EXECUTION_NODE_WS: &str = "ws://localhost:8546/";
/// The default Data directory, relative to the users home directory
pub const DEFAULT_ROOT_DIR: &str = ".anchor";
/// Default network, used to partition the data storage
pub const DEFAULT_HARDCODED_NETWORK: &str = "hoodi";
/// Base directory name for unnamed testnets passed through the --testnet-dir flag
pub const CUSTOM_TESTNET_DIR: &str = "custom";

/// Stores the core configuration for this Anchor instance.
#[derive(Clone)]
pub struct Config {
/// The data directory, which stores all validator databases
pub data_dir: PathBuf,
/// The SSV Network to use
pub ssv_network: SsvNetworkConfig,
/// The global config, containing datadir and SSV network to connect to.
pub global_config: GlobalConfig,
/// Path to the key file to use
pub key_file: Option<PathBuf>,
/// Path to a password file to use
Expand Down Expand Up @@ -82,20 +74,8 @@ pub struct Config {
impl Config {
/// Build a new configuration from defaults.
///
/// ssv_network: We pass this because it would be expensive to uselessly get a default eagerly.
fn new(ssv_network: SsvNetworkConfig) -> Self {
let data_dir = dirs::home_dir()
.unwrap_or_else(|| PathBuf::from("."))
.join(DEFAULT_ROOT_DIR)
.join(
ssv_network
.eth2_network
.config
.config_name
.as_deref()
.unwrap_or("custom"),
);

/// global_config: We pass this because it would be expensive to uselessly get a default.
fn new(global_config: GlobalConfig) -> Self {
let beacon_nodes = vec![
SensitiveUrl::parse(DEFAULT_BEACON_NODE)
.expect("beacon_nodes must always be a valid url."),
Expand All @@ -108,8 +88,7 @@ impl Config {
.expect("execution_nodes_websocket must always be a valid url.");

Self {
data_dir,
ssv_network,
global_config,
key_file: None,
password_file: None,
beacon_nodes,
Expand Down Expand Up @@ -138,24 +117,8 @@ impl Config {

/// Returns a `Default` implementation of `Self` with some parameters modified by the supplied
/// `cli_args`.
pub fn from_cli(cli_args: &Node) -> Result<Config, String> {
let eth2_network = if let Some(testnet_dir) = &cli_args.testnet_dir {
SsvNetworkConfig::load(testnet_dir.clone())
} else {
SsvNetworkConfig::constant(&cli_args.network)
.and_then(|net| net.ok_or_else(|| format!("Unknown network {}", cli_args.network)))
}?;

let mut config = Config::new(eth2_network);

if let Some(datadir) = cli_args.datadir.clone() {
config.data_dir = datadir;
}

if !config.data_dir.exists() {
fs::create_dir_all(&config.data_dir)
.map_err(|e| format!("Failed to create {:?}: {:?}", config.data_dir, e))?;
}
pub fn from_cli(cli_args: &Node, global_config: GlobalConfig) -> Result<Config, String> {
let mut config = Config::new(global_config);

config.key_file = cli_args.key_file.clone();
config.password_file = cli_args.password_file.clone();
Expand All @@ -176,7 +139,7 @@ pub fn from_cli(cli_args: &Node) -> Result<Config, String> {
config.disable_slashing_protection = cli_args.disable_slashing_protection;

// Network related
config.network.network_dir = config.data_dir.join("network");
config.network.network_dir = config.global_config.data_dir.join("network");
config.network.listen_addresses = parse_listening_addresses(cli_args)?;

for addr in cli_args.boot_nodes.clone() {
Expand All @@ -199,6 +162,7 @@ pub fn from_cli(cli_args: &Node) -> Result<Config, String> {
}
if cli_args.boot_nodes.is_empty() {
config.network.boot_nodes_enr = config
.global_config
.ssv_network
.ssv_boot_nodes
.clone()
Expand Down Expand Up @@ -512,18 +476,3 @@ pub fn parse_listening_addresses(cli_args: &Node) -> Result<ListenAddress, Strin

Ok(listening_addresses)
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
// Ensures the default config does not panic.
fn default_config() {
Config::new(
SsvNetworkConfig::constant(DEFAULT_HARDCODED_NETWORK)
.unwrap()
.unwrap(),
);
}
}
Loading