Add debug messages to TestingBeaconStateBuilder
This commit is contained in:
parent
1b252c3f82
commit
fbfa233d36
@ -1,5 +1,6 @@
|
|||||||
use criterion::Criterion;
|
use criterion::Criterion;
|
||||||
use criterion::{black_box, Benchmark};
|
use criterion::{black_box, Benchmark};
|
||||||
|
use log::debug;
|
||||||
use ssz::TreeHash;
|
use ssz::TreeHash;
|
||||||
use state_processing::{
|
use state_processing::{
|
||||||
per_block_processing,
|
per_block_processing,
|
||||||
@ -107,6 +108,10 @@ fn build_block(state: &mut BeaconState, keypairs: &[Keypair], spec: &ChainSpec)
|
|||||||
let mut validators_iter = (0..keypairs.len() as u64).into_iter();
|
let mut validators_iter = (0..keypairs.len() as u64).into_iter();
|
||||||
|
|
||||||
// Insert the maximum possible number of `ProposerSlashing` objects.
|
// Insert the maximum possible number of `ProposerSlashing` objects.
|
||||||
|
debug!(
|
||||||
|
"Inserting {} proposer slashings...",
|
||||||
|
spec.max_proposer_slashings
|
||||||
|
);
|
||||||
for _ in 0..spec.max_proposer_slashings {
|
for _ in 0..spec.max_proposer_slashings {
|
||||||
let validator_index = validators_iter.next().expect("Insufficient validators.");
|
let validator_index = validators_iter.next().expect("Insufficient validators.");
|
||||||
|
|
||||||
@ -119,6 +124,10 @@ fn build_block(state: &mut BeaconState, keypairs: &[Keypair], spec: &ChainSpec)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Insert the maximum possible number of `AttesterSlashing` objects
|
// Insert the maximum possible number of `AttesterSlashing` objects
|
||||||
|
debug!(
|
||||||
|
"Inserting {} attester slashings...",
|
||||||
|
spec.max_attester_slashings
|
||||||
|
);
|
||||||
for _ in 0..spec.max_attester_slashings {
|
for _ in 0..spec.max_attester_slashings {
|
||||||
let mut attesters: Vec<u64> = vec![];
|
let mut attesters: Vec<u64> = vec![];
|
||||||
let mut secret_keys: Vec<&SecretKey> = vec![];
|
let mut secret_keys: Vec<&SecretKey> = vec![];
|
||||||
@ -134,17 +143,20 @@ fn build_block(state: &mut BeaconState, keypairs: &[Keypair], spec: &ChainSpec)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Insert the maximum possible number of `Attestation` objects.
|
// Insert the maximum possible number of `Attestation` objects.
|
||||||
|
debug!("Inserting {} attestations...", spec.max_attestations);
|
||||||
let all_secret_keys: Vec<&SecretKey> = keypairs.iter().map(|keypair| &keypair.sk).collect();
|
let all_secret_keys: Vec<&SecretKey> = keypairs.iter().map(|keypair| &keypair.sk).collect();
|
||||||
builder
|
builder
|
||||||
.fill_with_attestations(state, &all_secret_keys, spec)
|
.fill_with_attestations(state, &all_secret_keys, spec)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Insert the maximum possible number of `Deposit` objects.
|
// Insert the maximum possible number of `Deposit` objects.
|
||||||
|
debug!("Inserting {} deposits...", spec.max_deposits);
|
||||||
for i in 0..spec.max_deposits {
|
for i in 0..spec.max_deposits {
|
||||||
builder.insert_deposit(32_000_000_000, state.deposit_index + i, state, spec);
|
builder.insert_deposit(32_000_000_000, state.deposit_index + i, state, spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert the maximum possible number of `Exit` objects.
|
// Insert the maximum possible number of `Exit` objects.
|
||||||
|
debug!("Inserting {} exits...", spec.max_voluntary_exits);
|
||||||
for _ in 0..spec.max_voluntary_exits {
|
for _ in 0..spec.max_voluntary_exits {
|
||||||
let validator_index = validators_iter.next().expect("Insufficient validators.");
|
let validator_index = validators_iter.next().expect("Insufficient validators.");
|
||||||
|
|
||||||
@ -157,6 +169,7 @@ fn build_block(state: &mut BeaconState, keypairs: &[Keypair], spec: &ChainSpec)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Insert the maximum possible number of `Transfer` objects.
|
// Insert the maximum possible number of `Transfer` objects.
|
||||||
|
debug!("Inserting {} transfers...", spec.max_transfers);
|
||||||
for _ in 0..spec.max_transfers {
|
for _ in 0..spec.max_transfers {
|
||||||
let validator_index = validators_iter.next().expect("Insufficient validators.");
|
let validator_index = validators_iter.next().expect("Insufficient validators.");
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use criterion::Benchmark;
|
use criterion::Benchmark;
|
||||||
use criterion::Criterion;
|
use criterion::Criterion;
|
||||||
use criterion::{criterion_group, criterion_main};
|
use criterion::{criterion_group, criterion_main};
|
||||||
|
use env_logger::{Builder, Env};
|
||||||
use types::test_utils::TestingBeaconStateBuilder;
|
use types::test_utils::TestingBeaconStateBuilder;
|
||||||
use types::*;
|
use types::*;
|
||||||
|
|
||||||
@ -9,50 +10,17 @@ mod bench_epoch_processing;
|
|||||||
|
|
||||||
pub const VALIDATOR_COUNT: usize = 300_032;
|
pub const VALIDATOR_COUNT: usize = 300_032;
|
||||||
|
|
||||||
|
// `LOG_LEVEL == "debug"` gives logs, but they're very noisy and slow down benching.
|
||||||
|
pub const LOG_LEVEL: &str = "";
|
||||||
|
|
||||||
pub fn state_processing(c: &mut Criterion) {
|
pub fn state_processing(c: &mut Criterion) {
|
||||||
|
if LOG_LEVEL != "" {
|
||||||
|
Builder::from_env(Env::default().default_filter_or(LOG_LEVEL)).init();
|
||||||
|
}
|
||||||
|
|
||||||
bench_block_processing::bench_block_processing_n_validators(c, VALIDATOR_COUNT);
|
bench_block_processing::bench_block_processing_n_validators(c, VALIDATOR_COUNT);
|
||||||
bench_epoch_processing::bench_epoch_processing_n_validators(c, VALIDATOR_COUNT);
|
bench_epoch_processing::bench_epoch_processing_n_validators(c, VALIDATOR_COUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn key_loading(c: &mut Criterion) {
|
criterion_group!(benches, state_processing);
|
||||||
let validator_count = 1000;
|
|
||||||
|
|
||||||
c.bench(
|
|
||||||
&format!("{}_validators", validator_count),
|
|
||||||
Benchmark::new("generated", move |b| {
|
|
||||||
b.iter_batched(
|
|
||||||
|| (),
|
|
||||||
|_| {
|
|
||||||
TestingBeaconStateBuilder::from_deterministic_keypairs(
|
|
||||||
validator_count,
|
|
||||||
&ChainSpec::foundation(),
|
|
||||||
)
|
|
||||||
},
|
|
||||||
criterion::BatchSize::SmallInput,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.sample_size(10),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Note: path needs to be relative to where cargo is executed from.
|
|
||||||
c.bench(
|
|
||||||
&format!("{}_validators", validator_count),
|
|
||||||
Benchmark::new("from_file", move |b| {
|
|
||||||
b.iter_batched(
|
|
||||||
|| (),
|
|
||||||
|_| {
|
|
||||||
TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(
|
|
||||||
validator_count,
|
|
||||||
&ChainSpec::foundation(),
|
|
||||||
)
|
|
||||||
},
|
|
||||||
criterion::BatchSize::SmallInput,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.sample_size(10),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// criterion_group!(benches, state_processing, key_loading);
|
|
||||||
criterion_group!(benches, key_loading);
|
|
||||||
criterion_main!(benches);
|
criterion_main!(benches);
|
||||||
|
@ -3,6 +3,7 @@ use crate::beacon_state::BeaconStateBuilder;
|
|||||||
use crate::*;
|
use crate::*;
|
||||||
use bls::get_withdrawal_credentials;
|
use bls::get_withdrawal_credentials;
|
||||||
use dirs;
|
use dirs;
|
||||||
|
use log::debug;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
@ -58,12 +59,14 @@ impl TestingBeaconStateBuilder {
|
|||||||
///
|
///
|
||||||
/// If the file does not exist, is invalid or does not contain enough keypairs.
|
/// If the file does not exist, is invalid or does not contain enough keypairs.
|
||||||
pub fn from_keypairs_file(validator_count: usize, path: &Path, spec: &ChainSpec) -> Self {
|
pub fn from_keypairs_file(validator_count: usize, path: &Path, spec: &ChainSpec) -> Self {
|
||||||
|
debug!("Loading {} keypairs from file...", validator_count);
|
||||||
let keypairs = Vec::from_raw_file(path, validator_count).unwrap();
|
let keypairs = Vec::from_raw_file(path, validator_count).unwrap();
|
||||||
TestingBeaconStateBuilder::from_keypairs(keypairs, spec)
|
TestingBeaconStateBuilder::from_keypairs(keypairs, spec)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generates the validator keypairs deterministically.
|
/// Generates the validator keypairs deterministically.
|
||||||
pub fn from_deterministic_keypairs(validator_count: usize, spec: &ChainSpec) -> Self {
|
pub fn from_deterministic_keypairs(validator_count: usize, spec: &ChainSpec) -> Self {
|
||||||
|
debug!("Generating {} deterministic keypairs...", validator_count);
|
||||||
let keypairs = generate_deterministic_keypairs(validator_count);
|
let keypairs = generate_deterministic_keypairs(validator_count);
|
||||||
TestingBeaconStateBuilder::from_keypairs(keypairs, spec)
|
TestingBeaconStateBuilder::from_keypairs(keypairs, spec)
|
||||||
}
|
}
|
||||||
@ -72,6 +75,10 @@ impl TestingBeaconStateBuilder {
|
|||||||
pub fn from_keypairs(keypairs: Vec<Keypair>, spec: &ChainSpec) -> Self {
|
pub fn from_keypairs(keypairs: Vec<Keypair>, spec: &ChainSpec) -> Self {
|
||||||
let validator_count = keypairs.len();
|
let validator_count = keypairs.len();
|
||||||
|
|
||||||
|
debug!(
|
||||||
|
"Building {} Validator objects from keypairs...",
|
||||||
|
validator_count
|
||||||
|
);
|
||||||
let validators = keypairs
|
let validators = keypairs
|
||||||
.par_iter()
|
.par_iter()
|
||||||
.map(|keypair| {
|
.map(|keypair| {
|
||||||
@ -103,6 +110,7 @@ impl TestingBeaconStateBuilder {
|
|||||||
|
|
||||||
let balances = vec![32_000_000_000; validator_count];
|
let balances = vec![32_000_000_000; validator_count];
|
||||||
|
|
||||||
|
debug!("Importing {} existing validators...", validator_count);
|
||||||
state_builder.import_existing_validators(
|
state_builder.import_existing_validators(
|
||||||
validators,
|
validators,
|
||||||
balances,
|
balances,
|
||||||
@ -110,10 +118,11 @@ impl TestingBeaconStateBuilder {
|
|||||||
spec,
|
spec,
|
||||||
);
|
);
|
||||||
|
|
||||||
Self {
|
let state = state_builder.build(spec).unwrap();
|
||||||
state: state_builder.build(spec).unwrap(),
|
|
||||||
keypairs,
|
debug!("BeaconState built.");
|
||||||
}
|
|
||||||
|
Self { state, keypairs }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Consume the builder and return the `BeaconState` and the keypairs for each validator.
|
/// Consume the builder and return the `BeaconState` and the keypairs for each validator.
|
||||||
|
Loading…
Reference in New Issue
Block a user