From 073e3529e9f7066f6aede86aa49f0905ee395916 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Sat, 20 Oct 2018 16:34:08 +1100 Subject: [PATCH] Add half-finished chain code --- Cargo.toml | 1 + beacon_chain/chain/Cargo.toml | 9 +++++ beacon_chain/chain/src/lib.rs | 67 +++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 beacon_chain/chain/Cargo.toml create mode 100644 beacon_chain/chain/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 0ac7299298..57f0feb472 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ name = "lighthouse" [workspace] members = [ + "beacon_chain/chain", "beacon_chain/types", "beacon_chain/utils/bls", "beacon_chain/utils/boolean-bitfield", diff --git a/beacon_chain/chain/Cargo.toml b/beacon_chain/chain/Cargo.toml new file mode 100644 index 0000000000..ab328dc268 --- /dev/null +++ b/beacon_chain/chain/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "chain" +version = "0.1.0" +authors = ["Paul Hauner "] + +[dependencies] +types = { path = "../types" } +validator_induction = { path = "../validator_induction" } +validator_shuffling = { path = "../validator_shuffling" } diff --git a/beacon_chain/chain/src/lib.rs b/beacon_chain/chain/src/lib.rs new file mode 100644 index 0000000000..cff48c986e --- /dev/null +++ b/beacon_chain/chain/src/lib.rs @@ -0,0 +1,67 @@ +extern crate types; +extern crate validator_induction; +extern crate validator_shuffling; + +use types::{ + ActiveState, + ChainConfig, + CrystallizedState, + ValidatorRecord, +}; +use validator_induction::{ + ValidatorInductor, + ValidatorRegistration, +}; +use validator_shuffling::shard_and_committees_for_cycle; + +pub struct ChainHead<'a> { + act_state: ActiveState, + cry_state: &'a CrystallizedState, + config: ChainConfig, +} + +impl<'a> ChainHead<'a> { + pub fn genesis( + initial_validator_entries: &[ValidatorRegistration], + config: ChainConfig) + -> Self + { + /* + * Parse the ValidatorRegistrations into ValidatorRecords and induct them. + * + * Ignore any records which fail proof-of-possession or are invalid. + */ + let validators = { + let mut validators = vec![]; + let inductor = ValidatorInductor { + current_slot: 0, + shard_count: config.shard_count, + validators: &mut validators, + empty_validator_start: 0, + }; + for registration in initial_validator_entries { + let _ = inductor.induct(®istration); + }; + validators + }; + + /* + * Delegate the validators to shards. + */ + let shard_and_committees = shard_and_committees_for_cycle( + &vec![0; 32], + &validators, + 0, + &config); + + //TODO: complete this + } +} + +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +}