Unify EthSpecs in Mainnet and Minimal

This commit is contained in:
Paul Hauner 2019-06-08 08:49:04 -04:00
parent caddeba81b
commit 749f2fcb5f
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
27 changed files with 119 additions and 186 deletions

View File

@ -82,7 +82,7 @@ impl<T: EthSpec, U: Store> Iterator for BlockRootsIterator<T, U> {
mod test { mod test {
use super::*; use super::*;
use store::MemoryStore; use store::MemoryStore;
use types::{test_utils::TestingBeaconStateBuilder, FoundationEthSpec, Keypair}; use types::{test_utils::TestingBeaconStateBuilder, Keypair, MainnetEthSpec};
fn get_state<T: EthSpec>() -> BeaconState<T> { fn get_state<T: EthSpec>() -> BeaconState<T> {
let builder = TestingBeaconStateBuilder::from_single_keypair( let builder = TestingBeaconStateBuilder::from_single_keypair(
@ -97,10 +97,10 @@ mod test {
#[test] #[test]
fn root_iter() { fn root_iter() {
let store = Arc::new(MemoryStore::open()); 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<FoundationEthSpec> = get_state(); let mut state_a: BeaconState<MainnetEthSpec> = get_state();
let mut state_b: BeaconState<FoundationEthSpec> = get_state(); let mut state_b: BeaconState<MainnetEthSpec> = get_state();
state_a.slot = Slot::from(slots_per_historical_root); state_a.slot = Slot::from(slots_per_historical_root);
state_b.slot = Slot::from(slots_per_historical_root * 2); state_b.slot = Slot::from(slots_per_historical_root * 2);
@ -122,7 +122,7 @@ mod test {
let mut collected: Vec<Hash256> = iter.collect(); let mut collected: Vec<Hash256> = iter.collect();
collected.reverse(); 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); assert_eq!(collected.len(), expected_len);

View File

@ -11,10 +11,10 @@ use std::sync::Arc;
use tree_hash::TreeHash; use tree_hash::TreeHash;
use types::{ use types::{
test_utils::TestingBeaconStateBuilder, BeaconBlock, ChainSpec, EthSpec, Hash256, 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; const TESTNET_VALIDATOR_COUNT: usize = 16;
/// Provides a new, initialized `BeaconChain` /// Provides a new, initialized `BeaconChain`
@ -35,7 +35,7 @@ impl BeaconChainTypes for TestnetMemoryBeaconChainTypes {
type Store = MemoryStore; type Store = MemoryStore;
type SlotClock = SystemTimeSlotClock; type SlotClock = SystemTimeSlotClock;
type ForkChoice = OptimizedLMDGhost<Self::Store, Self::EthSpec>; type ForkChoice = OptimizedLMDGhost<Self::Store, Self::EthSpec>;
type EthSpec = LighthouseTestnetEthSpec; type EthSpec = MinimalEthSpec;
} }
impl<T: BeaconChainTypes> InitialiseBeaconChain<T> for TestnetMemoryBeaconChainTypes {} impl<T: BeaconChainTypes> InitialiseBeaconChain<T> for TestnetMemoryBeaconChainTypes {}
@ -46,7 +46,7 @@ impl BeaconChainTypes for TestnetDiskBeaconChainTypes {
type Store = DiskStore; type Store = DiskStore;
type SlotClock = SystemTimeSlotClock; type SlotClock = SystemTimeSlotClock;
type ForkChoice = OptimizedLMDGhost<Self::Store, Self::EthSpec>; type ForkChoice = OptimizedLMDGhost<Self::Store, Self::EthSpec>;
type EthSpec = LighthouseTestnetEthSpec; type EthSpec = MinimalEthSpec;
} }
impl<T: BeaconChainTypes> InitialiseBeaconChain<T> for TestnetDiskBeaconChainTypes {} impl<T: BeaconChainTypes> InitialiseBeaconChain<T> for TestnetDiskBeaconChainTypes {}

View File

@ -31,7 +31,7 @@ impl Default for ClientConfig {
network: NetworkConfig::new(vec![]), network: NetworkConfig::new(vec![]),
rpc: rpc::RPCConfig::default(), rpc: rpc::RPCConfig::default(),
http: HttpServerConfig::default(), http: HttpServerConfig::default(),
spec: ChainSpec::lighthouse_testnet(), spec: ChainSpec::minimal(),
} }
} }
} }

View File

@ -261,7 +261,7 @@ mod test {
#[test] #[test]
fn ssz_encoding() { 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); let encoded = ssz_encode(&original);

View File

@ -61,7 +61,7 @@ mod tests {
#[test] #[test]
fn read_slot() { fn read_slot() {
let spec = FewValidatorsEthSpec::default_spec(); let spec = MinimalEthSpec::default_spec();
let test_slot = |slot: Slot| { let test_slot = |slot: Slot| {
let mut block = BeaconBlock::empty(&spec); let mut block = BeaconBlock::empty(&spec);
@ -85,7 +85,7 @@ mod tests {
#[test] #[test]
fn read_previous_block_root() { fn read_previous_block_root() {
let spec = FewValidatorsEthSpec::default_spec(); let spec = MinimalEthSpec::default_spec();
let test_root = |root: Hash256| { let test_root = |root: Hash256| {
let mut block = BeaconBlock::empty(&spec); let mut block = BeaconBlock::empty(&spec);
@ -130,7 +130,7 @@ mod tests {
fn chain_without_skips() { fn chain_without_skips() {
let n: usize = 10; let n: usize = 10;
let store = MemoryStore::open(); let store = MemoryStore::open();
let spec = FewValidatorsEthSpec::default_spec(); let spec = MinimalEthSpec::default_spec();
let slots: Vec<usize> = (0..n).collect(); let slots: Vec<usize> = (0..n).collect();
let blocks_and_roots = build_chain(&store, &slots, &spec); let blocks_and_roots = build_chain(&store, &slots, &spec);
@ -154,7 +154,7 @@ mod tests {
#[test] #[test]
fn chain_with_skips() { fn chain_with_skips() {
let store = MemoryStore::open(); let store = MemoryStore::open();
let spec = FewValidatorsEthSpec::default_spec(); let spec = MinimalEthSpec::default_spec();
let slots = vec![0, 1, 2, 5]; let slots = vec![0, 1, 2, 5];

View File

@ -3,10 +3,10 @@ use criterion::{criterion_group, criterion_main, Benchmark};
use fork_choice::{test_utils::TestingForkChoiceBuilder, ForkChoice, OptimizedLMDGhost}; use fork_choice::{test_utils::TestingForkChoiceBuilder, ForkChoice, OptimizedLMDGhost};
use std::sync::Arc; use std::sync::Arc;
use store::MemoryStore; use store::MemoryStore;
use types::{ChainSpec, EthSpec, FoundationEthSpec}; use types::{ChainSpec, EthSpec, MainnetEthSpec};
pub type TestedForkChoice<T, U> = OptimizedLMDGhost<T, U>; pub type TestedForkChoice<T, U> = OptimizedLMDGhost<T, U>;
pub type TestedEthSpec = FoundationEthSpec; pub type TestedEthSpec = MainnetEthSpec;
/// Helper function to setup a builder and spec. /// Helper function to setup a builder and spec.
fn setup( fn setup(

View File

@ -1,7 +1,7 @@
use fork_choice::{test_utils::TestingForkChoiceBuilder, ForkChoice, OptimizedLMDGhost}; use fork_choice::{test_utils::TestingForkChoiceBuilder, ForkChoice, OptimizedLMDGhost};
use std::sync::Arc; use std::sync::Arc;
use store::{MemoryStore, Store}; use store::{MemoryStore, Store};
use types::{BeaconBlock, ChainSpec, EthSpec, FoundationEthSpec, Hash256}; use types::{BeaconBlock, ChainSpec, EthSpec, Hash256, MainnetEthSpec};
fn main() { fn main() {
let validator_count = 16; let validator_count = 16;
@ -9,15 +9,15 @@ fn main() {
let repetitions = 50; let repetitions = 50;
let store = MemoryStore::open(); let store = MemoryStore::open();
let builder: TestingForkChoiceBuilder<MemoryStore, FoundationEthSpec> = let builder: TestingForkChoiceBuilder<MemoryStore, MainnetEthSpec> =
TestingForkChoiceBuilder::new(validator_count, chain_length, Arc::new(store)); TestingForkChoiceBuilder::new(validator_count, chain_length, Arc::new(store));
let fork_choosers: Vec<OptimizedLMDGhost<MemoryStore, FoundationEthSpec>> = (0..repetitions) let fork_choosers: Vec<OptimizedLMDGhost<MemoryStore, MainnetEthSpec>> = (0..repetitions)
.into_iter() .into_iter()
.map(|_| builder.build()) .map(|_| builder.build())
.collect(); .collect();
let spec = &FoundationEthSpec::default_spec(); let spec = &MainnetEthSpec::default_spec();
println!("Running {} times...", repetitions); println!("Running {} times...", repetitions);
for fc in fork_choosers { for fc in fork_choosers {

View File

@ -4,7 +4,7 @@ use std::sync::Arc;
use store::Store; use store::Store;
use types::{ use types::{
test_utils::{SeedableRng, TestRandom, TestingBeaconStateBuilder, XorShiftRng}, 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. /// Creates a chain of blocks and produces `ForkChoice` instances with pre-filled stores.
@ -16,11 +16,8 @@ pub struct TestingForkChoiceBuilder<S, E> {
impl<S: Store, E: EthSpec> TestingForkChoiceBuilder<S, E> { impl<S: Store, E: EthSpec> TestingForkChoiceBuilder<S, E> {
pub fn new(validator_count: usize, chain_length: usize, store: Arc<S>) -> Self { pub fn new(validator_count: usize, chain_length: usize, store: Arc<S>) -> Self {
let chain = get_chain_of_blocks::<FoundationEthSpec, S>( let chain =
chain_length, get_chain_of_blocks::<MainnetEthSpec, S>(chain_length, validator_count, store.clone());
validator_count,
store.clone(),
);
Self { Self {
store, store,

View File

@ -11,7 +11,7 @@ use std::sync::Arc;
use std::{fs::File, io::prelude::*, path::PathBuf}; use std::{fs::File, io::prelude::*, path::PathBuf};
use types::test_utils::TestingBeaconStateBuilder; use types::test_utils::TestingBeaconStateBuilder;
use types::{ use types::{
BeaconBlock, BeaconBlockBody, Eth1Data, EthSpec, FoundationEthSpec, Hash256, Keypair, Slot, BeaconBlock, BeaconBlockBody, Eth1Data, EthSpec, Hash256, Keypair, MainnetEthSpec, Slot,
}; };
use yaml_rust::yaml; use yaml_rust::yaml;
@ -22,7 +22,7 @@ fn test_optimized_lmd_ghost() {
// set up logging // set up logging
// Builder::from_env(Env::default().default_filter_or("trace")).init(); // Builder::from_env(Env::default().default_filter_or("trace")).init();
test_yaml_vectors::<OptimizedLMDGhost<MemoryStore, FoundationEthSpec>>( test_yaml_vectors::<OptimizedLMDGhost<MemoryStore, MainnetEthSpec>>(
"tests/lmd_ghost_test_vectors.yaml", "tests/lmd_ghost_test_vectors.yaml",
100, 100,
); );
@ -33,7 +33,7 @@ fn test_bitwise_lmd_ghost() {
// set up logging // set up logging
//Builder::from_env(Env::default().default_filter_or("trace")).init(); //Builder::from_env(Env::default().default_filter_or("trace")).init();
test_yaml_vectors::<BitwiseLMDGhost<MemoryStore, FoundationEthSpec>>( test_yaml_vectors::<BitwiseLMDGhost<MemoryStore, MainnetEthSpec>>(
"tests/bitwise_lmd_ghost_test_vectors.yaml", "tests/bitwise_lmd_ghost_test_vectors.yaml",
100, 100,
); );
@ -41,7 +41,7 @@ fn test_bitwise_lmd_ghost() {
#[test] #[test]
fn test_slow_lmd_ghost() { fn test_slow_lmd_ghost() {
test_yaml_vectors::<SlowLMDGhost<MemoryStore, FoundationEthSpec>>( test_yaml_vectors::<SlowLMDGhost<MemoryStore, MainnetEthSpec>>(
"tests/lmd_ghost_test_vectors.yaml", "tests/lmd_ghost_test_vectors.yaml",
100, 100,
); );
@ -61,7 +61,7 @@ fn test_yaml_vectors<T: ForkChoice<MemoryStore>>(
let test_cases = load_test_cases_from_yaml(yaml_file_path); let test_cases = load_test_cases_from_yaml(yaml_file_path);
// default vars // default vars
let spec = FoundationEthSpec::default_spec(); let spec = MainnetEthSpec::default_spec();
let zero_hash = Hash256::zero(); let zero_hash = Hash256::zero();
let eth1_data = Eth1Data { let eth1_data = Eth1Data {
deposit_count: 0, deposit_count: 0,
@ -204,9 +204,9 @@ where
let store = Arc::new(MemoryStore::open()); let store = Arc::new(MemoryStore::open());
let fork_choice = ForkChoice::new(store.clone()); let fork_choice = ForkChoice::new(store.clone());
let spec = FoundationEthSpec::default_spec(); let spec = MainnetEthSpec::default_spec();
let mut state_builder: TestingBeaconStateBuilder<FoundationEthSpec> = let mut state_builder: TestingBeaconStateBuilder<MainnetEthSpec> =
TestingBeaconStateBuilder::from_single_keypair(num_validators, &Keypair::random(), &spec); TestingBeaconStateBuilder::from_single_keypair(num_validators, &Keypair::random(), &spec);
state_builder.build_caches(&spec).unwrap(); state_builder.build_caches(&spec).unwrap();
let (state, _keypairs) = state_builder.build(); let (state, _keypairs) = state_builder.build();

View File

@ -675,12 +675,12 @@ mod tests {
.collect() .collect()
} }
fn test_state(rng: &mut XorShiftRng) -> (ChainSpec, BeaconState<FoundationEthSpec>) { fn test_state(rng: &mut XorShiftRng) -> (ChainSpec, BeaconState<MainnetEthSpec>) {
let spec = FoundationEthSpec::default_spec(); let spec = MainnetEthSpec::default_spec();
let mut state = BeaconState::random_for_test(rng); let mut state = BeaconState::random_for_test(rng);
state.fork = Fork::genesis(FoundationEthSpec::genesis_epoch()); state.fork = Fork::genesis(MainnetEthSpec::genesis_epoch());
(spec, state) (spec, state)
} }
@ -735,13 +735,13 @@ mod tests {
state_builder.build_caches(&spec).unwrap(); state_builder.build_caches(&spec).unwrap();
let (state, keypairs) = state_builder.build(); let (state, keypairs) = state_builder.build();
(state, keypairs, FoundationEthSpec::default_spec()) (state, keypairs, MainnetEthSpec::default_spec())
} }
#[test] #[test]
fn test_attestation_score() { fn test_attestation_score() {
let (ref mut state, ref keypairs, ref spec) = let (ref mut state, ref keypairs, ref spec) =
attestation_test_state::<FoundationEthSpec>(1); attestation_test_state::<MainnetEthSpec>(1);
let slot = state.slot - 1; let slot = state.slot - 1;
let committees = state let committees = state
@ -793,7 +793,7 @@ mod tests {
#[test] #[test]
fn attestation_aggregation_insert_get_prune() { fn attestation_aggregation_insert_get_prune() {
let (ref mut state, ref keypairs, ref spec) = let (ref mut state, ref keypairs, ref spec) =
attestation_test_state::<FoundationEthSpec>(1); attestation_test_state::<MainnetEthSpec>(1);
let op_pool = OperationPool::new(); let op_pool = OperationPool::new();
@ -861,7 +861,7 @@ mod tests {
#[test] #[test]
fn attestation_duplicate() { fn attestation_duplicate() {
let (ref mut state, ref keypairs, ref spec) = let (ref mut state, ref keypairs, ref spec) =
attestation_test_state::<FoundationEthSpec>(1); attestation_test_state::<MainnetEthSpec>(1);
let op_pool = OperationPool::new(); let op_pool = OperationPool::new();
@ -898,7 +898,7 @@ mod tests {
#[test] #[test]
fn attestation_pairwise_overlapping() { fn attestation_pairwise_overlapping() {
let (ref mut state, ref keypairs, ref spec) = let (ref mut state, ref keypairs, ref spec) =
attestation_test_state::<FoundationEthSpec>(1); attestation_test_state::<MainnetEthSpec>(1);
let op_pool = OperationPool::new(); let op_pool = OperationPool::new();
@ -946,7 +946,7 @@ mod tests {
let big_step_size = 4; let big_step_size = 4;
let (ref mut state, ref keypairs, ref spec) = let (ref mut state, ref keypairs, ref spec) =
attestation_test_state::<FoundationEthSpec>(big_step_size); attestation_test_state::<MainnetEthSpec>(big_step_size);
let op_pool = OperationPool::new(); let op_pool = OperationPool::new();

View File

@ -17,7 +17,7 @@ pub const SMALL_BENCHING_SAMPLE_SIZE: usize = 10;
/// Run the benchmarking suite on a foundation spec with 16,384 validators. /// 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) { pub fn bench_epoch_processing_n_validators(c: &mut Criterion, validator_count: usize) {
let spec = ChainSpec::foundation(); let spec = ChainSpec::mainnet();
let mut builder = let mut builder =
TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(validator_count, &spec); TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(validator_count, &spec);

View File

@ -25,7 +25,7 @@ pub fn block_processing_worst_case(c: &mut Criterion) {
); );
// Use the specifications from the Eth2.0 spec. // 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. // Create a builder for configuring the block and state for benching.
let mut bench_builder = BlockBenchingBuilder::new(VALIDATOR_COUNT, &spec); 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. // 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. // Create a builder for configuring the block and state for benching.
let mut bench_builder = BlockBenchingBuilder::new(VALIDATOR_COUNT, &spec); let mut bench_builder = BlockBenchingBuilder::new(VALIDATOR_COUNT, &spec);

View File

@ -9,7 +9,7 @@ pub const VALIDATOR_COUNT: usize = 10;
#[test] #[test]
fn valid_block_ok() { fn valid_block_ok() {
let spec = FoundationEthSpec::default_spec(); let spec = MainnetEthSpec::default_spec();
let builder = get_builder(&spec); let builder = get_builder(&spec);
let (block, mut state) = builder.build(None, None, &spec); let (block, mut state) = builder.build(None, None, &spec);
@ -20,7 +20,7 @@ fn valid_block_ok() {
#[test] #[test]
fn invalid_block_header_state_slot() { fn invalid_block_header_state_slot() {
let spec = FoundationEthSpec::default_spec(); let spec = MainnetEthSpec::default_spec();
let builder = get_builder(&spec); let builder = get_builder(&spec);
let (mut block, mut state) = builder.build(None, None, &spec); let (mut block, mut state) = builder.build(None, None, &spec);
@ -39,7 +39,7 @@ fn invalid_block_header_state_slot() {
#[test] #[test]
fn invalid_parent_block_root() { fn invalid_parent_block_root() {
let spec = FoundationEthSpec::default_spec(); let spec = MainnetEthSpec::default_spec();
let builder = get_builder(&spec); let builder = get_builder(&spec);
let invalid_parent_root = Hash256::from([0xAA; 32]); let invalid_parent_root = Hash256::from([0xAA; 32]);
let (block, mut state) = builder.build(None, Some(invalid_parent_root), &spec); let (block, mut state) = builder.build(None, Some(invalid_parent_root), &spec);
@ -59,14 +59,14 @@ fn invalid_parent_block_root() {
#[test] #[test]
fn invalid_block_signature() { fn invalid_block_signature() {
let spec = FoundationEthSpec::default_spec(); let spec = MainnetEthSpec::default_spec();
let builder = get_builder(&spec); let builder = get_builder(&spec);
let (mut block, mut state) = builder.build(None, None, &spec); let (mut block, mut state) = builder.build(None, None, &spec);
// sign the block with a keypair that is not the expected proposer // sign the block with a keypair that is not the expected proposer
let keypair = Keypair::random(); let keypair = Keypair::random();
let message = block.signed_root(); 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); let domain = spec.get_domain(epoch, Domain::BeaconProposer, &state.fork);
block.signature = Signature::new(&message, domain, &keypair.sk); block.signature = Signature::new(&message, domain, &keypair.sk);
@ -82,7 +82,7 @@ fn invalid_block_signature() {
#[test] #[test]
fn invalid_randao_reveal_signature() { fn invalid_randao_reveal_signature() {
let spec = FoundationEthSpec::default_spec(); let spec = MainnetEthSpec::default_spec();
let builder = get_builder(&spec); let builder = get_builder(&spec);
// sign randao reveal with random keypair // sign randao reveal with random keypair
@ -100,12 +100,12 @@ fn invalid_randao_reveal_signature() {
); );
} }
fn get_builder(spec: &ChainSpec) -> (BlockProcessingBuilder<FoundationEthSpec>) { fn get_builder(spec: &ChainSpec) -> (BlockProcessingBuilder<MainnetEthSpec>) {
let mut builder = BlockProcessingBuilder::new(VALIDATOR_COUNT, &spec); let mut builder = BlockProcessingBuilder::new(VALIDATOR_COUNT, &spec);
// Set the state and block to be in the last slot of the 4th epoch. // Set the state and block to be in the last slot of the 4th epoch.
let last_slot_of_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.set_slot(last_slot_of_epoch, &spec);
builder.build_caches(&spec); builder.build_caches(&spec);

View File

@ -8,13 +8,13 @@ use types::*;
fn runs_without_error() { fn runs_without_error() {
Builder::from_env(Env::default().default_filter_or("error")).init(); Builder::from_env(Env::default().default_filter_or("error")).init();
let spec = FewValidatorsEthSpec::default_spec(); let spec = MinimalEthSpec::default_spec();
let mut builder: TestingBeaconStateBuilder<FewValidatorsEthSpec> = let mut builder: TestingBeaconStateBuilder<MinimalEthSpec> =
TestingBeaconStateBuilder::from_deterministic_keypairs(8, &spec); TestingBeaconStateBuilder::from_deterministic_keypairs(8, &spec);
let target_slot = (FewValidatorsEthSpec::genesis_epoch() + 4) let target_slot =
.end_slot(FewValidatorsEthSpec::slots_per_epoch()); (MinimalEthSpec::genesis_epoch() + 4).end_slot(MinimalEthSpec::slots_per_epoch());
builder.teleport_to_slot(target_slot, &spec); builder.teleport_to_slot(target_slot, &spec);
let (mut state, _keypairs) = builder.build(); let (mut state, _keypairs) = builder.build();

View File

@ -95,9 +95,9 @@ pub trait EthSpec: 'static + Default + Sync + Send + Clone + Debug + PartialEq {
/// ///
/// Spec v0.6.1 /// Spec v0.6.1
#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)] #[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 ShardCount = U1024;
type SlotsPerHistoricalRoot = U8192; type SlotsPerHistoricalRoot = U8192;
type LatestRandaoMixesLength = U8192; type LatestRandaoMixesLength = U8192;
@ -107,17 +107,17 @@ impl EthSpec for FoundationEthSpec {
type GenesisEpoch = U0; type GenesisEpoch = U0;
fn default_spec() -> ChainSpec { fn default_spec() -> ChainSpec {
ChainSpec::foundation() ChainSpec::mainnet()
} }
} }
pub type FoundationBeaconState = BeaconState<FoundationEthSpec>; pub type FoundationBeaconState = BeaconState<MainnetEthSpec>;
/// Ethereum Foundation specifications, modified to be suitable for < 1000 validators. /// Ethereum Foundation specifications, modified to be suitable for < 1000 validators.
#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)] #[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 ShardCount = U8;
type SlotsPerHistoricalRoot = U8192; type SlotsPerHistoricalRoot = U8192;
type LatestRandaoMixesLength = U8192; type LatestRandaoMixesLength = U8192;
@ -127,28 +127,8 @@ impl EthSpec for FewValidatorsEthSpec {
type GenesisEpoch = U0; type GenesisEpoch = U0;
fn default_spec() -> ChainSpec { fn default_spec() -> ChainSpec {
ChainSpec::few_validators() ChainSpec::minimal()
} }
} }
pub type FewValidatorsBeaconState = BeaconState<FewValidatorsEthSpec>; pub type MinimalBeaconState = BeaconState<MinimalEthSpec>;
/// 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<LighthouseTestnetEthSpec>;

View File

@ -34,8 +34,8 @@ fn new_state<T: EthSpec>(validator_count: usize, slot: Slot) -> BeaconState<T> {
#[test] #[test]
fn fails_without_validators() { fn fails_without_validators() {
let state = new_state::<FewValidatorsEthSpec>(0, Slot::new(0)); let state = new_state::<MinimalEthSpec>(0, Slot::new(0));
let spec = &FewValidatorsEthSpec::default_spec(); let spec = &MinimalEthSpec::default_spec();
assert_eq!( assert_eq!(
CommitteeCache::initialized(&state, state.current_epoch(), &spec), CommitteeCache::initialized(&state, state.current_epoch(), &spec),
@ -45,8 +45,8 @@ fn fails_without_validators() {
#[test] #[test]
fn initializes_with_the_right_epoch() { fn initializes_with_the_right_epoch() {
let state = new_state::<FewValidatorsEthSpec>(16, Slot::new(0)); let state = new_state::<MinimalEthSpec>(16, Slot::new(0));
let spec = &FewValidatorsEthSpec::default_spec(); let spec = &MinimalEthSpec::default_spec();
let cache = CommitteeCache::default(); let cache = CommitteeCache::default();
assert_eq!(cache.initialized_epoch, None); assert_eq!(cache.initialized_epoch, None);
@ -63,14 +63,14 @@ fn initializes_with_the_right_epoch() {
#[test] #[test]
fn shuffles_for_the_right_epoch() { 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 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::<FewValidatorsEthSpec>(num_validators, slot); let mut state = new_state::<MinimalEthSpec>(num_validators, slot);
let spec = &FewValidatorsEthSpec::default_spec(); let spec = &MinimalEthSpec::default_spec();
let distinct_hashes: Vec<Hash256> = (0..FewValidatorsEthSpec::latest_randao_mixes_length()) let distinct_hashes: Vec<Hash256> = (0..MinimalEthSpec::latest_randao_mixes_length())
.into_iter() .into_iter()
.map(|i| Hash256::from(i as u64)) .map(|i| Hash256::from(i as u64))
.collect(); .collect();
@ -118,14 +118,14 @@ fn shuffles_for_the_right_epoch() {
#[test] #[test]
fn can_start_on_any_shard() { 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 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::<FewValidatorsEthSpec>(num_validators, slot); let mut state = new_state::<MinimalEthSpec>(num_validators, slot);
let spec = &FewValidatorsEthSpec::default_spec(); 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; state.latest_start_shard = i;
let cache = CommitteeCache::initialized(&state, state.current_epoch(), spec).unwrap(); let cache = CommitteeCache::initialized(&state, state.current_epoch(), spec).unwrap();
@ -154,7 +154,7 @@ impl EthSpec for ExcessShardsEthSpec {
type GenesisEpoch = U0; type GenesisEpoch = U0;
fn default_spec() -> ChainSpec { fn default_spec() -> ChainSpec {
ChainSpec::few_validators() ChainSpec::minimal()
} }
} }

View File

@ -53,7 +53,7 @@ fn test_beacon_proposer_index<T: EthSpec>() {
#[test] #[test]
fn beacon_proposer_index() { fn beacon_proposer_index() {
test_beacon_proposer_index::<FewValidatorsEthSpec>(); test_beacon_proposer_index::<MinimalEthSpec>();
} }
/// Should produce (note the set notation brackets): /// Should produce (note the set notation brackets):
@ -115,11 +115,11 @@ fn test_active_index<T: EthSpec>(state_slot: Slot) {
#[test] #[test]
fn get_active_index_root_index() { fn get_active_index_root_index() {
test_active_index::<FoundationEthSpec>(Slot::new(0)); test_active_index::<MainnetEthSpec>(Slot::new(0));
let epoch = Epoch::from(FoundationEthSpec::latest_active_index_roots() * 4); let epoch = Epoch::from(MainnetEthSpec::latest_active_index_roots() * 4);
let slot = epoch.start_slot(FoundationEthSpec::slots_per_epoch()); let slot = epoch.start_slot(MainnetEthSpec::slots_per_epoch());
test_active_index::<FoundationEthSpec>(slot); test_active_index::<MainnetEthSpec>(slot);
} }
/// Test that /// Test that
@ -166,14 +166,14 @@ fn test_cache_initialization<'a, T: EthSpec>(
#[test] #[test]
fn cache_initialization() { fn cache_initialization() {
let spec = FewValidatorsEthSpec::default_spec(); let spec = MinimalEthSpec::default_spec();
let builder: TestingBeaconStateBuilder<FewValidatorsEthSpec> = let builder: TestingBeaconStateBuilder<MinimalEthSpec> =
TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(16, &spec); TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(16, &spec);
let (mut state, _keypairs) = builder.build(); let (mut state, _keypairs) = builder.build();
state.slot = (FewValidatorsEthSpec::genesis_epoch() + 1) state.slot =
.start_slot(FewValidatorsEthSpec::slots_per_epoch()); (MinimalEthSpec::genesis_epoch() + 1).start_slot(MinimalEthSpec::slots_per_epoch());
test_cache_initialization(&mut state, RelativeEpoch::Previous, &spec); test_cache_initialization(&mut state, RelativeEpoch::Previous, &spec);
test_cache_initialization(&mut state, RelativeEpoch::Current, &spec); test_cache_initialization(&mut state, RelativeEpoch::Current, &spec);
@ -203,7 +203,7 @@ fn tree_hash_cache() {
#[cfg(test)] #[cfg(test)]
mod committees { mod committees {
use super::*; use super::*;
use crate::beacon_state::FewValidatorsEthSpec; use crate::beacon_state::MinimalEthSpec;
use swap_or_not_shuffle::shuffle_list; use swap_or_not_shuffle::shuffle_list;
fn execute_committee_consistency_test<T: EthSpec>( fn execute_committee_consistency_test<T: EthSpec>(
@ -347,16 +347,16 @@ mod committees {
#[test] #[test]
fn current_epoch_committee_consistency() { fn current_epoch_committee_consistency() {
committee_consistency_test_suite::<FewValidatorsEthSpec>(RelativeEpoch::Current); committee_consistency_test_suite::<MinimalEthSpec>(RelativeEpoch::Current);
} }
#[test] #[test]
fn previous_epoch_committee_consistency() { fn previous_epoch_committee_consistency() {
committee_consistency_test_suite::<FewValidatorsEthSpec>(RelativeEpoch::Previous); committee_consistency_test_suite::<MinimalEthSpec>(RelativeEpoch::Previous);
} }
#[test] #[test]
fn next_epoch_committee_consistency() { fn next_epoch_committee_consistency() {
committee_consistency_test_suite::<FewValidatorsEthSpec>(RelativeEpoch::Next); committee_consistency_test_suite::<MinimalEthSpec>(RelativeEpoch::Next);
} }
} }

View File

@ -136,7 +136,7 @@ impl ChainSpec {
/// Returns a `ChainSpec` compatible with the Ethereum Foundation specification. /// Returns a `ChainSpec` compatible with the Ethereum Foundation specification.
/// ///
/// Spec v0.6.1 /// Spec v0.6.1
pub fn foundation() -> Self { pub fn mainnet() -> Self {
Self { Self {
/* /*
* Misc * Misc
@ -217,43 +217,35 @@ impl ChainSpec {
* Boot nodes * Boot nodes
*/ */
boot_nodes: vec![], boot_nodes: vec![],
chain_id: 1, // foundation chain id chain_id: 1, // mainnet chain id
} }
} }
/// Returns a `ChainSpec` compatible with the Lighthouse testnet specification. /// Returns a `ChainSpec` compatible with the specification suitable for 8 validators.
/// pub fn minimal() -> Self {
/// Spec v0.4.0 let genesis_slot = Slot::new(0);
pub fn lighthouse_testnet() -> Self {
/* // Note: these bootnodes are placeholders.
* Lighthouse testnet bootnodes //
*/ // Should be updated once static bootnodes exist.
let boot_nodes = vec!["/ip4/127.0.0.1/tcp/9000" let boot_nodes = vec!["/ip4/127.0.0.1/tcp/9000"
.parse() .parse()
.expect("correct multiaddr")]; .expect("correct multiaddr")];
Self { Self {
boot_nodes, 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, target_committee_size: 1,
chain_id: 2, // lighthouse testnet chain id
genesis_slot, genesis_slot,
..ChainSpec::foundation() shuffle_round_count: 10,
..ChainSpec::mainnet()
} }
} }
} }
impl Default for ChainSpec { impl Default for ChainSpec {
fn default() -> Self { fn default() -> Self {
Self::foundation() Self::mainnet()
} }
} }
@ -263,8 +255,8 @@ mod tests {
use int_to_bytes::int_to_bytes8; use int_to_bytes::int_to_bytes8;
#[test] #[test]
fn test_foundation_spec_can_be_constructed() { fn test_mainnet_spec_can_be_constructed() {
let _ = ChainSpec::foundation(); let _ = ChainSpec::mainnet();
} }
fn test_domain(domain_type: Domain, raw_domain: u32, spec: &ChainSpec) { fn test_domain(domain_type: Domain, raw_domain: u32, spec: &ChainSpec) {
@ -281,7 +273,7 @@ mod tests {
#[test] #[test]
fn test_get_domain() { fn test_get_domain() {
let spec = ChainSpec::foundation(); let spec = ChainSpec::mainnet();
test_domain(Domain::BeaconProposer, spec.domain_beacon_proposer, &spec); test_domain(Domain::BeaconProposer, spec.domain_beacon_proposer, &spec);
test_domain(Domain::Randao, spec.domain_randao, &spec); test_domain(Domain::Randao, spec.domain_randao, &spec);

View File

@ -63,7 +63,7 @@ mod tests {
cached_tree_hash_tests!(Fork); cached_tree_hash_tests!(Fork);
fn test_genesis(epoch: Epoch) { fn test_genesis(epoch: Epoch) {
let mut spec = ChainSpec::foundation(); let mut spec = ChainSpec::mainnet();
let fork = Fork::genesis(epoch); let fork = Fork::genesis(epoch);

View File

@ -31,7 +31,7 @@ pub struct HistoricalBatch<T: EthSpec> {
mod tests { mod tests {
use super::*; use super::*;
pub type FoundationHistoricalBatch = HistoricalBatch<FoundationEthSpec>; pub type FoundationHistoricalBatch = HistoricalBatch<MainnetEthSpec>;
ssz_tests!(FoundationHistoricalBatch); ssz_tests!(FoundationHistoricalBatch);
cached_tree_hash_tests!(FoundationHistoricalBatch); cached_tree_hash_tests!(FoundationHistoricalBatch);

View File

@ -1,11 +1,11 @@
use crate::case_result::CaseResult; use crate::case_result::CaseResult;
use crate::cases::*; use crate::cases::*;
use crate::doc_header::DocHeader; use crate::doc_header::DocHeader;
use crate::eth_specs::{MainnetEthSpec, MinimalEthSpec};
use crate::yaml_decode::{yaml_split_header_and_cases, YamlDecode}; use crate::yaml_decode::{yaml_split_header_and_cases, YamlDecode};
use crate::EfTest; use crate::EfTest;
use serde_derive::Deserialize; use serde_derive::Deserialize;
use std::{fs::File, io::prelude::*, path::PathBuf}; use std::{fs::File, io::prelude::*, path::PathBuf};
use types::{MainnetEthSpec, MinimalEthSpec};
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct Doc { pub struct Doc {

View File

@ -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;

View File

@ -11,7 +11,6 @@ mod cases;
mod doc; mod doc;
mod doc_header; mod doc_header;
mod error; mod error;
mod eth_specs;
mod yaml_decode; mod yaml_decode;
/// Defined where an object can return the results of some test(s) adhering to the Ethereum /// Defined where an object can return the results of some test(s) adhering to the Ethereum

View File

@ -183,7 +183,7 @@ mod tests {
pub fn polling() { pub fn polling() {
let mut rng = XorShiftRng::from_seed([42; 16]); 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 slot_clock = Arc::new(TestingSlotClock::new(0));
let beacon_node = Arc::new(SimulatedBeaconNode::default()); let beacon_node = Arc::new(SimulatedBeaconNode::default());
let signer = Arc::new(LocalSigner::new(Keypair::random())); let signer = Arc::new(LocalSigner::new(Keypair::random()));

View File

@ -6,9 +6,7 @@ use std::fs;
use std::fs::File; use std::fs::File;
use std::io::{Error, ErrorKind}; use std::io::{Error, ErrorKind};
use std::path::PathBuf; use std::path::PathBuf;
use types::{ use types::{ChainSpec, EthSpec, MainnetEthSpec, MinimalEthSpec};
ChainSpec, EthSpec, FewValidatorsEthSpec, FoundationEthSpec, LighthouseTestnetEthSpec,
};
/// Stores the core configuration for this validator instance. /// Stores the core configuration for this validator instance.
#[derive(Clone)] #[derive(Clone)]
@ -34,13 +32,13 @@ impl Default for Config {
let server = "localhost:5051".to_string(); let server = "localhost:5051".to_string();
let spec = FoundationEthSpec::default_spec(); let spec = MainnetEthSpec::default_spec();
Self { Self {
data_dir, data_dir,
server, server,
spec, 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") { if let Some(spec_str) = args.value_of("spec") {
info!(log, "Using custom spec: {:?}", spec_str); info!(log, "Using custom spec: {:?}", spec_str);
config.spec = match spec_str { config.spec = match spec_str {
"foundation" => FoundationEthSpec::default_spec(), "mainnet" => MainnetEthSpec::default_spec(),
"few_validators" => FewValidatorsEthSpec::default_spec(), "minimal" => MinimalEthSpec::default_spec(),
"lighthouse_testnet" => LighthouseTestnetEthSpec::default_spec(),
// Should be impossible due to clap's `possible_values(..)` function. // Should be impossible due to clap's `possible_values(..)` function.
_ => unreachable!(), _ => unreachable!(),
}; };

View File

@ -163,7 +163,7 @@ mod tests {
#[test] #[test]
pub fn polling() { 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 duties_map = Arc::new(EpochDutiesMap::new(T::slots_per_epoch()));
let keypair = Keypair::random(); let keypair = Keypair::random();
let slot_clock = Arc::new(TestingSlotClock::new(0)); let slot_clock = Arc::new(TestingSlotClock::new(0));

View File

@ -46,8 +46,8 @@ fn main() {
.short("s") .short("s")
.help("Configuration of Beacon Chain") .help("Configuration of Beacon Chain")
.takes_value(true) .takes_value(true)
.possible_values(&["foundation", "few_validators", "lighthouse_testnet"]) .possible_values(&["mainnet", "minimal"])
.default_value("lighthouse_testnet"), .default_value("minimal"),
) )
.get_matches(); .get_matches();