Skip to content

Commit

Permalink
wire up everything (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
dknopik authored Jan 24, 2025
1 parent d1a55fb commit 5cc2376
Show file tree
Hide file tree
Showing 16 changed files with 471 additions and 144 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ ssv_types = { path = "anchor/common/ssv_types" }
version = { path = "anchor/common/version" }

beacon_node_fallback = { git = "https://github.com/sigp/lighthouse", rev = "1a77f7a0" }
bls = { git = "https://github.com/sigp/lighthouse", rev = "1a77f7a0" }
eth2 = { git = "https://github.com/sigp/lighthouse", rev = "1a77f7a0" }
eth2_config = { git = "https://github.com/sigp/lighthouse", rev = "1a77f7a0" }
eth2_network_config = { git = "https://github.com/sigp/lighthouse", rev = "1a77f7a0" }
health_metrics = { git = "https://github.com/sigp/lighthouse", rev = "1a77f7a0" }
lighthouse_network = { git = "https://github.com/sigp/lighthouse", rev = "1a77f7a0" }
metrics = { git = "https://github.com/sigp/lighthouse", rev = "1a77f7a0" }
Expand Down Expand Up @@ -74,7 +76,6 @@ dashmap = "6.1.0"
derive_more = { version = "1.0.0", features = ["full"] }
dirs = "5.0.1"
discv5 = "0.9.0"
either = "1.13.0"
futures = "0.3.30"
hex = "0.4.3"
hyper = "1.4"
Expand All @@ -98,6 +99,7 @@ tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["fmt", "env-filter"] }
tree_hash = "0.8"
tree_hash_derive = "0.8"
zeroize = "1.8.1"

[profile.maxperf]
inherits = "release"
Expand Down
10 changes: 10 additions & 0 deletions anchor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ rust-version = "1.83.0"

[dependencies]
async-channel = { workspace = true }
bls = { workspace = true }
clap = { workspace = true }
client = { workspace = true }
dirs = { workspace = true }
eth2_network_config = { workspace = true }
futures = { workspace = true }
sensitive_url = { workspace = true }
serde = { workspace = true }
Expand All @@ -21,3 +23,11 @@ types = { workspace = true }

[dev-dependencies]
regex = "1.10.6"

[features]
# Compiles the BLS crypto code so that the binary is portable across machines.
portable = ["bls/supranational-portable"]
# Compiles BLST so that it always uses ADX instructions.
modern = ["bls/supranational-force-adx"]
# Support minimal spec (used for testing only).
spec-minimal = []
5 changes: 5 additions & 0 deletions anchor/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ path = "src/lib.rs"
anchor_validator_store = { workspace = true }
beacon_node_fallback = { workspace = true }
clap = { workspace = true }
database = { workspace = true }
dirs = { workspace = true }
eth = { workspace = true }
eth2 = { workspace = true }
eth2_config = { workspace = true }
eth2_network_config = { workspace = true }
ethereum_hashing = "0.7.0"
fdlimit = "0.3"
http_api = { workspace = true }
http_metrics = { workspace = true }
hyper = { workspace = true }
network = { workspace = true }
openssl = { workspace = true }
parking_lot = { workspace = true }
processor = { workspace = true }
qbft_manager = { workspace = true }
Expand All @@ -39,3 +43,4 @@ unused_port = { workspace = true }
validator_metrics = { workspace = true }
validator_services = { workspace = true }
version = { workspace = true }
zeroize = { workspace = true }
22 changes: 16 additions & 6 deletions anchor/client/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,25 @@ pub struct Anchor {

#[clap(
long,
short = 't',
global = true,
value_name = "DIR",
help = "The directory which contains the password to unlock the validator \
voting keypairs. Each password should be contained in a file where the \
name is the 0x-prefixed hex representation of the validators voting public \
key. Defaults to ~/.lighthouse/{network}/secrets.",
conflicts_with = "datadir",
help = "Path to directory containing eth2_testnet specs.",
display_order = 0
)]
pub secrets_dir: Option<PathBuf>,
pub testnet_dir: Option<PathBuf>,

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

/* External APIs */
#[clap(
Expand Down
72 changes: 40 additions & 32 deletions anchor/client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,31 @@
// use clap_utils::{flags::DISABLE_MALLOC_TUNING_FLAG, parse_optional, parse_required};

use crate::cli::Anchor;
use eth2_network_config::Eth2NetworkConfig;
use network::{ListenAddr, ListenAddress};
use sensitive_url::SensitiveUrl;
use serde::{Deserialize, Serialize};
use std::fs;
use std::net::IpAddr;
use std::path::PathBuf;
use tracing::warn;

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:8545/";
/// 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 = "mainnet";
/// Directory within the network directory where secrets are stored.
pub const DEFAULT_SECRETS_DIR: &str = "secrets";
/// 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, Serialize, Deserialize)]
#[derive(Clone)]
pub struct Config {
/// The data directory, which stores all validator databases
pub data_dir: PathBuf,
/// The directory containing the passwords to unlock validator keystores.
pub secrets_dir: PathBuf,
/// The Eth2 Network to use
pub eth2_network: Eth2NetworkConfig,
/// The http endpoints of the beacon node APIs.
///
/// Should be similar to `["http://localhost:8080"]`
Expand Down Expand Up @@ -54,24 +55,34 @@ pub struct Config {
pub processor: processor::Config,
}

impl Default for Config {
impl Config {
/// Build a new configuration from defaults.
fn default() -> Self {
// WARNING: these directory defaults should be always overwritten with parameters from cli
// for specific networks.
///
/// eth2_network: We pass this because it would be expensive to uselessly get a default eagerly.
fn new(eth2_network: Eth2NetworkConfig) -> Self {
let data_dir = dirs::home_dir()
.unwrap_or_else(|| PathBuf::from("."))
.join(DEFAULT_ROOT_DIR)
.join(DEFAULT_HARDCODED_NETWORK);
let secrets_dir = data_dir.join(DEFAULT_SECRETS_DIR);
.join(
eth2_network
.config
.config_name
.as_deref()
.unwrap_or("custom"),
);

let beacon_nodes = vec![SensitiveUrl::parse(DEFAULT_BEACON_NODE)
.expect("beacon_nodes must always be a valid url.")];
let execution_nodes = vec![SensitiveUrl::parse(DEFAULT_EXECUTION_NODE)
.expect("execution_nodes must always be a valid url.")];
let execution_nodes = vec![
SensitiveUrl::parse(DEFAULT_EXECUTION_NODE)
.expect("execution_nodes must always be a valid url."),
SensitiveUrl::parse(DEFAULT_EXECUTION_NODE_WS)
.expect("execution_nodes must always be a valid url."),
];

Self {
data_dir,
secrets_dir,
eth2_network,
beacon_nodes,
proposer_nodes: vec![],
execution_nodes,
Expand All @@ -90,27 +101,20 @@ impl Default for Config {
/// Returns a `Default` implementation of `Self` with some parameters modified by the supplied
/// `cli_args`.
pub fn from_cli(cli_args: &Anchor) -> Result<Config, String> {
let mut config = Config::default();

let default_root_dir = dirs::home_dir()
.map(|home| home.join(DEFAULT_ROOT_DIR))
.unwrap_or_else(|| PathBuf::from("."));
let eth2_network = if let Some(_testnet_dir) = &cli_args.testnet_dir {
// todo
return Err("testnet dir not yet supported".into());
} else {
Eth2NetworkConfig::constant(&cli_args.network)
.and_then(|net| net.ok_or_else(|| format!("Unknown network {}", cli_args.network)))
}?;

let (mut data_dir, mut secrets_dir) = (None, None);
let mut config = Config::new(eth2_network);

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

if cli_args.secrets_dir.is_some() {
secrets_dir = cli_args.secrets_dir.clone();
}

config.data_dir = data_dir.unwrap_or_else(|| default_root_dir.join(DEFAULT_ROOT_DIR));

config.secrets_dir = secrets_dir.unwrap_or_else(|| default_root_dir.join(DEFAULT_SECRETS_DIR));

if !config.data_dir.exists() {
fs::create_dir_all(&config.data_dir)
.map_err(|e| format!("Failed to create {:?}: {:?}", config.data_dir, e))?;
Expand Down Expand Up @@ -390,6 +394,10 @@ mod tests {
#[test]
// Ensures the default config does not panic.
fn default_config() {
Config::default();
Config::new(
Eth2NetworkConfig::constant(DEFAULT_HARDCODED_NETWORK)
.unwrap()
.unwrap(),
);
}
}
Loading

0 comments on commit 5cc2376

Please sign in to comment.