Move benching_utils
structs into types
This commit is contained in:
parent
6ae99a1462
commit
0b7082e2b9
@ -4,7 +4,6 @@ members = [
|
|||||||
"eth2/block_proposer",
|
"eth2/block_proposer",
|
||||||
"eth2/fork_choice",
|
"eth2/fork_choice",
|
||||||
"eth2/state_processing",
|
"eth2/state_processing",
|
||||||
"eth2/state_processing/benching_utils",
|
|
||||||
"eth2/types",
|
"eth2/types",
|
||||||
"eth2/utils/bls",
|
"eth2/utils/bls",
|
||||||
"eth2/utils/boolean-bitfield",
|
"eth2/utils/boolean-bitfield",
|
||||||
|
@ -11,7 +11,6 @@ harness = false
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
criterion = "0.2"
|
criterion = "0.2"
|
||||||
env_logger = "0.6.0"
|
env_logger = "0.6.0"
|
||||||
benching_utils = { path = "./benching_utils" }
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bls = { path = "../utils/bls" }
|
bls = { path = "../utils/bls" }
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use benching_utils::{BeaconBlockBencher, BeaconStateBencher};
|
|
||||||
use criterion::Criterion;
|
use criterion::Criterion;
|
||||||
use criterion::{black_box, Benchmark};
|
use criterion::{black_box, Benchmark};
|
||||||
use ssz::TreeHash;
|
use ssz::TreeHash;
|
||||||
@ -10,6 +9,7 @@ use state_processing::{
|
|||||||
verify_block_signature,
|
verify_block_signature,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
use types::test_utils::{TestingBeaconBlockBuilder, TestingBeaconStateBuilder};
|
||||||
use types::*;
|
use types::*;
|
||||||
|
|
||||||
/// Run the benchmarking suite on a foundation spec with 16,384 validators.
|
/// Run the benchmarking suite on a foundation spec with 16,384 validators.
|
||||||
@ -82,7 +82,7 @@ pub fn block_processing_16k_validators(c: &mut Criterion) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn build_state(validator_count: usize, spec: &ChainSpec) -> (BeaconState, Vec<Keypair>) {
|
fn build_state(validator_count: usize, spec: &ChainSpec) -> (BeaconState, Vec<Keypair>) {
|
||||||
let mut builder = BeaconStateBencher::new(validator_count, &spec);
|
let mut builder = TestingBeaconStateBuilder::new(validator_count, &spec);
|
||||||
|
|
||||||
// Set the state to be just before an epoch transition.
|
// Set the state to be just before an epoch transition.
|
||||||
let target_slot = (spec.genesis_epoch + 4).end_slot(spec.slots_per_epoch);
|
let target_slot = (spec.genesis_epoch + 4).end_slot(spec.slots_per_epoch);
|
||||||
@ -95,7 +95,7 @@ fn build_state(validator_count: usize, spec: &ChainSpec) -> (BeaconState, Vec<Ke
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn build_block(state: &mut BeaconState, keypairs: &[Keypair], spec: &ChainSpec) -> BeaconBlock {
|
fn build_block(state: &mut BeaconState, keypairs: &[Keypair], spec: &ChainSpec) -> BeaconBlock {
|
||||||
let mut builder = BeaconBlockBencher::new(spec);
|
let mut builder = TestingBeaconBlockBuilder::new(spec);
|
||||||
|
|
||||||
builder.set_slot(state.slot);
|
builder.set_slot(state.slot);
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use benching_utils::BeaconStateBencher;
|
|
||||||
use criterion::Criterion;
|
use criterion::Criterion;
|
||||||
use criterion::{black_box, Benchmark};
|
use criterion::{black_box, Benchmark};
|
||||||
use ssz::TreeHash;
|
use ssz::TreeHash;
|
||||||
@ -11,6 +10,7 @@ use state_processing::{
|
|||||||
update_latest_slashed_balances,
|
update_latest_slashed_balances,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
use types::test_utils::TestingBeaconStateBuilder;
|
||||||
use types::{validator_registry::get_active_validator_indices, *};
|
use types::{validator_registry::get_active_validator_indices, *};
|
||||||
|
|
||||||
pub const BENCHING_SAMPLE_SIZE: usize = 10;
|
pub const BENCHING_SAMPLE_SIZE: usize = 10;
|
||||||
@ -22,7 +22,7 @@ pub fn epoch_processing_16k_validators(c: &mut Criterion) {
|
|||||||
|
|
||||||
let validator_count = 300_032;
|
let validator_count = 300_032;
|
||||||
|
|
||||||
let mut builder = BeaconStateBencher::new(validator_count, &spec);
|
let mut builder = TestingBeaconStateBuilder::new(validator_count, &spec);
|
||||||
|
|
||||||
// Set the state to be just before an epoch transition.
|
// Set the state to be just before an epoch transition.
|
||||||
let target_slot = (spec.genesis_epoch + 4).end_slot(spec.slots_per_epoch);
|
let target_slot = (spec.genesis_epoch + 4).end_slot(spec.slots_per_epoch);
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "benching_utils"
|
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["Paul Hauner <paul@paulhauner.com>"]
|
|
||||||
edition = "2018"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
bls = { path = "../../utils/bls" }
|
|
||||||
hashing = { path = "../../utils/hashing" }
|
|
||||||
int_to_bytes = { path = "../../utils/int_to_bytes" }
|
|
||||||
integer-sqrt = "0.1"
|
|
||||||
log = "0.4"
|
|
||||||
merkle_proof = { path = "../../utils/merkle_proof" }
|
|
||||||
ssz = { path = "../../utils/ssz" }
|
|
||||||
ssz_derive = { path = "../../utils/ssz_derive" }
|
|
||||||
types = { path = "../../types" }
|
|
||||||
rayon = "1.0"
|
|
@ -1,5 +0,0 @@
|
|||||||
mod beacon_block_bencher;
|
|
||||||
mod beacon_state_bencher;
|
|
||||||
|
|
||||||
pub use beacon_block_bencher::BeaconBlockBencher;
|
|
||||||
pub use beacon_state_bencher::BeaconStateBencher;
|
|
@ -1,7 +1,7 @@
|
|||||||
#![cfg(test)]
|
#![cfg(test)]
|
||||||
use crate::per_epoch_processing;
|
use crate::per_epoch_processing;
|
||||||
use benching_utils::BeaconStateBencher;
|
|
||||||
use env_logger::{Builder, Env};
|
use env_logger::{Builder, Env};
|
||||||
|
use types::test_utils::TestingBeaconStateBuilder;
|
||||||
use types::*;
|
use types::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -10,7 +10,7 @@ fn runs_without_error() {
|
|||||||
|
|
||||||
let spec = ChainSpec::few_validators();
|
let spec = ChainSpec::few_validators();
|
||||||
|
|
||||||
let mut builder = BeaconStateBencher::new(8, &spec);
|
let mut builder = TestingBeaconStateBuilder::new(8, &spec);
|
||||||
|
|
||||||
let target_slot = (spec.genesis_epoch + 4).end_slot(spec.slots_per_epoch);
|
let target_slot = (spec.genesis_epoch + 4).end_slot(spec.slots_per_epoch);
|
||||||
builder.teleport_to_slot(target_slot, &spec);
|
builder.teleport_to_slot(target_slot, &spec);
|
||||||
|
@ -6,7 +6,7 @@ use ssz::TreeHash;
|
|||||||
|
|
||||||
/// Builds a `BeaconState` for use in production.
|
/// Builds a `BeaconState` for use in production.
|
||||||
///
|
///
|
||||||
/// This struct should not be modified for use in testing scenarios. Use `TestingBeaconStateBuilder` for that purpose.
|
/// This struct should _not_ be modified for use in testing scenarios. Use `TestingBeaconStateBuilder` for that purpose.
|
||||||
///
|
///
|
||||||
/// This struct should remain safe and sensible for production usage.
|
/// This struct should remain safe and sensible for production usage.
|
||||||
pub struct BeaconStateBuilder {
|
pub struct BeaconStateBuilder {
|
||||||
|
@ -1,29 +1,20 @@
|
|||||||
#![cfg(test)]
|
#![cfg(test)]
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::test_utils::TestingBeaconStateBuilder;
|
||||||
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
||||||
use crate::{BeaconState, ChainSpec};
|
use crate::{BeaconState, ChainSpec};
|
||||||
use ssz::{ssz_encode, Decodable};
|
use ssz::{ssz_encode, Decodable};
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn can_produce_genesis_block() {
|
|
||||||
let mut builder = BeaconStateBuilder::new(2);
|
|
||||||
builder.build().unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Tests that `get_attestation_participants` is consistent with the result of
|
/// Tests that `get_attestation_participants` is consistent with the result of
|
||||||
/// get_crosslink_committees_at_slot` with a full bitfield.
|
/// get_crosslink_committees_at_slot` with a full bitfield.
|
||||||
#[test]
|
#[test]
|
||||||
pub fn get_attestation_participants_consistency() {
|
pub fn get_attestation_participants_consistency() {
|
||||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
let mut rng = XorShiftRng::from_seed([42; 16]);
|
||||||
|
|
||||||
let mut builder = BeaconStateBuilder::new(8);
|
let spec = ChainSpec::few_validators();
|
||||||
builder.spec = ChainSpec::few_validators();
|
let builder = TestingBeaconStateBuilder::new(8, &spec);
|
||||||
|
let (mut state, _keypairs) = builder.build();
|
||||||
builder.build().unwrap();
|
|
||||||
|
|
||||||
let mut state = builder.cloned_state();
|
|
||||||
let spec = builder.spec.clone();
|
|
||||||
|
|
||||||
state
|
state
|
||||||
.build_epoch_cache(RelativeEpoch::Previous, &spec)
|
.build_epoch_cache(RelativeEpoch::Previous, &spec)
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
mod test_random;
|
mod test_random;
|
||||||
mod testing_attestation_builder;
|
mod testing_attestation_builder;
|
||||||
|
mod testing_beacon_block_builder;
|
||||||
|
mod testing_beacon_state_builder;
|
||||||
mod testing_deposit_builder;
|
mod testing_deposit_builder;
|
||||||
mod testing_transfer_builder;
|
mod testing_transfer_builder;
|
||||||
mod testing_voluntary_exit_builder;
|
mod testing_voluntary_exit_builder;
|
||||||
@ -7,6 +9,8 @@ mod testing_voluntary_exit_builder;
|
|||||||
pub use rand::{prng::XorShiftRng, SeedableRng};
|
pub use rand::{prng::XorShiftRng, SeedableRng};
|
||||||
pub use test_random::TestRandom;
|
pub use test_random::TestRandom;
|
||||||
pub use testing_attestation_builder::TestingAttestationBuilder;
|
pub use testing_attestation_builder::TestingAttestationBuilder;
|
||||||
|
pub use testing_beacon_block_builder::TestingBeaconBlockBuilder;
|
||||||
|
pub use testing_beacon_state_builder::TestingBeaconStateBuilder;
|
||||||
pub use testing_deposit_builder::TestingDepositBuilder;
|
pub use testing_deposit_builder::TestingDepositBuilder;
|
||||||
pub use testing_transfer_builder::TestingTransferBuilder;
|
pub use testing_transfer_builder::TestingTransferBuilder;
|
||||||
pub use testing_voluntary_exit_builder::TestingVoluntaryExitBuilder;
|
pub use testing_voluntary_exit_builder::TestingVoluntaryExitBuilder;
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
use rayon::prelude::*;
|
use crate::{
|
||||||
use ssz::{SignedRoot, TreeHash};
|
|
||||||
use types::{
|
|
||||||
attester_slashing::AttesterSlashingBuilder,
|
attester_slashing::AttesterSlashingBuilder,
|
||||||
proposer_slashing::ProposerSlashingBuilder,
|
proposer_slashing::ProposerSlashingBuilder,
|
||||||
test_utils::{
|
test_utils::{
|
||||||
@ -9,12 +7,14 @@ use types::{
|
|||||||
},
|
},
|
||||||
*,
|
*,
|
||||||
};
|
};
|
||||||
|
use rayon::prelude::*;
|
||||||
|
use ssz::{SignedRoot, TreeHash};
|
||||||
|
|
||||||
pub struct BeaconBlockBencher {
|
pub struct TestingBeaconBlockBuilder {
|
||||||
block: BeaconBlock,
|
block: BeaconBlock,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BeaconBlockBencher {
|
impl TestingBeaconBlockBuilder {
|
||||||
pub fn new(spec: &ChainSpec) -> Self {
|
pub fn new(spec: &ChainSpec) -> Self {
|
||||||
Self {
|
Self {
|
||||||
block: BeaconBlock::genesis(spec.zero_hash, spec),
|
block: BeaconBlock::genesis(spec.zero_hash, spec),
|
@ -1,15 +1,15 @@
|
|||||||
|
use crate::beacon_state::BeaconStateBuilder;
|
||||||
|
use crate::*;
|
||||||
use bls::get_withdrawal_credentials;
|
use bls::get_withdrawal_credentials;
|
||||||
use int_to_bytes::int_to_bytes48;
|
use int_to_bytes::int_to_bytes48;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use types::beacon_state::BeaconStateBuilder;
|
|
||||||
use types::*;
|
|
||||||
|
|
||||||
pub struct BeaconStateBencher {
|
pub struct TestingBeaconStateBuilder {
|
||||||
state: BeaconState,
|
state: BeaconState,
|
||||||
keypairs: Vec<Keypair>,
|
keypairs: Vec<Keypair>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BeaconStateBencher {
|
impl TestingBeaconStateBuilder {
|
||||||
pub fn new(validator_count: usize, spec: &ChainSpec) -> Self {
|
pub fn new(validator_count: usize, spec: &ChainSpec) -> Self {
|
||||||
let keypairs: Vec<Keypair> = (0..validator_count)
|
let keypairs: Vec<Keypair> = (0..validator_count)
|
||||||
.collect::<Vec<usize>>()
|
.collect::<Vec<usize>>()
|
Loading…
Reference in New Issue
Block a user