Merge latest master in v0.2.0

This commit is contained in:
Age Manning
2020-04-08 16:46:37 +10:00
144 changed files with 2603 additions and 1308 deletions

View File

@@ -5,11 +5,13 @@ authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018"
[dependencies]
clap = "2.33.0"
tokio = "0.1.22"
slog = { version = "^2.2.3" , features = ["max_level_trace"] }
sloggers = "0.3.4"
types = { "path" = "../../eth2/types" }
eth2_config = { "path" = "../../eth2/utils/eth2_config" }
eth2_testnet_config = { path = "../../eth2/utils/eth2_testnet_config" }
env_logger = "0.6.1"
logging = { path = "../../eth2/utils/logging" }
slog-term = "^2.4.0"
@@ -18,3 +20,6 @@ ctrlc = { version = "3.1.1", features = ["termination"] }
futures = "0.1.25"
parking_lot = "0.7"
slog-json = "2.3.0"
[dev-dependencies]
beacon_node = { path = "../../beacon_node" }

View File

@@ -7,7 +7,9 @@
//! `Context` which can be handed to any service that wishes to start async tasks or perform
//! logging.
use eth2_config::Eth2Config;
use clap::ArgMatches;
use eth2_config::{read_from_file, Eth2Config};
use eth2_testnet_config::Eth2TestnetConfig;
use futures::{sync::oneshot, Future};
use slog::{info, o, Drain, Level, Logger};
use sloggers::{null::NullLoggerBuilder, Build};
@@ -19,6 +21,8 @@ use std::time::{SystemTime, UNIX_EPOCH};
use tokio::runtime::{Builder as RuntimeBuilder, Runtime, TaskExecutor};
use types::{EthSpec, InteropEthSpec, MainnetEthSpec, MinimalEthSpec};
pub const ETH2_CONFIG_FILENAME: &str = "eth2-spec.toml";
/// Builds an `Environment`.
pub struct EnvironmentBuilder<E: EthSpec> {
runtime: Option<Runtime>,
@@ -134,6 +138,73 @@ impl<E: EthSpec> EnvironmentBuilder<E> {
Ok(self)
}
/// Setups eth2 config using the CLI arguments.
pub fn setup_eth2_config(
mut self,
datadir: PathBuf,
eth2_testnet_config: Eth2TestnetConfig<E>,
cli_args: &ArgMatches,
) -> Result<Self, String> {
self.load_eth2_config(&datadir)?;
match cli_args.subcommand() {
("testnet", Some(sub_cli_args)) => {
// Modify the `SECONDS_PER_SLOT` "constant".
if let Some(slot_time) = sub_cli_args.value_of("slot-time") {
let slot_time = slot_time
.parse::<u64>()
.map_err(|e| format!("Unable to parse slot-time: {:?}", e))?;
self.eth2_config.spec.milliseconds_per_slot = slot_time;
}
}
_ => {
if !datadir.exists() {
// Create a new chain spec from the default configuration.
self.eth2_config.spec = eth2_testnet_config
.yaml_config
.as_ref()
.ok_or_else(|| {
"The testnet directory must contain a spec config".to_string()
})?
.apply_to_chain_spec::<E>(&self.eth2_config.spec)
.ok_or_else(|| {
format!(
"The loaded config is not compatible with the {} spec",
&self.eth2_config.spec_constants
)
})?;
}
}
}
Ok(self)
}
/// Loads the eth2 config if the file exists.
fn load_eth2_config(&mut self, datadir: &PathBuf) -> Result<(), String> {
let filename = datadir.join(ETH2_CONFIG_FILENAME);
if filename.exists() {
let loaded_eth2_config: Eth2Config = read_from_file(filename.clone())
.map_err(|e| format!("Unable to parse {:?} file: {:?}", filename, e))?
.ok_or_else(|| format!("{:?} file does not exist", filename))?;
// The loaded spec must be using the same spec constants (e.g., minimal, mainnet) as the
// client expects.
if loaded_eth2_config.spec_constants == self.eth2_config.spec_constants {
self.eth2_config = loaded_eth2_config;
} else {
return Err(format!(
"Eth2 config loaded from disk does not match client spec version. Got {} \
expected {}",
&loaded_eth2_config.spec_constants, &self.eth2_config.spec_constants
));
}
}
Ok(())
}
/// Consumes the builder, returning an `Environment`.
pub fn build(self) -> Result<Environment<E>, String> {
Ok(Environment {

View File

@@ -0,0 +1,93 @@
/*
*
* TODO: disabled until hardcoded testnet config is updated for v0.11
*
*
#![cfg(test)]
use clap::ArgMatches;
use environment::EnvironmentBuilder;
use eth2_testnet_config::Eth2TestnetConfig;
use std::path::PathBuf;
use types::{Epoch, MainnetEthSpec, YamlConfig};
fn builder() -> EnvironmentBuilder<MainnetEthSpec> {
EnvironmentBuilder::mainnet()
.single_thread_tokio_runtime()
.expect("should set runtime")
.null_logger()
.expect("should set logger")
}
fn dummy_data_dir() -> PathBuf {
PathBuf::from("./tests/datadir_that_does_not_exist")
}
fn eth2_testnet_config() -> Eth2TestnetConfig<MainnetEthSpec> {
Eth2TestnetConfig::hard_coded().expect("should decode hard_coded params")
}
mod setup_eth2_config {
use super::*;
#[test]
fn returns_err_if_the_loaded_config_doesnt_match() {
// `Minimal` spec
let path_to_minimal_spec = PathBuf::from("./tests/minimal_spec");
// `Mainnet` spec
let builder = builder();
let result = builder.setup_eth2_config(
path_to_minimal_spec,
eth2_testnet_config(),
&ArgMatches::default(),
);
assert!(result.is_err());
assert_eq!(
result.err().unwrap(),
"Eth2 config loaded from disk does not match client spec version. Got minimal expected mainnet"
);
}
#[test]
fn update_slot_time() {
// testnet
let cli_args =
beacon_node::cli_app().get_matches_from(vec!["app", "testnet", "--slot-time", "999"]);
let environment = builder()
.setup_eth2_config(dummy_data_dir(), eth2_testnet_config(), &cli_args)
.expect("should setup eth2_config")
.build()
.expect("should build environment");
assert_eq!(environment.eth2_config.spec.milliseconds_per_slot, 999);
}
#[test]
fn update_spec_with_yaml_config() {
let config_yaml = PathBuf::from("./tests/testnet_dir/config.yaml");
let mut eth2_testnet_config = eth2_testnet_config();
eth2_testnet_config.yaml_config =
Some(YamlConfig::from_file(config_yaml.as_path()).expect("should load yaml config"));
let environment = builder()
.setup_eth2_config(
dummy_data_dir(),
eth2_testnet_config,
&ArgMatches::default(),
)
.expect("should setup eth2_config")
.build()
.expect("should build environment");
assert_eq!(
environment.eth2_config.spec.far_future_epoch,
Epoch::new(999) // see testnet_dir/config.yaml
);
}
}
*/

View File

@@ -0,0 +1,42 @@
spec_constants = "minimal" # for testing
[spec]
genesis_slot = 0
base_rewards_per_epoch = 4
deposit_contract_tree_depth = 32
max_committees_per_slot = 64
target_committee_size = 128
min_per_epoch_churn_limit = 4
churn_limit_quotient = 65536
shuffle_round_count = 90
min_genesis_active_validator_count = 16384
min_genesis_time = 1578009600
min_deposit_amount = 1000000000
max_effective_balance = 32000000000
ejection_balance = 16000000000
effective_balance_increment = 1000000000
genesis_fork_version = "0x00000000"
bls_withdrawal_prefix_byte = "0x00"
min_genesis_delay = 86400
milliseconds_per_slot = 12000
min_attestation_inclusion_delay = 1
min_seed_lookahead = 1
max_seed_lookahead = 4
min_epochs_to_inactivity_penalty = 4
min_validator_withdrawability_delay = 256
persistent_committee_period = 2048
base_reward_factor = 64
whistleblower_reward_quotient = 512
proposer_reward_quotient = 8
inactivity_penalty_quotient = 33554432
min_slashing_penalty_quotient = 32
domain_beacon_proposer = 0
domain_beacon_attester = 1
domain_randao = 2
domain_deposit = 3
domain_voluntary_exit = 4
safe_slots_to_update_justified = 8
eth1_follow_distance = 1024
seconds_per_eth1_block = 14
boot_nodes = []
network_id = 1

View File

@@ -0,0 +1,56 @@
FAR_FUTURE_EPOCH: 999 # for testing
BASE_REWARDS_PER_EPOCH: 4
DEPOSIT_CONTRACT_TREE_DEPTH: 32
MAX_COMMITTEES_PER_SLOT: 64
TARGET_COMMITTEE_SIZE: 128
MIN_PER_EPOCH_CHURN_LIMIT: 4
CHURN_LIMIT_QUOTIENT: 65536
SHUFFLE_ROUND_COUNT: 90
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT: 4096
MIN_GENESIS_TIME: 0
MIN_GENESIS_DELAY: 3600
MIN_DEPOSIT_AMOUNT: 10000000
MAX_EFFECTIVE_BALANCE: 3200000000
EJECTION_BALANCE: 1600000000
EFFECTIVE_BALANCE_INCREMENT: 100000000
GENESIS_SLOT: 0
GENESIS_FORK_VERSION: 0x01030307
BLS_WITHDRAWAL_PREFIX: 0x00
SECONDS_PER_SLOT: 12
MIN_ATTESTATION_INCLUSION_DELAY: 1
MIN_SEED_LOOKAHEAD: 1
MAX_SEED_LOOKAHEAD: 4
MIN_EPOCHS_TO_INACTIVITY_PENALTY: 4
MIN_VALIDATOR_WITHDRAWABILITY_DELAY: 256
PERSISTENT_COMMITTEE_PERIOD: 2048
BASE_REWARD_FACTOR: 64
WHISTLEBLOWER_REWARD_QUOTIENT: 512
PROPOSER_REWARD_QUOTIENT: 8
INACTIVITY_PENALTY_QUOTIENT: 33554432
MIN_SLASHING_PENALTY_QUOTIENT: 32
SAFE_SLOTS_TO_UPDATE_JUSTIFIED: 8
DOMAIN_BEACON_PROPOSER: 0x00000000
DOMAIN_BEACON_ATTESTER: 0x01000000
DOMAIN_RANDAO: 0x02000000
DOMAIN_DEPOSIT: 0x03000000
DOMAIN_VOLUNTARY_EXIT: 0x04000000
JUSTIFICATION_BITS_LENGTH: 0x04000000
MAX_VALIDATORS_PER_COMMITTEE: 2048
GENESIS_EPOCH: 0
SLOTS_PER_EPOCH: 32
SLOTS_PER_ETH1_VOTING_PERIOD: 1024
SLOTS_PER_HISTORICAL_ROOT: 8192
EPOCHS_PER_HISTORICAL_VECTOR: 65536
EPOCHS_PER_SLASHINGS_VECTOR: 8192
HISTORICAL_ROOTS_LIMIT: 16777216
VALIDATOR_REGISTRY_LIMIT: 1099511627776
MAX_PROPOSER_SLASHINGS: 16
MAX_ATTESTER_SLASHINGS: 1
MAX_ATTESTATIONS: 128
MAX_DEPOSITS: 16
MAX_VOLUNTARY_EXITS: 16
ETH1_FOLLOW_DISTANCE: 16
TARGET_AGGREGATORS_PER_COMMITTEE: 0
RANDOM_SUBNETS_PER_VALIDATOR: 0
EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION: 0
SECONDS_PER_ETH1_BLOCK: 14

View File

@@ -1,7 +1,7 @@
#[macro_use]
extern crate clap;
use beacon_node::ProductionBeaconNode;
use beacon_node::{get_data_dir, get_eth2_testnet_config, get_testnet_dir, ProductionBeaconNode};
use clap::{App, Arg, ArgMatches};
use env_logger::{Builder, Env};
use environment::EnvironmentBuilder;
@@ -114,6 +114,11 @@ fn run<E: EthSpec>(
let mut environment = environment_builder
.async_logger(debug_level, log_format)?
.multi_threaded_tokio_runtime()?
.setup_eth2_config(
get_data_dir(matches),
get_eth2_testnet_config(&get_testnet_dir(matches))?,
matches,
)?
.build()?;
let log = environment.core_context().log;