Finish genesis for BeaconChain

This commit is contained in:
Paul Hauner
2018-10-22 06:48:44 +11:00
parent 41bfb7a0e2
commit 42e774cb48
9 changed files with 65 additions and 41 deletions

View File

@@ -4,6 +4,7 @@ use super::{
SpecialRecord,
};
#[derive(Debug, PartialEq)]
pub struct ActiveState {
pub pending_attestations: Vec<AttestationRecord>,
pub pending_specials: Vec<SpecialRecord>,

View File

@@ -1,8 +1,12 @@
use super::ValidatorRegistration;
#[derive(Debug, Clone, PartialEq)]
pub struct ChainConfig {
pub cycle_length: u8,
pub shard_count: u16,
pub min_committee_size: u64,
pub genesis_time: u64,
pub initial_validators: Vec<ValidatorRegistration>,
}
/*
@@ -17,6 +21,7 @@ impl ChainConfig {
shard_count: 1024,
min_committee_size: 128,
genesis_time: GENESIS_TIME, // arbitrary
initial_validators: vec![],
}
}
@@ -41,6 +46,7 @@ impl ChainConfig {
shard_count: 2,
min_committee_size: 2,
genesis_time: GENESIS_TIME, // arbitrary
initial_validators: vec![],
}
}
}

View File

@@ -1,6 +1,6 @@
use super::Hash256;
#[derive(Clone)]
#[derive(Clone, Debug, PartialEq)]
pub struct CrosslinkRecord {
pub recently_changed: bool,
pub slot: u64,

View File

@@ -4,6 +4,7 @@ use super::shard_and_committee::ShardAndCommittee;
use super::Hash256;
#[derive(Debug, PartialEq)]
pub struct CrystallizedState {
pub validator_set_change_slot: u64,
pub validators: Vec<ValidatorRecord>,

View File

@@ -1,4 +1,4 @@
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
pub struct ShardAndCommittee {
pub shard_id: u16,
pub committee: Vec<usize>

View File

@@ -1,4 +1,5 @@
use bls::{
create_proof_of_possession,
Keypair,
PublicKey,
Signature,
@@ -18,3 +19,17 @@ pub struct ValidatorRegistration {
pub randao_commitment: Hash256,
pub proof_of_possession: Signature,
}
impl ValidatorRegistration {
pub fn random() -> Self {
let keypair = Keypair::random();
Self {
pubkey: keypair.pk.clone(),
withdrawal_shard: 0,
withdrawal_address: Address::random(),
randao_commitment: Hash256::random(),
proof_of_possession: create_proof_of_possession(&keypair),
}
}
}