Update test_harness to spec v0.2.0
This commit is contained in:
parent
5fefc79521
commit
12076bce76
@ -1,6 +1,7 @@
|
|||||||
use super::ValidatorHarness;
|
use super::ValidatorHarness;
|
||||||
use beacon_chain::BeaconChain;
|
use beacon_chain::BeaconChain;
|
||||||
pub use beacon_chain::{CheckPoint, Error as BeaconChainError};
|
pub use beacon_chain::{CheckPoint, Error as BeaconChainError};
|
||||||
|
use bls::create_proof_of_possession;
|
||||||
use db::{
|
use db::{
|
||||||
stores::{BeaconBlockStore, BeaconStateStore},
|
stores::{BeaconBlockStore, BeaconStateStore},
|
||||||
MemoryDB,
|
MemoryDB,
|
||||||
@ -13,7 +14,10 @@ use std::fs::File;
|
|||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::{BeaconBlock, ChainSpec, FreeAttestation, Keypair, Slot, Validator};
|
use types::{
|
||||||
|
BeaconBlock, ChainSpec, Deposit, DepositData, DepositInput, Eth1Data, FreeAttestation, Hash256,
|
||||||
|
Keypair, Slot,
|
||||||
|
};
|
||||||
|
|
||||||
/// The beacon chain harness simulates a single beacon node with `validator_count` validators connected
|
/// The beacon chain harness simulates a single beacon node with `validator_count` validators connected
|
||||||
/// to it. Each validator is provided a borrow to the beacon chain, where it may read
|
/// to it. Each validator is provided a borrow to the beacon chain, where it may read
|
||||||
@ -35,16 +39,17 @@ impl BeaconChainHarness {
|
|||||||
///
|
///
|
||||||
/// - A keypair, `BlockProducer` and `Attester` for each validator.
|
/// - A keypair, `BlockProducer` and `Attester` for each validator.
|
||||||
/// - A new BeaconChain struct where the given validators are in the genesis.
|
/// - A new BeaconChain struct where the given validators are in the genesis.
|
||||||
pub fn new(mut spec: ChainSpec, validator_count: usize) -> Self {
|
pub fn new(spec: ChainSpec, validator_count: usize) -> Self {
|
||||||
let db = Arc::new(MemoryDB::open());
|
let db = Arc::new(MemoryDB::open());
|
||||||
let block_store = Arc::new(BeaconBlockStore::new(db.clone()));
|
let block_store = Arc::new(BeaconBlockStore::new(db.clone()));
|
||||||
let state_store = Arc::new(BeaconStateStore::new(db.clone()));
|
let state_store = Arc::new(BeaconStateStore::new(db.clone()));
|
||||||
|
|
||||||
|
let genesis_time = 1_549_935_547; // 12th Feb 2018 (arbitrary value in the past).
|
||||||
let slot_clock = TestingSlotClock::new(spec.genesis_slot.as_u64());
|
let slot_clock = TestingSlotClock::new(spec.genesis_slot.as_u64());
|
||||||
|
let latest_eth1_data = Eth1Data {
|
||||||
// Remove the validators present in the spec (if any).
|
deposit_root: Hash256::zero(),
|
||||||
spec.initial_validators = Vec::with_capacity(validator_count);
|
block_hash: Hash256::zero(),
|
||||||
spec.initial_balances = Vec::with_capacity(validator_count);
|
};
|
||||||
|
|
||||||
debug!("Generating validator keypairs...");
|
debug!("Generating validator keypairs...");
|
||||||
|
|
||||||
@ -54,25 +59,26 @@ impl BeaconChainHarness {
|
|||||||
.map(|_| Keypair::random())
|
.map(|_| Keypair::random())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
debug!("Creating validator records...");
|
debug!("Creating validator deposits...");
|
||||||
|
|
||||||
spec.initial_validators = keypairs
|
let mut initial_validator_deposits = Vec::with_capacity(validator_count);
|
||||||
|
initial_validator_deposits = keypairs
|
||||||
.par_iter()
|
.par_iter()
|
||||||
.map(|keypair| Validator {
|
.map(|keypair| Deposit {
|
||||||
|
branch: vec![], // branch verification is not specified.
|
||||||
|
index: 0, // index verification is not specified.
|
||||||
|
deposit_data: DepositData {
|
||||||
|
amount: 32_000_000_000, // 32 ETH (in Gwei)
|
||||||
|
timestamp: genesis_time - 1,
|
||||||
|
deposit_input: DepositInput {
|
||||||
pubkey: keypair.pk.clone(),
|
pubkey: keypair.pk.clone(),
|
||||||
activation_slot: Slot::new(0),
|
withdrawal_credentials: Hash256::zero(), // Withdrawal not possible.
|
||||||
..std::default::Default::default()
|
proof_of_possession: create_proof_of_possession(&keypair),
|
||||||
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
debug!("Setting validator balances...");
|
|
||||||
|
|
||||||
spec.initial_balances = spec
|
|
||||||
.initial_validators
|
|
||||||
.par_iter()
|
|
||||||
.map(|_| 32_000_000_000) // 32 ETH
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
debug!("Creating the BeaconChain...");
|
debug!("Creating the BeaconChain...");
|
||||||
|
|
||||||
// Create the Beacon Chain
|
// Create the Beacon Chain
|
||||||
@ -81,6 +87,9 @@ impl BeaconChainHarness {
|
|||||||
state_store.clone(),
|
state_store.clone(),
|
||||||
block_store.clone(),
|
block_store.clone(),
|
||||||
slot_clock,
|
slot_clock,
|
||||||
|
genesis_time,
|
||||||
|
latest_eth1_data,
|
||||||
|
initial_validator_deposits,
|
||||||
spec.clone(),
|
spec.clone(),
|
||||||
)
|
)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
@ -136,7 +145,7 @@ impl BeaconChainHarness {
|
|||||||
.beacon_chain
|
.beacon_chain
|
||||||
.state
|
.state
|
||||||
.read()
|
.read()
|
||||||
.get_crosslink_committees_at_slot(present_slot, &self.spec)
|
.get_crosslink_committees_at_slot(present_slot, false, &self.spec)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.fold(vec![], |mut acc, (committee, _slot)| {
|
.fold(vec![], |mut acc, (committee, _slot)| {
|
||||||
|
@ -11,7 +11,7 @@ use db::ClientDB;
|
|||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use slot_clock::SlotClock;
|
use slot_clock::SlotClock;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::{AttestationData, BeaconBlock, FreeAttestation, PublicKey, Signature, Slot};
|
use types::{AttestationData, BeaconBlock, FreeAttestation, Signature, Slot};
|
||||||
|
|
||||||
// mod attester;
|
// mod attester;
|
||||||
// mod producer;
|
// mod producer;
|
||||||
@ -70,20 +70,6 @@ impl<T: ClientDB, U: SlotClock> AttesterBeaconNode for DirectBeaconNode<T, U> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ClientDB, U: SlotClock> BeaconBlockNode for DirectBeaconNode<T, U> {
|
impl<T: ClientDB, U: SlotClock> BeaconBlockNode for DirectBeaconNode<T, U> {
|
||||||
/// Requests the `proposer_nonce` from the `BeaconChain`.
|
|
||||||
fn proposer_nonce(&self, pubkey: &PublicKey) -> Result<u64, BeaconBlockNodeError> {
|
|
||||||
let validator_index = self
|
|
||||||
.beacon_chain
|
|
||||||
.validator_index(pubkey)
|
|
||||||
.ok_or_else(|| BeaconBlockNodeError::RemoteFailure("pubkey unknown.".to_string()))?;
|
|
||||||
|
|
||||||
self.beacon_chain
|
|
||||||
.proposer_slots(validator_index)
|
|
||||||
.ok_or_else(|| {
|
|
||||||
BeaconBlockNodeError::RemoteFailure("validator_index unknown.".to_string())
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Requests a new `BeaconBlock from the `BeaconChain`.
|
/// Requests a new `BeaconBlock from the `BeaconChain`.
|
||||||
fn produce_beacon_block(
|
fn produce_beacon_block(
|
||||||
&self,
|
&self,
|
||||||
|
Loading…
Reference in New Issue
Block a user