Added/modified types and constants according to specs

This commit is contained in:
Kirk Baird
2019-01-16 10:39:02 +11:00
parent 0b47b81a6c
commit 8dec3c1dc7
9 changed files with 160 additions and 48 deletions

View File

@@ -1,17 +1,15 @@
use bls::{Signature, BLS_AGG_SIG_BYTE_SIZE};
use spec::ChainSpec;
use ssz::{encode::encode_length, Decodable, LENGTH_BYTES};
use types::{BeaconBlock, BeaconBlockBody, Hash256};
/// Generate a genesis BeaconBlock.
pub fn genesis_beacon_block(state_root: Hash256, spec: &ChainSpec) -> BeaconBlock {
BeaconBlock {
slot: spec.initial_slot_number,
slot: spec.genesis_slot_number,
parent_root: spec.zero_hash,
state_root,
randao_reveal: spec.zero_hash,
candidate_pow_receipt_root: spec.zero_hash,
signature: genesis_signature(),
signature: spec.empty_signature.clone(),
body: BeaconBlockBody {
proposer_slashings: vec![],
casper_slashings: vec![],
@@ -25,19 +23,11 @@ pub fn genesis_beacon_block(state_root: Hash256, spec: &ChainSpec) -> BeaconBloc
}
}
fn genesis_signature() -> Signature {
let mut bytes = encode_length(BLS_AGG_SIG_BYTE_SIZE, LENGTH_BYTES);
bytes.append(&mut vec![0; BLS_AGG_SIG_BYTE_SIZE]);
let (signature, _) = match Signature::ssz_decode(&bytes, 0) {
Ok(sig) => sig,
Err(_) => unreachable!(),
};
signature
}
#[cfg(test)]
mod tests {
use super::*;
use bls::{Signature};
#[test]
fn test_genesis() {
@@ -101,5 +91,6 @@ mod tests {
for item in raw_sig_bytes.iter() {
assert!(*item == 0);
}
assert_eq!(genesis_block.signature, Signature::empty_sig());
}
}

View File

@@ -21,7 +21,7 @@ pub fn genesis_beacon_state(spec: &ChainSpec) -> Result<BeaconState, Error> {
};
let initial_crosslink = CrosslinkRecord {
slot: spec.initial_slot_number,
slot: spec.genesis_slot_number,
shard_block_root: spec.zero_hash,
};
@@ -29,19 +29,19 @@ pub fn genesis_beacon_state(spec: &ChainSpec) -> Result<BeaconState, Error> {
/*
* Misc
*/
slot: spec.initial_slot_number,
slot: spec.genesis_slot_number,
genesis_time: spec.genesis_time,
fork_data: ForkData {
pre_fork_version: spec.initial_fork_version,
post_fork_version: spec.initial_fork_version,
fork_slot: spec.initial_slot_number,
pre_fork_version: spec.genesis_fork_version,
post_fork_version: spec.genesis_fork_version,
fork_slot: spec.genesis_slot_number,
},
/*
* Validator registry
*/
validator_registry: spec.initial_validators.clone(),
validator_balances: spec.initial_balances.clone(),
validator_registry_latest_change_slot: spec.initial_slot_number,
validator_registry_latest_change_slot: spec.genesis_slot_number,
validator_registry_exit_count: 0,
validator_registry_delta_chain_tip: spec.zero_hash,
/*
@@ -52,7 +52,12 @@ pub fn genesis_beacon_state(spec: &ChainSpec) -> Result<BeaconState, Error> {
spec.zero_hash;
(spec.latest_randao_mixes_length / spec.epoch_length) as usize
],
shard_committees_at_slots: vec![],
previous_epoch_start_shard: spec.genesis_start_shard,
current_epoch_start_shard: spec.genesis_start_shard,
previous_epoch_calculation_slot: spec.genesis_slot_number,
current_epoch_calculation_slot: spec.genesis_slot_number,
previous_epoch_randao_mix: spec.zero_hash,
current_epoch_randao_mix: spec.zero_hash,
/*
* Custody challenges
*/
@@ -60,10 +65,10 @@ pub fn genesis_beacon_state(spec: &ChainSpec) -> Result<BeaconState, Error> {
/*
* Finality
*/
previous_justified_slot: spec.initial_slot_number,
justified_slot: spec.initial_slot_number,
previous_justified_slot: spec.genesis_slot_number,
justified_slot: spec.genesis_slot_number,
justification_bitfield: 0,
finalized_slot: spec.initial_slot_number,
finalized_slot: spec.genesis_slot_number,
/*
* Recent state
*/