Rename beacon_chain/ -> eth2/

This commit is contained in:
Paul Hauner
2019-01-22 16:16:02 +11:00
parent 87c73b1af9
commit e16f9e0aec
92 changed files with 0 additions and 0 deletions

140
eth2/spec/src/foundation.rs Normal file
View File

@@ -0,0 +1,140 @@
use super::ChainSpec;
use bls::{Keypair, PublicKey, SecretKey, Signature};
use types::{Address, Hash256, ValidatorRecord};
/// The size of a validators deposit in GWei.
pub const DEPOSIT_GWEI: u64 = 32_000_000_000;
impl ChainSpec {
/// Returns a `ChainSpec` compatible with the specification from Ethereum Foundation.
///
/// Of course, the actual foundation specs are unknown at this point so these are just a rough
/// estimate.
pub fn foundation() -> Self {
Self {
/*
* Misc
*/
shard_count: 1_024,
target_committee_size: 128,
ejection_balance: 16,
max_balance_churn_quotient: 32,
gwei_per_eth: u64::pow(10, 9),
beacon_chain_shard_number: u64::max_value(),
max_casper_votes: 1_024,
latest_block_roots_length: 8_192,
latest_randao_mixes_length: 8_192,
latest_penalized_exit_length: 8_192,
max_withdrawals_per_epoch: 4,
/*
* Deposit contract
*/
deposit_contract_address: Address::from("TBD".as_bytes()),
deposit_contract_tree_depth: 32,
min_deposit: 1,
max_deposit: 32,
/*
* Initial Values
*/
genesis_fork_version: 0,
genesis_slot_number: 0,
genesis_start_shard: 0,
far_future_slot: u64::max_value(),
zero_hash: Hash256::zero(),
empty_signature: Signature::empty_signature(),
bls_withdrawal_prefix_byte: 0x00,
/*
* Time parameters
*/
slot_duration: 6,
min_attestation_inclusion_delay: 4,
epoch_length: 64,
seed_lookahead: 64,
entry_exit_delay: 256,
pow_receipt_root_voting_period: 1_024,
min_validator_withdrawal_time: u64::pow(2, 14),
/*
* Reward and penalty quotients
*/
base_reward_quotient: 1_024,
whistleblower_reward_quotient: 512,
includer_reward_quotient: 8,
inactivity_penalty_quotient: u64::pow(2, 24),
/*
* Max operations per block
*/
max_proposer_slashings: 16,
max_casper_slashings: 16,
max_attestations: 128,
max_deposits: 16,
max_exits: 16,
/*
* Intialization parameters
*/
initial_validators: initial_validators_for_testing(),
initial_balances: initial_balances_for_testing(),
genesis_time: 1_544_672_897,
processed_pow_receipt_root: Hash256::from("pow_root".as_bytes()),
}
}
}
/// Generate a set of validator records to use with testing until the real chain starts.
fn initial_validators_for_testing() -> Vec<ValidatorRecord> {
// Some dummy private keys to start with.
let key_strings = vec![
"jzjxxgjajfjrmgodszzsgqccmhnyvetcuxobhtynojtpdtbj",
"gpeehcjudxdijzhjgirfuhahmnjutlchjmoffxmimbdejakd",
"ntrrdwwebodokuwaclhoqreqyodngoyhurvesghjfxeswoaj",
"cibmzkqrzdgdlrvqaxinwpvyhcgjkeysrsjkqtkcxvznsvth",
"erqrfuahdwprsstkawggounxmihzhrvbhchcyiwtaypqcedr",
];
let mut initial_validators = Vec::with_capacity(key_strings.len());
for key_string in key_strings {
let keypair = {
let secret_key = match SecretKey::from_bytes(&key_string.as_bytes()) {
Ok(key) => key,
Err(_) => unreachable!(), // Keys are static and should not fail.
};
let public_key = PublicKey::from_secret_key(&secret_key);
Keypair {
sk: secret_key,
pk: public_key,
}
};
let validator_record = ValidatorRecord {
pubkey: keypair.pk.clone(),
withdrawal_credentials: Hash256::zero(),
randao_commitment: Hash256::zero(),
randao_layers: 0,
activation_slot: u64::max_value(),
exit_slot: u64::max_value(),
withdrawal_slot: u64::max_value(),
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
}
fn initial_balances_for_testing() -> Vec<u64> {
vec![DEPOSIT_GWEI; 4]
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_foundation_spec_can_be_constructed() {
let _ = ChainSpec::foundation();
}
}

74
eth2/spec/src/lib.rs Normal file
View File

@@ -0,0 +1,74 @@
extern crate bls;
extern crate types;
mod foundation;
use bls::Signature;
use types::{Address, Hash256, ValidatorRecord};
#[derive(PartialEq, Debug)]
pub struct ChainSpec {
/*
* Misc
*/
pub shard_count: u64,
pub target_committee_size: u64,
pub ejection_balance: u64,
pub max_balance_churn_quotient: u64,
pub gwei_per_eth: u64,
pub beacon_chain_shard_number: u64,
pub max_casper_votes: u64,
pub latest_block_roots_length: u64,
pub latest_randao_mixes_length: u64,
pub latest_penalized_exit_length: u64,
pub max_withdrawals_per_epoch: u64,
/*
* Deposit contract
*/
pub deposit_contract_address: Address,
pub deposit_contract_tree_depth: u64,
pub min_deposit: u64,
pub max_deposit: u64,
/*
* Initial Values
*/
pub genesis_fork_version: u64,
pub genesis_slot_number: u64,
pub genesis_start_shard: u64,
pub far_future_slot: u64,
pub zero_hash: Hash256,
pub empty_signature: Signature,
pub bls_withdrawal_prefix_byte: u8,
/*
* Time parameters
*/
pub slot_duration: u64,
pub min_attestation_inclusion_delay: u64,
pub epoch_length: u64,
pub seed_lookahead: u64,
pub entry_exit_delay: u64,
pub pow_receipt_root_voting_period: u64, // a.k.a. deposit_root_voting_period
pub min_validator_withdrawal_time: u64,
/*
* Reward and penalty quotients
*/
pub base_reward_quotient: u64,
pub whistleblower_reward_quotient: u64,
pub includer_reward_quotient: u64,
pub inactivity_penalty_quotient: u64,
/*
* Max operations per block
*/
pub max_proposer_slashings: u64,
pub max_casper_slashings: u64,
pub max_attestations: u64,
pub max_deposits: u64,
pub max_exits: u64,
/*
* Intialization parameters
*/
pub initial_validators: Vec<ValidatorRecord>,
pub initial_balances: Vec<u64>,
pub genesis_time: u64,
pub processed_pow_receipt_root: Hash256,
}