Rename BeaconStateTypes to EthSpec

This commit is contained in:
Paul Hauner
2019-05-10 14:47:09 +10:00
parent 75b310a078
commit ce8ebeccbc
60 changed files with 223 additions and 235 deletions
+3 -3
View File
@@ -11,7 +11,7 @@ use log::{debug, trace};
use std::collections::HashMap;
use std::marker::PhantomData;
use std::sync::Arc;
use types::{BeaconBlock, BeaconState, BeaconStateTypes, ChainSpec, Hash256, Slot, SlotHeight};
use types::{BeaconBlock, BeaconState, ChainSpec, EthSpec, Hash256, Slot, SlotHeight};
//TODO: Pruning - Children
//TODO: Handle Syncing
@@ -54,7 +54,7 @@ pub struct BitwiseLMDGhost<T: ClientDB + Sized, B> {
_phantom: PhantomData<B>,
}
impl<T, B: BeaconStateTypes> BitwiseLMDGhost<T, B>
impl<T, B: EthSpec> BitwiseLMDGhost<T, B>
where
T: ClientDB + Sized,
{
@@ -243,7 +243,7 @@ where
}
}
impl<T: ClientDB + Sized, B: BeaconStateTypes> ForkChoice for BitwiseLMDGhost<T, B> {
impl<T: ClientDB + Sized, B: EthSpec> ForkChoice for BitwiseLMDGhost<T, B> {
fn add_block(
&mut self,
block: &BeaconBlock,
+3 -3
View File
@@ -11,7 +11,7 @@ use std::cmp::Ordering;
use std::collections::HashMap;
use std::marker::PhantomData;
use std::sync::Arc;
use types::{BeaconBlock, BeaconState, BeaconStateTypes, ChainSpec, Hash256, Slot, SlotHeight};
use types::{BeaconBlock, BeaconState, ChainSpec, EthSpec, Hash256, Slot, SlotHeight};
//TODO: Pruning - Children
//TODO: Handle Syncing
@@ -54,7 +54,7 @@ pub struct OptimizedLMDGhost<T: ClientDB + Sized, B> {
_phantom: PhantomData<B>,
}
impl<T, B: BeaconStateTypes> OptimizedLMDGhost<T, B>
impl<T, B: EthSpec> OptimizedLMDGhost<T, B>
where
T: ClientDB + Sized,
{
@@ -214,7 +214,7 @@ where
}
}
impl<T: ClientDB + Sized, B: BeaconStateTypes> ForkChoice for OptimizedLMDGhost<T, B> {
impl<T: ClientDB + Sized, B: EthSpec> ForkChoice for OptimizedLMDGhost<T, B> {
fn add_block(
&mut self,
block: &BeaconBlock,
+3 -3
View File
@@ -9,7 +9,7 @@ use log::{debug, trace};
use std::collections::HashMap;
use std::marker::PhantomData;
use std::sync::Arc;
use types::{BeaconBlock, BeaconState, BeaconStateTypes, ChainSpec, Hash256, Slot};
use types::{BeaconBlock, BeaconState, ChainSpec, EthSpec, Hash256, Slot};
//TODO: Pruning and syncing
@@ -26,7 +26,7 @@ pub struct SlowLMDGhost<T: ClientDB + Sized, B> {
_phantom: PhantomData<B>,
}
impl<T, B: BeaconStateTypes> SlowLMDGhost<T, B>
impl<T, B: EthSpec> SlowLMDGhost<T, B>
where
T: ClientDB + Sized,
{
@@ -108,7 +108,7 @@ where
}
}
impl<T: ClientDB + Sized, B: BeaconStateTypes> ForkChoice for SlowLMDGhost<T, B> {
impl<T: ClientDB + Sized, B: EthSpec> ForkChoice for SlowLMDGhost<T, B> {
/// Process when a block is added
fn add_block(
&mut self,
+7 -8
View File
@@ -26,8 +26,7 @@ use std::sync::Arc;
use std::{fs::File, io::prelude::*, path::PathBuf};
use types::test_utils::TestingBeaconStateBuilder;
use types::{
BeaconBlock, BeaconBlockBody, BeaconStateTypes, Eth1Data, FoundationStateTypes, Hash256,
Keypair, Slot,
BeaconBlock, BeaconBlockBody, Eth1Data, EthSpec, FoundationEthSpec, Hash256, Keypair, Slot,
};
use yaml_rust::yaml;
@@ -85,7 +84,7 @@ fn test_yaml_vectors(
let test_cases = load_test_cases_from_yaml(yaml_file_path);
// default vars
let spec = FoundationStateTypes::spec();
let spec = FoundationEthSpec::spec();
let zero_hash = Hash256::zero();
let eth1_data = Eth1Data {
deposit_root: zero_hash.clone(),
@@ -231,26 +230,26 @@ fn setup_inital_state(
// the fork choice instantiation
let fork_choice: Box<ForkChoice> = match fork_choice_algo {
ForkChoiceAlgorithm::OptimizedLMDGhost => {
let f: OptimizedLMDGhost<MemoryDB, FoundationStateTypes> =
let f: OptimizedLMDGhost<MemoryDB, FoundationEthSpec> =
OptimizedLMDGhost::new(block_store.clone(), state_store.clone());
Box::new(f)
}
ForkChoiceAlgorithm::BitwiseLMDGhost => {
let f: BitwiseLMDGhost<MemoryDB, FoundationStateTypes> =
let f: BitwiseLMDGhost<MemoryDB, FoundationEthSpec> =
BitwiseLMDGhost::new(block_store.clone(), state_store.clone());
Box::new(f)
}
ForkChoiceAlgorithm::SlowLMDGhost => {
let f: SlowLMDGhost<MemoryDB, FoundationStateTypes> =
let f: SlowLMDGhost<MemoryDB, FoundationEthSpec> =
SlowLMDGhost::new(block_store.clone(), state_store.clone());
Box::new(f)
}
ForkChoiceAlgorithm::LongestChain => Box::new(LongestChain::new(block_store.clone())),
};
let spec = FoundationStateTypes::spec();
let spec = FoundationEthSpec::spec();
let mut state_builder: TestingBeaconStateBuilder<FoundationStateTypes> =
let mut state_builder: TestingBeaconStateBuilder<FoundationEthSpec> =
TestingBeaconStateBuilder::from_single_keypair(num_validators, &Keypair::random(), &spec);
state_builder.build_caches(&spec).unwrap();
let (state, _keypairs) = state_builder.build();
+22 -25
View File
@@ -16,8 +16,8 @@ use std::collections::{btree_map::Entry, hash_map, BTreeMap, HashMap, HashSet};
use std::marker::PhantomData;
use types::chain_spec::Domain;
use types::{
Attestation, AttestationData, AttesterSlashing, BeaconState, BeaconStateTypes, ChainSpec,
Deposit, Epoch, ProposerSlashing, Transfer, Validator, VoluntaryExit,
Attestation, AttestationData, AttesterSlashing, BeaconState, ChainSpec, Deposit, Epoch,
EthSpec, ProposerSlashing, Transfer, Validator, VoluntaryExit,
};
#[cfg(test)]
@@ -26,7 +26,7 @@ const VERIFY_DEPOSIT_PROOFS: bool = false;
const VERIFY_DEPOSIT_PROOFS: bool = false; // TODO: enable this
#[derive(Default)]
pub struct OperationPool<T: BeaconStateTypes + Default> {
pub struct OperationPool<T: EthSpec + Default> {
/// Map from attestation ID (see below) to vectors of attestations.
attestations: RwLock<HashMap<AttestationId, Vec<Attestation>>>,
/// Map from deposit index to deposit data.
@@ -54,7 +54,7 @@ struct AttestationId(Vec<u8>);
const DOMAIN_BYTES_LEN: usize = 8;
impl AttestationId {
fn from_data<T: BeaconStateTypes>(
fn from_data<T: EthSpec>(
attestation: &AttestationData,
state: &BeaconState<T>,
spec: &ChainSpec,
@@ -65,7 +65,7 @@ impl AttestationId {
AttestationId(bytes)
}
fn compute_domain_bytes<T: BeaconStateTypes>(
fn compute_domain_bytes<T: EthSpec>(
epoch: Epoch,
state: &BeaconState<T>,
spec: &ChainSpec,
@@ -85,7 +85,7 @@ impl AttestationId {
/// receive for including it in a block.
// TODO: this could be optimised with a map from validator index to whether that validator has
// attested in each of the current and previous epochs. Currently quadractic in number of validators.
fn attestation_score<T: BeaconStateTypes>(
fn attestation_score<T: EthSpec>(
attestation: &Attestation,
state: &BeaconState<T>,
spec: &ChainSpec,
@@ -127,7 +127,7 @@ pub enum DepositInsertStatus {
Replaced(Box<Deposit>),
}
impl<T: BeaconStateTypes> OperationPool<T> {
impl<T: EthSpec> OperationPool<T> {
/// Create a new operation pool.
pub fn new() -> Self {
Self::default()
@@ -501,7 +501,7 @@ impl<T: BeaconStateTypes> OperationPool<T> {
///
/// - Their `AttestationData` is equal.
/// - `attestation` does not contain any signatures that `PendingAttestation` does not have.
fn superior_attestation_exists_in_state<T: BeaconStateTypes>(
fn superior_attestation_exists_in_state<T: EthSpec>(
state: &BeaconState<T>,
attestation: &Attestation,
) -> bool {
@@ -539,7 +539,7 @@ where
/// The keys in the map should be validator indices, which will be looked up
/// in the state's validator registry and then passed to `prune_if`.
/// Entries for unknown validators will be kept.
fn prune_validator_hash_map<T, F, B: BeaconStateTypes>(
fn prune_validator_hash_map<T, F, B: EthSpec>(
map: &mut HashMap<u64, T>,
prune_if: F,
finalized_state: &BeaconState<B>,
@@ -666,7 +666,7 @@ mod tests {
}
// Create a random deposit (with a valid proof of posession)
fn make_deposit<T: BeaconStateTypes>(
fn make_deposit<T: EthSpec>(
rng: &mut XorShiftRng,
state: &BeaconState<T>,
spec: &ChainSpec,
@@ -689,7 +689,7 @@ mod tests {
}
// Create `count` dummy deposits with sequential deposit IDs beginning from `start`.
fn dummy_deposits<T: BeaconStateTypes>(
fn dummy_deposits<T: EthSpec>(
rng: &mut XorShiftRng,
state: &BeaconState<T>,
spec: &ChainSpec,
@@ -706,8 +706,8 @@ mod tests {
.collect()
}
fn test_state(rng: &mut XorShiftRng) -> (ChainSpec, BeaconState<FoundationStateTypes>) {
let spec = FoundationStateTypes::spec();
fn test_state(rng: &mut XorShiftRng) -> (ChainSpec, BeaconState<FoundationEthSpec>) {
let spec = FoundationEthSpec::spec();
let mut state = BeaconState::random_for_test(rng);
@@ -722,10 +722,7 @@ mod tests {
/// Create a signed attestation for use in tests.
/// Signed by all validators in `committee[signing_range]` and `committee[extra_signer]`.
fn signed_attestation<
R: std::slice::SliceIndex<[usize], Output = [usize]>,
B: BeaconStateTypes,
>(
fn signed_attestation<R: std::slice::SliceIndex<[usize], Output = [usize]>, B: EthSpec>(
committee: &CrosslinkCommittee,
keypairs: &[Keypair],
signing_range: R,
@@ -757,7 +754,7 @@ mod tests {
}
/// Test state for attestation-related tests.
fn attestation_test_state<B: BeaconStateTypes>(
fn attestation_test_state<B: EthSpec>(
num_committees: usize,
) -> (BeaconState<B>, Vec<Keypair>, ChainSpec) {
let spec = B::spec();
@@ -774,11 +771,11 @@ mod tests {
state_builder.build_caches(&spec).unwrap();
let (state, keypairs) = state_builder.build();
(state, keypairs, FoundationStateTypes::spec())
(state, keypairs, FoundationEthSpec::spec())
}
/// Set the latest crosslink in the state to match the attestation.
fn fake_latest_crosslink<B: BeaconStateTypes>(
fn fake_latest_crosslink<B: EthSpec>(
att: &Attestation,
state: &mut BeaconState<B>,
spec: &ChainSpec,
@@ -792,7 +789,7 @@ mod tests {
#[test]
fn test_attestation_score() {
let (ref mut state, ref keypairs, ref spec) =
attestation_test_state::<FoundationStateTypes>(1);
attestation_test_state::<FoundationEthSpec>(1);
let slot = state.slot - 1;
let committees = state
@@ -824,7 +821,7 @@ mod tests {
#[test]
fn attestation_aggregation_insert_get_prune() {
let (ref mut state, ref keypairs, ref spec) =
attestation_test_state::<FoundationStateTypes>(1);
attestation_test_state::<FoundationEthSpec>(1);
let op_pool = OperationPool::new();
@@ -890,7 +887,7 @@ mod tests {
#[test]
fn attestation_duplicate() {
let (ref mut state, ref keypairs, ref spec) =
attestation_test_state::<FoundationStateTypes>(1);
attestation_test_state::<FoundationEthSpec>(1);
let op_pool = OperationPool::new();
@@ -917,7 +914,7 @@ mod tests {
#[test]
fn attestation_pairwise_overlapping() {
let (ref mut state, ref keypairs, ref spec) =
attestation_test_state::<FoundationStateTypes>(1);
attestation_test_state::<FoundationEthSpec>(1);
let op_pool = OperationPool::new();
@@ -963,7 +960,7 @@ mod tests {
let big_step_size = 4;
let (ref mut state, ref keypairs, ref spec) =
attestation_test_state::<FoundationStateTypes>(big_step_size);
attestation_test_state::<FoundationEthSpec>(big_step_size);
let op_pool = OperationPool::new();
@@ -3,7 +3,7 @@ use types::{BeaconStateError as Error, *};
/// Exit the validator of the given `index`.
///
/// Spec v0.5.1
pub fn exit_validator<T: BeaconStateTypes>(
pub fn exit_validator<T: EthSpec>(
state: &mut BeaconState<T>,
validator_index: usize,
spec: &ChainSpec,
@@ -4,7 +4,7 @@ use types::{BeaconStateError as Error, *};
/// Slash the validator with index ``index``.
///
/// Spec v0.5.1
pub fn slash_validator<T: BeaconStateTypes>(
pub fn slash_validator<T: EthSpec>(
state: &mut BeaconState<T>,
validator_index: usize,
spec: &ChainSpec,
@@ -10,7 +10,7 @@ pub enum GenesisError {
/// Returns the genesis `BeaconState`
///
/// Spec v0.5.1
pub fn get_genesis_state<T: BeaconStateTypes>(
pub fn get_genesis_state<T: EthSpec>(
genesis_validator_deposits: &[Deposit],
genesis_time: u64,
genesis_eth1_data: Eth1Data,
@@ -40,7 +40,7 @@ const VERIFY_DEPOSIT_MERKLE_PROOFS: bool = false;
/// returns an error describing why the block was invalid or how the function failed to execute.
///
/// Spec v0.5.1
pub fn per_block_processing<T: BeaconStateTypes>(
pub fn per_block_processing<T: EthSpec>(
state: &mut BeaconState<T>,
block: &BeaconBlock,
spec: &ChainSpec,
@@ -55,7 +55,7 @@ pub fn per_block_processing<T: BeaconStateTypes>(
/// returns an error describing why the block was invalid or how the function failed to execute.
///
/// Spec v0.5.1
pub fn per_block_processing_without_verifying_block_signature<T: BeaconStateTypes>(
pub fn per_block_processing_without_verifying_block_signature<T: EthSpec>(
state: &mut BeaconState<T>,
block: &BeaconBlock,
spec: &ChainSpec,
@@ -70,7 +70,7 @@ pub fn per_block_processing_without_verifying_block_signature<T: BeaconStateType
/// returns an error describing why the block was invalid or how the function failed to execute.
///
/// Spec v0.5.1
fn per_block_processing_signature_optional<T: BeaconStateTypes>(
fn per_block_processing_signature_optional<T: EthSpec>(
mut state: &mut BeaconState<T>,
block: &BeaconBlock,
should_verify_block_signature: bool,
@@ -100,7 +100,7 @@ fn per_block_processing_signature_optional<T: BeaconStateTypes>(
/// Processes the block header.
///
/// Spec v0.5.1
pub fn process_block_header<T: BeaconStateTypes>(
pub fn process_block_header<T: EthSpec>(
state: &mut BeaconState<T>,
block: &BeaconBlock,
spec: &ChainSpec,
@@ -125,7 +125,7 @@ pub fn process_block_header<T: BeaconStateTypes>(
/// Verifies the signature of a block.
///
/// Spec v0.5.1
pub fn verify_block_signature<T: BeaconStateTypes>(
pub fn verify_block_signature<T: EthSpec>(
state: &BeaconState<T>,
block: &BeaconBlock,
spec: &ChainSpec,
@@ -153,7 +153,7 @@ pub fn verify_block_signature<T: BeaconStateTypes>(
/// `state.latest_randao_mixes`.
///
/// Spec v0.5.1
pub fn process_randao<T: BeaconStateTypes>(
pub fn process_randao<T: EthSpec>(
state: &mut BeaconState<T>,
block: &BeaconBlock,
spec: &ChainSpec,
@@ -184,7 +184,7 @@ pub fn process_randao<T: BeaconStateTypes>(
/// Update the `state.eth1_data_votes` based upon the `eth1_data` provided.
///
/// Spec v0.5.1
pub fn process_eth1_data<T: BeaconStateTypes>(
pub fn process_eth1_data<T: EthSpec>(
state: &mut BeaconState<T>,
eth1_data: &Eth1Data,
) -> Result<(), Error> {
@@ -213,7 +213,7 @@ pub fn process_eth1_data<T: BeaconStateTypes>(
/// an `Err` describing the invalid object or cause of failure.
///
/// Spec v0.5.1
pub fn process_proposer_slashings<T: BeaconStateTypes>(
pub fn process_proposer_slashings<T: EthSpec>(
state: &mut BeaconState<T>,
proposer_slashings: &[ProposerSlashing],
spec: &ChainSpec,
@@ -246,7 +246,7 @@ pub fn process_proposer_slashings<T: BeaconStateTypes>(
/// an `Err` describing the invalid object or cause of failure.
///
/// Spec v0.5.1
pub fn process_attester_slashings<T: BeaconStateTypes>(
pub fn process_attester_slashings<T: EthSpec>(
state: &mut BeaconState<T>,
attester_slashings: &[AttesterSlashing],
spec: &ChainSpec,
@@ -304,7 +304,7 @@ pub fn process_attester_slashings<T: BeaconStateTypes>(
/// an `Err` describing the invalid object or cause of failure.
///
/// Spec v0.5.1
pub fn process_attestations<T: BeaconStateTypes>(
pub fn process_attestations<T: EthSpec>(
state: &mut BeaconState<T>,
attestations: &[Attestation],
spec: &ChainSpec,
@@ -346,7 +346,7 @@ pub fn process_attestations<T: BeaconStateTypes>(
/// an `Err` describing the invalid object or cause of failure.
///
/// Spec v0.5.1
pub fn process_deposits<T: BeaconStateTypes>(
pub fn process_deposits<T: EthSpec>(
state: &mut BeaconState<T>,
deposits: &[Deposit],
spec: &ChainSpec,
@@ -416,7 +416,7 @@ pub fn process_deposits<T: BeaconStateTypes>(
/// an `Err` describing the invalid object or cause of failure.
///
/// Spec v0.5.1
pub fn process_exits<T: BeaconStateTypes>(
pub fn process_exits<T: EthSpec>(
state: &mut BeaconState<T>,
voluntary_exits: &[VoluntaryExit],
spec: &ChainSpec,
@@ -448,7 +448,7 @@ pub fn process_exits<T: BeaconStateTypes>(
/// an `Err` describing the invalid object or cause of failure.
///
/// Spec v0.5.1
pub fn process_transfers<T: BeaconStateTypes>(
pub fn process_transfers<T: EthSpec>(
state: &mut BeaconState<T>,
transfers: &[Transfer],
spec: &ChainSpec,
@@ -9,7 +9,7 @@ use types::*;
/// Returns `Ok(())` if the `Attestation` is valid, otherwise indicates the reason for invalidity.
///
/// Spec v0.5.1
pub fn validate_attestation<T: BeaconStateTypes>(
pub fn validate_attestation<T: EthSpec>(
state: &BeaconState<T>,
attestation: &Attestation,
spec: &ChainSpec,
@@ -18,7 +18,7 @@ pub fn validate_attestation<T: BeaconStateTypes>(
}
/// Like `validate_attestation` but doesn't run checks which may become true in future states.
pub fn validate_attestation_time_independent_only<T: BeaconStateTypes>(
pub fn validate_attestation_time_independent_only<T: EthSpec>(
state: &BeaconState<T>,
attestation: &Attestation,
spec: &ChainSpec,
@@ -32,7 +32,7 @@ pub fn validate_attestation_time_independent_only<T: BeaconStateTypes>(
/// Returns `Ok(())` if the `Attestation` is valid, otherwise indicates the reason for invalidity.
///
/// Spec v0.5.1
pub fn validate_attestation_without_signature<T: BeaconStateTypes>(
pub fn validate_attestation_without_signature<T: EthSpec>(
state: &BeaconState<T>,
attestation: &Attestation,
spec: &ChainSpec,
@@ -45,7 +45,7 @@ pub fn validate_attestation_without_signature<T: BeaconStateTypes>(
///
///
/// Spec v0.5.1
fn validate_attestation_parametric<T: BeaconStateTypes>(
fn validate_attestation_parametric<T: EthSpec>(
state: &BeaconState<T>,
attestation: &Attestation,
spec: &ChainSpec,
@@ -168,7 +168,7 @@ fn validate_attestation_parametric<T: BeaconStateTypes>(
/// match the current (or previous) justified epoch and root from the state.
///
/// Spec v0.5.1
fn verify_justified_epoch_and_root<T: BeaconStateTypes>(
fn verify_justified_epoch_and_root<T: EthSpec>(
attestation: &Attestation,
state: &BeaconState<T>,
spec: &ChainSpec,
@@ -223,7 +223,7 @@ fn verify_justified_epoch_and_root<T: BeaconStateTypes>(
/// - A `validator_index` in `committee` is not in `state.validator_registry`.
///
/// Spec v0.5.1
fn verify_attestation_signature<T: BeaconStateTypes>(
fn verify_attestation_signature<T: EthSpec>(
state: &BeaconState<T>,
committee: &[usize],
a: &Attestation,
@@ -8,7 +8,7 @@ use types::*;
/// Returns `Ok(())` if the `AttesterSlashing` is valid, otherwise indicates the reason for invalidity.
///
/// Spec v0.5.1
pub fn verify_attester_slashing<T: BeaconStateTypes>(
pub fn verify_attester_slashing<T: EthSpec>(
state: &BeaconState<T>,
attester_slashing: &AttesterSlashing,
should_verify_slashable_attestations: bool,
@@ -42,7 +42,7 @@ pub fn verify_attester_slashing<T: BeaconStateTypes>(
/// Returns Ok(indices) if `indices.len() > 0`.
///
/// Spec v0.5.1
pub fn gather_attester_slashing_indices<T: BeaconStateTypes>(
pub fn gather_attester_slashing_indices<T: EthSpec>(
state: &BeaconState<T>,
attester_slashing: &AttesterSlashing,
spec: &ChainSpec,
@@ -57,7 +57,7 @@ pub fn gather_attester_slashing_indices<T: BeaconStateTypes>(
/// Same as `gather_attester_slashing_indices` but allows the caller to specify the criteria
/// for determining whether a given validator should be considered slashed.
pub fn gather_attester_slashing_indices_modular<F, T: BeaconStateTypes>(
pub fn gather_attester_slashing_indices_modular<F, T: EthSpec>(
state: &BeaconState<T>,
attester_slashing: &AttesterSlashing,
is_slashed: F,
@@ -16,7 +16,7 @@ use types::*;
/// Note: this function is incomplete.
///
/// Spec v0.5.1
pub fn verify_deposit<T: BeaconStateTypes>(
pub fn verify_deposit<T: EthSpec>(
state: &BeaconState<T>,
deposit: &Deposit,
verify_merkle_branch: bool,
@@ -47,7 +47,7 @@ pub fn verify_deposit<T: BeaconStateTypes>(
/// Verify that the `Deposit` index is correct.
///
/// Spec v0.5.1
pub fn verify_deposit_index<T: BeaconStateTypes>(
pub fn verify_deposit_index<T: EthSpec>(
state: &BeaconState<T>,
deposit: &Deposit,
) -> Result<(), Error> {
@@ -68,7 +68,7 @@ pub fn verify_deposit_index<T: BeaconStateTypes>(
/// ## Errors
///
/// Errors if the state's `pubkey_cache` is not current.
pub fn get_existing_validator_index<T: BeaconStateTypes>(
pub fn get_existing_validator_index<T: EthSpec>(
state: &BeaconState<T>,
deposit: &Deposit,
) -> Result<Option<u64>, Error> {
@@ -92,7 +92,7 @@ pub fn get_existing_validator_index<T: BeaconStateTypes>(
/// Verify that a deposit is included in the state's eth1 deposit root.
///
/// Spec v0.5.1
fn verify_deposit_merkle_proof<T: BeaconStateTypes>(
fn verify_deposit_merkle_proof<T: EthSpec>(
state: &BeaconState<T>,
deposit: &Deposit,
spec: &ChainSpec,
@@ -8,7 +8,7 @@ use types::*;
/// Returns `Ok(())` if the `Exit` is valid, otherwise indicates the reason for invalidity.
///
/// Spec v0.5.1
pub fn verify_exit<T: BeaconStateTypes>(
pub fn verify_exit<T: EthSpec>(
state: &BeaconState<T>,
exit: &VoluntaryExit,
spec: &ChainSpec,
@@ -17,7 +17,7 @@ pub fn verify_exit<T: BeaconStateTypes>(
}
/// Like `verify_exit` but doesn't run checks which may become true in future states.
pub fn verify_exit_time_independent_only<T: BeaconStateTypes>(
pub fn verify_exit_time_independent_only<T: EthSpec>(
state: &BeaconState<T>,
exit: &VoluntaryExit,
spec: &ChainSpec,
@@ -26,7 +26,7 @@ pub fn verify_exit_time_independent_only<T: BeaconStateTypes>(
}
/// Parametric version of `verify_exit` that skips some checks if `time_independent_only` is true.
fn verify_exit_parametric<T: BeaconStateTypes>(
fn verify_exit_parametric<T: EthSpec>(
state: &BeaconState<T>,
exit: &VoluntaryExit,
spec: &ChainSpec,
@@ -8,7 +8,7 @@ use types::*;
/// Returns `Ok(())` if the `ProposerSlashing` is valid, otherwise indicates the reason for invalidity.
///
/// Spec v0.5.1
pub fn verify_proposer_slashing<T: BeaconStateTypes>(
pub fn verify_proposer_slashing<T: EthSpec>(
proposer_slashing: &ProposerSlashing,
state: &BeaconState<T>,
spec: &ChainSpec,
@@ -11,7 +11,7 @@ use types::*;
/// Returns `Ok(())` if the `SlashableAttestation` is valid, otherwise indicates the reason for invalidity.
///
/// Spec v0.5.1
pub fn verify_slashable_attestation<T: BeaconStateTypes>(
pub fn verify_slashable_attestation<T: EthSpec>(
state: &BeaconState<T>,
slashable_attestation: &SlashableAttestation,
spec: &ChainSpec,
@@ -11,7 +11,7 @@ use types::*;
/// Note: this function is incomplete.
///
/// Spec v0.5.1
pub fn verify_transfer<T: BeaconStateTypes>(
pub fn verify_transfer<T: EthSpec>(
state: &BeaconState<T>,
transfer: &Transfer,
spec: &ChainSpec,
@@ -20,7 +20,7 @@ pub fn verify_transfer<T: BeaconStateTypes>(
}
/// Like `verify_transfer` but doesn't run checks which may become true in future states.
pub fn verify_transfer_time_independent_only<T: BeaconStateTypes>(
pub fn verify_transfer_time_independent_only<T: EthSpec>(
state: &BeaconState<T>,
transfer: &Transfer,
spec: &ChainSpec,
@@ -29,7 +29,7 @@ pub fn verify_transfer_time_independent_only<T: BeaconStateTypes>(
}
/// Parametric version of `verify_transfer` that allows some checks to be skipped.
fn verify_transfer_parametric<T: BeaconStateTypes>(
fn verify_transfer_parametric<T: EthSpec>(
state: &BeaconState<T>,
transfer: &Transfer,
spec: &ChainSpec,
@@ -123,7 +123,7 @@ fn verify_transfer_parametric<T: BeaconStateTypes>(
/// Does not check that the transfer is valid, however checks for overflow in all actions.
///
/// Spec v0.5.1
pub fn execute_transfer<T: BeaconStateTypes>(
pub fn execute_transfer<T: EthSpec>(
state: &mut BeaconState<T>,
transfer: &Transfer,
spec: &ChainSpec,
@@ -33,7 +33,7 @@ pub type WinningRootHashSet = HashMap<u64, WinningRoot>;
/// returned, a state might be "half-processed" and therefore in an invalid state.
///
/// Spec v0.5.1
pub fn per_epoch_processing<T: BeaconStateTypes>(
pub fn per_epoch_processing<T: EthSpec>(
state: &mut BeaconState<T>,
spec: &ChainSpec,
) -> Result<(), Error> {
@@ -90,7 +90,7 @@ pub fn per_epoch_processing<T: BeaconStateTypes>(
/// Maybe resets the eth1 period.
///
/// Spec v0.5.1
pub fn maybe_reset_eth1_period<T: BeaconStateTypes>(state: &mut BeaconState<T>, spec: &ChainSpec) {
pub fn maybe_reset_eth1_period<T: EthSpec>(state: &mut BeaconState<T>, spec: &ChainSpec) {
let next_epoch = state.next_epoch(spec);
let voting_period = spec.epochs_per_eth1_voting_period;
@@ -112,7 +112,7 @@ pub fn maybe_reset_eth1_period<T: BeaconStateTypes>(state: &mut BeaconState<T>,
/// - `previous_justified_epoch`
///
/// Spec v0.5.1
pub fn update_justification_and_finalization<T: BeaconStateTypes>(
pub fn update_justification_and_finalization<T: EthSpec>(
state: &mut BeaconState<T>,
total_balances: &TotalBalances,
spec: &ChainSpec,
@@ -182,7 +182,7 @@ pub fn update_justification_and_finalization<T: BeaconStateTypes>(
/// Also returns a `WinningRootHashSet` for later use during epoch processing.
///
/// Spec v0.5.1
pub fn process_crosslinks<T: BeaconStateTypes>(
pub fn process_crosslinks<T: EthSpec>(
state: &mut BeaconState<T>,
spec: &ChainSpec,
) -> Result<WinningRootHashSet, Error> {
@@ -225,7 +225,7 @@ pub fn process_crosslinks<T: BeaconStateTypes>(
/// Finish up an epoch update.
///
/// Spec v0.5.1
pub fn finish_epoch_update<T: BeaconStateTypes>(
pub fn finish_epoch_update<T: EthSpec>(
state: &mut BeaconState<T>,
spec: &ChainSpec,
) -> Result<(), Error> {
@@ -33,7 +33,7 @@ impl std::ops::AddAssign for Delta {
/// Apply attester and proposer rewards.
///
/// Spec v0.5.1
pub fn apply_rewards<T: BeaconStateTypes>(
pub fn apply_rewards<T: EthSpec>(
state: &mut BeaconState<T>,
validator_statuses: &mut ValidatorStatuses,
winning_root_for_shards: &WinningRootHashSet,
@@ -80,7 +80,7 @@ pub fn apply_rewards<T: BeaconStateTypes>(
/// attestation in the previous epoch.
///
/// Spec v0.5.1
fn get_proposer_deltas<T: BeaconStateTypes>(
fn get_proposer_deltas<T: EthSpec>(
deltas: &mut Vec<Delta>,
state: &mut BeaconState<T>,
validator_statuses: &mut ValidatorStatuses,
@@ -121,7 +121,7 @@ fn get_proposer_deltas<T: BeaconStateTypes>(
/// Apply rewards for participation in attestations during the previous epoch.
///
/// Spec v0.5.1
fn get_justification_and_finalization_deltas<T: BeaconStateTypes>(
fn get_justification_and_finalization_deltas<T: EthSpec>(
deltas: &mut Vec<Delta>,
state: &BeaconState<T>,
validator_statuses: &ValidatorStatuses,
@@ -262,7 +262,7 @@ fn compute_inactivity_leak_delta(
/// Calculate the deltas based upon the winning roots for attestations during the previous epoch.
///
/// Spec v0.5.1
fn get_crosslink_deltas<T: BeaconStateTypes>(
fn get_crosslink_deltas<T: EthSpec>(
deltas: &mut Vec<Delta>,
state: &BeaconState<T>,
validator_statuses: &ValidatorStatuses,
@@ -296,7 +296,7 @@ fn get_crosslink_deltas<T: BeaconStateTypes>(
/// Returns the base reward for some validator.
///
/// Spec v0.5.1
fn get_base_reward<T: BeaconStateTypes>(
fn get_base_reward<T: EthSpec>(
state: &BeaconState<T>,
index: usize,
previous_total_balance: u64,
@@ -313,7 +313,7 @@ fn get_base_reward<T: BeaconStateTypes>(
/// Returns the inactivity penalty for some validator.
///
/// Spec v0.5.1
fn get_inactivity_penalty<T: BeaconStateTypes>(
fn get_inactivity_penalty<T: EthSpec>(
state: &BeaconState<T>,
index: usize,
epochs_since_finality: u64,
@@ -329,6 +329,6 @@ fn get_inactivity_penalty<T: BeaconStateTypes>(
/// Returns the epochs since the last finalized epoch.
///
/// Spec v0.5.1
fn epochs_since_finality<T: BeaconStateTypes>(state: &BeaconState<T>, spec: &ChainSpec) -> Epoch {
fn epochs_since_finality<T: EthSpec>(state: &BeaconState<T>, spec: &ChainSpec) -> Epoch {
state.current_epoch(spec) + 1 - state.finalized_epoch
}
@@ -4,7 +4,7 @@ use types::*;
/// Returns validator indices which participated in the attestation.
///
/// Spec v0.5.1
pub fn get_attestation_participants<T: BeaconStateTypes>(
pub fn get_attestation_participants<T: EthSpec>(
state: &BeaconState<T>,
attestation_data: &AttestationData,
bitfield: &Bitfield,
@@ -6,7 +6,7 @@ use types::*;
/// slot.
///
/// Spec v0.5.1
pub fn inclusion_distance<T: BeaconStateTypes>(
pub fn inclusion_distance<T: EthSpec>(
state: &BeaconState<T>,
attestations: &[&PendingAttestation],
validator_index: usize,
@@ -19,7 +19,7 @@ pub fn inclusion_distance<T: BeaconStateTypes>(
/// Returns the slot of the earliest included attestation for some validator.
///
/// Spec v0.5.1
pub fn inclusion_slot<T: BeaconStateTypes>(
pub fn inclusion_slot<T: EthSpec>(
state: &BeaconState<T>,
attestations: &[&PendingAttestation],
validator_index: usize,
@@ -32,7 +32,7 @@ pub fn inclusion_slot<T: BeaconStateTypes>(
/// Finds the earliest included attestation for some validator.
///
/// Spec v0.5.1
fn earliest_included_attestation<T: BeaconStateTypes>(
fn earliest_included_attestation<T: EthSpec>(
state: &BeaconState<T>,
attestations: &[&PendingAttestation],
validator_index: usize,
@@ -5,7 +5,7 @@ use types::{BeaconStateError as Error, *};
/// ``EJECTION_BALANCE``.
///
/// Spec v0.5.1
pub fn process_ejections<T: BeaconStateTypes>(
pub fn process_ejections<T: EthSpec>(
state: &mut BeaconState<T>,
spec: &ChainSpec,
) -> Result<(), Error> {
@@ -3,7 +3,7 @@ use types::*;
/// Process the exit queue.
///
/// Spec v0.5.1
pub fn process_exit_queue<T: BeaconStateTypes>(state: &mut BeaconState<T>, spec: &ChainSpec) {
pub fn process_exit_queue<T: EthSpec>(state: &mut BeaconState<T>, spec: &ChainSpec) {
let current_epoch = state.current_epoch(spec);
let eligible = |index: usize| {
@@ -32,7 +32,7 @@ pub fn process_exit_queue<T: BeaconStateTypes>(state: &mut BeaconState<T>, spec:
/// Initiate an exit for the validator of the given `index`.
///
/// Spec v0.5.1
fn prepare_validator_for_withdrawal<T: BeaconStateTypes>(
fn prepare_validator_for_withdrawal<T: EthSpec>(
state: &mut BeaconState<T>,
validator_index: usize,
spec: &ChainSpec,
@@ -3,7 +3,7 @@ use types::{BeaconStateError as Error, *};
/// Process slashings.
///
/// Spec v0.5.1
pub fn process_slashings<T: BeaconStateTypes>(
pub fn process_slashings<T: EthSpec>(
state: &mut BeaconState<T>,
current_total_balance: u64,
spec: &ChainSpec,
@@ -8,9 +8,9 @@ use types::*;
fn runs_without_error() {
Builder::from_env(Env::default().default_filter_or("error")).init();
let spec = FewValidatorsStateTypes::spec();
let spec = FewValidatorsEthSpec::spec();
let mut builder: TestingBeaconStateBuilder<FewValidatorsStateTypes> =
let mut builder: TestingBeaconStateBuilder<FewValidatorsEthSpec> =
TestingBeaconStateBuilder::from_deterministic_keypairs(8, &spec);
let target_slot = (spec.genesis_epoch + 4).end_slot(spec.slots_per_epoch);
@@ -5,7 +5,7 @@ use types::*;
/// Peforms a validator registry update, if required.
///
/// Spec v0.5.1
pub fn update_registry_and_shuffling_data<T: BeaconStateTypes>(
pub fn update_registry_and_shuffling_data<T: EthSpec>(
state: &mut BeaconState<T>,
current_total_balance: u64,
spec: &ChainSpec,
@@ -50,7 +50,7 @@ pub fn update_registry_and_shuffling_data<T: BeaconStateTypes>(
/// Returns `true` if the validator registry should be updated during an epoch processing.
///
/// Spec v0.5.1
pub fn should_update_validator_registry<T: BeaconStateTypes>(
pub fn should_update_validator_registry<T: EthSpec>(
state: &BeaconState<T>,
spec: &ChainSpec,
) -> Result<bool, BeaconStateError> {
@@ -79,7 +79,7 @@ pub fn should_update_validator_registry<T: BeaconStateTypes>(
/// Note: Utilizes the cache and will fail if the appropriate cache is not initialized.
///
/// Spec v0.5.1
pub fn update_validator_registry<T: BeaconStateTypes>(
pub fn update_validator_registry<T: EthSpec>(
state: &mut BeaconState<T>,
current_total_balance: u64,
spec: &ChainSpec,
@@ -134,7 +134,7 @@ pub fn update_validator_registry<T: BeaconStateTypes>(
/// Activate the validator of the given ``index``.
///
/// Spec v0.5.1
pub fn activate_validator<T: BeaconStateTypes>(
pub fn activate_validator<T: EthSpec>(
state: &mut BeaconState<T>,
validator_index: usize,
is_genesis: bool,
@@ -161,7 +161,7 @@ impl ValidatorStatuses {
/// - Total balances for the current and previous epochs.
///
/// Spec v0.5.1
pub fn new<T: BeaconStateTypes>(
pub fn new<T: EthSpec>(
state: &BeaconState<T>,
spec: &ChainSpec,
) -> Result<Self, BeaconStateError> {
@@ -199,7 +199,7 @@ impl ValidatorStatuses {
/// `total_balances` fields.
///
/// Spec v0.5.1
pub fn process_attestations<T: BeaconStateTypes>(
pub fn process_attestations<T: EthSpec>(
&mut self,
state: &BeaconState<T>,
spec: &ChainSpec,
@@ -265,7 +265,7 @@ impl ValidatorStatuses {
/// "winning" shard block root for the previous epoch.
///
/// Spec v0.5.1
pub fn process_winning_roots<T: BeaconStateTypes>(
pub fn process_winning_roots<T: EthSpec>(
&mut self,
state: &BeaconState<T>,
winning_roots: &WinningRootHashSet,
@@ -316,7 +316,7 @@ fn is_from_epoch(a: &PendingAttestation, epoch: Epoch, spec: &ChainSpec) -> bool
/// the first slot of the given epoch.
///
/// Spec v0.5.1
fn has_common_epoch_boundary_root<T: BeaconStateTypes>(
fn has_common_epoch_boundary_root<T: EthSpec>(
a: &PendingAttestation,
state: &BeaconState<T>,
epoch: Epoch,
@@ -332,7 +332,7 @@ fn has_common_epoch_boundary_root<T: BeaconStateTypes>(
/// the current slot of the `PendingAttestation`.
///
/// Spec v0.5.1
fn has_common_beacon_block_root<T: BeaconStateTypes>(
fn has_common_beacon_block_root<T: EthSpec>(
a: &PendingAttestation,
state: &BeaconState<T>,
) -> Result<bool, BeaconStateError> {
@@ -35,7 +35,7 @@ impl WinningRoot {
/// per-epoch processing.
///
/// Spec v0.5.1
pub fn winning_root<T: BeaconStateTypes>(
pub fn winning_root<T: EthSpec>(
state: &BeaconState<T>,
shard: u64,
spec: &ChainSpec,
@@ -90,7 +90,7 @@ pub fn winning_root<T: BeaconStateTypes>(
/// Returns `true` if pending attestation `a` is eligible to become a winning root.
///
/// Spec v0.5.1
fn is_eligible_for_winning_root<T: BeaconStateTypes>(
fn is_eligible_for_winning_root<T: EthSpec>(
state: &BeaconState<T>,
a: &PendingAttestation,
shard: Shard,
@@ -105,7 +105,7 @@ fn is_eligible_for_winning_root<T: BeaconStateTypes>(
/// Returns all indices which voted for a given crosslink. Does not contain duplicates.
///
/// Spec v0.5.1
fn get_attesting_validator_indices<T: BeaconStateTypes>(
fn get_attesting_validator_indices<T: EthSpec>(
state: &BeaconState<T>,
shard: u64,
crosslink_data_root: &Hash256,
@@ -11,7 +11,7 @@ pub enum Error {
/// Advances a state forward by one slot, performing per-epoch processing if required.
///
/// Spec v0.5.1
pub fn per_slot_processing<T: BeaconStateTypes>(
pub fn per_slot_processing<T: EthSpec>(
state: &mut BeaconState<T>,
spec: &ChainSpec,
) -> Result<(), Error> {
@@ -26,10 +26,7 @@ pub fn per_slot_processing<T: BeaconStateTypes>(
Ok(())
}
fn cache_state<T: BeaconStateTypes>(
state: &mut BeaconState<T>,
spec: &ChainSpec,
) -> Result<(), Error> {
fn cache_state<T: EthSpec>(state: &mut BeaconState<T>, spec: &ChainSpec) -> Result<(), Error> {
let previous_slot_state_root = state.update_tree_hash_cache()?;
// Note: increment the state slot here to allow use of our `state_root` and `block_root`
+2 -2
View File
@@ -67,7 +67,7 @@ pub enum Error {
)]
pub struct BeaconState<T>
where
T: BeaconStateTypes,
T: EthSpec,
{
// Misc
pub slot: Slot,
@@ -140,7 +140,7 @@ where
pub tree_hash_cache: TreeHashCache,
}
impl<T: BeaconStateTypes> BeaconState<T> {
impl<T: EthSpec> BeaconState<T> {
/// Produce the first state of the Beacon Chain.
///
/// This does not fully build a genesis beacon state, it omits processing of initial validator
@@ -3,7 +3,7 @@ use fixed_len_vec::typenum::{Unsigned, U1024, U8, U8192};
use serde_derive::{Deserialize, Serialize};
use std::fmt::Debug;
pub trait BeaconStateTypes:
pub trait EthSpec:
'static + Default + Sync + Send + Clone + Debug + PartialEq + serde::de::DeserializeOwned
{
type ShardCount: Unsigned + Clone + Sync + Send + Debug + PartialEq;
@@ -54,9 +54,9 @@ pub trait BeaconStateTypes:
///
/// Spec v0.5.1
#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)]
pub struct FoundationStateTypes;
pub struct FoundationEthSpec;
impl BeaconStateTypes for FoundationStateTypes {
impl EthSpec for FoundationEthSpec {
type ShardCount = U1024;
type SlotsPerHistoricalRoot = U8192;
type LatestRandaoMixesLength = U8192;
@@ -68,15 +68,15 @@ impl BeaconStateTypes for FoundationStateTypes {
}
}
pub type FoundationBeaconState = BeaconState<FoundationStateTypes>;
pub type FoundationBeaconState = BeaconState<FoundationEthSpec>;
/// Ethereum Foundation specifications, modified to be suitable for < 1000 validators.
///
/// Spec v0.5.1
#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)]
pub struct FewValidatorsStateTypes;
pub struct FewValidatorsEthSpec;
impl BeaconStateTypes for FewValidatorsStateTypes {
impl EthSpec for FewValidatorsEthSpec {
type ShardCount = U8;
type SlotsPerHistoricalRoot = U8192;
type LatestRandaoMixesLength = U8192;
@@ -88,15 +88,15 @@ impl BeaconStateTypes for FewValidatorsStateTypes {
}
}
pub type FewValidatorsBeaconState = BeaconState<FewValidatorsStateTypes>;
pub type FewValidatorsBeaconState = BeaconState<FewValidatorsEthSpec>;
/// Specifications suitable for a small-scale (< 1000 validators) lighthouse testnet.
///
/// Spec v0.5.1
#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)]
pub struct LighthouseTestnetStateTypes;
pub struct LighthouseTestnetEthSpec;
impl BeaconStateTypes for LighthouseTestnetStateTypes {
impl EthSpec for LighthouseTestnetEthSpec {
type ShardCount = U8;
type SlotsPerHistoricalRoot = U8192;
type LatestRandaoMixesLength = U8192;
@@ -108,4 +108,4 @@ impl BeaconStateTypes for LighthouseTestnetStateTypes {
}
}
pub type LighthouseTestnetBeaconState = BeaconState<LighthouseTestnetStateTypes>;
pub type LighthouseTestnetBeaconState = BeaconState<LighthouseTestnetEthSpec>;
+4 -4
View File
@@ -28,7 +28,7 @@ pub struct EpochCache {
impl EpochCache {
/// Return a new, fully initialized cache.
pub fn initialized<T: BeaconStateTypes>(
pub fn initialized<T: EthSpec>(
state: &BeaconState<T>,
relative_epoch: RelativeEpoch,
spec: &ChainSpec,
@@ -200,7 +200,7 @@ pub struct EpochCrosslinkCommitteesBuilder {
impl EpochCrosslinkCommitteesBuilder {
/// Instantiates a builder that will build for the `state`'s previous epoch.
pub fn for_previous_epoch<T: BeaconStateTypes>(
pub fn for_previous_epoch<T: EthSpec>(
state: &BeaconState<T>,
active_validator_indices: Vec<usize>,
spec: &ChainSpec,
@@ -215,7 +215,7 @@ impl EpochCrosslinkCommitteesBuilder {
}
/// Instantiates a builder that will build for the `state`'s next epoch.
pub fn for_current_epoch<T: BeaconStateTypes>(
pub fn for_current_epoch<T: EthSpec>(
state: &BeaconState<T>,
active_validator_indices: Vec<usize>,
spec: &ChainSpec,
@@ -233,7 +233,7 @@ impl EpochCrosslinkCommitteesBuilder {
///
/// Note: there are two possible epoch builds for the next epoch, one where there is a registry
/// change and one where there is not.
pub fn for_next_epoch<T: BeaconStateTypes>(
pub fn for_next_epoch<T: EthSpec>(
state: &BeaconState<T>,
active_validator_indices: Vec<usize>,
registry_change: bool,
@@ -1,11 +1,11 @@
#![cfg(test)]
use super::*;
use crate::beacon_state::FewValidatorsStateTypes;
use crate::beacon_state::FewValidatorsEthSpec;
use crate::test_utils::*;
use swap_or_not_shuffle::shuffle_list;
fn do_sane_cache_test<T: BeaconStateTypes>(
fn do_sane_cache_test<T: EthSpec>(
state: BeaconState<T>,
epoch: Epoch,
relative_epoch: RelativeEpoch,
@@ -65,10 +65,7 @@ fn do_sane_cache_test<T: BeaconStateTypes>(
}
}
fn setup_sane_cache_test<T: BeaconStateTypes>(
validator_count: usize,
spec: &ChainSpec,
) -> BeaconState<T> {
fn setup_sane_cache_test<T: EthSpec>(validator_count: usize, spec: &ChainSpec) -> BeaconState<T> {
let mut builder =
TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(validator_count, spec);
@@ -102,11 +99,11 @@ fn setup_sane_cache_test<T: BeaconStateTypes>(
#[test]
fn builds_sane_current_epoch_cache() {
let mut spec = FewValidatorsStateTypes::spec();
let mut spec = FewValidatorsEthSpec::spec();
spec.shard_count = 4;
let validator_count = (spec.shard_count * spec.target_committee_size) + 1;
let state: BeaconState<FewValidatorsStateTypes> =
let state: BeaconState<FewValidatorsEthSpec> =
setup_sane_cache_test(validator_count as usize, &spec);
do_sane_cache_test(
@@ -122,11 +119,11 @@ fn builds_sane_current_epoch_cache() {
#[test]
fn builds_sane_previous_epoch_cache() {
let mut spec = FewValidatorsStateTypes::spec();
let mut spec = FewValidatorsEthSpec::spec();
spec.shard_count = 2;
let validator_count = (spec.shard_count * spec.target_committee_size) + 1;
let state: BeaconState<FewValidatorsStateTypes> =
let state: BeaconState<FewValidatorsEthSpec> =
setup_sane_cache_test(validator_count as usize, &spec);
do_sane_cache_test(
@@ -142,11 +139,11 @@ fn builds_sane_previous_epoch_cache() {
#[test]
fn builds_sane_next_without_update_epoch_cache() {
let mut spec = FewValidatorsStateTypes::spec();
let mut spec = FewValidatorsEthSpec::spec();
spec.shard_count = 2;
let validator_count = (spec.shard_count * spec.target_committee_size) + 1;
let mut state: BeaconState<FewValidatorsStateTypes> =
let mut state: BeaconState<FewValidatorsEthSpec> =
setup_sane_cache_test(validator_count as usize, &spec);
state.validator_registry_update_epoch = state.slot.epoch(spec.slots_per_epoch);
+4 -4
View File
@@ -1,6 +1,6 @@
#![cfg(test)]
use super::*;
use crate::beacon_state::FewValidatorsStateTypes;
use crate::beacon_state::FewValidatorsEthSpec;
use crate::test_utils::*;
ssz_tests!(FoundationBeaconState);
@@ -11,7 +11,7 @@ cached_tree_hash_tests!(FoundationBeaconState);
/// 1. Using the cache before it's built fails.
/// 2. Using the cache after it's build passes.
/// 3. Using the cache after it's dropped fails.
fn test_cache_initialization<'a, T: BeaconStateTypes>(
fn test_cache_initialization<'a, T: EthSpec>(
state: &'a mut BeaconState<T>,
relative_epoch: RelativeEpoch,
spec: &ChainSpec,
@@ -46,9 +46,9 @@ fn test_cache_initialization<'a, T: BeaconStateTypes>(
#[test]
fn cache_initialization() {
let spec = FewValidatorsStateTypes::spec();
let spec = FewValidatorsEthSpec::spec();
let builder: TestingBeaconStateBuilder<FewValidatorsStateTypes> =
let builder: TestingBeaconStateBuilder<FewValidatorsEthSpec> =
TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(16, &spec);
let (mut state, _keypairs) = builder.build();
+2 -2
View File
@@ -22,7 +22,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash};
CachedTreeHash,
TestRandom,
)]
pub struct HistoricalBatch<T: BeaconStateTypes> {
pub struct HistoricalBatch<T: EthSpec> {
pub block_roots: FixedLenVec<Hash256, T::SlotsPerHistoricalRoot>,
pub state_roots: FixedLenVec<Hash256, T::SlotsPerHistoricalRoot>,
}
@@ -31,7 +31,7 @@ pub struct HistoricalBatch<T: BeaconStateTypes> {
mod tests {
use super::*;
pub type FoundationHistoricalBatch = HistoricalBatch<FoundationStateTypes>;
pub type FoundationHistoricalBatch = HistoricalBatch<FoundationEthSpec>;
ssz_tests!(FoundationHistoricalBatch);
cached_tree_hash_tests!(FoundationHistoricalBatch);
@@ -12,7 +12,7 @@ pub struct TestingAttestationBuilder {
impl TestingAttestationBuilder {
/// Create a new attestation builder.
pub fn new<T: BeaconStateTypes>(
pub fn new<T: EthSpec>(
state: &BeaconState<T>,
committee: &[usize],
slot: Slot,
@@ -10,7 +10,7 @@ pub struct TestingAttestationDataBuilder {
impl TestingAttestationDataBuilder {
/// Configures a new `AttestationData` which attests to all of the same parameters as the
/// state.
pub fn new<T: BeaconStateTypes>(
pub fn new<T: EthSpec>(
state: &BeaconState<T>,
shard: u64,
slot: Slot,
@@ -82,7 +82,7 @@ impl TestingBeaconBlockBuilder {
///
/// Note: the signed messages of the split committees will be identical -- it would be possible
/// to aggregate these split attestations.
pub fn insert_attestations<T: BeaconStateTypes>(
pub fn insert_attestations<T: EthSpec>(
&mut self,
state: &BeaconState<T>,
secret_keys: &[&SecretKey],
@@ -171,7 +171,7 @@ impl TestingBeaconBlockBuilder {
}
/// Insert a `Valid` deposit into the state.
pub fn insert_deposit<T: BeaconStateTypes>(
pub fn insert_deposit<T: EthSpec>(
&mut self,
amount: u64,
index: u64,
@@ -193,7 +193,7 @@ impl TestingBeaconBlockBuilder {
}
/// Insert a `Valid` exit into the state.
pub fn insert_exit<T: BeaconStateTypes>(
pub fn insert_exit<T: EthSpec>(
&mut self,
state: &BeaconState<T>,
validator_index: u64,
@@ -214,7 +214,7 @@ impl TestingBeaconBlockBuilder {
///
/// Note: this will set the validator to be withdrawable by directly modifying the state
/// validator registry. This _may_ cause problems historic hashes, etc.
pub fn insert_transfer<T: BeaconStateTypes>(
pub fn insert_transfer<T: EthSpec>(
&mut self,
state: &BeaconState<T>,
from: u64,
@@ -25,12 +25,12 @@ pub fn keypairs_path() -> PathBuf {
///
/// This struct should **never be used for production purposes.**
#[derive(Clone)]
pub struct TestingBeaconStateBuilder<T: BeaconStateTypes> {
pub struct TestingBeaconStateBuilder<T: EthSpec> {
state: BeaconState<T>,
keypairs: Vec<Keypair>,
}
impl<T: BeaconStateTypes> TestingBeaconStateBuilder<T> {
impl<T: EthSpec> TestingBeaconStateBuilder<T> {
/// Attempts to load validators from a file in `$HOME/.lighthouse/keypairs.raw_keypairs`. If
/// the file is unavailable, it generates the keys at runtime.
///
@@ -16,7 +16,7 @@ impl TestingPendingAttestationBuilder {
///
/// * The aggregation and custody bitfields will all be empty, they need to be set with
/// `Self::add_committee_participation`.
pub fn new<T: BeaconStateTypes>(
pub fn new<T: EthSpec>(
state: &BeaconState<T>,
shard: u64,
slot: Slot,