Skip to content

Commit

Permalink
All binaries get directory info from common::directory crate
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanjay176 committed Aug 17, 2020
1 parent 8a7c130 commit 01e6166
Show file tree
Hide file tree
Showing 22 changed files with 134 additions and 117 deletions.
15 changes: 15 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ members = [
"common/compare_fields",
"common/compare_fields_derive",
"common/deposit_contract",
"common/directory",
"common/eth2_config",
"common/eth2_interop_keypairs",
"common/eth2_testnet_config",
Expand Down
1 change: 1 addition & 0 deletions account_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ eth2_testnet_config = { path = "../common/eth2_testnet_config" }
web3 = "0.11.0"
futures = { version = "0.3.5", features = ["compat"] }
clap_utils = { path = "../common/clap_utils" }
directory = { path = "../common/directory" }
eth2_wallet = { path = "../crypto/eth2_wallet" }
eth2_wallet_manager = { path = "../common/eth2_wallet_manager" }
rand = "0.7.2"
Expand Down
46 changes: 0 additions & 46 deletions account_manager/src/common.rs

This file was deleted.

1 change: 0 additions & 1 deletion account_manager/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mod common;
pub mod validator;
pub mod wallet;

Expand Down
11 changes: 4 additions & 7 deletions account_manager/src/validator/create.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::{
common::{base_secrets_dir, base_validator_dir, ensure_dir_exists},
SECRETS_DIR_FLAG, VALIDATOR_DIR_FLAG,
};
use crate::{BASE_DIR_FLAG, SECRETS_DIR_FLAG, VALIDATOR_DIR_FLAG};
use account_utils::{random_password, strip_off_newlines, validator_definitions};
use clap::{App, Arg, ArgMatches};
use directory::{custom_base_dir, ensure_dir_exists, DEFAULT_SECRET_DIR, DEFAULT_VALIDATOR_DIR};
use environment::Environment;
use eth2_wallet::PlainText;
use eth2_wallet_manager::WalletManager;
Expand All @@ -14,7 +12,6 @@ use types::EthSpec;
use validator_dir::Builder as ValidatorDirBuilder;

pub const CMD: &str = "create";
pub const BASE_DIR_FLAG: &str = "base-dir";
pub const WALLET_NAME_FLAG: &str = "wallet-name";
pub const WALLET_PASSPHRASE_FLAG: &str = "wallet-passphrase";
pub const DEPOSIT_GWEI_FLAG: &str = "deposit-gwei";
Expand Down Expand Up @@ -114,8 +111,8 @@ pub fn cli_run<T: EthSpec>(
let name: String = clap_utils::parse_required(matches, WALLET_NAME_FLAG)?;
let wallet_password_path: PathBuf =
clap_utils::parse_required(matches, WALLET_PASSPHRASE_FLAG)?;
let validator_dir = base_validator_dir(matches, VALIDATOR_DIR_FLAG)?;
let secrets_dir = base_secrets_dir(matches, SECRETS_DIR_FLAG)?;
let validator_dir = custom_base_dir(matches, VALIDATOR_DIR_FLAG, DEFAULT_VALIDATOR_DIR)?;
let secrets_dir = custom_base_dir(matches, SECRETS_DIR_FLAG, DEFAULT_SECRET_DIR)?;
let deposit_gwei = clap_utils::parse_optional(matches, DEPOSIT_GWEI_FLAG)?
.unwrap_or_else(|| spec.max_effective_balance);
let count: Option<usize> = clap_utils::parse_optional(matches, COUNT_FLAG)?;
Expand Down
7 changes: 4 additions & 3 deletions account_manager/src/validator/deposit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{common::base_validator_dir, VALIDATOR_DIR_FLAG};
use crate::VALIDATOR_DIR_FLAG;
use clap::{App, Arg, ArgMatches};
use deposit_contract::DEPOSIT_GAS;
use directory::{custom_base_dir, DEFAULT_VALIDATOR_DIR};
use environment::Environment;
use futures::{
compat::Future01CompatExt,
Expand Down Expand Up @@ -52,7 +53,7 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
.value_name("VALIDATOR_DIRECTORY")
.help(
"The path to the validator client data directory. \
Defaults to ~/.lighthouse/validators",
Defaults to ~/.lighthouse/{tesntet}/validators",
)
.takes_value(true),
)
Expand Down Expand Up @@ -212,7 +213,7 @@ pub fn cli_run<T: EthSpec>(
) -> Result<(), String> {
let log = env.core_context().log().clone();

let data_dir = base_validator_dir(matches, VALIDATOR_DIR_FLAG)?;
let data_dir = custom_base_dir(matches, VALIDATOR_DIR_FLAG, DEFAULT_VALIDATOR_DIR)?;
let validator: String = clap_utils::parse_required(matches, VALIDATOR_FLAG)?;
let eth1_ipc_path: Option<PathBuf> = clap_utils::parse_optional(matches, ETH1_IPC_FLAG)?;
let eth1_http_url: Option<String> = clap_utils::parse_optional(matches, ETH1_HTTP_FLAG)?;
Expand Down
10 changes: 4 additions & 6 deletions account_manager/src/validator/import.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
common::{base_validator_dir, ensure_dir_exists},
VALIDATOR_DIR_FLAG,
};
use crate::VALIDATOR_DIR_FLAG;
use account_utils::{
eth2_keystore::Keystore,
read_password_from_user,
Expand All @@ -11,6 +8,7 @@ use account_utils::{
},
};
use clap::{App, Arg, ArgMatches};
use directory::{custom_base_dir, ensure_dir_exists, DEFAULT_VALIDATOR_DIR};
use std::fs;
use std::path::PathBuf;
use std::thread::sleep;
Expand Down Expand Up @@ -62,7 +60,7 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
.value_name("VALIDATOR_DIRECTORY")
.help(
"The path where the validator directories will be created. \
Defaults to ~/.lighthouse/validators",
Defaults to ~/.lighthouse/{testnet}/validators",
)
.takes_value(true),
)
Expand All @@ -76,7 +74,7 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
pub fn cli_run(matches: &ArgMatches) -> Result<(), String> {
let keystore: Option<PathBuf> = clap_utils::parse_optional(matches, KEYSTORE_FLAG)?;
let keystores_dir: Option<PathBuf> = clap_utils::parse_optional(matches, DIR_FLAG)?;
let validator_dir = base_validator_dir(matches, VALIDATOR_DIR_FLAG)?;
let validator_dir = custom_base_dir(matches, VALIDATOR_DIR_FLAG, DEFAULT_VALIDATOR_DIR)?;
let stdin_password = matches.is_present(STDIN_PASSWORD_FLAG);

ensure_dir_exists(&validator_dir)?;
Expand Down
6 changes: 3 additions & 3 deletions account_manager/src/validator/list.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::common::base_validator_dir;
use crate::VALIDATOR_DIR_FLAG;
use clap::{App, Arg, ArgMatches};
use directory::{custom_base_dir, DEFAULT_VALIDATOR_DIR};
use validator_dir::Manager as ValidatorManager;

pub const CMD: &str = "list";
Expand All @@ -13,15 +13,15 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
.value_name("VALIDATOR_DIRECTORY")
.help(
"The path to search for validator directories. \
Defaults to ~/.lighthouse/validators",
Defaults to ~/.lighthouse/{testnet}/validators",
)
.takes_value(true),
)
.about("Lists the names of all validators.")
}

pub fn cli_run(matches: &ArgMatches<'_>) -> Result<(), String> {
let data_dir = base_validator_dir(matches, VALIDATOR_DIR_FLAG)?;
let data_dir = custom_base_dir(matches, VALIDATOR_DIR_FLAG, DEFAULT_VALIDATOR_DIR)?;

let mgr = ValidatorManager::open(&data_dir)
.map_err(|e| format!("Unable to read --{}: {:?}", VALIDATOR_DIR_FLAG, e))?;
Expand Down
13 changes: 7 additions & 6 deletions account_manager/src/validator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ pub mod deposit;
pub mod import;
pub mod list;

use crate::common::base_wallet_dir;
use crate::BASE_DIR_FLAG;
use clap::{App, Arg, ArgMatches};
use directory::{custom_base_dir, DEFAULT_WALLET_DIR};
use environment::Environment;
use types::EthSpec;

Expand All @@ -14,10 +15,10 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
App::new(CMD)
.about("Provides commands for managing Eth2 validators.")
.arg(
Arg::with_name("base-dir")
.long("base-dir")
.value_name("BASE_DIRECTORY")
.help("A path containing Eth2 EIP-2386 wallets. Defaults to ~/.lighthouse/wallets")
Arg::with_name(BASE_DIR_FLAG)
.long(BASE_DIR_FLAG)
.value_name(BASE_DIR_FLAG)
.help("A path containing Eth2 EIP-2386 wallets. Defaults to ~/.lighthouse/{testnet}/wallets")
.takes_value(true),
)
.subcommand(create::cli_app())
Expand All @@ -27,7 +28,7 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
}

pub fn cli_run<T: EthSpec>(matches: &ArgMatches, env: Environment<T>) -> Result<(), String> {
let base_wallet_dir = base_wallet_dir(matches, "base-dir")?;
let base_wallet_dir = custom_base_dir(matches, BASE_DIR_FLAG, DEFAULT_WALLET_DIR)?;

match matches.subcommand() {
(create::CMD, Some(matches)) => create::cli_run::<T>(matches, env, base_wallet_dir),
Expand Down
8 changes: 3 additions & 5 deletions account_manager/src/wallet/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
pub mod create;
pub mod list;

use crate::{
common::{base_wallet_dir, ensure_dir_exists},
BASE_DIR_FLAG,
};
use crate::BASE_DIR_FLAG;
use clap::{App, Arg, ArgMatches};
use directory::{custom_base_dir, ensure_dir_exists, DEFAULT_WALLET_DIR};

pub const CMD: &str = "wallet";

Expand All @@ -24,7 +22,7 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
}

pub fn cli_run(matches: &ArgMatches) -> Result<(), String> {
let base_dir = base_wallet_dir(matches, BASE_DIR_FLAG)?;
let base_dir = custom_base_dir(matches, BASE_DIR_FLAG, DEFAULT_WALLET_DIR)?;
ensure_dir_exists(&base_dir)?;

match matches.subcommand() {
Expand Down
1 change: 1 addition & 0 deletions beacon_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tokio = { version = "0.2.21", features = ["time"] }
exit-future = "0.2.0"
dirs = "2.0.2"
logging = { path = "../common/logging" }
directory = {path = "../common/directory"}
futures = "0.3.5"
environment = { path = "../lighthouse/environment" }
genesis = { path = "genesis" }
Expand Down
1 change: 1 addition & 0 deletions beacon_node/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ lazy_static = "1.4.0"
lighthouse_metrics = { path = "../../common/lighthouse_metrics" }
time = "0.2.16"
bus = "2.2.3"
directory = {path = "../../common/directory"}
5 changes: 2 additions & 3 deletions beacon_node/client/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use directory::DEFAULT_ROOT_DIR;
use network::NetworkConfig;
use serde_derive::{Deserialize, Serialize};
use std::fs;
use std::path::PathBuf;
use types::Graffiti;

pub const DEFAULT_DATADIR: &str = ".lighthouse";

/// The number initial validators when starting the `Minimal`.
const TESTNET_SPEC_CONSTANTS: &str = "minimal";

Expand Down Expand Up @@ -71,7 +70,7 @@ pub struct Config {
impl Default for Config {
fn default() -> Self {
Self {
data_dir: PathBuf::from(DEFAULT_DATADIR),
data_dir: PathBuf::from(DEFAULT_ROOT_DIR),
db_name: "chain_db".to_string(),
freezer_db_path: None,
log_file: PathBuf::from(""),
Expand Down
16 changes: 7 additions & 9 deletions beacon_node/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use beacon_chain::builder::PUBKEY_CACHE_FILENAME;
use clap::ArgMatches;
use clap_utils::{get_testnet_dir, BAD_TESTNET_DIR_MESSAGE};
use client::{config::DEFAULT_DATADIR, ClientConfig, ClientGenesis};
use clap_utils::BAD_TESTNET_DIR_MESSAGE;
use client::{ClientConfig, ClientGenesis};
use directory::{get_testnet_dir, DEFAULT_BEACON_NODE_DIR, DEFAULT_NETWORK_DIR, DEFAULT_ROOT_DIR};
use eth2_libp2p::{multiaddr::Protocol, Enr, Multiaddr};
use eth2_testnet_config::Eth2TestnetConfig;
use slog::{crit, info, Logger};
Expand All @@ -13,9 +14,6 @@ use std::net::{TcpListener, UdpSocket};
use std::path::PathBuf;
use types::{ChainSpec, EthSpec, GRAFFITI_BYTES_LEN};

pub const BEACON_NODE_DIR: &str = "beacon";
pub const NETWORK_DIR: &str = "network";

/// Gets the fully-initialized global client.
///
/// The top-level `clap` arguments should be provided as `cli_args`.
Expand Down Expand Up @@ -79,7 +77,7 @@ pub fn get_config<E: EthSpec>(
if let Some(dir) = cli_args.value_of("network-dir") {
client_config.network.network_dir = PathBuf::from(dir);
} else {
client_config.network.network_dir = client_config.data_dir.join(NETWORK_DIR);
client_config.network.network_dir = client_config.data_dir.join(DEFAULT_NETWORK_DIR);
};

if let Some(listen_address_str) = cli_args.value_of("listen-address") {
Expand Down Expand Up @@ -398,12 +396,12 @@ pub fn get_data_dir(cli_args: &ArgMatches) -> PathBuf {

cli_args
.value_of("datadir")
.map(|path| PathBuf::from(path).join(BEACON_NODE_DIR))
.map(|path| PathBuf::from(path).join(DEFAULT_BEACON_NODE_DIR))
.or_else(|| {
dirs::home_dir().map(|home| {
home.join(DEFAULT_DATADIR)
home.join(DEFAULT_ROOT_DIR)
.join(get_testnet_dir(cli_args))
.join(BEACON_NODE_DIR)
.join(DEFAULT_BEACON_NODE_DIR)
})
})
.unwrap_or_else(|| PathBuf::from("."))
Expand Down
Loading

0 comments on commit 01e6166

Please sign in to comment.