Merge branch 'master' into validator-record-update

This commit is contained in:
Grant Wuerker
2018-12-26 20:26:33 -06:00
27 changed files with 432 additions and 234 deletions

View File

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

View File

@@ -2,37 +2,53 @@ use super::candidate_pow_receipt_root_record::CandidatePoWReceiptRootRecord;
use super::crosslink_record::CrosslinkRecord;
use super::fork_data::ForkData;
use super::pending_attestation_record::PendingAttestationRecord;
use super::shard_and_committee::ShardAndCommittee;
use super::shard_committee::ShardCommittee;
use super::shard_reassignment_record::ShardReassignmentRecord;
use super::validator_record::ValidatorRecord;
use super::Hash256;
#[derive(Debug, PartialEq, Default)]
#[derive(Debug, PartialEq, Clone)]
pub struct BeaconState {
pub slot: u64,
// Misc
pub slot: u64,
pub genesis_time: u64,
pub fork_data: ForkData,
// Validator registry
pub validator_registry: Vec<ValidatorRecord>,
pub validator_balances: Vec<u64>,
pub validator_registry_latest_change_slot: u64,
pub validator_registry_exit_count: u64,
pub validator_registry_delta_chain_tip: Hash256,
pub latest_randao_mixes: Vec<Hash256>,
pub latest_vdf_outputs: Vec<Hash256>,
pub shard_committees_at_slots: Vec<Vec<ShardAndCommittee>>,
// Randomness and committees
pub randao_mix: Hash256,
pub next_seed: Hash256,
pub shard_committees_at_slots: Vec<Vec<ShardCommittee>>,
pub persistent_committees: Vec<Vec<u32>>,
pub persistent_committee_reassignments: Vec<ShardReassignmentRecord>,
// Finality
pub previous_justified_slot: u64,
pub justified_slot: u64,
pub justification_bitfield: u64,
pub finalized_slot: u64,
// Recent state
pub latest_crosslinks: Vec<CrosslinkRecord>,
// TODO: remove this, it's no longer in the spec
pub latest_state_recalculation_slot: u64,
pub latest_block_roots: Vec<Hash256>,
pub latest_penalized_exit_balances: Vec<u64>,
pub latest_attestations: Vec<PendingAttestationRecord>,
pub batched_block_roots: Vec<Hash256>,
// PoW receipt root
pub processed_pow_receipt_root: Hash256,
pub candidate_pow_receipt_roots: Vec<CandidatePoWReceiptRootRecord>,
}
impl BeaconState {
pub fn canonical_root(&self) -> Hash256 {
// TODO: implement tree hashing.
// https://github.com/sigp/lighthouse/issues/70
Hash256::zero()
}
}

View File

@@ -1,6 +1,6 @@
use super::Hash256;
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct CandidatePoWReceiptRootRecord {
pub candidate_pow_receipt_root: Hash256,
pub votes: u64,

View File

@@ -3,7 +3,7 @@ use super::Hash256;
#[derive(Clone, Debug, PartialEq)]
pub struct CrosslinkRecord {
pub slot: u64,
pub shard_block_hash: Hash256,
pub shard_block_root: Hash256,
}
impl CrosslinkRecord {
@@ -11,7 +11,7 @@ impl CrosslinkRecord {
pub fn zero() -> Self {
Self {
slot: 0,
shard_block_hash: Hash256::zero(),
shard_block_root: Hash256::zero(),
}
}
}

View File

@@ -1,5 +1,5 @@
use super::crosslink_record::CrosslinkRecord;
use super::shard_and_committee::ShardAndCommittee;
use super::shard_committee::ShardCommittee;
use super::validator_record::ValidatorRecord;
use super::Hash256;
@@ -12,7 +12,7 @@ pub struct CrystallizedState {
pub last_finalized_slot: u64,
pub last_justified_slot: u64,
pub justified_streak: u64,
pub shard_and_committee_for_slots: Vec<Vec<ShardAndCommittee>>,
pub shard_and_committee_for_slots: Vec<Vec<ShardCommittee>>,
pub deposits_penalized_in_period: Vec<u32>,
pub validator_set_delta_hash_chain: Hash256,
pub pre_fork_version: u32,

View File

@@ -24,7 +24,7 @@ pub mod fork_data;
pub mod pending_attestation_record;
pub mod proposal_signed_data;
pub mod proposer_slashing;
pub mod shard_and_committee;
pub mod shard_committee;
pub mod shard_reassignment_record;
pub mod special_record;
pub mod slashable_vote_data;
@@ -52,7 +52,7 @@ pub use crate::pending_attestation_record::PendingAttestationRecord;
pub use crate::proposal_signed_data::ProposalSignedData;
pub use crate::proposer_slashing::ProposerSlashing;
pub use crate::slashable_vote_data::SlashableVoteData;
pub use crate::shard_and_committee::ShardAndCommittee;
pub use crate::shard_committee::ShardCommittee;
pub use crate::special_record::{SpecialRecord, SpecialRecordKind};
pub use crate::validator_record::{ValidatorRecord, ValidatorStatus};

View File

@@ -1,10 +1,10 @@
#[derive(Clone, Debug, PartialEq)]
pub struct ShardAndCommittee {
pub struct ShardCommittee {
pub shard: u16,
pub committee: Vec<usize>,
}
impl ShardAndCommittee {
impl ShardCommittee {
/// Returns a new instance where the `shard_id` is zero and the
/// committee is an empty vector.
pub fn zero() -> Self {
@@ -21,7 +21,7 @@ mod tests {
#[test]
fn test_shard_and_committee_zero() {
let s = ShardAndCommittee::zero();
let s = ShardCommittee::zero();
assert_eq!(s.shard, 0);
assert_eq!(s.committee.len(), 0);
}

View File

@@ -1,4 +1,4 @@
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct ShardReassignmentRecord {
pub validator_index: u64,
pub shard: u64,

View File

@@ -0,0 +1,26 @@
use super::{Address, Hash256};
use bls::{create_proof_of_possession, Keypair, PublicKey, Signature};
/// The information gathered from the PoW chain validator registration function.
#[derive(Debug, Clone, PartialEq)]
pub struct ValidatorRegistration {
pub pubkey: PublicKey,
pub withdrawal_shard: u64,
pub withdrawal_address: Address,
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),
}
}
}