Add BeaconBlock genesis
This commit is contained in:
parent
b978db23fc
commit
3c4541156a
@ -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" }
|
||||||
|
38
beacon_chain/genesis/src/beacon_block.rs
Normal file
38
beacon_chain/genesis/src/beacon_block.rs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@ -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};
|
||||||
|
@ -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,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user