More updates base upon the specs, again
This commit is contained in:
parent
e047fbe914
commit
c860191f14
@ -4,7 +4,7 @@ use types::{BeaconBlock, BeaconBlockBody, Eth1Data, Hash256};
|
||||
/// Generate a genesis BeaconBlock.
|
||||
pub fn genesis_beacon_block(state_root: Hash256, spec: &ChainSpec) -> BeaconBlock {
|
||||
BeaconBlock {
|
||||
slot: spec.genesis_slot_number,
|
||||
slot: spec.genesis_slot,
|
||||
parent_root: spec.zero_hash,
|
||||
state_root,
|
||||
randao_reveal: spec.empty_signature.clone(),
|
||||
|
@ -1,5 +1,5 @@
|
||||
use spec::ChainSpec;
|
||||
use types::{BeaconState, CrosslinkRecord, ForkData};
|
||||
use types::{BeaconState, Crosslink, Fork};
|
||||
use validator_shuffling::{shard_and_committees_for_cycle, ValidatorAssignmentError};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@ -20,8 +20,8 @@ pub fn genesis_beacon_state(spec: &ChainSpec) -> Result<BeaconState, Error> {
|
||||
a
|
||||
};
|
||||
|
||||
let initial_crosslink = CrosslinkRecord {
|
||||
slot: spec.genesis_slot_number,
|
||||
let initial_crosslink = Crosslink {
|
||||
slot: spec.genesis_slot,
|
||||
shard_block_root: spec.zero_hash,
|
||||
};
|
||||
|
||||
@ -29,19 +29,19 @@ pub fn genesis_beacon_state(spec: &ChainSpec) -> Result<BeaconState, Error> {
|
||||
/*
|
||||
* Misc
|
||||
*/
|
||||
slot: spec.genesis_slot_number,
|
||||
slot: spec.genesis_slot,
|
||||
genesis_time: spec.genesis_time,
|
||||
fork_data: ForkData {
|
||||
fork_data: Fork {
|
||||
pre_fork_version: spec.genesis_fork_version,
|
||||
post_fork_version: spec.genesis_fork_version,
|
||||
fork_slot: spec.genesis_slot_number,
|
||||
fork_slot: spec.genesis_slot,
|
||||
},
|
||||
/*
|
||||
* Validator registry
|
||||
*/
|
||||
validator_registry: spec.initial_validators.clone(),
|
||||
validator_balances: spec.initial_balances.clone(),
|
||||
validator_registry_latest_change_slot: spec.genesis_slot_number,
|
||||
validator_registry_update_slot: spec.genesis_slot,
|
||||
validator_registry_exit_count: 0,
|
||||
validator_registry_delta_chain_tip: spec.zero_hash,
|
||||
/*
|
||||
@ -54,8 +54,8 @@ pub fn genesis_beacon_state(spec: &ChainSpec) -> Result<BeaconState, Error> {
|
||||
],
|
||||
previous_epoch_start_shard: spec.genesis_start_shard,
|
||||
current_epoch_start_shard: spec.genesis_start_shard,
|
||||
previous_epoch_calculation_slot: spec.genesis_slot_number,
|
||||
current_epoch_calculation_slot: spec.genesis_slot_number,
|
||||
previous_epoch_calculation_slot: spec.genesis_slot,
|
||||
current_epoch_calculation_slot: spec.genesis_slot,
|
||||
previous_epoch_randao_mix: spec.zero_hash,
|
||||
current_epoch_randao_mix: spec.zero_hash,
|
||||
/*
|
||||
@ -65,10 +65,10 @@ pub fn genesis_beacon_state(spec: &ChainSpec) -> Result<BeaconState, Error> {
|
||||
/*
|
||||
* Finality
|
||||
*/
|
||||
previous_justified_slot: spec.genesis_slot_number,
|
||||
justified_slot: spec.genesis_slot_number,
|
||||
previous_justified_slot: spec.genesis_slot,
|
||||
justified_slot: spec.genesis_slot,
|
||||
justification_bitfield: 0,
|
||||
finalized_slot: spec.genesis_slot_number,
|
||||
finalized_slot: spec.genesis_slot,
|
||||
/*
|
||||
* Recent state
|
||||
*/
|
||||
@ -129,7 +129,7 @@ mod tests {
|
||||
|
||||
assert_eq!(state.validator_registry, spec.initial_validators);
|
||||
assert_eq!(state.validator_balances, spec.initial_balances);
|
||||
assert!(state.validator_registry_latest_change_slot == 0);
|
||||
assert!(state.validator_registry_update_slot == 0);
|
||||
assert!(state.validator_registry_exit_count == 0);
|
||||
assert_eq!(state.validator_registry_delta_chain_tip, Hash256::zero());
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use super::ChainSpec;
|
||||
use bls::{Keypair, PublicKey, SecretKey, Signature};
|
||||
|
||||
use types::{Address, Eth1Data, Hash256, ValidatorRecord};
|
||||
use types::{Address, Eth1Data, Hash256, Validator};
|
||||
|
||||
/// The size of a validators deposit in GWei.
|
||||
pub const DEPOSIT_GWEI: u64 = 32_000_000_000;
|
||||
@ -37,7 +37,7 @@ impl ChainSpec {
|
||||
* Initial Values
|
||||
*/
|
||||
genesis_fork_version: 0,
|
||||
genesis_slot_number: 0,
|
||||
genesis_slot: 0,
|
||||
genesis_start_shard: 0,
|
||||
far_future_slot: u64::max_value(),
|
||||
zero_hash: Hash256::zero(),
|
||||
@ -83,7 +83,7 @@ impl ChainSpec {
|
||||
}
|
||||
|
||||
/// Generate a set of validator records to use with testing until the real chain starts.
|
||||
fn initial_validators_for_testing() -> Vec<ValidatorRecord> {
|
||||
fn initial_validators_for_testing() -> Vec<Validator> {
|
||||
// Some dummy private keys to start with.
|
||||
let key_strings = vec![
|
||||
"jzjxxgjajfjrmgodszzsgqccmhnyvetcuxobhtynojtpdtbj",
|
||||
@ -106,7 +106,7 @@ fn initial_validators_for_testing() -> Vec<ValidatorRecord> {
|
||||
pk: public_key,
|
||||
}
|
||||
};
|
||||
let validator_record = ValidatorRecord {
|
||||
let validator = Validator {
|
||||
pubkey: keypair.pk.clone(),
|
||||
withdrawal_credentials: Hash256::zero(),
|
||||
proposer_slots: 0,
|
||||
@ -116,11 +116,10 @@ fn initial_validators_for_testing() -> Vec<ValidatorRecord> {
|
||||
penalized_slot: u64::max_value(),
|
||||
exit_count: 0,
|
||||
status_flags: None,
|
||||
custody_commitment: Hash256::zero(),
|
||||
latest_custody_reseed_slot: 0,
|
||||
penultimate_custody_reseed_slot: 0,
|
||||
};
|
||||
initial_validators.push(validator_record);
|
||||
initial_validators.push(validator);
|
||||
}
|
||||
|
||||
initial_validators
|
||||
|
@ -4,7 +4,7 @@ extern crate types;
|
||||
mod foundation;
|
||||
|
||||
use bls::Signature;
|
||||
use types::{Address, Eth1Data, Hash256, ValidatorRecord};
|
||||
use types::{Address, Eth1Data, Hash256, Validator};
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub struct ChainSpec {
|
||||
@ -32,7 +32,7 @@ pub struct ChainSpec {
|
||||
* Initial Values
|
||||
*/
|
||||
pub genesis_fork_version: u64,
|
||||
pub genesis_slot_number: u64,
|
||||
pub genesis_slot: u64,
|
||||
pub genesis_start_shard: u64,
|
||||
pub far_future_slot: u64,
|
||||
pub zero_hash: Hash256,
|
||||
@ -66,7 +66,7 @@ pub struct ChainSpec {
|
||||
/*
|
||||
* Intialization parameters
|
||||
*/
|
||||
pub initial_validators: Vec<ValidatorRecord>,
|
||||
pub initial_validators: Vec<Validator>,
|
||||
pub initial_balances: Vec<u64>,
|
||||
pub genesis_time: u64,
|
||||
pub intial_eth1_data: Eth1Data,
|
||||
|
@ -1,9 +1,9 @@
|
||||
use super::crosslink_record::CrosslinkRecord;
|
||||
use super::crosslink::Crosslink;
|
||||
use super::eth1_data::Eth1Data;
|
||||
use super::eth1_data_vote::Eth1DataVote;
|
||||
use super::fork_data::ForkData;
|
||||
use super::pending_attestation_record::PendingAttestationRecord;
|
||||
use super::validator_record::ValidatorRecord;
|
||||
use super::fork::Fork;
|
||||
use super::pending_attestation::PendingAttestation;
|
||||
use super::validator::Validator;
|
||||
use super::Hash256;
|
||||
use crate::test_utils::TestRandom;
|
||||
use hashing::canonical_hash;
|
||||
@ -18,12 +18,12 @@ pub struct BeaconState {
|
||||
// Misc
|
||||
pub slot: u64,
|
||||
pub genesis_time: u64,
|
||||
pub fork_data: ForkData,
|
||||
pub fork_data: Fork,
|
||||
|
||||
// Validator registry
|
||||
pub validator_registry: Vec<ValidatorRecord>,
|
||||
pub validator_registry: Vec<Validator>,
|
||||
pub validator_balances: Vec<u64>,
|
||||
pub validator_registry_latest_change_slot: u64,
|
||||
pub validator_registry_update_slot: u64,
|
||||
pub validator_registry_exit_count: u64,
|
||||
pub validator_registry_delta_chain_tip: Hash256,
|
||||
|
||||
@ -47,10 +47,10 @@ pub struct BeaconState {
|
||||
pub finalized_slot: u64,
|
||||
|
||||
// Recent state
|
||||
pub latest_crosslinks: Vec<CrosslinkRecord>,
|
||||
pub latest_crosslinks: Vec<Crosslink>,
|
||||
pub latest_block_roots: Vec<Hash256>,
|
||||
pub latest_penalized_exit_balances: Vec<u64>,
|
||||
pub latest_attestations: Vec<PendingAttestationRecord>,
|
||||
pub latest_attestations: Vec<PendingAttestation>,
|
||||
pub batched_block_roots: Vec<Hash256>,
|
||||
|
||||
// Ethereum 1.0 chain data
|
||||
@ -73,7 +73,7 @@ impl Encodable for BeaconState {
|
||||
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_update_slot);
|
||||
s.append(&self.validator_registry_exit_count);
|
||||
s.append(&self.validator_registry_delta_chain_tip);
|
||||
s.append(&self.latest_randao_mixes);
|
||||
@ -106,7 +106,7 @@ impl Decodable for BeaconState {
|
||||
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_update_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)?;
|
||||
let (latest_randao_mixes, i) = <_>::ssz_decode(bytes, i)?;
|
||||
@ -137,7 +137,7 @@ impl Decodable for BeaconState {
|
||||
fork_data,
|
||||
validator_registry,
|
||||
validator_balances,
|
||||
validator_registry_latest_change_slot,
|
||||
validator_registry_update_slot,
|
||||
validator_registry_exit_count,
|
||||
validator_registry_delta_chain_tip,
|
||||
latest_randao_mixes,
|
||||
@ -174,7 +174,7 @@ impl<T: RngCore> TestRandom<T> for BeaconState {
|
||||
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_update_slot: <_>::random_for_test(rng),
|
||||
validator_registry_exit_count: <_>::random_for_test(rng),
|
||||
validator_registry_delta_chain_tip: <_>::random_for_test(rng),
|
||||
latest_randao_mixes: <_>::random_for_test(rng),
|
||||
|
@ -4,12 +4,12 @@ use crate::test_utils::TestRandom;
|
||||
use rand::RngCore;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct CrosslinkRecord {
|
||||
pub struct Crosslink {
|
||||
pub slot: u64,
|
||||
pub shard_block_root: Hash256,
|
||||
}
|
||||
|
||||
impl CrosslinkRecord {
|
||||
impl Crosslink {
|
||||
/// Generates a new instance where `dynasty` and `hash` are both zero.
|
||||
pub fn zero() -> Self {
|
||||
Self {
|
||||
@ -19,14 +19,14 @@ impl CrosslinkRecord {
|
||||
}
|
||||
}
|
||||
|
||||
impl Encodable for CrosslinkRecord {
|
||||
impl Encodable for Crosslink {
|
||||
fn ssz_append(&self, s: &mut SszStream) {
|
||||
s.append(&self.slot);
|
||||
s.append(&self.shard_block_root);
|
||||
}
|
||||
}
|
||||
|
||||
impl Decodable for CrosslinkRecord {
|
||||
impl Decodable for Crosslink {
|
||||
fn ssz_decode(bytes: &[u8], i: usize) -> Result<(Self, usize), DecodeError> {
|
||||
let (slot, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (shard_block_root, i) = <_>::ssz_decode(bytes, i)?;
|
||||
@ -41,7 +41,7 @@ impl Decodable for CrosslinkRecord {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: RngCore> TestRandom<T> for CrosslinkRecord {
|
||||
impl<T: RngCore> TestRandom<T> for Crosslink {
|
||||
fn random_for_test(rng: &mut T) -> Self {
|
||||
Self {
|
||||
slot: <_>::random_for_test(rng),
|
||||
@ -59,7 +59,7 @@ mod tests {
|
||||
#[test]
|
||||
pub fn test_ssz_round_trip() {
|
||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
||||
let original = CrosslinkRecord::random_for_test(&mut rng);
|
||||
let original = Crosslink::random_for_test(&mut rng);
|
||||
|
||||
let bytes = ssz_encode(&original);
|
||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
@ -5,30 +5,30 @@ use rand::RngCore;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct DepositData {
|
||||
pub deposit_input: DepositInput,
|
||||
pub value: u64,
|
||||
pub amount: u64,
|
||||
pub timestamp: u64,
|
||||
pub deposit_input: DepositInput,
|
||||
}
|
||||
|
||||
impl Encodable for DepositData {
|
||||
fn ssz_append(&self, s: &mut SszStream) {
|
||||
s.append(&self.deposit_input);
|
||||
s.append(&self.value);
|
||||
s.append(&self.amount);
|
||||
s.append(&self.timestamp);
|
||||
s.append(&self.deposit_input);
|
||||
}
|
||||
}
|
||||
|
||||
impl Decodable for DepositData {
|
||||
fn ssz_decode(bytes: &[u8], i: usize) -> Result<(Self, usize), DecodeError> {
|
||||
let (deposit_input, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (value, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (amount, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (timestamp, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (deposit_input, i) = <_>::ssz_decode(bytes, i)?;
|
||||
|
||||
Ok((
|
||||
Self {
|
||||
deposit_input,
|
||||
value,
|
||||
amount,
|
||||
timestamp,
|
||||
deposit_input,
|
||||
},
|
||||
i,
|
||||
))
|
||||
@ -38,9 +38,9 @@ impl Decodable for DepositData {
|
||||
impl<T: RngCore> TestRandom<T> for DepositData {
|
||||
fn random_for_test(rng: &mut T) -> Self {
|
||||
Self {
|
||||
deposit_input: <_>::random_for_test(rng),
|
||||
value: <_>::random_for_test(rng),
|
||||
amount: <_>::random_for_test(rng),
|
||||
timestamp: <_>::random_for_test(rng),
|
||||
deposit_input: <_>::random_for_test(rng),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,6 @@ use rand::RngCore;
|
||||
pub struct DepositInput {
|
||||
pub pubkey: PublicKey,
|
||||
pub withdrawal_credentials: Hash256,
|
||||
pub randao_commitment: Hash256,
|
||||
pub custody_commitment: Hash256,
|
||||
pub proof_of_possession: Signature,
|
||||
}
|
||||
|
||||
@ -17,8 +15,6 @@ impl Encodable for DepositInput {
|
||||
fn ssz_append(&self, s: &mut SszStream) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -27,16 +23,12 @@ impl Decodable for DepositInput {
|
||||
fn ssz_decode(bytes: &[u8], i: usize) -> Result<(Self, usize), DecodeError> {
|
||||
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((
|
||||
Self {
|
||||
pubkey,
|
||||
withdrawal_credentials,
|
||||
randao_commitment,
|
||||
custody_commitment,
|
||||
proof_of_possession,
|
||||
},
|
||||
i,
|
||||
@ -49,8 +41,6 @@ impl<T: RngCore> TestRandom<T> for DepositInput {
|
||||
Self {
|
||||
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),
|
||||
}
|
||||
}
|
||||
|
@ -3,13 +3,13 @@ use crate::test_utils::TestRandom;
|
||||
use rand::RngCore;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
pub struct ForkData {
|
||||
pub struct Fork {
|
||||
pub pre_fork_version: u64,
|
||||
pub post_fork_version: u64,
|
||||
pub fork_slot: u64,
|
||||
}
|
||||
|
||||
impl Encodable for ForkData {
|
||||
impl Encodable for Fork {
|
||||
fn ssz_append(&self, s: &mut SszStream) {
|
||||
s.append(&self.pre_fork_version);
|
||||
s.append(&self.post_fork_version);
|
||||
@ -17,7 +17,7 @@ impl Encodable for ForkData {
|
||||
}
|
||||
}
|
||||
|
||||
impl Decodable for ForkData {
|
||||
impl Decodable for Fork {
|
||||
fn ssz_decode(bytes: &[u8], i: usize) -> Result<(Self, usize), DecodeError> {
|
||||
let (pre_fork_version, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (post_fork_version, i) = <_>::ssz_decode(bytes, i)?;
|
||||
@ -34,7 +34,7 @@ impl Decodable for ForkData {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: RngCore> TestRandom<T> for ForkData {
|
||||
impl<T: RngCore> TestRandom<T> for Fork {
|
||||
fn random_for_test(rng: &mut T) -> Self {
|
||||
Self {
|
||||
pre_fork_version: <_>::random_for_test(rng),
|
||||
@ -53,7 +53,7 @@ mod tests {
|
||||
#[test]
|
||||
pub fn test_ssz_round_trip() {
|
||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
||||
let original = ForkData::random_for_test(&mut rng);
|
||||
let original = Fork::random_for_test(&mut rng);
|
||||
|
||||
let bytes = ssz_encode(&original);
|
||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
@ -11,22 +11,22 @@ pub mod beacon_block;
|
||||
pub mod beacon_block_body;
|
||||
pub mod beacon_state;
|
||||
pub mod casper_slashing;
|
||||
pub mod crosslink_record;
|
||||
pub mod crosslink;
|
||||
pub mod deposit;
|
||||
pub mod deposit_data;
|
||||
pub mod deposit_input;
|
||||
pub mod eth1_data;
|
||||
pub mod eth1_data_vote;
|
||||
pub mod exit;
|
||||
pub mod fork_data;
|
||||
pub mod pending_attestation_record;
|
||||
pub mod fork;
|
||||
pub mod pending_attestation;
|
||||
pub mod proposal_signed_data;
|
||||
pub mod proposer_slashing;
|
||||
pub mod shard_committee;
|
||||
pub mod shard_reassignment_record;
|
||||
pub mod slashable_vote_data;
|
||||
pub mod special_record;
|
||||
pub mod validator_record;
|
||||
pub mod validator;
|
||||
pub mod validator_registry;
|
||||
pub mod validator_registry_delta_block;
|
||||
|
||||
@ -41,21 +41,21 @@ pub use crate::beacon_block::BeaconBlock;
|
||||
pub use crate::beacon_block_body::BeaconBlockBody;
|
||||
pub use crate::beacon_state::BeaconState;
|
||||
pub use crate::casper_slashing::CasperSlashing;
|
||||
pub use crate::crosslink_record::CrosslinkRecord;
|
||||
pub use crate::crosslink::Crosslink;
|
||||
pub use crate::deposit::Deposit;
|
||||
pub use crate::deposit_data::DepositData;
|
||||
pub use crate::deposit_input::DepositInput;
|
||||
pub use crate::eth1_data::Eth1Data;
|
||||
pub use crate::eth1_data_vote::Eth1DataVote;
|
||||
pub use crate::exit::Exit;
|
||||
pub use crate::fork_data::ForkData;
|
||||
pub use crate::pending_attestation_record::PendingAttestationRecord;
|
||||
pub use crate::fork::Fork;
|
||||
pub use crate::pending_attestation::PendingAttestation;
|
||||
pub use crate::proposal_signed_data::ProposalSignedData;
|
||||
pub use crate::proposer_slashing::ProposerSlashing;
|
||||
pub use crate::shard_committee::ShardCommittee;
|
||||
pub use crate::slashable_vote_data::SlashableVoteData;
|
||||
pub use crate::special_record::{SpecialRecord, SpecialRecordKind};
|
||||
pub use crate::validator_record::{StatusFlags as ValidatorStatusFlags, ValidatorRecord};
|
||||
pub use crate::validator::{StatusFlags as ValidatorStatusFlags, Validator};
|
||||
pub use crate::validator_registry_delta_block::ValidatorRegistryDeltaBlock;
|
||||
|
||||
pub type Hash256 = H256;
|
||||
|
@ -4,33 +4,33 @@ use crate::test_utils::TestRandom;
|
||||
use rand::RngCore;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct PendingAttestationRecord {
|
||||
pub struct PendingAttestation {
|
||||
pub data: AttestationData,
|
||||
pub participation_bitfield: Bitfield,
|
||||
pub aggregation_bitfield: Bitfield,
|
||||
pub custody_bitfield: Bitfield,
|
||||
pub slot_included: u64,
|
||||
}
|
||||
|
||||
impl Encodable for PendingAttestationRecord {
|
||||
impl Encodable for PendingAttestation {
|
||||
fn ssz_append(&self, s: &mut SszStream) {
|
||||
s.append(&self.data);
|
||||
s.append(&self.participation_bitfield);
|
||||
s.append(&self.aggregation_bitfield);
|
||||
s.append(&self.custody_bitfield);
|
||||
s.append(&self.slot_included);
|
||||
}
|
||||
}
|
||||
|
||||
impl Decodable for PendingAttestationRecord {
|
||||
impl Decodable for PendingAttestation {
|
||||
fn ssz_decode(bytes: &[u8], i: usize) -> Result<(Self, usize), DecodeError> {
|
||||
let (data, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (participation_bitfield, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (aggregation_bitfield, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (custody_bitfield, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (slot_included, i) = <_>::ssz_decode(bytes, i)?;
|
||||
|
||||
Ok((
|
||||
Self {
|
||||
data,
|
||||
participation_bitfield,
|
||||
aggregation_bitfield,
|
||||
custody_bitfield,
|
||||
slot_included,
|
||||
},
|
||||
@ -39,11 +39,11 @@ impl Decodable for PendingAttestationRecord {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: RngCore> TestRandom<T> for PendingAttestationRecord {
|
||||
impl<T: RngCore> TestRandom<T> for PendingAttestation {
|
||||
fn random_for_test(rng: &mut T) -> Self {
|
||||
Self {
|
||||
data: <_>::random_for_test(rng),
|
||||
participation_bitfield: <_>::random_for_test(rng),
|
||||
aggregation_bitfield: <_>::random_for_test(rng),
|
||||
custody_bitfield: <_>::random_for_test(rng),
|
||||
slot_included: <_>::random_for_test(rng),
|
||||
}
|
||||
@ -59,7 +59,7 @@ mod tests {
|
||||
#[test]
|
||||
pub fn test_ssz_round_trip() {
|
||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
||||
let original = PendingAttestationRecord::random_for_test(&mut rng);
|
||||
let original = PendingAttestation::random_for_test(&mut rng);
|
||||
|
||||
let bytes = ssz_encode(&original);
|
||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
@ -6,16 +6,16 @@ use rand::RngCore;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct SlashableVoteData {
|
||||
pub aggregate_signature_poc_0_indices: Vec<u32>,
|
||||
pub aggregate_signature_poc_1_indices: Vec<u32>,
|
||||
pub custody_bit_0_indices: Vec<u32>,
|
||||
pub custody_bit_1_indices: Vec<u32>,
|
||||
pub data: AttestationData,
|
||||
pub aggregate_signature: AggregateSignature,
|
||||
}
|
||||
|
||||
impl Encodable for SlashableVoteData {
|
||||
fn ssz_append(&self, s: &mut SszStream) {
|
||||
s.append_vec(&self.aggregate_signature_poc_0_indices);
|
||||
s.append_vec(&self.aggregate_signature_poc_1_indices);
|
||||
s.append_vec(&self.custody_bit_0_indices);
|
||||
s.append_vec(&self.custody_bit_1_indices);
|
||||
s.append(&self.data);
|
||||
s.append(&self.aggregate_signature);
|
||||
}
|
||||
@ -23,15 +23,15 @@ impl Encodable for SlashableVoteData {
|
||||
|
||||
impl Decodable for SlashableVoteData {
|
||||
fn ssz_decode(bytes: &[u8], i: usize) -> Result<(Self, usize), DecodeError> {
|
||||
let (aggregate_signature_poc_0_indices, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (aggregate_signature_poc_1_indices, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (custody_bit_0_indices, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (custody_bit_1_indices, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (data, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (aggregate_signature, i) = <_>::ssz_decode(bytes, i)?;
|
||||
|
||||
Ok((
|
||||
SlashableVoteData {
|
||||
aggregate_signature_poc_0_indices,
|
||||
aggregate_signature_poc_1_indices,
|
||||
custody_bit_0_indices,
|
||||
custody_bit_1_indices,
|
||||
data,
|
||||
aggregate_signature,
|
||||
},
|
||||
@ -43,8 +43,8 @@ impl Decodable for SlashableVoteData {
|
||||
impl<T: RngCore> TestRandom<T> for SlashableVoteData {
|
||||
fn random_for_test(rng: &mut T) -> Self {
|
||||
Self {
|
||||
aggregate_signature_poc_0_indices: <_>::random_for_test(rng),
|
||||
aggregate_signature_poc_1_indices: <_>::random_for_test(rng),
|
||||
custody_bit_0_indices: <_>::random_for_test(rng),
|
||||
custody_bit_1_indices: <_>::random_for_test(rng),
|
||||
data: <_>::random_for_test(rng),
|
||||
aggregate_signature: <_>::random_for_test(rng),
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ impl From<StatusFlagsDecodeError> for DecodeError {
|
||||
}
|
||||
}
|
||||
|
||||
/// Handles the serialization logic for the `status_flags` field of the `ValidatorRecord`.
|
||||
/// Handles the serialization logic for the `status_flags` field of the `Validator`.
|
||||
fn status_flag_to_byte(flag: Option<StatusFlags>) -> u8 {
|
||||
if let Some(flag) = flag {
|
||||
match flag {
|
||||
@ -33,7 +33,7 @@ fn status_flag_to_byte(flag: Option<StatusFlags>) -> u8 {
|
||||
}
|
||||
}
|
||||
|
||||
/// Handles the deserialization logic for the `status_flags` field of the `ValidatorRecord`.
|
||||
/// Handles the deserialization logic for the `status_flags` field of the `Validator`.
|
||||
fn status_flag_from_byte(flag: u8) -> Result<Option<StatusFlags>, StatusFlagsDecodeError> {
|
||||
match flag {
|
||||
0 => Ok(None),
|
||||
@ -44,7 +44,7 @@ fn status_flag_from_byte(flag: u8) -> Result<Option<StatusFlags>, StatusFlagsDec
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ValidatorRecord {
|
||||
pub struct Validator {
|
||||
pub pubkey: PublicKey,
|
||||
pub withdrawal_credentials: Hash256,
|
||||
pub proposer_slots: u64,
|
||||
@ -54,20 +54,19 @@ pub struct ValidatorRecord {
|
||||
pub penalized_slot: u64,
|
||||
pub exit_count: u64,
|
||||
pub status_flags: Option<StatusFlags>,
|
||||
pub custody_commitment: Hash256,
|
||||
pub latest_custody_reseed_slot: u64,
|
||||
pub penultimate_custody_reseed_slot: u64,
|
||||
}
|
||||
|
||||
impl ValidatorRecord {
|
||||
impl Validator {
|
||||
/// This predicate indicates if the validator represented by this record is considered "active" at `slot`.
|
||||
pub fn is_active_at(&self, slot: u64) -> bool {
|
||||
self.activation_slot <= slot && slot < self.exit_slot
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ValidatorRecord {
|
||||
/// Yields a "default" `ValidatorRecord`. Primarily used for testing.
|
||||
impl Default for Validator {
|
||||
/// Yields a "default" `Validator`. Primarily used for testing.
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
pubkey: PublicKey::default(),
|
||||
@ -79,7 +78,6 @@ impl Default for ValidatorRecord {
|
||||
penalized_slot: std::u64::MAX,
|
||||
exit_count: 0,
|
||||
status_flags: None,
|
||||
custody_commitment: Hash256::default(),
|
||||
latest_custody_reseed_slot: 0, // NOTE: is `GENESIS_SLOT`
|
||||
penultimate_custody_reseed_slot: 0, // NOTE: is `GENESIS_SLOT`
|
||||
}
|
||||
@ -93,7 +91,7 @@ impl<T: RngCore> TestRandom<T> for StatusFlags {
|
||||
}
|
||||
}
|
||||
|
||||
impl Encodable for ValidatorRecord {
|
||||
impl Encodable for Validator {
|
||||
fn ssz_append(&self, s: &mut SszStream) {
|
||||
s.append(&self.pubkey);
|
||||
s.append(&self.withdrawal_credentials);
|
||||
@ -104,13 +102,12 @@ impl Encodable for ValidatorRecord {
|
||||
s.append(&self.penalized_slot);
|
||||
s.append(&self.exit_count);
|
||||
s.append(&status_flag_to_byte(self.status_flags));
|
||||
s.append(&self.custody_commitment);
|
||||
s.append(&self.latest_custody_reseed_slot);
|
||||
s.append(&self.penultimate_custody_reseed_slot);
|
||||
}
|
||||
}
|
||||
|
||||
impl Decodable for ValidatorRecord {
|
||||
impl Decodable for Validator {
|
||||
fn ssz_decode(bytes: &[u8], i: usize) -> Result<(Self, usize), DecodeError> {
|
||||
let (pubkey, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (withdrawal_credentials, i) = <_>::ssz_decode(bytes, i)?;
|
||||
@ -121,7 +118,6 @@ impl Decodable for ValidatorRecord {
|
||||
let (penalized_slot, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (exit_count, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (status_flags_byte, i): (u8, usize) = <_>::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)?;
|
||||
|
||||
@ -138,7 +134,6 @@ impl Decodable for ValidatorRecord {
|
||||
penalized_slot,
|
||||
exit_count,
|
||||
status_flags,
|
||||
custody_commitment,
|
||||
latest_custody_reseed_slot,
|
||||
penultimate_custody_reseed_slot,
|
||||
},
|
||||
@ -147,7 +142,7 @@ impl Decodable for ValidatorRecord {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: RngCore> TestRandom<T> for ValidatorRecord {
|
||||
impl<T: RngCore> TestRandom<T> for Validator {
|
||||
fn random_for_test(rng: &mut T) -> Self {
|
||||
Self {
|
||||
pubkey: <_>::random_for_test(rng),
|
||||
@ -159,7 +154,6 @@ impl<T: RngCore> TestRandom<T> for ValidatorRecord {
|
||||
penalized_slot: <_>::random_for_test(rng),
|
||||
exit_count: <_>::random_for_test(rng),
|
||||
status_flags: Some(<_>::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),
|
||||
}
|
||||
@ -175,7 +169,7 @@ mod tests {
|
||||
#[test]
|
||||
pub fn test_ssz_round_trip() {
|
||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
||||
let original = ValidatorRecord::random_for_test(&mut rng);
|
||||
let original = Validator::random_for_test(&mut rng);
|
||||
|
||||
let bytes = ssz_encode(&original);
|
||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
||||
@ -186,7 +180,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_validator_can_be_active() {
|
||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
||||
let mut validator = ValidatorRecord::random_for_test(&mut rng);
|
||||
let mut validator = Validator::random_for_test(&mut rng);
|
||||
|
||||
let activation_slot = u64::random_for_test(&mut rng);
|
||||
let exit_slot = activation_slot + 234;
|
@ -1,9 +1,9 @@
|
||||
/// Contains logic to manipulate a `&[ValidatorRecord]`.
|
||||
/// Contains logic to manipulate a `&[Validator]`.
|
||||
/// For now, we avoid defining a newtype and just have flat functions here.
|
||||
use super::validator_record::*;
|
||||
use super::validator::*;
|
||||
|
||||
/// Given an indexed sequence of `validators`, return the indices corresponding to validators that are active at `slot`.
|
||||
pub fn get_active_validator_indices(validators: &[ValidatorRecord], slot: u64) -> Vec<usize> {
|
||||
pub fn get_active_validator_indices(validators: &[Validator], slot: u64) -> Vec<usize> {
|
||||
validators
|
||||
.iter()
|
||||
.enumerate()
|
||||
@ -38,7 +38,7 @@ mod tests {
|
||||
let mut validators = vec![];
|
||||
let count_validators = 10;
|
||||
for _ in 0..count_validators {
|
||||
validators.push(ValidatorRecord::default())
|
||||
validators.push(Validator::default())
|
||||
}
|
||||
|
||||
let some_slot = u64::random_for_test(&mut rng);
|
||||
@ -55,7 +55,7 @@ mod tests {
|
||||
let mut validators = (0..count_validators)
|
||||
.into_iter()
|
||||
.map(|_| {
|
||||
let mut validator = ValidatorRecord::default();
|
||||
let mut validator = Validator::default();
|
||||
|
||||
let activation_offset = u64::random_for_test(&mut rng);
|
||||
let exit_offset = u64::random_for_test(&mut rng);
|
||||
@ -79,7 +79,7 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
fn set_validators_to_default_entry_exit(validators: &mut [ValidatorRecord]) {
|
||||
fn set_validators_to_default_entry_exit(validators: &mut [Validator]) {
|
||||
for validator in validators.iter_mut() {
|
||||
validator.activation_slot = std::u64::MAX;
|
||||
validator.exit_slot = std::u64::MAX;
|
||||
@ -87,7 +87,7 @@ mod tests {
|
||||
}
|
||||
|
||||
// sets all `validators` to be active as of some slot prior to `slot`. returns the activation slot.
|
||||
fn set_validators_to_activated(validators: &mut [ValidatorRecord], slot: u64) -> u64 {
|
||||
fn set_validators_to_activated(validators: &mut [Validator], slot: u64) -> u64 {
|
||||
let activation_slot = slot - 10;
|
||||
for validator in validators.iter_mut() {
|
||||
validator.activation_slot = activation_slot;
|
||||
@ -96,11 +96,7 @@ mod tests {
|
||||
}
|
||||
|
||||
// sets all `validators` to be exited as of some slot before `slot`.
|
||||
fn set_validators_to_exited(
|
||||
validators: &mut [ValidatorRecord],
|
||||
slot: u64,
|
||||
activation_slot: u64,
|
||||
) {
|
||||
fn set_validators_to_exited(validators: &mut [Validator], slot: u64, activation_slot: u64) {
|
||||
assert!(activation_slot < slot);
|
||||
let mut exit_slot = activation_slot + 10;
|
||||
while exit_slot >= slot {
|
||||
@ -123,7 +119,7 @@ mod tests {
|
||||
let mut validators = (0..COUNT_VALIDATORS)
|
||||
.into_iter()
|
||||
.map(|_| {
|
||||
let mut validator = ValidatorRecord::default();
|
||||
let mut validator = Validator::default();
|
||||
|
||||
let activation_offset = u64::random_for_test(&mut rng);
|
||||
let exit_offset = u64::random_for_test(&mut rng);
|
||||
|
@ -15,7 +15,7 @@ pub struct ValidatorRegistryDeltaBlock {
|
||||
}
|
||||
|
||||
impl Default for ValidatorRegistryDeltaBlock {
|
||||
/// Yields a "default" `ValidatorRecord`. Primarily used for testing.
|
||||
/// Yields a "default" `Validator`. Primarily used for testing.
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
latest_registry_delta_root: Hash256::zero(),
|
||||
|
@ -1,6 +1,6 @@
|
||||
use bls::verify_proof_of_possession;
|
||||
use spec::ChainSpec;
|
||||
use types::{BeaconState, Deposit, ValidatorRecord};
|
||||
use types::{BeaconState, Deposit, Validator};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub enum ValidatorInductionError {
|
||||
@ -32,14 +32,14 @@ pub fn process_deposit(
|
||||
if state.validator_registry[i].withdrawal_credentials
|
||||
== deposit_input.withdrawal_credentials
|
||||
{
|
||||
state.validator_balances[i] += deposit_data.value;
|
||||
state.validator_balances[i] += deposit_data.amount;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
Err(ValidatorInductionError::InvalidWithdrawalCredentials)
|
||||
}
|
||||
None => {
|
||||
let validator = ValidatorRecord {
|
||||
let validator = Validator {
|
||||
pubkey: deposit_input.pubkey.clone(),
|
||||
withdrawal_credentials: deposit_input.withdrawal_credentials,
|
||||
proposer_slots: 0,
|
||||
@ -49,14 +49,13 @@ pub fn process_deposit(
|
||||
penalized_slot: spec.far_future_slot,
|
||||
exit_count: 0,
|
||||
status_flags: None,
|
||||
custody_commitment: deposit_input.custody_commitment,
|
||||
latest_custody_reseed_slot: 0,
|
||||
penultimate_custody_reseed_slot: 0,
|
||||
};
|
||||
|
||||
let _index = state.validator_registry.len();
|
||||
state.validator_registry.push(validator);
|
||||
state.validator_balances.push(deposit_data.value);
|
||||
state.validator_balances.push(deposit_data.amount);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@ -82,12 +81,12 @@ mod tests {
|
||||
deposit
|
||||
}
|
||||
|
||||
fn get_validator() -> ValidatorRecord {
|
||||
fn get_validator() -> Validator {
|
||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
||||
ValidatorRecord::random_for_test(&mut rng)
|
||||
Validator::random_for_test(&mut rng)
|
||||
}
|
||||
|
||||
fn deposit_equals_record(dep: &Deposit, val: &ValidatorRecord) -> bool {
|
||||
fn deposit_equals_record(dep: &Deposit, val: &Validator) -> bool {
|
||||
(dep.deposit_data.deposit_input.pubkey == val.pubkey)
|
||||
& (dep.deposit_data.deposit_input.withdrawal_credentials == val.withdrawal_credentials)
|
||||
& (verify_proof_of_possession(
|
||||
@ -101,7 +100,7 @@ mod tests {
|
||||
let mut state = BeaconState::default();
|
||||
let mut deposit = get_deposit();
|
||||
let spec = ChainSpec::foundation();
|
||||
deposit.deposit_data.value = DEPOSIT_GWEI;
|
||||
deposit.deposit_data.amount = DEPOSIT_GWEI;
|
||||
|
||||
let result = process_deposit(&mut state, &deposit, &spec);
|
||||
|
||||
@ -122,7 +121,7 @@ mod tests {
|
||||
for i in 0..5 {
|
||||
let mut deposit = get_deposit();
|
||||
let result = process_deposit(&mut state, &deposit, &spec);
|
||||
deposit.deposit_data.value = DEPOSIT_GWEI;
|
||||
deposit.deposit_data.amount = DEPOSIT_GWEI;
|
||||
assert_eq!(result.unwrap(), ());
|
||||
assert!(deposit_equals_record(
|
||||
&deposit,
|
||||
@ -141,7 +140,7 @@ mod tests {
|
||||
let mut deposit = get_deposit();
|
||||
let mut validator = get_validator();
|
||||
|
||||
deposit.deposit_data.value = DEPOSIT_GWEI;
|
||||
deposit.deposit_data.amount = DEPOSIT_GWEI;
|
||||
validator.pubkey = deposit.deposit_data.deposit_input.pubkey.clone();
|
||||
validator.withdrawal_credentials =
|
||||
deposit.deposit_data.deposit_input.withdrawal_credentials;
|
||||
@ -166,7 +165,7 @@ mod tests {
|
||||
let mut state = BeaconState::default();
|
||||
let mut deposit = get_deposit();
|
||||
let spec = ChainSpec::foundation();
|
||||
deposit.deposit_data.value = DEPOSIT_GWEI;
|
||||
deposit.deposit_data.amount = DEPOSIT_GWEI;
|
||||
deposit.deposit_data.deposit_input.proof_of_possession =
|
||||
create_proof_of_possession(&Keypair::random());
|
||||
|
||||
|
@ -3,7 +3,7 @@ use std::cmp::min;
|
||||
use honey_badger_split::SplitExt;
|
||||
use spec::ChainSpec;
|
||||
use types::validator_registry::get_active_validator_indices;
|
||||
use types::{ShardCommittee, ValidatorRecord};
|
||||
use types::{ShardCommittee, Validator};
|
||||
use vec_shuffle::{shuffle, ShuffleErr};
|
||||
|
||||
type DelegatedCycle = Vec<Vec<ShardCommittee>>;
|
||||
@ -20,7 +20,7 @@ pub enum ValidatorAssignmentError {
|
||||
/// References get_new_shuffling (ethereum 2.1 specification)
|
||||
pub fn shard_and_committees_for_cycle(
|
||||
seed: &[u8],
|
||||
validators: &[ValidatorRecord],
|
||||
validators: &[Validator],
|
||||
crosslinking_shard_start: u16,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<DelegatedCycle, ValidatorAssignmentError> {
|
||||
|
Loading…
Reference in New Issue
Block a user