Merge pull request #116 from g-r-a-n-t/validator-record-update

Validator record update
This commit is contained in:
Paul Hauner
2019-01-09 09:57:24 +11:00
committed by GitHub
12 changed files with 227 additions and 297 deletions

View File

@@ -10,7 +10,7 @@ use crate::test_utils::TestRandom;
use rand::RngCore;
use ssz::{Decodable, DecodeError, Encodable, SszStream};
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, PartialEq, Clone, Default)]
pub struct BeaconState {
// Misc
pub slot: u64,
@@ -19,6 +19,7 @@ pub struct BeaconState {
// 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,
@@ -61,6 +62,7 @@ impl Encodable for BeaconState {
s.append(&self.genesis_time);
s.append(&self.fork_data);
s.append(&self.validator_registry);
s.append(&self.validator_balances);
s.append(&self.validator_registry_latest_change_slot);
s.append(&self.validator_registry_exit_count);
s.append(&self.validator_registry_delta_chain_tip);
@@ -88,6 +90,7 @@ impl Decodable for BeaconState {
let (genesis_time, i) = <_>::ssz_decode(bytes, i)?;
let (fork_data, i) = <_>::ssz_decode(bytes, i)?;
let (validator_registry, i) = <_>::ssz_decode(bytes, i)?;
let (validator_balances, i) = <_>::ssz_decode(bytes, i)?;
let (validator_registry_latest_change_slot, i) = <_>::ssz_decode(bytes, i)?;
let (validator_registry_exit_count, i) = <_>::ssz_decode(bytes, i)?;
let (validator_registry_delta_chain_tip, i) = <_>::ssz_decode(bytes, i)?;
@@ -113,6 +116,7 @@ impl Decodable for BeaconState {
genesis_time,
fork_data,
validator_registry,
validator_balances,
validator_registry_latest_change_slot,
validator_registry_exit_count,
validator_registry_delta_chain_tip,
@@ -144,6 +148,7 @@ impl<T: RngCore> TestRandom<T> for BeaconState {
genesis_time: <_>::random_for_test(rng),
fork_data: <_>::random_for_test(rng),
validator_registry: <_>::random_for_test(rng),
validator_balances: <_>::random_for_test(rng),
validator_registry_latest_change_slot: <_>::random_for_test(rng),
validator_registry_exit_count: <_>::random_for_test(rng),
validator_registry_delta_chain_tip: <_>::random_for_test(rng),

View File

@@ -9,6 +9,7 @@ pub struct DepositInput {
pub pubkey: PublicKey,
pub withdrawal_credentials: Hash256,
pub randao_commitment: Hash256,
pub custody_commitment: Hash256,
pub proof_of_possession: Signature,
}
@@ -17,6 +18,7 @@ impl Encodable for DepositInput {
s.append(&self.pubkey);
s.append(&self.withdrawal_credentials);
s.append(&self.randao_commitment);
s.append(&self.custody_commitment);
s.append(&self.proof_of_possession);
}
}
@@ -26,6 +28,7 @@ impl Decodable for DepositInput {
let (pubkey, i) = <_>::ssz_decode(bytes, i)?;
let (withdrawal_credentials, i) = <_>::ssz_decode(bytes, i)?;
let (randao_commitment, i) = <_>::ssz_decode(bytes, i)?;
let (custody_commitment, i) = <_>::ssz_decode(bytes, i)?;
let (proof_of_possession, i) = <_>::ssz_decode(bytes, i)?;
Ok((
@@ -33,6 +36,7 @@ impl Decodable for DepositInput {
pubkey,
withdrawal_credentials,
randao_commitment,
custody_commitment,
proof_of_possession,
},
i,
@@ -46,6 +50,7 @@ impl<T: RngCore> TestRandom<T> for DepositInput {
pubkey: <_>::random_for_test(rng),
withdrawal_credentials: <_>::random_for_test(rng),
randao_commitment: <_>::random_for_test(rng),
custody_commitment: <_>::random_for_test(rng),
proof_of_possession: <_>::random_for_test(rng),
}
}

View File

@@ -2,7 +2,7 @@ use super::ssz::{Decodable, DecodeError, Encodable, SszStream};
use crate::test_utils::TestRandom;
use rand::RngCore;
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ForkData {
pub pre_fork_version: u64,
pub post_fork_version: u64,

View File

@@ -26,7 +26,6 @@ pub mod shard_reassignment_record;
pub mod special_record;
pub mod slashable_vote_data;
pub mod validator_record;
pub mod validator_registration;
use self::ethereum_types::{H160, H256, U256};
use std::collections::HashMap;
@@ -50,7 +49,6 @@ pub use crate::slashable_vote_data::SlashableVoteData;
pub use crate::shard_committee::ShardCommittee;
pub use crate::special_record::{SpecialRecord, SpecialRecordKind};
pub use crate::validator_record::{ValidatorRecord, ValidatorStatus};
pub use crate::validator_registration::ValidatorRegistration;
pub type Hash256 = H256;
pub type Address = H160;

View File

@@ -1,5 +1,5 @@
use super::bls::PublicKey;
use super::{Address, Hash256};
use super::{Hash256};
use crate::test_utils::TestRandom;
use rand::RngCore;
use ssz::{Decodable, DecodeError, Encodable, SszStream};
@@ -32,13 +32,15 @@ impl convert::From<u8> for ValidatorStatus {
#[derive(Debug, Clone, PartialEq)]
pub struct ValidatorRecord {
pub pubkey: PublicKey,
pub withdrawal_shard: u64,
pub withdrawal_address: Address,
pub withdrawal_credentials: Hash256,
pub randao_commitment: Hash256,
pub randao_last_change: u64,
pub balance: u64,
pub randao_layers: u64,
pub status: ValidatorStatus,
pub exit_slot: u64,
pub latest_status_change_slot: u64,
pub exit_count: u64,
pub custody_commitment: Hash256,
pub latest_custody_reseed_slot: u64,
pub penultimate_custody_reseed_slot: u64
}
impl ValidatorRecord {
@@ -94,37 +96,43 @@ impl<T: RngCore> TestRandom<T> for ValidatorStatus {
impl Encodable for ValidatorRecord {
fn ssz_append(&self, s: &mut SszStream) {
s.append(&self.pubkey);
s.append(&self.withdrawal_shard);
s.append(&self.withdrawal_address);
s.append(&self.withdrawal_credentials);
s.append(&self.randao_commitment);
s.append(&self.randao_last_change);
s.append(&self.balance);
s.append(&self.randao_layers);
s.append(&self.status);
s.append(&self.exit_slot);
s.append(&self.latest_status_change_slot);
s.append(&self.exit_count);
s.append(&self.custody_commitment);
s.append(&self.latest_custody_reseed_slot);
s.append(&self.penultimate_custody_reseed_slot);
}
}
impl Decodable for ValidatorRecord {
fn ssz_decode(bytes: &[u8], i: usize) -> Result<(Self, usize), DecodeError> {
let (pubkey, i) = <_>::ssz_decode(bytes, i)?;
let (withdrawal_shard, i) = <_>::ssz_decode(bytes, i)?;
let (withdrawal_address, i) = <_>::ssz_decode(bytes, i)?;
let (withdrawal_credentials, i) = <_>::ssz_decode(bytes, i)?;
let (randao_commitment, i) = <_>::ssz_decode(bytes, i)?;
let (randao_last_change, i) = <_>::ssz_decode(bytes, i)?;
let (balance, i) = <_>::ssz_decode(bytes, i)?;
let (randao_layers, i) = <_>::ssz_decode(bytes, i)?;
let (status, i) = <_>::ssz_decode(bytes, i)?;
let (exit_slot, i) = <_>::ssz_decode(bytes, i)?;
let (latest_status_change_slot, i) = <_>::ssz_decode(bytes, i)?;
let (exit_count, i) = <_>::ssz_decode(bytes, i)?;
let (custody_commitment, i) = <_>::ssz_decode(bytes, i)?;
let (latest_custody_reseed_slot, i) = <_>::ssz_decode(bytes, i)?;
let (penultimate_custody_reseed_slot, i) = <_>::ssz_decode(bytes, i)?;
Ok((
Self {
pubkey,
withdrawal_shard,
withdrawal_address,
withdrawal_credentials,
randao_commitment,
randao_last_change,
balance,
randao_layers,
status,
exit_slot,
latest_status_change_slot,
exit_count,
custody_commitment,
latest_custody_reseed_slot,
penultimate_custody_reseed_slot
},
i,
))
@@ -135,13 +143,15 @@ impl<T: RngCore> TestRandom<T> for ValidatorRecord {
fn random_for_test(rng: &mut T) -> Self {
Self {
pubkey: <_>::random_for_test(rng),
withdrawal_shard: <_>::random_for_test(rng),
withdrawal_address: <_>::random_for_test(rng),
withdrawal_credentials: <_>::random_for_test(rng),
randao_commitment: <_>::random_for_test(rng),
randao_last_change: <_>::random_for_test(rng),
balance: <_>::random_for_test(rng),
randao_layers: <_>::random_for_test(rng),
status: <_>::random_for_test(rng),
exit_slot: <_>::random_for_test(rng),
latest_status_change_slot: <_>::random_for_test(rng),
exit_count: <_>::random_for_test(rng),
custody_commitment: <_>::random_for_test(rng),
latest_custody_reseed_slot: <_>::random_for_test(rng),
penultimate_custody_reseed_slot: <_>::random_for_test(rng),
}
}
}