Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -88,3 +88,4 @@ un
onchain
cli
ENR
stdin
18 changes: 17 additions & 1 deletion Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ members = [
"anchor/client",
"anchor/common/api_types",
"anchor/common/bls_lagrange",
"anchor/common/global_config",
"anchor/common/logging",
"anchor/common/qbft",
"anchor/common/ssv_network_config",
"anchor/common/ssv_types",
Expand Down Expand Up @@ -42,11 +44,12 @@ 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" }
keysplit = { path = "anchor/keysplit" }
logging = { path = "anchor/logging" }
logging = { path = "anchor/common/logging" }
message_receiver = { path = "anchor/message_receiver" }
message_sender = { path = "anchor/message_sender" }
message_validator = { path = "anchor/message_validator" }
Expand Down
2 changes: 2 additions & 0 deletions anchor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,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,

// External APIs
#[clap(
long,
Expand Down Expand Up @@ -527,7 +492,7 @@ pub struct Node {
pub disable_latency_measurement_service: bool,

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

pub fn get_color_style() -> Styles {
Expand Down
64 changes: 12 additions & 52 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::{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,
/// The http endpoints of the beacon node APIs.
///
/// Should be similar to `["http://localhost:8080"]`
Expand Down Expand Up @@ -78,20 +70,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 @@ -104,8 +84,7 @@ impl Config {
.expect("execution_nodes_websocket must always be a valid url.");

Self {
data_dir,
ssv_network,
global_config,
beacon_nodes,
proposer_nodes: vec![],
execution_nodes,
Expand All @@ -132,24 +111,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);

if let Some(ref beacon_nodes) = cli_args.beacon_nodes {
parse_urls(&mut config.beacon_nodes, beacon_nodes, "beacon node")?;
Expand All @@ -167,7 +130,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 @@ -190,6 +153,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 @@ -482,10 +446,6 @@ mod tests {
#[test]
// Ensures the default config does not panic.
fn default_config() {
Config::new(
SsvNetworkConfig::constant(DEFAULT_HARDCODED_NETWORK)
.unwrap()
.unwrap(),
);
Config::new(GlobalConfig::default());
}
}
Loading