Add half-finished chain code
This commit is contained in:
parent
606c32950d
commit
073e3529e9
@ -32,6 +32,7 @@ name = "lighthouse"
|
||||
|
||||
[workspace]
|
||||
members = [
|
||||
"beacon_chain/chain",
|
||||
"beacon_chain/types",
|
||||
"beacon_chain/utils/bls",
|
||||
"beacon_chain/utils/boolean-bitfield",
|
||||
|
9
beacon_chain/chain/Cargo.toml
Normal file
9
beacon_chain/chain/Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "chain"
|
||||
version = "0.1.0"
|
||||
authors = ["Paul Hauner <paul@paulhauner.com>"]
|
||||
|
||||
[dependencies]
|
||||
types = { path = "../types" }
|
||||
validator_induction = { path = "../validator_induction" }
|
||||
validator_shuffling = { path = "../validator_shuffling" }
|
67
beacon_chain/chain/src/lib.rs
Normal file
67
beacon_chain/chain/src/lib.rs
Normal file
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user