Add support for loading keypairs from file

This commit is contained in:
Paul Hauner
2019-03-12 12:46:44 +11:00
parent 9de6a0c733
commit f34ae86cde
19 changed files with 264 additions and 183 deletions

View File

@@ -9,14 +9,19 @@ use state_processing::{
verify_block_signature,
},
};
use std::path::Path;
use types::test_utils::{TestingBeaconBlockBuilder, TestingBeaconStateBuilder};
use types::*;
/// Run the benchmarking suite on a foundation spec with 16,384 validators.
pub fn bench_block_processing_n_validators(c: &mut Criterion, validator_count: usize) {
pub fn bench_block_processing_n_validators(
c: &mut Criterion,
validator_count: usize,
keypair_file: Option<&Path>,
) {
let spec = ChainSpec::foundation();
let (mut state, keypairs) = build_state(validator_count, &spec);
let (mut state, keypairs) = build_state(validator_count, keypair_file, &spec);
let block = build_block(&mut state, &keypairs, &spec);
assert_eq!(
@@ -79,8 +84,12 @@ pub fn bench_block_processing_n_validators(c: &mut Criterion, validator_count: u
);
}
fn build_state(validator_count: usize, spec: &ChainSpec) -> (BeaconState, Vec<Keypair>) {
let mut builder = TestingBeaconStateBuilder::new(validator_count, &spec);
fn build_state(
validator_count: usize,
keypair_file: Option<&Path>,
spec: &ChainSpec,
) -> (BeaconState, Vec<Keypair>) {
let mut builder = TestingBeaconStateBuilder::new(validator_count, keypair_file, &spec);
// Set the state to be just before an epoch transition.
let target_slot = (spec.genesis_epoch + 4).end_slot(spec.slots_per_epoch);

View File

@@ -10,6 +10,7 @@ use state_processing::{
update_latest_slashed_balances,
},
};
use std::path::Path;
use types::test_utils::TestingBeaconStateBuilder;
use types::{validator_registry::get_active_validator_indices, *};
@@ -17,10 +18,14 @@ pub const BENCHING_SAMPLE_SIZE: usize = 10;
pub const SMALL_BENCHING_SAMPLE_SIZE: usize = 10;
/// Run the benchmarking suite on a foundation spec with 16,384 validators.
pub fn bench_epoch_processing_n_validators(c: &mut Criterion, validator_count: usize) {
pub fn bench_epoch_processing_n_validators(
c: &mut Criterion,
validator_count: usize,
keypair_file: Option<&Path>,
) {
let spec = ChainSpec::foundation();
let mut builder = TestingBeaconStateBuilder::new(validator_count, &spec);
let mut builder = TestingBeaconStateBuilder::new(validator_count, keypair_file, &spec);
// Set the state to be just before an epoch transition.
let target_slot = (spec.genesis_epoch + 4).end_slot(spec.slots_per_epoch);

View File

@@ -1,5 +1,9 @@
use criterion::Benchmark;
use criterion::Criterion;
use criterion::{criterion_group, criterion_main};
use std::path::Path;
use types::test_utils::TestingBeaconStateBuilder;
use types::*;
mod bench_block_processing;
mod bench_epoch_processing;
@@ -7,9 +11,47 @@ mod bench_epoch_processing;
pub const VALIDATOR_COUNT: usize = 300_032;
pub fn state_processing(c: &mut Criterion) {
bench_block_processing::bench_block_processing_n_validators(c, VALIDATOR_COUNT);
bench_epoch_processing::bench_epoch_processing_n_validators(c, VALIDATOR_COUNT);
bench_block_processing::bench_block_processing_n_validators(c, VALIDATOR_COUNT, None);
bench_epoch_processing::bench_epoch_processing_n_validators(c, VALIDATOR_COUNT, None);
}
criterion_group!(benches, state_processing,);
pub fn key_loading(c: &mut Criterion) {
let validator_count = 1000;
c.bench(
&format!("{}_validators", validator_count),
Benchmark::new("generated", move |b| {
b.iter_batched(
|| (),
|_| TestingBeaconStateBuilder::new(validator_count, None, &ChainSpec::foundation()),
criterion::BatchSize::SmallInput,
)
})
.sample_size(10),
);
// Note: path needs to be relative to where cargo is executed from.
let keypair_file =
Path::new("../../beacon_node/beacon_chain/test_harness/keypairs.raw_keypairs");
c.bench(
&format!("{}_validators", validator_count),
Benchmark::new("from_file", move |b| {
b.iter_batched(
|| (),
|_| {
TestingBeaconStateBuilder::new(
validator_count,
Some(&keypair_file),
&ChainSpec::foundation(),
)
},
criterion::BatchSize::SmallInput,
)
})
.sample_size(10),
);
}
// criterion_group!(benches, state_processing, key_loading);
criterion_group!(benches, key_loading);
criterion_main!(benches);

View File

@@ -10,7 +10,7 @@ fn runs_without_error() {
let spec = ChainSpec::few_validators();
let mut builder = TestingBeaconStateBuilder::new(8, &spec);
let mut builder = TestingBeaconStateBuilder::new(8, None, &spec);
let target_slot = (spec.genesis_epoch + 4).end_slot(spec.slots_per_epoch);
builder.teleport_to_slot(target_slot, &spec);