Remove unused errors from genesis crate
This commit is contained in:
parent
cb85fbcdb2
commit
dcb507ca18
@ -1,30 +1,12 @@
|
|||||||
use types::{BeaconState, ChainSpec, Crosslink, Fork};
|
use types::{BeaconState, ChainSpec, Crosslink, Fork};
|
||||||
use validator_shuffling::{shard_and_committees_for_cycle, ValidatorAssignmentError};
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
pub enum Error {
|
|
||||||
NoValidators,
|
|
||||||
ValidationAssignmentError(ValidatorAssignmentError),
|
|
||||||
NotImplemented,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn genesis_beacon_state(spec: &ChainSpec) -> Result<BeaconState, Error> {
|
|
||||||
/*
|
|
||||||
* Assign the validators to shards, using all zeros as the seed.
|
|
||||||
*/
|
|
||||||
let _shard_and_committee_for_slots = {
|
|
||||||
let mut a = shard_and_committees_for_cycle(&[0; 32], &spec.initial_validators, 0, &spec)?;
|
|
||||||
let mut b = a.clone();
|
|
||||||
a.append(&mut b);
|
|
||||||
a
|
|
||||||
};
|
|
||||||
|
|
||||||
|
pub fn genesis_beacon_state(spec: &ChainSpec) -> BeaconState {
|
||||||
let initial_crosslink = Crosslink {
|
let initial_crosslink = Crosslink {
|
||||||
slot: spec.genesis_slot,
|
slot: spec.genesis_slot,
|
||||||
shard_block_root: spec.zero_hash,
|
shard_block_root: spec.zero_hash,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(BeaconState {
|
BeaconState {
|
||||||
/*
|
/*
|
||||||
* Misc
|
* Misc
|
||||||
*/
|
*/
|
||||||
@ -81,12 +63,6 @@ pub fn genesis_beacon_state(spec: &ChainSpec) -> Result<BeaconState, Error> {
|
|||||||
*/
|
*/
|
||||||
latest_eth1_data: spec.intial_eth1_data.clone(),
|
latest_eth1_data: spec.intial_eth1_data.clone(),
|
||||||
eth1_data_votes: vec![],
|
eth1_data_votes: vec![],
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<ValidatorAssignmentError> for Error {
|
|
||||||
fn from(e: ValidatorAssignmentError) -> Error {
|
|
||||||
Error::ValidationAssignmentError(e)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +75,7 @@ mod tests {
|
|||||||
fn test_genesis_state() {
|
fn test_genesis_state() {
|
||||||
let spec = ChainSpec::foundation();
|
let spec = ChainSpec::foundation();
|
||||||
|
|
||||||
let state = genesis_beacon_state(&spec).unwrap();
|
let state = genesis_beacon_state(&spec);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
state.validator_registry.len(),
|
state.validator_registry.len(),
|
||||||
@ -111,7 +87,7 @@ mod tests {
|
|||||||
fn test_genesis_state_misc() {
|
fn test_genesis_state_misc() {
|
||||||
let spec = ChainSpec::foundation();
|
let spec = ChainSpec::foundation();
|
||||||
|
|
||||||
let state = genesis_beacon_state(&spec).unwrap();
|
let state = genesis_beacon_state(&spec);
|
||||||
|
|
||||||
assert_eq!(state.slot, 0);
|
assert_eq!(state.slot, 0);
|
||||||
assert_eq!(state.genesis_time, spec.genesis_time);
|
assert_eq!(state.genesis_time, spec.genesis_time);
|
||||||
@ -124,7 +100,7 @@ mod tests {
|
|||||||
fn test_genesis_state_validators() {
|
fn test_genesis_state_validators() {
|
||||||
let spec = ChainSpec::foundation();
|
let spec = ChainSpec::foundation();
|
||||||
|
|
||||||
let state = genesis_beacon_state(&spec).unwrap();
|
let state = genesis_beacon_state(&spec);
|
||||||
|
|
||||||
assert_eq!(state.validator_registry, spec.initial_validators);
|
assert_eq!(state.validator_registry, spec.initial_validators);
|
||||||
assert_eq!(state.validator_balances, spec.initial_balances);
|
assert_eq!(state.validator_balances, spec.initial_balances);
|
||||||
@ -137,7 +113,7 @@ mod tests {
|
|||||||
fn test_genesis_state_randomness_committees() {
|
fn test_genesis_state_randomness_committees() {
|
||||||
let spec = ChainSpec::foundation();
|
let spec = ChainSpec::foundation();
|
||||||
|
|
||||||
let state = genesis_beacon_state(&spec).unwrap();
|
let state = genesis_beacon_state(&spec);
|
||||||
|
|
||||||
// Array of size 8,192 each being zero_hash
|
// Array of size 8,192 each being zero_hash
|
||||||
assert_eq!(state.latest_randao_mixes.len(), 8_192);
|
assert_eq!(state.latest_randao_mixes.len(), 8_192);
|
||||||
@ -166,7 +142,7 @@ mod tests {
|
|||||||
fn test_genesis_state_finanilty() {
|
fn test_genesis_state_finanilty() {
|
||||||
let spec = ChainSpec::foundation();
|
let spec = ChainSpec::foundation();
|
||||||
|
|
||||||
let state = genesis_beacon_state(&spec).unwrap();
|
let state = genesis_beacon_state(&spec);
|
||||||
|
|
||||||
assert_eq!(state.previous_justified_slot, 0);
|
assert_eq!(state.previous_justified_slot, 0);
|
||||||
assert_eq!(state.justified_slot, 0);
|
assert_eq!(state.justified_slot, 0);
|
||||||
@ -178,7 +154,7 @@ mod tests {
|
|||||||
fn test_genesis_state_recent_state() {
|
fn test_genesis_state_recent_state() {
|
||||||
let spec = ChainSpec::foundation();
|
let spec = ChainSpec::foundation();
|
||||||
|
|
||||||
let state = genesis_beacon_state(&spec).unwrap();
|
let state = genesis_beacon_state(&spec);
|
||||||
|
|
||||||
// Test latest_crosslinks
|
// Test latest_crosslinks
|
||||||
assert_eq!(state.latest_crosslinks.len(), 1_024);
|
assert_eq!(state.latest_crosslinks.len(), 1_024);
|
||||||
@ -210,7 +186,7 @@ mod tests {
|
|||||||
fn test_genesis_state_deposit_root() {
|
fn test_genesis_state_deposit_root() {
|
||||||
let spec = ChainSpec::foundation();
|
let spec = ChainSpec::foundation();
|
||||||
|
|
||||||
let state = genesis_beacon_state(&spec).unwrap();
|
let state = genesis_beacon_state(&spec);
|
||||||
|
|
||||||
assert_eq!(&state.latest_eth1_data, &spec.intial_eth1_data);
|
assert_eq!(&state.latest_eth1_data, &spec.intial_eth1_data);
|
||||||
assert!(state.eth1_data_votes.is_empty());
|
assert!(state.eth1_data_votes.is_empty());
|
||||||
|
@ -2,4 +2,4 @@ mod beacon_block;
|
|||||||
mod beacon_state;
|
mod beacon_state;
|
||||||
|
|
||||||
pub use crate::beacon_block::genesis_beacon_block;
|
pub use crate::beacon_block::genesis_beacon_block;
|
||||||
pub use crate::beacon_state::{genesis_beacon_state, Error as GenesisError};
|
pub use crate::beacon_state::genesis_beacon_state;
|
||||||
|
Loading…
Reference in New Issue
Block a user