mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 18:32:42 +00:00
Add eth2_config crate, integrate into val client
This commit is contained in:
@@ -8,7 +8,7 @@ use std::path::PathBuf;
|
||||
/// The core configuration of a Lighthouse beacon node.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ClientConfig {
|
||||
pub data_dir: String,
|
||||
pub data_dir: PathBuf,
|
||||
pub db_type: String,
|
||||
db_name: String,
|
||||
pub network: network::NetworkConfig,
|
||||
@@ -19,7 +19,7 @@ pub struct ClientConfig {
|
||||
impl Default for ClientConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
data_dir: ".lighthouse".to_string(),
|
||||
data_dir: PathBuf::from(".lighthouse"),
|
||||
db_type: "disk".to_string(),
|
||||
db_name: "chain_db".to_string(),
|
||||
// Note: there are no default bootnodes specified.
|
||||
@@ -51,7 +51,7 @@ impl ClientConfig {
|
||||
/// invalid.
|
||||
pub fn apply_cli_args(&mut self, args: &ArgMatches) -> Result<(), &'static str> {
|
||||
if let Some(dir) = args.value_of("datadir") {
|
||||
self.data_dir = dir.to_string();
|
||||
self.data_dir = PathBuf::from(dir);
|
||||
};
|
||||
|
||||
if let Some(dir) = args.value_of("db") {
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
use clap::ArgMatches;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::time::SystemTime;
|
||||
use types::ChainSpec;
|
||||
|
||||
/// The core configuration of a Lighthouse beacon node.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct Eth2Config {
|
||||
pub spec_constants: String,
|
||||
pub spec: ChainSpec,
|
||||
}
|
||||
|
||||
impl Default for Eth2Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
spec_constants: "minimal".to_string(),
|
||||
spec: ChainSpec::minimal(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Eth2Config {
|
||||
pub fn mainnet() -> Self {
|
||||
Self {
|
||||
spec_constants: "mainnet".to_string(),
|
||||
spec: ChainSpec::mainnet(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn minimal() -> Self {
|
||||
Self {
|
||||
spec_constants: "minimal".to_string(),
|
||||
spec: ChainSpec::minimal(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Eth2Config {
|
||||
/// Apply the following arguments to `self`, replacing values if they are specified in `args`.
|
||||
///
|
||||
/// Returns an error if arguments are obviously invalid. May succeed even if some values are
|
||||
/// invalid.
|
||||
pub fn apply_cli_args(&mut self, args: &ArgMatches) -> Result<(), &'static str> {
|
||||
if args.is_present("recent_genesis") {
|
||||
self.spec.genesis_time = recent_genesis_time()
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the system time, mod 30 minutes.
|
||||
///
|
||||
/// Used for easily creating testnets.
|
||||
fn recent_genesis_time() -> u64 {
|
||||
let now = SystemTime::now()
|
||||
.duration_since(SystemTime::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs();
|
||||
let secs_after_last_period = now.checked_rem(30 * 60).unwrap_or(0);
|
||||
// genesis is now the last 30 minute block.
|
||||
now - secs_after_last_period
|
||||
}
|
||||
@@ -3,7 +3,6 @@ extern crate slog;
|
||||
mod beacon_chain_types;
|
||||
mod client_config;
|
||||
pub mod error;
|
||||
mod eth2_config;
|
||||
pub mod notifier;
|
||||
|
||||
use beacon_chain::BeaconChain;
|
||||
|
||||
Reference in New Issue
Block a user