Add BeaconBlock genesis

This commit is contained in:
Paul Hauner 2018-12-25 19:25:48 +11:00
parent b978db23fc
commit 3c4541156a
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
5 changed files with 44 additions and 4 deletions

View File

@ -2,6 +2,7 @@
name = "genesis" name = "genesis"
version = "0.1.0" version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"] authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018"
[dependencies] [dependencies]
bls = { path = "../utils/bls" } bls = { path = "../utils/bls" }

View File

@ -0,0 +1,38 @@
use bls::Signature;
use spec::ChainSpec;
use types::{BeaconBlock, BeaconBlockBody};
/// Generate a genesis BeaconBlock.
pub fn genesis_beacon_block(spec: &ChainSpec) -> BeaconBlock {
BeaconBlock {
slot: spec.initial_slot_number,
parent_root: spec.zero_hash,
state_root: spec.zero_hash,
randao_reveal: spec.zero_hash,
candidate_pow_receipt_root: spec.zero_hash,
signature: Signature::default(),
body: BeaconBlockBody {
proposer_slashings: vec![],
casper_slashings: vec![],
attestations: vec![],
deposits: vec![],
exits: vec![],
},
}
}
#[cfg(test)]
mod tests {
use super::*;
// TODO: enhance these tests.
// https://github.com/sigp/lighthouse/issues/117
#[test]
fn test_genesis() {
let spec = ChainSpec::foundation();
// This only checks that the function runs without panic.
genesis_beacon_block(&spec);
}
}

View File

@ -4,6 +4,7 @@ extern crate validator_induction;
extern crate validator_shuffling; extern crate validator_shuffling;
mod beacon_state; mod beacon_state;
mod beacon_block;
pub use beacon_state::{genesis_beacon_state, Error as GenesisError}; pub use crate::beacon_block::genesis_beacon_block;
pub use crate::beacon_state::{genesis_beacon_state, Error as GenesisError};

View File

@ -1,7 +1,7 @@
use super::ssz::{Decodable, DecodeError, Encodable, SszStream}; use super::ssz::{Decodable, DecodeError, Encodable, SszStream};
use super::{BeaconBlockBody, Hash256}; use super::{BeaconBlockBody, Hash256};
use crate::test_utils::TestRandom; use crate::test_utils::TestRandom;
use bls::AggregateSignature; use bls::Signature;
use rand::RngCore; use rand::RngCore;
#[derive(Debug, PartialEq, Clone, Default)] #[derive(Debug, PartialEq, Clone, Default)]
@ -11,7 +11,7 @@ pub struct BeaconBlock {
pub state_root: Hash256, pub state_root: Hash256,
pub randao_reveal: Hash256, pub randao_reveal: Hash256,
pub candidate_pow_receipt_root: Hash256, pub candidate_pow_receipt_root: Hash256,
pub signature: AggregateSignature, pub signature: Signature,
pub body: BeaconBlockBody, pub body: BeaconBlockBody,
} }