Split BeaconState::genesis into two functions

This allows us to build a genesis state without inducting all the
validators. This will be a signigicant speed up for tests as we can
avoid generating keypairs and checking proof-of-possessions.
This commit is contained in:
Paul Hauner 2019-02-26 20:16:14 +13:00
parent d140563545
commit f82c4268e2
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C

View File

@ -117,19 +117,18 @@ pub struct BeaconState {
impl BeaconState {
/// Produce the first state of the Beacon Chain.
pub fn genesis(
pub fn genesis_without_validators(
genesis_time: u64,
initial_validator_deposits: Vec<Deposit>,
latest_eth1_data: Eth1Data,
spec: &ChainSpec,
) -> Result<BeaconState, Error> {
debug!("Creating genesis state.");
debug!("Creating genesis state (without validator processing).");
let initial_crosslink = Crosslink {
epoch: spec.genesis_epoch,
shard_block_root: spec.zero_hash,
};
let mut genesis_state = BeaconState {
Ok(BeaconState {
/*
* Misc
*/
@ -188,7 +187,19 @@ impl BeaconState {
*/
cache_index_offset: 0,
caches: vec![EpochCache::empty(); CACHED_EPOCHS],
};
})
}
/// Produce the first state of the Beacon Chain.
pub fn genesis(
genesis_time: u64,
initial_validator_deposits: Vec<Deposit>,
latest_eth1_data: Eth1Data,
spec: &ChainSpec,
) -> Result<BeaconState, Error> {
let mut genesis_state =
BeaconState::genesis_without_validators(genesis_time, latest_eth1_data, spec)?;
trace!("Processing genesis deposits...");
let deposit_data = initial_validator_deposits
.iter()