spec: update chain spec for v0.6.1

This commit is contained in:
Michael Sproul 2019-05-07 13:29:14 +10:00
parent 839ef0119b
commit 5c03f7b06c
No known key found for this signature in database
GPG Key ID: 77B1309D2E54E914
9 changed files with 59 additions and 72 deletions

View File

@ -1,5 +1,5 @@
use crate::test_utils::TestRandom; use crate::test_utils::TestRandom;
use crate::{Crosslink, Epoch, Hash256, Slot}; use crate::{Epoch, Hash256, Slot};
use rand::RngCore; use rand::RngCore;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode}; use ssz_derive::{Decode, Encode};
@ -37,7 +37,7 @@ pub struct AttestationData {
// Crosslink Vote // Crosslink Vote
pub shard: u64, pub shard: u64,
pub previous_crosslink_root: Crosslink, pub previous_crosslink_root: Hash256,
pub crosslink_data_root: Hash256, pub crosslink_data_root: Hash256,
} }

View File

@ -43,7 +43,7 @@ impl BeaconBlock {
previous_block_root: spec.zero_hash, previous_block_root: spec.zero_hash,
state_root: spec.zero_hash, state_root: spec.zero_hash,
body: BeaconBlockBody { body: BeaconBlockBody {
randao_reveal: spec.empty_signature.clone(), randao_reveal: Signature::empty_signature(),
eth1_data: Eth1Data { eth1_data: Eth1Data {
deposit_root: spec.zero_hash, deposit_root: spec.zero_hash,
block_hash: spec.zero_hash, block_hash: spec.zero_hash,
@ -56,7 +56,7 @@ impl BeaconBlock {
voluntary_exits: vec![], voluntary_exits: vec![],
transfers: vec![], transfers: vec![],
}, },
signature: spec.empty_signature.clone(), signature: Signature::empty_signature(),
} }
} }
@ -91,7 +91,7 @@ impl BeaconBlock {
pub fn temporary_block_header(&self, spec: &ChainSpec) -> BeaconBlockHeader { pub fn temporary_block_header(&self, spec: &ChainSpec) -> BeaconBlockHeader {
BeaconBlockHeader { BeaconBlockHeader {
state_root: spec.zero_hash, state_root: spec.zero_hash,
signature: spec.empty_signature.clone(), signature: Signature::empty_signature(),
..self.block_header() ..self.block_header()
} }
} }

View File

@ -1,26 +1,23 @@
use crate::*; use crate::*;
use bls::Signature;
use int_to_bytes::int_to_bytes4; use int_to_bytes::int_to_bytes4;
use serde_derive::Deserialize; use serde_derive::Deserialize;
use test_utils::u8_from_hex_str; use test_utils::u8_from_hex_str;
const GWEI: u64 = 1_000_000_000;
/// Each of the BLS signature domains. /// Each of the BLS signature domains.
/// ///
/// Spec v0.5.1 /// Spec v0.6.1
pub enum Domain { pub enum Domain {
BeaconBlock, BeaconProposer,
Randao, Randao,
Attestation, Attestation,
Deposit, Deposit,
Exit, VoluntaryExit,
Transfer, Transfer,
} }
/// Holds all the "constants" for a BeaconChain. /// Holds all the "constants" for a BeaconChain.
/// ///
/// Spec v0.5.1 /// Spec v0.6.1
#[derive(PartialEq, Debug, Clone, Deserialize)] #[derive(PartialEq, Debug, Clone, Deserialize)]
#[serde(default)] #[serde(default)]
pub struct ChainSpec { pub struct ChainSpec {
@ -29,35 +26,32 @@ pub struct ChainSpec {
*/ */
pub shard_count: u64, pub shard_count: u64,
pub target_committee_size: u64, pub target_committee_size: u64,
pub max_balance_churn_quotient: u64, pub max_indices_per_attestation: u64,
pub max_indices_per_slashable_vote: usize, pub min_per_epoch_churn_limit: u64,
pub max_exit_dequeues_per_epoch: u64, pub churn_limit_quotient: u64,
pub base_rewards_per_epoch: u64,
pub shuffle_round_count: u8, pub shuffle_round_count: u8,
/* /*
* Deposit contract * Deposit contract
*/ */
pub deposit_contract_address: Address,
pub deposit_contract_tree_depth: u64, pub deposit_contract_tree_depth: u64,
/* /*
* Gwei values * Gwei values
*/ */
pub min_deposit_amount: u64, pub min_deposit_amount: u64,
pub max_deposit_amount: u64, pub max_effective_balance: u64,
pub fork_choice_balance_increment: u64,
pub ejection_balance: u64, pub ejection_balance: u64,
pub effective_balance_increment: u64,
/* /*
* Initial Values * Initial Values
*/ */
pub genesis_fork_version: u32,
pub genesis_slot: Slot, pub genesis_slot: Slot,
pub genesis_epoch: Epoch, pub genesis_epoch: Epoch,
pub genesis_start_shard: u64,
pub far_future_epoch: Epoch, pub far_future_epoch: Epoch,
pub zero_hash: Hash256, pub zero_hash: Hash256,
pub empty_signature: Signature,
#[serde(deserialize_with = "u8_from_hex_str")] #[serde(deserialize_with = "u8_from_hex_str")]
pub bls_withdrawal_prefix_byte: u8, pub bls_withdrawal_prefix_byte: u8,
@ -69,10 +63,12 @@ pub struct ChainSpec {
pub slots_per_epoch: u64, pub slots_per_epoch: u64,
pub min_seed_lookahead: Epoch, pub min_seed_lookahead: Epoch,
pub activation_exit_delay: u64, pub activation_exit_delay: u64,
pub epochs_per_eth1_voting_period: u64, pub slots_per_eth1_voting_period: u64,
pub slots_per_historical_root: usize, pub slots_per_historical_root: usize,
pub min_validator_withdrawability_delay: Epoch, pub min_validator_withdrawability_delay: Epoch,
pub persistent_committee_period: u64, pub persistent_committee_period: u64,
pub max_crosslink_epochs: u64,
pub min_epochs_to_inactivity_penalty: u64,
/* /*
* State list lengths * State list lengths
@ -85,10 +81,10 @@ pub struct ChainSpec {
* Reward and penalty quotients * Reward and penalty quotients
*/ */
pub base_reward_quotient: u64, pub base_reward_quotient: u64,
pub whistleblower_reward_quotient: u64, pub whistleblowing_reward_quotient: u64,
pub attestation_inclusion_reward_quotient: u64, pub proposer_reward_quotient: u64,
pub inactivity_penalty_quotient: u64, pub inactivity_penalty_quotient: u64,
pub min_penalty_quotient: u64, pub min_slashing_penalty_quotient: u64,
/* /*
* Max operations per block * Max operations per block
@ -108,11 +104,11 @@ pub struct ChainSpec {
* *
* Use `ChainSpec::get_domain(..)` to access these values. * Use `ChainSpec::get_domain(..)` to access these values.
*/ */
domain_beacon_block: u32, domain_beacon_proposer: u32,
domain_randao: u32, domain_randao: u32,
domain_attestation: u32, domain_attestation: u32,
domain_deposit: u32, domain_deposit: u32,
domain_exit: u32, domain_voluntary_exit: u32,
domain_transfer: u32, domain_transfer: u32,
/* /*
@ -139,14 +135,14 @@ impl ChainSpec {
/// Get the domain number that represents the fork meta and signature domain. /// Get the domain number that represents the fork meta and signature domain.
/// ///
/// Spec v0.5.1 /// Spec v0.6.1
pub fn get_domain(&self, epoch: Epoch, domain: Domain, fork: &Fork) -> u64 { pub fn get_domain(&self, epoch: Epoch, domain: Domain, fork: &Fork) -> u64 {
let domain_constant = match domain { let domain_constant = match domain {
Domain::BeaconBlock => self.domain_beacon_block, Domain::BeaconProposer => self.domain_beacon_proposer,
Domain::Randao => self.domain_randao, Domain::Randao => self.domain_randao,
Domain::Attestation => self.domain_attestation, Domain::Attestation => self.domain_attestation,
Domain::Deposit => self.domain_deposit, Domain::Deposit => self.domain_deposit,
Domain::Exit => self.domain_exit, Domain::VoluntaryExit => self.domain_voluntary_exit,
Domain::Transfer => self.domain_transfer, Domain::Transfer => self.domain_transfer,
}; };
@ -161,47 +157,40 @@ impl ChainSpec {
/// Returns a `ChainSpec` compatible with the Ethereum Foundation specification. /// Returns a `ChainSpec` compatible with the Ethereum Foundation specification.
/// ///
/// Spec v0.5.1 /// Spec v0.6.1
pub fn foundation() -> Self { pub fn foundation() -> Self {
let genesis_slot = Slot::new(2_u64.pow(32));
let slots_per_epoch = 64;
let genesis_epoch = genesis_slot.epoch(slots_per_epoch);
Self { Self {
/* /*
* Misc * Misc
*/ */
shard_count: 1_024, shard_count: 1_024,
target_committee_size: 128, target_committee_size: 128,
max_balance_churn_quotient: 32, max_indices_per_attestation: 4096,
max_indices_per_slashable_vote: 4_096, min_per_epoch_churn_limit: 4,
max_exit_dequeues_per_epoch: 4, churn_limit_quotient: 65_536,
base_rewards_per_epoch: 5,
shuffle_round_count: 90, shuffle_round_count: 90,
/* /*
* Deposit contract * Deposit contract
*/ */
deposit_contract_address: Address::zero(),
deposit_contract_tree_depth: 32, deposit_contract_tree_depth: 32,
/* /*
* Gwei values * Gwei values
*/ */
min_deposit_amount: u64::pow(2, 0) * GWEI, min_deposit_amount: u64::pow(2, 0) * u64::pow(10, 9),
max_deposit_amount: u64::pow(2, 5) * GWEI, max_effective_balance: u64::pow(2, 5) * u64::pow(10, 9),
fork_choice_balance_increment: u64::pow(2, 0) * GWEI, ejection_balance: u64::pow(2, 4) * u64::pow(10, 9),
ejection_balance: u64::pow(2, 4) * GWEI, effective_balance_increment: u64::pow(2, 0) * u64::pow(10, 9),
/* /*
* Initial Values * Initial Values
*/ */
genesis_fork_version: 0, genesis_slot: Slot::new(0),
genesis_slot, genesis_epoch: Epoch::new(0),
genesis_epoch,
genesis_start_shard: 0,
far_future_epoch: Epoch::new(u64::max_value()), far_future_epoch: Epoch::new(u64::max_value()),
zero_hash: Hash256::zero(), zero_hash: Hash256::zero(),
empty_signature: Signature::empty_signature(),
bls_withdrawal_prefix_byte: 0, bls_withdrawal_prefix_byte: 0,
/* /*
@ -209,13 +198,15 @@ impl ChainSpec {
*/ */
seconds_per_slot: 6, seconds_per_slot: 6,
min_attestation_inclusion_delay: 4, min_attestation_inclusion_delay: 4,
slots_per_epoch, slots_per_epoch: 64,
min_seed_lookahead: Epoch::new(1), min_seed_lookahead: Epoch::new(1),
activation_exit_delay: 4, activation_exit_delay: 4,
epochs_per_eth1_voting_period: 16, slots_per_eth1_voting_period: 1_024,
slots_per_historical_root: 8_192, slots_per_historical_root: 8_192,
min_validator_withdrawability_delay: Epoch::new(256), min_validator_withdrawability_delay: Epoch::new(256),
persistent_committee_period: 2_048, persistent_committee_period: 2_048,
max_crosslink_epochs: 64,
min_epochs_to_inactivity_penalty: 4,
/* /*
* State list lengths * State list lengths
@ -228,10 +219,10 @@ impl ChainSpec {
* Reward and penalty quotients * Reward and penalty quotients
*/ */
base_reward_quotient: 32, base_reward_quotient: 32,
whistleblower_reward_quotient: 512, whistleblowing_reward_quotient: 512,
attestation_inclusion_reward_quotient: 8, proposer_reward_quotient: 8,
inactivity_penalty_quotient: 16_777_216, inactivity_penalty_quotient: 33_554_432,
min_penalty_quotient: 32, min_slashing_penalty_quotient: 32,
/* /*
* Max operations per block * Max operations per block
@ -241,16 +232,16 @@ impl ChainSpec {
max_attestations: 128, max_attestations: 128,
max_deposits: 16, max_deposits: 16,
max_voluntary_exits: 16, max_voluntary_exits: 16,
max_transfers: 16, max_transfers: 0,
/* /*
* Signature domains * Signature domains
*/ */
domain_beacon_block: 0, domain_beacon_proposer: 0,
domain_randao: 1, domain_randao: 1,
domain_attestation: 2, domain_attestation: 2,
domain_deposit: 3, domain_deposit: 3,
domain_exit: 4, domain_voluntary_exit: 4,
domain_transfer: 5, domain_transfer: 5,
/* /*

View File

@ -49,11 +49,7 @@ impl TestingAttestationDataBuilder {
// Crosslink vote // Crosslink vote
shard, shard,
previous_crosslink_root: Crosslink { previous_crosslink_root: spec.zero_hash,
epoch: slot.epoch(spec.slots_per_epoch),
previous_crosslink_root: spec.zero_hash,
crosslink_data_root: spec.zero_hash,
},
crosslink_data_root: spec.zero_hash, crosslink_data_root: spec.zero_hash,
}; };

View File

@ -34,11 +34,7 @@ impl TestingAttesterSlashingBuilder {
source_root: hash_1, source_root: hash_1,
target_root: hash_1, target_root: hash_1,
shard, shard,
previous_crosslink_root: Crosslink { previous_crosslink_root: hash_1,
epoch,
previous_crosslink_root: hash_1,
crosslink_data_root: hash_1,
},
crosslink_data_root: hash_1, crosslink_data_root: hash_1,
}; };

View File

@ -34,7 +34,7 @@ impl TestingBeaconBlockBuilder {
pub fn sign(&mut self, sk: &SecretKey, fork: &Fork, spec: &ChainSpec) { pub fn sign(&mut self, sk: &SecretKey, fork: &Fork, spec: &ChainSpec) {
let message = self.block.signed_root(); let message = self.block.signed_root();
let epoch = self.block.slot.epoch(spec.slots_per_epoch); let epoch = self.block.slot.epoch(spec.slots_per_epoch);
let domain = spec.get_domain(epoch, Domain::BeaconBlock, fork); let domain = spec.get_domain(epoch, Domain::BeaconProposer, fork);
self.block.signature = Signature::new(&message, domain, sk); self.block.signature = Signature::new(&message, domain, sk);
} }

View File

@ -41,13 +41,13 @@ impl TestingProposerSlashingBuilder {
header_1.signature = { header_1.signature = {
let message = header_1.signed_root(); let message = header_1.signed_root();
let epoch = slot.epoch(spec.slots_per_epoch); let epoch = slot.epoch(spec.slots_per_epoch);
signer(proposer_index, &message[..], epoch, Domain::BeaconBlock) signer(proposer_index, &message[..], epoch, Domain::BeaconProposer)
}; };
header_2.signature = { header_2.signature = {
let message = header_2.signed_root(); let message = header_2.signed_root();
let epoch = slot.epoch(spec.slots_per_epoch); let epoch = slot.epoch(spec.slots_per_epoch);
signer(proposer_index, &message[..], epoch, Domain::BeaconBlock) signer(proposer_index, &message[..], epoch, Domain::BeaconProposer)
}; };
ProposerSlashing { ProposerSlashing {

View File

@ -25,7 +25,7 @@ impl TestingVoluntaryExitBuilder {
/// The signing secret key must match that of the exiting validator. /// The signing secret key must match that of the exiting validator.
pub fn sign(&mut self, secret_key: &SecretKey, fork: &Fork, spec: &ChainSpec) { pub fn sign(&mut self, secret_key: &SecretKey, fork: &Fork, spec: &ChainSpec) {
let message = self.exit.signed_root(); let message = self.exit.signed_root();
let domain = spec.get_domain(self.exit.epoch, Domain::Exit, fork); let domain = spec.get_domain(self.exit.epoch, Domain::VoluntaryExit, fork);
self.exit.signature = Signature::new(&message, domain, secret_key); self.exit.signature = Signature::new(&message, domain, secret_key);
} }

View File

@ -37,6 +37,11 @@ impl Validator {
self.activation_epoch <= epoch && epoch < self.exit_epoch self.activation_epoch <= epoch && epoch < self.exit_epoch
} }
/// Returns `true` if the validator is slashable at some epoch.
pub fn is_slashable_at(&self, epoch: Epoch) -> bool {
!self.slashed && self.activation_epoch <= epoch && epoch < self.withdrawable_epoch
}
/// Returns `true` if the validator is considered exited at some epoch. /// Returns `true` if the validator is considered exited at some epoch.
pub fn is_exited_at(&self, epoch: Epoch) -> bool { pub fn is_exited_at(&self, epoch: Epoch) -> bool {
self.exit_epoch <= epoch self.exit_epoch <= epoch
@ -77,7 +82,6 @@ mod tests {
assert_eq!(v.is_active_at(epoch), false); assert_eq!(v.is_active_at(epoch), false);
assert_eq!(v.is_exited_at(epoch), false); assert_eq!(v.is_exited_at(epoch), false);
assert_eq!(v.is_withdrawable_at(epoch), false); assert_eq!(v.is_withdrawable_at(epoch), false);
assert_eq!(v.initiated_exit, false);
assert_eq!(v.slashed, false); assert_eq!(v.slashed, false);
} }