Break BeaconChainHarness validator gen into fn
Prepares for allowing for loading from file
This commit is contained in:
parent
9a964be58b
commit
b98f514d68
@ -1,12 +1,12 @@
|
|||||||
use super::ValidatorHarness;
|
use super::ValidatorHarness;
|
||||||
use beacon_chain::{BeaconChain, BlockProcessingOutcome};
|
use beacon_chain::{BeaconChain, BlockProcessingOutcome};
|
||||||
pub use beacon_chain::{BeaconChainError, CheckPoint};
|
pub use beacon_chain::{BeaconChainError, CheckPoint};
|
||||||
use bls::{create_proof_of_possession, get_withdrawal_credentials};
|
|
||||||
use db::{
|
use db::{
|
||||||
stores::{BeaconBlockStore, BeaconStateStore},
|
stores::{BeaconBlockStore, BeaconStateStore},
|
||||||
MemoryDB,
|
MemoryDB,
|
||||||
};
|
};
|
||||||
use fork_choice::BitwiseLMDGhost;
|
use fork_choice::BitwiseLMDGhost;
|
||||||
|
use generate_deposits::generate_deposits_with_random_keypairs;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use slot_clock::TestingSlotClock;
|
use slot_clock::TestingSlotClock;
|
||||||
@ -15,6 +15,8 @@ use std::iter::FromIterator;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::*;
|
use types::*;
|
||||||
|
|
||||||
|
mod generate_deposits;
|
||||||
|
|
||||||
/// 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
|
||||||
/// information and submit blocks/attestations for processing.
|
/// information and submit blocks/attestations for processing.
|
||||||
@ -47,40 +49,8 @@ impl BeaconChainHarness {
|
|||||||
block_hash: Hash256::zero(),
|
block_hash: Hash256::zero(),
|
||||||
};
|
};
|
||||||
|
|
||||||
debug!("Generating validator keypairs...");
|
let (keypairs, initial_validator_deposits) =
|
||||||
|
generate_deposits_with_random_keypairs(validator_count, genesis_time, &spec);
|
||||||
let keypairs: Vec<Keypair> = (0..validator_count)
|
|
||||||
.collect::<Vec<usize>>()
|
|
||||||
.par_iter()
|
|
||||||
.map(|_| Keypair::random())
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
debug!("Creating validator deposits...");
|
|
||||||
|
|
||||||
let initial_validator_deposits = keypairs
|
|
||||||
.par_iter()
|
|
||||||
.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(),
|
|
||||||
// Validator can withdraw using their main keypair.
|
|
||||||
withdrawal_credentials: Hash256::from_slice(
|
|
||||||
&get_withdrawal_credentials(
|
|
||||||
&keypair.pk,
|
|
||||||
spec.bls_withdrawal_prefix_byte,
|
|
||||||
)[..],
|
|
||||||
),
|
|
||||||
proof_of_possession: create_proof_of_possession(&keypair),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
debug!("Creating the BeaconChain...");
|
|
||||||
|
|
||||||
// Create the Beacon Chain
|
// Create the Beacon Chain
|
||||||
let beacon_chain = Arc::new(
|
let beacon_chain = Arc::new(
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
use bls::{create_proof_of_possession, get_withdrawal_credentials};
|
||||||
|
use log::debug;
|
||||||
|
use rayon::prelude::*;
|
||||||
|
use types::*;
|
||||||
|
|
||||||
|
/// Generates `validator_count` deposits using randomly generated keypairs and some default specs
|
||||||
|
/// for the deposits.
|
||||||
|
pub fn generate_deposits_with_random_keypairs(
|
||||||
|
validator_count: usize,
|
||||||
|
genesis_time: u64,
|
||||||
|
spec: &ChainSpec,
|
||||||
|
) -> (Vec<Keypair>, Vec<Deposit>) {
|
||||||
|
debug!(
|
||||||
|
"Generating {} random validator keypairs...",
|
||||||
|
validator_count
|
||||||
|
);
|
||||||
|
|
||||||
|
let keypairs: Vec<Keypair> = (0..validator_count)
|
||||||
|
.collect::<Vec<usize>>()
|
||||||
|
.par_iter()
|
||||||
|
.map(|_| Keypair::random())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
debug!(
|
||||||
|
"Generating {} validator deposits from random keypairs...",
|
||||||
|
validator_count
|
||||||
|
);
|
||||||
|
|
||||||
|
let initial_validator_deposits =
|
||||||
|
keypairs
|
||||||
|
.par_iter()
|
||||||
|
.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(),
|
||||||
|
// Validator can withdraw using their main keypair.
|
||||||
|
withdrawal_credentials: Hash256::from_slice(
|
||||||
|
&get_withdrawal_credentials(
|
||||||
|
&keypair.pk,
|
||||||
|
spec.bls_withdrawal_prefix_byte,
|
||||||
|
)[..],
|
||||||
|
),
|
||||||
|
proof_of_possession: create_proof_of_possession(&keypair),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
(keypairs, initial_validator_deposits)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user