From 749f2fcb5fed6150bd7b3ef4066e0e9cda4f79da Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Sat, 8 Jun 2019 08:49:04 -0400 Subject: [PATCH] Unify EthSpecs in `Mainnet` and `Minimal` --- beacon_node/beacon_chain/src/iter.rs | 10 ++--- beacon_node/client/src/beacon_chain_types.rs | 8 ++-- beacon_node/client/src/client_config.rs | 2 +- beacon_node/eth2-libp2p/src/behaviour.rs | 2 +- beacon_node/store/src/block_at_slot.rs | 8 ++-- eth2/fork_choice/benches/benches.rs | 4 +- eth2/fork_choice/examples/example.rs | 8 ++-- eth2/fork_choice/src/test_utils.rs | 9 ++--- eth2/fork_choice/tests/tests.rs | 14 +++---- eth2/operation_pool/src/lib.rs | 18 ++++----- .../benches/bench_epoch_processing.rs | 2 +- eth2/state_processing/benches/benches.rs | 4 +- .../src/per_block_processing/tests.rs | 16 ++++---- .../src/per_epoch_processing/tests.rs | 8 ++-- .../src/beacon_state/beacon_state_types.rs | 36 ++++------------- .../src/beacon_state/committee_cache/tests.rs | 30 +++++++------- eth2/types/src/beacon_state/tests.rs | 26 ++++++------ eth2/types/src/chain_spec.rs | 40 ++++++++----------- eth2/types/src/fork.rs | 2 +- eth2/types/src/historical_batch.rs | 2 +- tests/ef_tests/src/doc.rs | 2 +- tests/ef_tests/src/eth_specs.rs | 32 --------------- tests/ef_tests/src/lib.rs | 1 - validator_client/src/block_producer/mod.rs | 2 +- validator_client/src/config.rs | 13 +++--- validator_client/src/duties/mod.rs | 2 +- validator_client/src/main.rs | 4 +- 27 files changed, 119 insertions(+), 186 deletions(-) delete mode 100644 tests/ef_tests/src/eth_specs.rs diff --git a/beacon_node/beacon_chain/src/iter.rs b/beacon_node/beacon_chain/src/iter.rs index 48caaf618..b54dd1d2a 100644 --- a/beacon_node/beacon_chain/src/iter.rs +++ b/beacon_node/beacon_chain/src/iter.rs @@ -82,7 +82,7 @@ impl Iterator for BlockRootsIterator { mod test { use super::*; use store::MemoryStore; - use types::{test_utils::TestingBeaconStateBuilder, FoundationEthSpec, Keypair}; + use types::{test_utils::TestingBeaconStateBuilder, Keypair, MainnetEthSpec}; fn get_state() -> BeaconState { let builder = TestingBeaconStateBuilder::from_single_keypair( @@ -97,10 +97,10 @@ mod test { #[test] fn root_iter() { let store = Arc::new(MemoryStore::open()); - let slots_per_historical_root = FoundationEthSpec::slots_per_historical_root(); + let slots_per_historical_root = MainnetEthSpec::slots_per_historical_root(); - let mut state_a: BeaconState = get_state(); - let mut state_b: BeaconState = get_state(); + let mut state_a: BeaconState = get_state(); + let mut state_b: BeaconState = get_state(); state_a.slot = Slot::from(slots_per_historical_root); state_b.slot = Slot::from(slots_per_historical_root * 2); @@ -122,7 +122,7 @@ mod test { let mut collected: Vec = iter.collect(); collected.reverse(); - let expected_len = 2 * FoundationEthSpec::slots_per_historical_root() - 1; + let expected_len = 2 * MainnetEthSpec::slots_per_historical_root() - 1; assert_eq!(collected.len(), expected_len); diff --git a/beacon_node/client/src/beacon_chain_types.rs b/beacon_node/client/src/beacon_chain_types.rs index 9747b1dd8..133ebcc94 100644 --- a/beacon_node/client/src/beacon_chain_types.rs +++ b/beacon_node/client/src/beacon_chain_types.rs @@ -11,10 +11,10 @@ use std::sync::Arc; use tree_hash::TreeHash; use types::{ test_utils::TestingBeaconStateBuilder, BeaconBlock, ChainSpec, EthSpec, Hash256, - LighthouseTestnetEthSpec, + MinimalEthSpec, }; -/// The number initial validators when starting the `LighthouseTestnet`. +/// The number initial validators when starting the `Minimal`. const TESTNET_VALIDATOR_COUNT: usize = 16; /// Provides a new, initialized `BeaconChain` @@ -35,7 +35,7 @@ impl BeaconChainTypes for TestnetMemoryBeaconChainTypes { type Store = MemoryStore; type SlotClock = SystemTimeSlotClock; type ForkChoice = OptimizedLMDGhost; - type EthSpec = LighthouseTestnetEthSpec; + type EthSpec = MinimalEthSpec; } impl InitialiseBeaconChain for TestnetMemoryBeaconChainTypes {} @@ -46,7 +46,7 @@ impl BeaconChainTypes for TestnetDiskBeaconChainTypes { type Store = DiskStore; type SlotClock = SystemTimeSlotClock; type ForkChoice = OptimizedLMDGhost; - type EthSpec = LighthouseTestnetEthSpec; + type EthSpec = MinimalEthSpec; } impl InitialiseBeaconChain for TestnetDiskBeaconChainTypes {} diff --git a/beacon_node/client/src/client_config.rs b/beacon_node/client/src/client_config.rs index 6c42f1ea6..1f875f02d 100644 --- a/beacon_node/client/src/client_config.rs +++ b/beacon_node/client/src/client_config.rs @@ -31,7 +31,7 @@ impl Default for ClientConfig { network: NetworkConfig::new(vec![]), rpc: rpc::RPCConfig::default(), http: HttpServerConfig::default(), - spec: ChainSpec::lighthouse_testnet(), + spec: ChainSpec::minimal(), } } } diff --git a/beacon_node/eth2-libp2p/src/behaviour.rs b/beacon_node/eth2-libp2p/src/behaviour.rs index 476cddfbb..10b140c3b 100644 --- a/beacon_node/eth2-libp2p/src/behaviour.rs +++ b/beacon_node/eth2-libp2p/src/behaviour.rs @@ -261,7 +261,7 @@ mod test { #[test] fn ssz_encoding() { - let original = PubsubMessage::Block(BeaconBlock::empty(&FoundationEthSpec::default_spec())); + let original = PubsubMessage::Block(BeaconBlock::empty(&MainnetEthSpec::default_spec())); let encoded = ssz_encode(&original); diff --git a/beacon_node/store/src/block_at_slot.rs b/beacon_node/store/src/block_at_slot.rs index b7346e90d..5a0dd6861 100644 --- a/beacon_node/store/src/block_at_slot.rs +++ b/beacon_node/store/src/block_at_slot.rs @@ -61,7 +61,7 @@ mod tests { #[test] fn read_slot() { - let spec = FewValidatorsEthSpec::default_spec(); + let spec = MinimalEthSpec::default_spec(); let test_slot = |slot: Slot| { let mut block = BeaconBlock::empty(&spec); @@ -85,7 +85,7 @@ mod tests { #[test] fn read_previous_block_root() { - let spec = FewValidatorsEthSpec::default_spec(); + let spec = MinimalEthSpec::default_spec(); let test_root = |root: Hash256| { let mut block = BeaconBlock::empty(&spec); @@ -130,7 +130,7 @@ mod tests { fn chain_without_skips() { let n: usize = 10; let store = MemoryStore::open(); - let spec = FewValidatorsEthSpec::default_spec(); + let spec = MinimalEthSpec::default_spec(); let slots: Vec = (0..n).collect(); let blocks_and_roots = build_chain(&store, &slots, &spec); @@ -154,7 +154,7 @@ mod tests { #[test] fn chain_with_skips() { let store = MemoryStore::open(); - let spec = FewValidatorsEthSpec::default_spec(); + let spec = MinimalEthSpec::default_spec(); let slots = vec![0, 1, 2, 5]; diff --git a/eth2/fork_choice/benches/benches.rs b/eth2/fork_choice/benches/benches.rs index b0495a80c..f311e1ccb 100644 --- a/eth2/fork_choice/benches/benches.rs +++ b/eth2/fork_choice/benches/benches.rs @@ -3,10 +3,10 @@ use criterion::{criterion_group, criterion_main, Benchmark}; use fork_choice::{test_utils::TestingForkChoiceBuilder, ForkChoice, OptimizedLMDGhost}; use std::sync::Arc; use store::MemoryStore; -use types::{ChainSpec, EthSpec, FoundationEthSpec}; +use types::{ChainSpec, EthSpec, MainnetEthSpec}; pub type TestedForkChoice = OptimizedLMDGhost; -pub type TestedEthSpec = FoundationEthSpec; +pub type TestedEthSpec = MainnetEthSpec; /// Helper function to setup a builder and spec. fn setup( diff --git a/eth2/fork_choice/examples/example.rs b/eth2/fork_choice/examples/example.rs index 7e42ad144..a912c3753 100644 --- a/eth2/fork_choice/examples/example.rs +++ b/eth2/fork_choice/examples/example.rs @@ -1,7 +1,7 @@ use fork_choice::{test_utils::TestingForkChoiceBuilder, ForkChoice, OptimizedLMDGhost}; use std::sync::Arc; use store::{MemoryStore, Store}; -use types::{BeaconBlock, ChainSpec, EthSpec, FoundationEthSpec, Hash256}; +use types::{BeaconBlock, ChainSpec, EthSpec, Hash256, MainnetEthSpec}; fn main() { let validator_count = 16; @@ -9,15 +9,15 @@ fn main() { let repetitions = 50; let store = MemoryStore::open(); - let builder: TestingForkChoiceBuilder = + let builder: TestingForkChoiceBuilder = TestingForkChoiceBuilder::new(validator_count, chain_length, Arc::new(store)); - let fork_choosers: Vec> = (0..repetitions) + let fork_choosers: Vec> = (0..repetitions) .into_iter() .map(|_| builder.build()) .collect(); - let spec = &FoundationEthSpec::default_spec(); + let spec = &MainnetEthSpec::default_spec(); println!("Running {} times...", repetitions); for fc in fork_choosers { diff --git a/eth2/fork_choice/src/test_utils.rs b/eth2/fork_choice/src/test_utils.rs index c3bf39930..840d7a76b 100644 --- a/eth2/fork_choice/src/test_utils.rs +++ b/eth2/fork_choice/src/test_utils.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use store::Store; use types::{ test_utils::{SeedableRng, TestRandom, TestingBeaconStateBuilder, XorShiftRng}, - BeaconBlock, BeaconState, EthSpec, FoundationEthSpec, Hash256, Keypair, + BeaconBlock, BeaconState, EthSpec, Hash256, Keypair, MainnetEthSpec, }; /// Creates a chain of blocks and produces `ForkChoice` instances with pre-filled stores. @@ -16,11 +16,8 @@ pub struct TestingForkChoiceBuilder { impl TestingForkChoiceBuilder { pub fn new(validator_count: usize, chain_length: usize, store: Arc) -> Self { - let chain = get_chain_of_blocks::( - chain_length, - validator_count, - store.clone(), - ); + let chain = + get_chain_of_blocks::(chain_length, validator_count, store.clone()); Self { store, diff --git a/eth2/fork_choice/tests/tests.rs b/eth2/fork_choice/tests/tests.rs index 59e4e0ee0..39e70a7dd 100644 --- a/eth2/fork_choice/tests/tests.rs +++ b/eth2/fork_choice/tests/tests.rs @@ -11,7 +11,7 @@ use std::sync::Arc; use std::{fs::File, io::prelude::*, path::PathBuf}; use types::test_utils::TestingBeaconStateBuilder; use types::{ - BeaconBlock, BeaconBlockBody, Eth1Data, EthSpec, FoundationEthSpec, Hash256, Keypair, Slot, + BeaconBlock, BeaconBlockBody, Eth1Data, EthSpec, Hash256, Keypair, MainnetEthSpec, Slot, }; use yaml_rust::yaml; @@ -22,7 +22,7 @@ fn test_optimized_lmd_ghost() { // set up logging // Builder::from_env(Env::default().default_filter_or("trace")).init(); - test_yaml_vectors::>( + test_yaml_vectors::>( "tests/lmd_ghost_test_vectors.yaml", 100, ); @@ -33,7 +33,7 @@ fn test_bitwise_lmd_ghost() { // set up logging //Builder::from_env(Env::default().default_filter_or("trace")).init(); - test_yaml_vectors::>( + test_yaml_vectors::>( "tests/bitwise_lmd_ghost_test_vectors.yaml", 100, ); @@ -41,7 +41,7 @@ fn test_bitwise_lmd_ghost() { #[test] fn test_slow_lmd_ghost() { - test_yaml_vectors::>( + test_yaml_vectors::>( "tests/lmd_ghost_test_vectors.yaml", 100, ); @@ -61,7 +61,7 @@ fn test_yaml_vectors>( let test_cases = load_test_cases_from_yaml(yaml_file_path); // default vars - let spec = FoundationEthSpec::default_spec(); + let spec = MainnetEthSpec::default_spec(); let zero_hash = Hash256::zero(); let eth1_data = Eth1Data { deposit_count: 0, @@ -204,9 +204,9 @@ where let store = Arc::new(MemoryStore::open()); let fork_choice = ForkChoice::new(store.clone()); - let spec = FoundationEthSpec::default_spec(); + let spec = MainnetEthSpec::default_spec(); - let mut state_builder: TestingBeaconStateBuilder = + let mut state_builder: TestingBeaconStateBuilder = TestingBeaconStateBuilder::from_single_keypair(num_validators, &Keypair::random(), &spec); state_builder.build_caches(&spec).unwrap(); let (state, _keypairs) = state_builder.build(); diff --git a/eth2/operation_pool/src/lib.rs b/eth2/operation_pool/src/lib.rs index ae8a6ae11..0afd72918 100644 --- a/eth2/operation_pool/src/lib.rs +++ b/eth2/operation_pool/src/lib.rs @@ -675,12 +675,12 @@ mod tests { .collect() } - fn test_state(rng: &mut XorShiftRng) -> (ChainSpec, BeaconState) { - let spec = FoundationEthSpec::default_spec(); + fn test_state(rng: &mut XorShiftRng) -> (ChainSpec, BeaconState) { + let spec = MainnetEthSpec::default_spec(); let mut state = BeaconState::random_for_test(rng); - state.fork = Fork::genesis(FoundationEthSpec::genesis_epoch()); + state.fork = Fork::genesis(MainnetEthSpec::genesis_epoch()); (spec, state) } @@ -735,13 +735,13 @@ mod tests { state_builder.build_caches(&spec).unwrap(); let (state, keypairs) = state_builder.build(); - (state, keypairs, FoundationEthSpec::default_spec()) + (state, keypairs, MainnetEthSpec::default_spec()) } #[test] fn test_attestation_score() { let (ref mut state, ref keypairs, ref spec) = - attestation_test_state::(1); + attestation_test_state::(1); let slot = state.slot - 1; let committees = state @@ -793,7 +793,7 @@ mod tests { #[test] fn attestation_aggregation_insert_get_prune() { let (ref mut state, ref keypairs, ref spec) = - attestation_test_state::(1); + attestation_test_state::(1); let op_pool = OperationPool::new(); @@ -861,7 +861,7 @@ mod tests { #[test] fn attestation_duplicate() { let (ref mut state, ref keypairs, ref spec) = - attestation_test_state::(1); + attestation_test_state::(1); let op_pool = OperationPool::new(); @@ -898,7 +898,7 @@ mod tests { #[test] fn attestation_pairwise_overlapping() { let (ref mut state, ref keypairs, ref spec) = - attestation_test_state::(1); + attestation_test_state::(1); let op_pool = OperationPool::new(); @@ -946,7 +946,7 @@ mod tests { let big_step_size = 4; let (ref mut state, ref keypairs, ref spec) = - attestation_test_state::(big_step_size); + attestation_test_state::(big_step_size); let op_pool = OperationPool::new(); diff --git a/eth2/state_processing/benches/bench_epoch_processing.rs b/eth2/state_processing/benches/bench_epoch_processing.rs index 665aabbff..e89305ce4 100644 --- a/eth2/state_processing/benches/bench_epoch_processing.rs +++ b/eth2/state_processing/benches/bench_epoch_processing.rs @@ -17,7 +17,7 @@ pub const SMALL_BENCHING_SAMPLE_SIZE: usize = 10; /// Run the benchmarking suite on a foundation spec with 16,384 validators. pub fn bench_epoch_processing_n_validators(c: &mut Criterion, validator_count: usize) { - let spec = ChainSpec::foundation(); + let spec = ChainSpec::mainnet(); let mut builder = TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(validator_count, &spec); diff --git a/eth2/state_processing/benches/benches.rs b/eth2/state_processing/benches/benches.rs index 656ad9e4e..3d884c3d8 100644 --- a/eth2/state_processing/benches/benches.rs +++ b/eth2/state_processing/benches/benches.rs @@ -25,7 +25,7 @@ pub fn block_processing_worst_case(c: &mut Criterion) { ); // Use the specifications from the Eth2.0 spec. - let spec = ChainSpec::foundation(); + let spec = ChainSpec::mainnet(); // Create a builder for configuring the block and state for benching. let mut bench_builder = BlockBenchingBuilder::new(VALIDATOR_COUNT, &spec); @@ -59,7 +59,7 @@ pub fn block_processing_reasonable_case(c: &mut Criterion) { ); // Use the specifications from the Eth2.0 spec. - let spec = ChainSpec::foundation(); + let spec = ChainSpec::mainnet(); // Create a builder for configuring the block and state for benching. let mut bench_builder = BlockBenchingBuilder::new(VALIDATOR_COUNT, &spec); diff --git a/eth2/state_processing/src/per_block_processing/tests.rs b/eth2/state_processing/src/per_block_processing/tests.rs index c2a9840aa..525637fea 100644 --- a/eth2/state_processing/src/per_block_processing/tests.rs +++ b/eth2/state_processing/src/per_block_processing/tests.rs @@ -9,7 +9,7 @@ pub const VALIDATOR_COUNT: usize = 10; #[test] fn valid_block_ok() { - let spec = FoundationEthSpec::default_spec(); + let spec = MainnetEthSpec::default_spec(); let builder = get_builder(&spec); let (block, mut state) = builder.build(None, None, &spec); @@ -20,7 +20,7 @@ fn valid_block_ok() { #[test] fn invalid_block_header_state_slot() { - let spec = FoundationEthSpec::default_spec(); + let spec = MainnetEthSpec::default_spec(); let builder = get_builder(&spec); let (mut block, mut state) = builder.build(None, None, &spec); @@ -39,7 +39,7 @@ fn invalid_block_header_state_slot() { #[test] fn invalid_parent_block_root() { - let spec = FoundationEthSpec::default_spec(); + let spec = MainnetEthSpec::default_spec(); let builder = get_builder(&spec); let invalid_parent_root = Hash256::from([0xAA; 32]); let (block, mut state) = builder.build(None, Some(invalid_parent_root), &spec); @@ -59,14 +59,14 @@ fn invalid_parent_block_root() { #[test] fn invalid_block_signature() { - let spec = FoundationEthSpec::default_spec(); + let spec = MainnetEthSpec::default_spec(); let builder = get_builder(&spec); let (mut block, mut state) = builder.build(None, None, &spec); // sign the block with a keypair that is not the expected proposer let keypair = Keypair::random(); let message = block.signed_root(); - let epoch = block.slot.epoch(FoundationEthSpec::slots_per_epoch()); + let epoch = block.slot.epoch(MainnetEthSpec::slots_per_epoch()); let domain = spec.get_domain(epoch, Domain::BeaconProposer, &state.fork); block.signature = Signature::new(&message, domain, &keypair.sk); @@ -82,7 +82,7 @@ fn invalid_block_signature() { #[test] fn invalid_randao_reveal_signature() { - let spec = FoundationEthSpec::default_spec(); + let spec = MainnetEthSpec::default_spec(); let builder = get_builder(&spec); // sign randao reveal with random keypair @@ -100,12 +100,12 @@ fn invalid_randao_reveal_signature() { ); } -fn get_builder(spec: &ChainSpec) -> (BlockProcessingBuilder) { +fn get_builder(spec: &ChainSpec) -> (BlockProcessingBuilder) { let mut builder = BlockProcessingBuilder::new(VALIDATOR_COUNT, &spec); // Set the state and block to be in the last slot of the 4th epoch. let last_slot_of_epoch = - (FoundationEthSpec::genesis_epoch() + 4).end_slot(FoundationEthSpec::slots_per_epoch()); + (MainnetEthSpec::genesis_epoch() + 4).end_slot(MainnetEthSpec::slots_per_epoch()); builder.set_slot(last_slot_of_epoch, &spec); builder.build_caches(&spec); diff --git a/eth2/state_processing/src/per_epoch_processing/tests.rs b/eth2/state_processing/src/per_epoch_processing/tests.rs index dffe2b593..306acb7ee 100644 --- a/eth2/state_processing/src/per_epoch_processing/tests.rs +++ b/eth2/state_processing/src/per_epoch_processing/tests.rs @@ -8,13 +8,13 @@ use types::*; fn runs_without_error() { Builder::from_env(Env::default().default_filter_or("error")).init(); - let spec = FewValidatorsEthSpec::default_spec(); + let spec = MinimalEthSpec::default_spec(); - let mut builder: TestingBeaconStateBuilder = + let mut builder: TestingBeaconStateBuilder = TestingBeaconStateBuilder::from_deterministic_keypairs(8, &spec); - let target_slot = (FewValidatorsEthSpec::genesis_epoch() + 4) - .end_slot(FewValidatorsEthSpec::slots_per_epoch()); + let target_slot = + (MinimalEthSpec::genesis_epoch() + 4).end_slot(MinimalEthSpec::slots_per_epoch()); builder.teleport_to_slot(target_slot, &spec); let (mut state, _keypairs) = builder.build(); diff --git a/eth2/types/src/beacon_state/beacon_state_types.rs b/eth2/types/src/beacon_state/beacon_state_types.rs index 6d0dd4768..d69350f9d 100644 --- a/eth2/types/src/beacon_state/beacon_state_types.rs +++ b/eth2/types/src/beacon_state/beacon_state_types.rs @@ -95,9 +95,9 @@ pub trait EthSpec: 'static + Default + Sync + Send + Clone + Debug + PartialEq { /// /// Spec v0.6.1 #[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)] -pub struct FoundationEthSpec; +pub struct MainnetEthSpec; -impl EthSpec for FoundationEthSpec { +impl EthSpec for MainnetEthSpec { type ShardCount = U1024; type SlotsPerHistoricalRoot = U8192; type LatestRandaoMixesLength = U8192; @@ -107,17 +107,17 @@ impl EthSpec for FoundationEthSpec { type GenesisEpoch = U0; fn default_spec() -> ChainSpec { - ChainSpec::foundation() + ChainSpec::mainnet() } } -pub type FoundationBeaconState = BeaconState; +pub type FoundationBeaconState = BeaconState; /// Ethereum Foundation specifications, modified to be suitable for < 1000 validators. #[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)] -pub struct FewValidatorsEthSpec; +pub struct MinimalEthSpec; -impl EthSpec for FewValidatorsEthSpec { +impl EthSpec for MinimalEthSpec { type ShardCount = U8; type SlotsPerHistoricalRoot = U8192; type LatestRandaoMixesLength = U8192; @@ -127,28 +127,8 @@ impl EthSpec for FewValidatorsEthSpec { type GenesisEpoch = U0; fn default_spec() -> ChainSpec { - ChainSpec::few_validators() + ChainSpec::minimal() } } -pub type FewValidatorsBeaconState = BeaconState; - -/// Specifications suitable for a small-scale (< 1000 validators) lighthouse testnet. -#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)] -pub struct LighthouseTestnetEthSpec; - -impl EthSpec for LighthouseTestnetEthSpec { - type ShardCount = U8; - type SlotsPerHistoricalRoot = U8192; - type LatestRandaoMixesLength = U8192; - type LatestActiveIndexRootsLength = U8192; - type LatestSlashedExitLength = U8192; - type SlotsPerEpoch = U8; - type GenesisEpoch = U0; - - fn default_spec() -> ChainSpec { - ChainSpec::lighthouse_testnet() - } -} - -pub type LighthouseTestnetBeaconState = BeaconState; +pub type MinimalBeaconState = BeaconState; diff --git a/eth2/types/src/beacon_state/committee_cache/tests.rs b/eth2/types/src/beacon_state/committee_cache/tests.rs index 8f1fbe187..d30d0724d 100644 --- a/eth2/types/src/beacon_state/committee_cache/tests.rs +++ b/eth2/types/src/beacon_state/committee_cache/tests.rs @@ -34,8 +34,8 @@ fn new_state(validator_count: usize, slot: Slot) -> BeaconState { #[test] fn fails_without_validators() { - let state = new_state::(0, Slot::new(0)); - let spec = &FewValidatorsEthSpec::default_spec(); + let state = new_state::(0, Slot::new(0)); + let spec = &MinimalEthSpec::default_spec(); assert_eq!( CommitteeCache::initialized(&state, state.current_epoch(), &spec), @@ -45,8 +45,8 @@ fn fails_without_validators() { #[test] fn initializes_with_the_right_epoch() { - let state = new_state::(16, Slot::new(0)); - let spec = &FewValidatorsEthSpec::default_spec(); + let state = new_state::(16, Slot::new(0)); + let spec = &MinimalEthSpec::default_spec(); let cache = CommitteeCache::default(); assert_eq!(cache.initialized_epoch, None); @@ -63,14 +63,14 @@ fn initializes_with_the_right_epoch() { #[test] fn shuffles_for_the_right_epoch() { - let num_validators = FewValidatorsEthSpec::minimum_validator_count() * 2; + let num_validators = MinimalEthSpec::minimum_validator_count() * 2; let epoch = Epoch::new(100_000_000); - let slot = epoch.start_slot(FewValidatorsEthSpec::slots_per_epoch()); + let slot = epoch.start_slot(MinimalEthSpec::slots_per_epoch()); - let mut state = new_state::(num_validators, slot); - let spec = &FewValidatorsEthSpec::default_spec(); + let mut state = new_state::(num_validators, slot); + let spec = &MinimalEthSpec::default_spec(); - let distinct_hashes: Vec = (0..FewValidatorsEthSpec::latest_randao_mixes_length()) + let distinct_hashes: Vec = (0..MinimalEthSpec::latest_randao_mixes_length()) .into_iter() .map(|i| Hash256::from(i as u64)) .collect(); @@ -118,14 +118,14 @@ fn shuffles_for_the_right_epoch() { #[test] fn can_start_on_any_shard() { - let num_validators = FewValidatorsEthSpec::minimum_validator_count() * 2; + let num_validators = MinimalEthSpec::minimum_validator_count() * 2; let epoch = Epoch::new(100_000_000); - let slot = epoch.start_slot(FewValidatorsEthSpec::slots_per_epoch()); + let slot = epoch.start_slot(MinimalEthSpec::slots_per_epoch()); - let mut state = new_state::(num_validators, slot); - let spec = &FewValidatorsEthSpec::default_spec(); + let mut state = new_state::(num_validators, slot); + let spec = &MinimalEthSpec::default_spec(); - for i in 0..FewValidatorsEthSpec::shard_count() as u64 { + for i in 0..MinimalEthSpec::shard_count() as u64 { state.latest_start_shard = i; let cache = CommitteeCache::initialized(&state, state.current_epoch(), spec).unwrap(); @@ -154,7 +154,7 @@ impl EthSpec for ExcessShardsEthSpec { type GenesisEpoch = U0; fn default_spec() -> ChainSpec { - ChainSpec::few_validators() + ChainSpec::minimal() } } diff --git a/eth2/types/src/beacon_state/tests.rs b/eth2/types/src/beacon_state/tests.rs index a668f99fe..b3c641f61 100644 --- a/eth2/types/src/beacon_state/tests.rs +++ b/eth2/types/src/beacon_state/tests.rs @@ -53,7 +53,7 @@ fn test_beacon_proposer_index() { #[test] fn beacon_proposer_index() { - test_beacon_proposer_index::(); + test_beacon_proposer_index::(); } /// Should produce (note the set notation brackets): @@ -115,11 +115,11 @@ fn test_active_index(state_slot: Slot) { #[test] fn get_active_index_root_index() { - test_active_index::(Slot::new(0)); + test_active_index::(Slot::new(0)); - let epoch = Epoch::from(FoundationEthSpec::latest_active_index_roots() * 4); - let slot = epoch.start_slot(FoundationEthSpec::slots_per_epoch()); - test_active_index::(slot); + let epoch = Epoch::from(MainnetEthSpec::latest_active_index_roots() * 4); + let slot = epoch.start_slot(MainnetEthSpec::slots_per_epoch()); + test_active_index::(slot); } /// Test that @@ -166,14 +166,14 @@ fn test_cache_initialization<'a, T: EthSpec>( #[test] fn cache_initialization() { - let spec = FewValidatorsEthSpec::default_spec(); + let spec = MinimalEthSpec::default_spec(); - let builder: TestingBeaconStateBuilder = + let builder: TestingBeaconStateBuilder = TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(16, &spec); let (mut state, _keypairs) = builder.build(); - state.slot = (FewValidatorsEthSpec::genesis_epoch() + 1) - .start_slot(FewValidatorsEthSpec::slots_per_epoch()); + state.slot = + (MinimalEthSpec::genesis_epoch() + 1).start_slot(MinimalEthSpec::slots_per_epoch()); test_cache_initialization(&mut state, RelativeEpoch::Previous, &spec); test_cache_initialization(&mut state, RelativeEpoch::Current, &spec); @@ -203,7 +203,7 @@ fn tree_hash_cache() { #[cfg(test)] mod committees { use super::*; - use crate::beacon_state::FewValidatorsEthSpec; + use crate::beacon_state::MinimalEthSpec; use swap_or_not_shuffle::shuffle_list; fn execute_committee_consistency_test( @@ -347,16 +347,16 @@ mod committees { #[test] fn current_epoch_committee_consistency() { - committee_consistency_test_suite::(RelativeEpoch::Current); + committee_consistency_test_suite::(RelativeEpoch::Current); } #[test] fn previous_epoch_committee_consistency() { - committee_consistency_test_suite::(RelativeEpoch::Previous); + committee_consistency_test_suite::(RelativeEpoch::Previous); } #[test] fn next_epoch_committee_consistency() { - committee_consistency_test_suite::(RelativeEpoch::Next); + committee_consistency_test_suite::(RelativeEpoch::Next); } } diff --git a/eth2/types/src/chain_spec.rs b/eth2/types/src/chain_spec.rs index a1267e37d..0a2602ea8 100644 --- a/eth2/types/src/chain_spec.rs +++ b/eth2/types/src/chain_spec.rs @@ -136,7 +136,7 @@ impl ChainSpec { /// Returns a `ChainSpec` compatible with the Ethereum Foundation specification. /// /// Spec v0.6.1 - pub fn foundation() -> Self { + pub fn mainnet() -> Self { Self { /* * Misc @@ -217,43 +217,35 @@ impl ChainSpec { * Boot nodes */ boot_nodes: vec![], - chain_id: 1, // foundation chain id + chain_id: 1, // mainnet chain id } } - /// Returns a `ChainSpec` compatible with the Lighthouse testnet specification. - /// - /// Spec v0.4.0 - pub fn lighthouse_testnet() -> Self { - /* - * Lighthouse testnet bootnodes - */ + /// Returns a `ChainSpec` compatible with the specification suitable for 8 validators. + pub fn minimal() -> Self { + let genesis_slot = Slot::new(0); + + // Note: these bootnodes are placeholders. + // + // Should be updated once static bootnodes exist. let boot_nodes = vec!["/ip4/127.0.0.1/tcp/9000" .parse() .expect("correct multiaddr")]; Self { boot_nodes, - chain_id: 2, // lighthouse testnet chain id - ..ChainSpec::few_validators() - } - } - - /// Returns a `ChainSpec` compatible with the specification suitable for 8 validators. - pub fn few_validators() -> Self { - let genesis_slot = Slot::new(0); - - Self { target_committee_size: 1, + chain_id: 2, // lighthouse testnet chain id genesis_slot, - ..ChainSpec::foundation() + shuffle_round_count: 10, + ..ChainSpec::mainnet() } } } impl Default for ChainSpec { fn default() -> Self { - Self::foundation() + Self::mainnet() } } @@ -263,8 +255,8 @@ mod tests { use int_to_bytes::int_to_bytes8; #[test] - fn test_foundation_spec_can_be_constructed() { - let _ = ChainSpec::foundation(); + fn test_mainnet_spec_can_be_constructed() { + let _ = ChainSpec::mainnet(); } fn test_domain(domain_type: Domain, raw_domain: u32, spec: &ChainSpec) { @@ -281,7 +273,7 @@ mod tests { #[test] fn test_get_domain() { - let spec = ChainSpec::foundation(); + let spec = ChainSpec::mainnet(); test_domain(Domain::BeaconProposer, spec.domain_beacon_proposer, &spec); test_domain(Domain::Randao, spec.domain_randao, &spec); diff --git a/eth2/types/src/fork.rs b/eth2/types/src/fork.rs index ec5f3af4c..60ab208ad 100644 --- a/eth2/types/src/fork.rs +++ b/eth2/types/src/fork.rs @@ -63,7 +63,7 @@ mod tests { cached_tree_hash_tests!(Fork); fn test_genesis(epoch: Epoch) { - let mut spec = ChainSpec::foundation(); + let mut spec = ChainSpec::mainnet(); let fork = Fork::genesis(epoch); diff --git a/eth2/types/src/historical_batch.rs b/eth2/types/src/historical_batch.rs index 3480508dc..0d8916216 100644 --- a/eth2/types/src/historical_batch.rs +++ b/eth2/types/src/historical_batch.rs @@ -31,7 +31,7 @@ pub struct HistoricalBatch { mod tests { use super::*; - pub type FoundationHistoricalBatch = HistoricalBatch; + pub type FoundationHistoricalBatch = HistoricalBatch; ssz_tests!(FoundationHistoricalBatch); cached_tree_hash_tests!(FoundationHistoricalBatch); diff --git a/tests/ef_tests/src/doc.rs b/tests/ef_tests/src/doc.rs index f69d1f998..301ba9178 100644 --- a/tests/ef_tests/src/doc.rs +++ b/tests/ef_tests/src/doc.rs @@ -1,11 +1,11 @@ use crate::case_result::CaseResult; use crate::cases::*; use crate::doc_header::DocHeader; -use crate::eth_specs::{MainnetEthSpec, MinimalEthSpec}; use crate::yaml_decode::{yaml_split_header_and_cases, YamlDecode}; use crate::EfTest; use serde_derive::Deserialize; use std::{fs::File, io::prelude::*, path::PathBuf}; +use types::{MainnetEthSpec, MinimalEthSpec}; #[derive(Debug, Deserialize)] pub struct Doc { diff --git a/tests/ef_tests/src/eth_specs.rs b/tests/ef_tests/src/eth_specs.rs deleted file mode 100644 index f0ee1e9f0..000000000 --- a/tests/ef_tests/src/eth_specs.rs +++ /dev/null @@ -1,32 +0,0 @@ -use serde_derive::{Deserialize, Serialize}; -use types::{ - typenum::{U0, U64, U8}, - ChainSpec, EthSpec, FewValidatorsEthSpec, FoundationEthSpec, -}; - -/// "Minimal" testing specification, as defined here: -/// -/// https://github.com/ethereum/eth2.0-specs/blob/v0.6.1/configs/constant_presets/minimal.yaml -/// -/// Spec v0.6.1 -#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)] -pub struct MinimalEthSpec; - -impl EthSpec for MinimalEthSpec { - type ShardCount = U8; - type SlotsPerHistoricalRoot = U64; - type LatestRandaoMixesLength = U64; - type LatestActiveIndexRootsLength = U64; - type LatestSlashedExitLength = U64; - type SlotsPerEpoch = U8; - type GenesisEpoch = U0; - - fn default_spec() -> ChainSpec { - // TODO: this spec is likely incorrect! - let mut spec = FewValidatorsEthSpec::default_spec(); - spec.shuffle_round_count = 10; - spec - } -} - -pub type MainnetEthSpec = FoundationEthSpec; diff --git a/tests/ef_tests/src/lib.rs b/tests/ef_tests/src/lib.rs index 942a6dbb7..ac238bb1c 100644 --- a/tests/ef_tests/src/lib.rs +++ b/tests/ef_tests/src/lib.rs @@ -11,7 +11,6 @@ mod cases; mod doc; mod doc_header; mod error; -mod eth_specs; mod yaml_decode; /// Defined where an object can return the results of some test(s) adhering to the Ethereum diff --git a/validator_client/src/block_producer/mod.rs b/validator_client/src/block_producer/mod.rs index 9c19e3532..212db1f8e 100644 --- a/validator_client/src/block_producer/mod.rs +++ b/validator_client/src/block_producer/mod.rs @@ -183,7 +183,7 @@ mod tests { pub fn polling() { let mut rng = XorShiftRng::from_seed([42; 16]); - let spec = Arc::new(ChainSpec::foundation()); + let spec = Arc::new(ChainSpec::mainnet()); let slot_clock = Arc::new(TestingSlotClock::new(0)); let beacon_node = Arc::new(SimulatedBeaconNode::default()); let signer = Arc::new(LocalSigner::new(Keypair::random())); diff --git a/validator_client/src/config.rs b/validator_client/src/config.rs index f5d795ede..b6e2c5bb5 100644 --- a/validator_client/src/config.rs +++ b/validator_client/src/config.rs @@ -6,9 +6,7 @@ use std::fs; use std::fs::File; use std::io::{Error, ErrorKind}; use std::path::PathBuf; -use types::{ - ChainSpec, EthSpec, FewValidatorsEthSpec, FoundationEthSpec, LighthouseTestnetEthSpec, -}; +use types::{ChainSpec, EthSpec, MainnetEthSpec, MinimalEthSpec}; /// Stores the core configuration for this validator instance. #[derive(Clone)] @@ -34,13 +32,13 @@ impl Default for Config { let server = "localhost:5051".to_string(); - let spec = FoundationEthSpec::default_spec(); + let spec = MainnetEthSpec::default_spec(); Self { data_dir, server, spec, - slots_per_epoch: FoundationEthSpec::slots_per_epoch(), + slots_per_epoch: MainnetEthSpec::slots_per_epoch(), } } } @@ -69,9 +67,8 @@ impl Config { if let Some(spec_str) = args.value_of("spec") { info!(log, "Using custom spec: {:?}", spec_str); config.spec = match spec_str { - "foundation" => FoundationEthSpec::default_spec(), - "few_validators" => FewValidatorsEthSpec::default_spec(), - "lighthouse_testnet" => LighthouseTestnetEthSpec::default_spec(), + "mainnet" => MainnetEthSpec::default_spec(), + "minimal" => MinimalEthSpec::default_spec(), // Should be impossible due to clap's `possible_values(..)` function. _ => unreachable!(), }; diff --git a/validator_client/src/duties/mod.rs b/validator_client/src/duties/mod.rs index 3f75c937d..f0269a41f 100644 --- a/validator_client/src/duties/mod.rs +++ b/validator_client/src/duties/mod.rs @@ -163,7 +163,7 @@ mod tests { #[test] pub fn polling() { - let spec = Arc::new(ChainSpec::foundation()); + let spec = Arc::new(ChainSpec::mainnet()); let duties_map = Arc::new(EpochDutiesMap::new(T::slots_per_epoch())); let keypair = Keypair::random(); let slot_clock = Arc::new(TestingSlotClock::new(0)); diff --git a/validator_client/src/main.rs b/validator_client/src/main.rs index 038399936..d755db4d2 100644 --- a/validator_client/src/main.rs +++ b/validator_client/src/main.rs @@ -46,8 +46,8 @@ fn main() { .short("s") .help("Configuration of Beacon Chain") .takes_value(true) - .possible_values(&["foundation", "few_validators", "lighthouse_testnet"]) - .default_value("lighthouse_testnet"), + .possible_values(&["mainnet", "minimal"]) + .default_value("minimal"), ) .get_matches();