Update constants / types to match specs as of 23.1.19
This commit is contained in:
parent
038e32a303
commit
560dbe4ae1
@ -1,5 +1,5 @@
|
|||||||
use spec::ChainSpec;
|
use spec::ChainSpec;
|
||||||
use types::{BeaconBlock, BeaconBlockBody, Hash256};
|
use types::{BeaconBlock, BeaconBlockBody, Eth1Data, Hash256};
|
||||||
|
|
||||||
/// Generate a genesis BeaconBlock.
|
/// Generate a genesis BeaconBlock.
|
||||||
pub fn genesis_beacon_block(state_root: Hash256, spec: &ChainSpec) -> BeaconBlock {
|
pub fn genesis_beacon_block(state_root: Hash256, spec: &ChainSpec) -> BeaconBlock {
|
||||||
@ -8,7 +8,10 @@ pub fn genesis_beacon_block(state_root: Hash256, spec: &ChainSpec) -> BeaconBloc
|
|||||||
parent_root: spec.zero_hash,
|
parent_root: spec.zero_hash,
|
||||||
state_root,
|
state_root,
|
||||||
randao_reveal: spec.zero_hash,
|
randao_reveal: spec.zero_hash,
|
||||||
candidate_pow_receipt_root: spec.zero_hash,
|
eth1_data: Eth1Data {
|
||||||
|
deposit_root: Hash256::zero(),
|
||||||
|
block_hash: Hash256::zero(),
|
||||||
|
},
|
||||||
signature: spec.empty_signature.clone(),
|
signature: spec.empty_signature.clone(),
|
||||||
body: BeaconBlockBody {
|
body: BeaconBlockBody {
|
||||||
proposer_slashings: vec![],
|
proposer_slashings: vec![],
|
||||||
@ -48,7 +51,8 @@ mod tests {
|
|||||||
assert!(genesis_block.slot == 0);
|
assert!(genesis_block.slot == 0);
|
||||||
assert!(genesis_block.parent_root.is_zero());
|
assert!(genesis_block.parent_root.is_zero());
|
||||||
assert!(genesis_block.randao_reveal.is_zero());
|
assert!(genesis_block.randao_reveal.is_zero());
|
||||||
assert!(genesis_block.candidate_pow_receipt_root.is_zero()); // aka deposit_root
|
assert!(genesis_block.eth1_data.deposit_root.is_zero());
|
||||||
|
assert!(genesis_block.eth1_data.block_hash.is_zero());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -80,8 +80,8 @@ pub fn genesis_beacon_state(spec: &ChainSpec) -> Result<BeaconState, Error> {
|
|||||||
/*
|
/*
|
||||||
* PoW receipt root
|
* PoW receipt root
|
||||||
*/
|
*/
|
||||||
processed_pow_receipt_root: spec.processed_pow_receipt_root,
|
latest_eth1_data: spec.intial_eth1_data.clone(),
|
||||||
candidate_pow_receipt_roots: vec![],
|
eth1_data_votes: vec![],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,10 +213,7 @@ mod tests {
|
|||||||
|
|
||||||
let state = genesis_beacon_state(&spec).unwrap();
|
let state = genesis_beacon_state(&spec).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(&state.latest_eth1_data, &spec.intial_eth1_data);
|
||||||
state.processed_pow_receipt_root,
|
assert!(state.eth1_data_votes.is_empty());
|
||||||
spec.processed_pow_receipt_root
|
|
||||||
);
|
|
||||||
assert!(state.candidate_pow_receipt_roots.is_empty());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use super::ChainSpec;
|
use super::ChainSpec;
|
||||||
use bls::{Keypair, PublicKey, SecretKey, Signature};
|
use bls::{Keypair, PublicKey, SecretKey, Signature};
|
||||||
|
|
||||||
use types::{Address, Hash256, ValidatorRecord};
|
use types::{Address, Eth1Data, Hash256, ValidatorRecord};
|
||||||
|
|
||||||
/// The size of a validators deposit in GWei.
|
/// The size of a validators deposit in GWei.
|
||||||
pub const DEPOSIT_GWEI: u64 = 32_000_000_000;
|
pub const DEPOSIT_GWEI: u64 = 32_000_000_000;
|
||||||
@ -18,9 +18,8 @@ impl ChainSpec {
|
|||||||
*/
|
*/
|
||||||
shard_count: 1_024,
|
shard_count: 1_024,
|
||||||
target_committee_size: 128,
|
target_committee_size: 128,
|
||||||
ejection_balance: 16,
|
ejection_balance: 16 * u64::pow(10, 9),
|
||||||
max_balance_churn_quotient: 32,
|
max_balance_churn_quotient: 32,
|
||||||
gwei_per_eth: u64::pow(10, 9),
|
|
||||||
beacon_chain_shard_number: u64::max_value(),
|
beacon_chain_shard_number: u64::max_value(),
|
||||||
max_casper_votes: 1_024,
|
max_casper_votes: 1_024,
|
||||||
latest_block_roots_length: 8_192,
|
latest_block_roots_length: 8_192,
|
||||||
@ -32,8 +31,8 @@ impl ChainSpec {
|
|||||||
*/
|
*/
|
||||||
deposit_contract_address: Address::from("TBD".as_bytes()),
|
deposit_contract_address: Address::from("TBD".as_bytes()),
|
||||||
deposit_contract_tree_depth: 32,
|
deposit_contract_tree_depth: 32,
|
||||||
min_deposit: 1,
|
min_deposit: 1 * u64::pow(10, 9),
|
||||||
max_deposit: 32,
|
max_deposit: 32 * u64::pow(10, 9),
|
||||||
/*
|
/*
|
||||||
* Initial Values
|
* Initial Values
|
||||||
*/
|
*/
|
||||||
@ -52,12 +51,12 @@ impl ChainSpec {
|
|||||||
epoch_length: 64,
|
epoch_length: 64,
|
||||||
seed_lookahead: 64,
|
seed_lookahead: 64,
|
||||||
entry_exit_delay: 256,
|
entry_exit_delay: 256,
|
||||||
pow_receipt_root_voting_period: 1_024,
|
eth1_data_voting_period: 1_024,
|
||||||
min_validator_withdrawal_time: u64::pow(2, 14),
|
min_validator_withdrawal_time: u64::pow(2, 14),
|
||||||
/*
|
/*
|
||||||
* Reward and penalty quotients
|
* Reward and penalty quotients
|
||||||
*/
|
*/
|
||||||
base_reward_quotient: 1_024,
|
base_reward_quotient: 32,
|
||||||
whistleblower_reward_quotient: 512,
|
whistleblower_reward_quotient: 512,
|
||||||
includer_reward_quotient: 8,
|
includer_reward_quotient: 8,
|
||||||
inactivity_penalty_quotient: u64::pow(2, 24),
|
inactivity_penalty_quotient: u64::pow(2, 24),
|
||||||
@ -75,7 +74,10 @@ impl ChainSpec {
|
|||||||
initial_validators: initial_validators_for_testing(),
|
initial_validators: initial_validators_for_testing(),
|
||||||
initial_balances: initial_balances_for_testing(),
|
initial_balances: initial_balances_for_testing(),
|
||||||
genesis_time: 1_544_672_897,
|
genesis_time: 1_544_672_897,
|
||||||
processed_pow_receipt_root: Hash256::from("pow_root".as_bytes()),
|
intial_eth1_data: Eth1Data {
|
||||||
|
deposit_root: Hash256::from("deposit_root".as_bytes()),
|
||||||
|
block_hash: Hash256::from("block_hash".as_bytes()),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ extern crate types;
|
|||||||
mod foundation;
|
mod foundation;
|
||||||
|
|
||||||
use bls::Signature;
|
use bls::Signature;
|
||||||
use types::{Address, Hash256, ValidatorRecord};
|
use types::{Address, Eth1Data, Hash256, ValidatorRecord};
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
pub struct ChainSpec {
|
pub struct ChainSpec {
|
||||||
@ -15,7 +15,6 @@ pub struct ChainSpec {
|
|||||||
pub target_committee_size: u64,
|
pub target_committee_size: u64,
|
||||||
pub ejection_balance: u64,
|
pub ejection_balance: u64,
|
||||||
pub max_balance_churn_quotient: u64,
|
pub max_balance_churn_quotient: u64,
|
||||||
pub gwei_per_eth: u64,
|
|
||||||
pub beacon_chain_shard_number: u64,
|
pub beacon_chain_shard_number: u64,
|
||||||
pub max_casper_votes: u64,
|
pub max_casper_votes: u64,
|
||||||
pub latest_block_roots_length: u64,
|
pub latest_block_roots_length: u64,
|
||||||
@ -47,7 +46,7 @@ pub struct ChainSpec {
|
|||||||
pub epoch_length: u64,
|
pub epoch_length: u64,
|
||||||
pub seed_lookahead: u64,
|
pub seed_lookahead: u64,
|
||||||
pub entry_exit_delay: u64,
|
pub entry_exit_delay: u64,
|
||||||
pub pow_receipt_root_voting_period: u64, // a.k.a. deposit_root_voting_period
|
pub eth1_data_voting_period: u64,
|
||||||
pub min_validator_withdrawal_time: u64,
|
pub min_validator_withdrawal_time: u64,
|
||||||
/*
|
/*
|
||||||
* Reward and penalty quotients
|
* Reward and penalty quotients
|
||||||
@ -70,5 +69,5 @@ pub struct ChainSpec {
|
|||||||
pub initial_validators: Vec<ValidatorRecord>,
|
pub initial_validators: Vec<ValidatorRecord>,
|
||||||
pub initial_balances: Vec<u64>,
|
pub initial_balances: Vec<u64>,
|
||||||
pub genesis_time: u64,
|
pub genesis_time: u64,
|
||||||
pub processed_pow_receipt_root: Hash256,
|
pub intial_eth1_data: Eth1Data,
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use super::ssz::{ssz_encode, Decodable, DecodeError, Encodable, SszStream};
|
use super::ssz::{ssz_encode, Decodable, DecodeError, Encodable, SszStream};
|
||||||
use super::{BeaconBlockBody, Hash256};
|
use super::{BeaconBlockBody, Eth1Data, Hash256};
|
||||||
use crate::test_utils::TestRandom;
|
use crate::test_utils::TestRandom;
|
||||||
use bls::Signature;
|
use bls::Signature;
|
||||||
use hashing::canonical_hash;
|
use hashing::canonical_hash;
|
||||||
@ -11,7 +11,7 @@ pub struct BeaconBlock {
|
|||||||
pub parent_root: Hash256,
|
pub parent_root: Hash256,
|
||||||
pub state_root: Hash256,
|
pub state_root: Hash256,
|
||||||
pub randao_reveal: Hash256,
|
pub randao_reveal: Hash256,
|
||||||
pub candidate_pow_receipt_root: Hash256,
|
pub eth1_data: Eth1Data,
|
||||||
pub signature: Signature,
|
pub signature: Signature,
|
||||||
pub body: BeaconBlockBody,
|
pub body: BeaconBlockBody,
|
||||||
}
|
}
|
||||||
@ -30,7 +30,7 @@ impl Encodable for BeaconBlock {
|
|||||||
s.append(&self.parent_root);
|
s.append(&self.parent_root);
|
||||||
s.append(&self.state_root);
|
s.append(&self.state_root);
|
||||||
s.append(&self.randao_reveal);
|
s.append(&self.randao_reveal);
|
||||||
s.append(&self.candidate_pow_receipt_root);
|
s.append(&self.eth1_data);
|
||||||
s.append(&self.signature);
|
s.append(&self.signature);
|
||||||
s.append(&self.body);
|
s.append(&self.body);
|
||||||
}
|
}
|
||||||
@ -42,7 +42,7 @@ impl Decodable for BeaconBlock {
|
|||||||
let (parent_root, i) = <_>::ssz_decode(bytes, i)?;
|
let (parent_root, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
let (state_root, i) = <_>::ssz_decode(bytes, i)?;
|
let (state_root, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
let (randao_reveal, i) = <_>::ssz_decode(bytes, i)?;
|
let (randao_reveal, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
let (candidate_pow_receipt_root, i) = <_>::ssz_decode(bytes, i)?;
|
let (eth1_data, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
let (signature, i) = <_>::ssz_decode(bytes, i)?;
|
let (signature, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
let (body, i) = <_>::ssz_decode(bytes, i)?;
|
let (body, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ impl Decodable for BeaconBlock {
|
|||||||
parent_root,
|
parent_root,
|
||||||
state_root,
|
state_root,
|
||||||
randao_reveal,
|
randao_reveal,
|
||||||
candidate_pow_receipt_root,
|
eth1_data,
|
||||||
signature,
|
signature,
|
||||||
body,
|
body,
|
||||||
},
|
},
|
||||||
@ -68,7 +68,7 @@ impl<T: RngCore> TestRandom<T> for BeaconBlock {
|
|||||||
parent_root: <_>::random_for_test(rng),
|
parent_root: <_>::random_for_test(rng),
|
||||||
state_root: <_>::random_for_test(rng),
|
state_root: <_>::random_for_test(rng),
|
||||||
randao_reveal: <_>::random_for_test(rng),
|
randao_reveal: <_>::random_for_test(rng),
|
||||||
candidate_pow_receipt_root: <_>::random_for_test(rng),
|
eth1_data: <_>::random_for_test(rng),
|
||||||
signature: <_>::random_for_test(rng),
|
signature: <_>::random_for_test(rng),
|
||||||
body: <_>::random_for_test(rng),
|
body: <_>::random_for_test(rng),
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use super::candidate_pow_receipt_root_record::CandidatePoWReceiptRootRecord;
|
|
||||||
use super::crosslink_record::CrosslinkRecord;
|
use super::crosslink_record::CrosslinkRecord;
|
||||||
|
use super::eth1_data::Eth1Data;
|
||||||
|
use super::eth1_data_vote::Eth1DataVote;
|
||||||
use super::fork_data::ForkData;
|
use super::fork_data::ForkData;
|
||||||
use super::pending_attestation_record::PendingAttestationRecord;
|
use super::pending_attestation_record::PendingAttestationRecord;
|
||||||
use super::validator_record::ValidatorRecord;
|
use super::validator_record::ValidatorRecord;
|
||||||
@ -52,9 +53,9 @@ pub struct BeaconState {
|
|||||||
pub latest_attestations: Vec<PendingAttestationRecord>,
|
pub latest_attestations: Vec<PendingAttestationRecord>,
|
||||||
pub batched_block_roots: Vec<Hash256>,
|
pub batched_block_roots: Vec<Hash256>,
|
||||||
|
|
||||||
// PoW receipt root (a.k.a. deposit root)
|
// Ethereum 1.0 chain data
|
||||||
pub processed_pow_receipt_root: Hash256,
|
pub latest_eth1_data: Eth1Data,
|
||||||
pub candidate_pow_receipt_roots: Vec<CandidatePoWReceiptRootRecord>,
|
pub eth1_data_votes: Vec<Eth1DataVote>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BeaconState {
|
impl BeaconState {
|
||||||
@ -93,8 +94,8 @@ impl Encodable for BeaconState {
|
|||||||
s.append(&self.latest_penalized_exit_balances);
|
s.append(&self.latest_penalized_exit_balances);
|
||||||
s.append(&self.latest_attestations);
|
s.append(&self.latest_attestations);
|
||||||
s.append(&self.batched_block_roots);
|
s.append(&self.batched_block_roots);
|
||||||
s.append(&self.processed_pow_receipt_root);
|
s.append(&self.latest_eth1_data);
|
||||||
s.append(&self.candidate_pow_receipt_roots);
|
s.append(&self.eth1_data_votes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,8 +127,8 @@ impl Decodable for BeaconState {
|
|||||||
let (latest_penalized_exit_balances, i) = <_>::ssz_decode(bytes, i)?;
|
let (latest_penalized_exit_balances, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
let (latest_attestations, i) = <_>::ssz_decode(bytes, i)?;
|
let (latest_attestations, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
let (batched_block_roots, i) = <_>::ssz_decode(bytes, i)?;
|
let (batched_block_roots, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
let (processed_pow_receipt_root, i) = <_>::ssz_decode(bytes, i)?;
|
let (latest_eth1_data, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
let (candidate_pow_receipt_roots, i) = <_>::ssz_decode(bytes, i)?;
|
let (eth1_data_votes, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
Self {
|
Self {
|
||||||
@ -157,8 +158,8 @@ impl Decodable for BeaconState {
|
|||||||
latest_penalized_exit_balances,
|
latest_penalized_exit_balances,
|
||||||
latest_attestations,
|
latest_attestations,
|
||||||
batched_block_roots,
|
batched_block_roots,
|
||||||
processed_pow_receipt_root,
|
latest_eth1_data,
|
||||||
candidate_pow_receipt_roots,
|
eth1_data_votes,
|
||||||
},
|
},
|
||||||
i,
|
i,
|
||||||
))
|
))
|
||||||
@ -194,8 +195,8 @@ impl<T: RngCore> TestRandom<T> for BeaconState {
|
|||||||
latest_penalized_exit_balances: <_>::random_for_test(rng),
|
latest_penalized_exit_balances: <_>::random_for_test(rng),
|
||||||
latest_attestations: <_>::random_for_test(rng),
|
latest_attestations: <_>::random_for_test(rng),
|
||||||
batched_block_roots: <_>::random_for_test(rng),
|
batched_block_roots: <_>::random_for_test(rng),
|
||||||
processed_pow_receipt_root: <_>::random_for_test(rng),
|
latest_eth1_data: <_>::random_for_test(rng),
|
||||||
candidate_pow_receipt_roots: <_>::random_for_test(rng),
|
eth1_data_votes: <_>::random_for_test(rng),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,39 +4,39 @@ use crate::test_utils::TestRandom;
|
|||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
|
|
||||||
// Note: this is refer to as DepositRootVote in specs
|
// Note: this is refer to as DepositRootVote in specs
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone, Default)]
|
||||||
pub struct CandidatePoWReceiptRootRecord {
|
pub struct Eth1Data {
|
||||||
pub candidate_pow_receipt_root: Hash256,
|
pub deposit_root: Hash256,
|
||||||
pub votes: u64,
|
pub block_hash: Hash256,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Encodable for CandidatePoWReceiptRootRecord {
|
impl Encodable for Eth1Data {
|
||||||
fn ssz_append(&self, s: &mut SszStream) {
|
fn ssz_append(&self, s: &mut SszStream) {
|
||||||
s.append(&self.candidate_pow_receipt_root);
|
s.append(&self.deposit_root);
|
||||||
s.append(&self.votes);
|
s.append(&self.block_hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Decodable for CandidatePoWReceiptRootRecord {
|
impl Decodable for Eth1Data {
|
||||||
fn ssz_decode(bytes: &[u8], i: usize) -> Result<(Self, usize), DecodeError> {
|
fn ssz_decode(bytes: &[u8], i: usize) -> Result<(Self, usize), DecodeError> {
|
||||||
let (candidate_pow_receipt_root, i) = <_>::ssz_decode(bytes, i)?;
|
let (deposit_root, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
let (votes, i) = <_>::ssz_decode(bytes, i)?;
|
let (block_hash, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
Self {
|
Self {
|
||||||
candidate_pow_receipt_root,
|
deposit_root,
|
||||||
votes,
|
block_hash,
|
||||||
},
|
},
|
||||||
i,
|
i,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: RngCore> TestRandom<T> for CandidatePoWReceiptRootRecord {
|
impl<T: RngCore> TestRandom<T> for Eth1Data {
|
||||||
fn random_for_test(rng: &mut T) -> Self {
|
fn random_for_test(rng: &mut T) -> Self {
|
||||||
Self {
|
Self {
|
||||||
candidate_pow_receipt_root: <_>::random_for_test(rng),
|
deposit_root: <_>::random_for_test(rng),
|
||||||
votes: <_>::random_for_test(rng),
|
block_hash: <_>::random_for_test(rng),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
pub fn test_ssz_round_trip() {
|
pub fn test_ssz_round_trip() {
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
let mut rng = XorShiftRng::from_seed([42; 16]);
|
||||||
let original = CandidatePoWReceiptRootRecord::random_for_test(&mut rng);
|
let original = Eth1Data::random_for_test(&mut rng);
|
||||||
|
|
||||||
let bytes = ssz_encode(&original);
|
let bytes = ssz_encode(&original);
|
||||||
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
60
eth2/types/src/eth1_data_vote.rs
Normal file
60
eth2/types/src/eth1_data_vote.rs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
use super::ssz::{Decodable, DecodeError, Encodable, SszStream};
|
||||||
|
use super::Eth1Data;
|
||||||
|
use crate::test_utils::TestRandom;
|
||||||
|
use rand::RngCore;
|
||||||
|
|
||||||
|
// Note: this is refer to as DepositRootVote in specs
|
||||||
|
#[derive(Debug, PartialEq, Clone, Default)]
|
||||||
|
pub struct Eth1DataVote {
|
||||||
|
pub eth1_data: Eth1Data,
|
||||||
|
pub vote_count: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Encodable for Eth1DataVote {
|
||||||
|
fn ssz_append(&self, s: &mut SszStream) {
|
||||||
|
s.append(&self.eth1_data);
|
||||||
|
s.append(&self.vote_count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Decodable for Eth1DataVote {
|
||||||
|
fn ssz_decode(bytes: &[u8], i: usize) -> Result<(Self, usize), DecodeError> {
|
||||||
|
let (eth1_data, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
|
let (vote_count, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
|
|
||||||
|
Ok((
|
||||||
|
Self {
|
||||||
|
eth1_data,
|
||||||
|
vote_count,
|
||||||
|
},
|
||||||
|
i,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: RngCore> TestRandom<T> for Eth1DataVote {
|
||||||
|
fn random_for_test(rng: &mut T) -> Self {
|
||||||
|
Self {
|
||||||
|
eth1_data: <_>::random_for_test(rng),
|
||||||
|
vote_count: <_>::random_for_test(rng),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::super::ssz::ssz_encode;
|
||||||
|
use super::*;
|
||||||
|
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
pub fn test_ssz_round_trip() {
|
||||||
|
let mut rng = XorShiftRng::from_seed([42; 16]);
|
||||||
|
let original = Eth1DataVote::random_for_test(&mut rng);
|
||||||
|
|
||||||
|
let bytes = ssz_encode(&original);
|
||||||
|
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(original, decoded);
|
||||||
|
}
|
||||||
|
}
|
@ -10,12 +10,13 @@ pub mod attestation_data;
|
|||||||
pub mod beacon_block;
|
pub mod beacon_block;
|
||||||
pub mod beacon_block_body;
|
pub mod beacon_block_body;
|
||||||
pub mod beacon_state;
|
pub mod beacon_state;
|
||||||
pub mod candidate_pow_receipt_root_record;
|
|
||||||
pub mod casper_slashing;
|
pub mod casper_slashing;
|
||||||
pub mod crosslink_record;
|
pub mod crosslink_record;
|
||||||
pub mod deposit;
|
pub mod deposit;
|
||||||
pub mod deposit_data;
|
pub mod deposit_data;
|
||||||
pub mod deposit_input;
|
pub mod deposit_input;
|
||||||
|
pub mod eth1_data;
|
||||||
|
pub mod eth1_data_vote;
|
||||||
pub mod exit;
|
pub mod exit;
|
||||||
pub mod fork_data;
|
pub mod fork_data;
|
||||||
pub mod pending_attestation_record;
|
pub mod pending_attestation_record;
|
||||||
@ -27,6 +28,7 @@ pub mod slashable_vote_data;
|
|||||||
pub mod special_record;
|
pub mod special_record;
|
||||||
pub mod validator_record;
|
pub mod validator_record;
|
||||||
pub mod validator_registry;
|
pub mod validator_registry;
|
||||||
|
pub mod validator_registry_delta_block;
|
||||||
|
|
||||||
pub mod readers;
|
pub mod readers;
|
||||||
|
|
||||||
@ -43,6 +45,8 @@ pub use crate::crosslink_record::CrosslinkRecord;
|
|||||||
pub use crate::deposit::Deposit;
|
pub use crate::deposit::Deposit;
|
||||||
pub use crate::deposit_data::DepositData;
|
pub use crate::deposit_data::DepositData;
|
||||||
pub use crate::deposit_input::DepositInput;
|
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::exit::Exit;
|
||||||
pub use crate::fork_data::ForkData;
|
pub use crate::fork_data::ForkData;
|
||||||
pub use crate::pending_attestation_record::PendingAttestationRecord;
|
pub use crate::pending_attestation_record::PendingAttestationRecord;
|
||||||
@ -52,6 +56,7 @@ pub use crate::shard_committee::ShardCommittee;
|
|||||||
pub use crate::slashable_vote_data::SlashableVoteData;
|
pub use crate::slashable_vote_data::SlashableVoteData;
|
||||||
pub use crate::special_record::{SpecialRecord, SpecialRecordKind};
|
pub use crate::special_record::{SpecialRecord, SpecialRecordKind};
|
||||||
pub use crate::validator_record::{StatusFlags as ValidatorStatusFlags, ValidatorRecord};
|
pub use crate::validator_record::{StatusFlags as ValidatorStatusFlags, ValidatorRecord};
|
||||||
|
pub use crate::validator_registry_delta_block::ValidatorRegistryDeltaBlock;
|
||||||
|
|
||||||
pub type Hash256 = H256;
|
pub type Hash256 = H256;
|
||||||
pub type Address = H160;
|
pub type Address = H160;
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
use super::{Address, Hash256};
|
|
||||||
use bls::{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,
|
|
||||||
}
|
|
89
eth2/types/src/validator_registry_delta_block.rs
Normal file
89
eth2/types/src/validator_registry_delta_block.rs
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
use super::Hash256;
|
||||||
|
use crate::test_utils::TestRandom;
|
||||||
|
use bls::PublicKey;
|
||||||
|
use rand::RngCore;
|
||||||
|
use ssz::{Decodable, DecodeError, Encodable, SszStream};
|
||||||
|
|
||||||
|
// The information gathered from the PoW chain validator registration function.
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub struct ValidatorRegistryDeltaBlock {
|
||||||
|
pub latest_registry_delta_root: Hash256,
|
||||||
|
pub validator_index: u32,
|
||||||
|
pub pubkey: PublicKey,
|
||||||
|
pub slot: u64,
|
||||||
|
pub flag: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ValidatorRegistryDeltaBlock {
|
||||||
|
/// Yields a "default" `ValidatorRecord`. Primarily used for testing.
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
latest_registry_delta_root: Hash256::zero(),
|
||||||
|
validator_index: std::u32::MAX,
|
||||||
|
pubkey: PublicKey::default(),
|
||||||
|
slot: std::u64::MAX,
|
||||||
|
flag: std::u64::MAX,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Encodable for ValidatorRegistryDeltaBlock {
|
||||||
|
fn ssz_append(&self, s: &mut SszStream) {
|
||||||
|
s.append(&self.latest_registry_delta_root);
|
||||||
|
s.append(&self.validator_index);
|
||||||
|
s.append(&self.pubkey);
|
||||||
|
s.append(&self.slot);
|
||||||
|
s.append(&self.flag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Decodable for ValidatorRegistryDeltaBlock {
|
||||||
|
fn ssz_decode(bytes: &[u8], i: usize) -> Result<(Self, usize), DecodeError> {
|
||||||
|
let (latest_registry_delta_root, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
|
let (validator_index, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
|
let (pubkey, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
|
let (slot, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
|
let (flag, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
|
|
||||||
|
Ok((
|
||||||
|
Self {
|
||||||
|
latest_registry_delta_root,
|
||||||
|
validator_index,
|
||||||
|
pubkey,
|
||||||
|
slot,
|
||||||
|
flag,
|
||||||
|
},
|
||||||
|
i,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: RngCore> TestRandom<T> for ValidatorRegistryDeltaBlock {
|
||||||
|
fn random_for_test(rng: &mut T) -> Self {
|
||||||
|
Self {
|
||||||
|
latest_registry_delta_root: <_>::random_for_test(rng),
|
||||||
|
validator_index: <_>::random_for_test(rng),
|
||||||
|
pubkey: <_>::random_for_test(rng),
|
||||||
|
slot: <_>::random_for_test(rng),
|
||||||
|
flag: <_>::random_for_test(rng),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::super::ssz::ssz_encode;
|
||||||
|
use super::*;
|
||||||
|
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
pub fn test_ssz_round_trip() {
|
||||||
|
let mut rng = XorShiftRng::from_seed([42; 16]);
|
||||||
|
let original = ValidatorRegistryDeltaBlock::random_for_test(&mut rng);
|
||||||
|
|
||||||
|
let bytes = ssz_encode(&original);
|
||||||
|
let (decoded, _) = <_>::ssz_decode(&bytes, 0).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(original, decoded);
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,7 @@ use protos::services::{
|
|||||||
};
|
};
|
||||||
use protos::services_grpc::BeaconBlockServiceClient;
|
use protos::services_grpc::BeaconBlockServiceClient;
|
||||||
use ssz::{ssz_encode, Decodable};
|
use ssz::{ssz_encode, Decodable};
|
||||||
use types::{BeaconBlock, BeaconBlockBody, Hash256, Signature};
|
use types::{BeaconBlock, BeaconBlockBody, Eth1Data, Hash256, Signature};
|
||||||
|
|
||||||
impl BeaconNode for BeaconBlockServiceClient {
|
impl BeaconNode for BeaconBlockServiceClient {
|
||||||
/// Request a Beacon Node (BN) to produce a new block at the supplied slot.
|
/// Request a Beacon Node (BN) to produce a new block at the supplied slot.
|
||||||
@ -31,7 +31,10 @@ impl BeaconNode for BeaconBlockServiceClient {
|
|||||||
parent_root: Hash256::zero(),
|
parent_root: Hash256::zero(),
|
||||||
state_root: Hash256::zero(),
|
state_root: Hash256::zero(),
|
||||||
randao_reveal: Hash256::from(block.get_randao_reveal()),
|
randao_reveal: Hash256::from(block.get_randao_reveal()),
|
||||||
candidate_pow_receipt_root: Hash256::zero(),
|
eth1_data: Eth1Data {
|
||||||
|
deposit_root: Hash256::zero(),
|
||||||
|
block_hash: Hash256::zero(),
|
||||||
|
},
|
||||||
signature,
|
signature,
|
||||||
body: BeaconBlockBody {
|
body: BeaconBlockBody {
|
||||||
proposer_slashings: vec![],
|
proposer_slashings: vec![],
|
||||||
|
Loading…
Reference in New Issue
Block a user