Add BeaconChain
benchmarking
This commit is contained in:
parent
8e9a139560
commit
2bda7e3d14
@ -4,6 +4,13 @@ version = "0.1.0"
|
|||||||
authors = ["Paul Hauner <paul@paulhauner.com>"]
|
authors = ["Paul Hauner <paul@paulhauner.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
[[bench]]
|
||||||
|
name = "state_transition"
|
||||||
|
harness = false
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
criterion = "0.2"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
beacon_chain = { path = "../../beacon_chain" }
|
beacon_chain = { path = "../../beacon_chain" }
|
||||||
block_producer = { path = "../../../eth2/block_producer" }
|
block_producer = { path = "../../../eth2/block_producer" }
|
||||||
|
@ -0,0 +1,64 @@
|
|||||||
|
use criterion::Criterion;
|
||||||
|
use criterion::{criterion_group, criterion_main};
|
||||||
|
use test_harness::BeaconChainHarness;
|
||||||
|
use types::ChainSpec;
|
||||||
|
|
||||||
|
fn mid_epoch_state_transition(c: &mut Criterion) {
|
||||||
|
let validator_count = 2;
|
||||||
|
let mut rig = BeaconChainHarness::new(ChainSpec::foundation(), validator_count);
|
||||||
|
|
||||||
|
let two_and_half_epochs = (rig.spec.epoch_length * 2) + (rig.spec.epoch_length / 2);
|
||||||
|
|
||||||
|
for _ in 0..two_and_half_epochs {
|
||||||
|
rig.advance_chain_with_block();
|
||||||
|
}
|
||||||
|
|
||||||
|
let block = rig.advance_chain_without_block();
|
||||||
|
let state = rig.beacon_chain.canonical_head().beacon_state.clone();
|
||||||
|
|
||||||
|
c.bench_function("mid-epoch state transition 10k validators", move |b| {
|
||||||
|
let block = block.clone();
|
||||||
|
let state = state.clone();
|
||||||
|
b.iter(|| {
|
||||||
|
rig.beacon_chain
|
||||||
|
.state_transition(state.clone(), &block.clone())
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn epoch_boundary_state_transition(c: &mut Criterion) {
|
||||||
|
let validator_count = 10_000;
|
||||||
|
let mut rig = BeaconChainHarness::new(ChainSpec::foundation(), validator_count);
|
||||||
|
|
||||||
|
let three_epochs = rig.spec.epoch_length * 3;
|
||||||
|
|
||||||
|
for _ in 0..(three_epochs - 1) {
|
||||||
|
rig.advance_chain_with_block();
|
||||||
|
}
|
||||||
|
|
||||||
|
let state = rig.beacon_chain.canonical_head().beacon_state.clone();
|
||||||
|
assert_eq!(
|
||||||
|
state.slot % rig.spec.epoch_length,
|
||||||
|
rig.spec.epoch_length - 1,
|
||||||
|
);
|
||||||
|
let block = rig.advance_chain_without_block();
|
||||||
|
|
||||||
|
c.bench_function("epoch boundary state transition 10k validators", move |b| {
|
||||||
|
let block = block.clone();
|
||||||
|
let state = state.clone();
|
||||||
|
b.iter(|| {
|
||||||
|
let state = rig
|
||||||
|
.beacon_chain
|
||||||
|
.state_transition(state.clone(), &block.clone())
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(state.slot % rig.spec.epoch_length, 0);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
criterion_group!(
|
||||||
|
benches,
|
||||||
|
mid_epoch_state_transition,
|
||||||
|
epoch_boundary_state_transition
|
||||||
|
);
|
||||||
|
criterion_main!(benches);
|
@ -1,12 +1,10 @@
|
|||||||
use super::TestValidator;
|
use super::TestValidator;
|
||||||
pub use beacon_chain::dump::{Error as DumpError, SlotDump};
|
pub use beacon_chain::dump::{Error as DumpError, SlotDump};
|
||||||
use beacon_chain::BeaconChain;
|
use beacon_chain::BeaconChain;
|
||||||
use block_producer::BeaconNode;
|
|
||||||
use db::{
|
use db::{
|
||||||
stores::{BeaconBlockStore, BeaconStateStore},
|
stores::{BeaconBlockStore, BeaconStateStore},
|
||||||
MemoryDB,
|
MemoryDB,
|
||||||
};
|
};
|
||||||
use serde_json::Result as SerdeResult;
|
|
||||||
use slot_clock::TestingSlotClock;
|
use slot_clock::TestingSlotClock;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
@ -14,11 +12,11 @@ use std::sync::Arc;
|
|||||||
use types::{BeaconBlock, ChainSpec, Keypair, Validator};
|
use types::{BeaconBlock, ChainSpec, Keypair, Validator};
|
||||||
|
|
||||||
pub struct BeaconChainHarness {
|
pub struct BeaconChainHarness {
|
||||||
db: Arc<MemoryDB>,
|
pub db: Arc<MemoryDB>,
|
||||||
beacon_chain: Arc<BeaconChain<MemoryDB, TestingSlotClock>>,
|
pub beacon_chain: Arc<BeaconChain<MemoryDB, TestingSlotClock>>,
|
||||||
block_store: Arc<BeaconBlockStore<MemoryDB>>,
|
pub block_store: Arc<BeaconBlockStore<MemoryDB>>,
|
||||||
state_store: Arc<BeaconStateStore<MemoryDB>>,
|
pub state_store: Arc<BeaconStateStore<MemoryDB>>,
|
||||||
validators: Vec<TestValidator>,
|
pub validators: Vec<TestValidator>,
|
||||||
pub spec: ChainSpec,
|
pub spec: ChainSpec,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,6 +74,10 @@ impl BeaconChainHarness {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn advance_chain_without_block(&mut self) -> BeaconBlock {
|
||||||
|
self.produce_next_slot()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn advance_chain_with_block(&mut self) {
|
pub fn advance_chain_with_block(&mut self) {
|
||||||
let block = self.produce_next_slot();
|
let block = self.produce_next_slot();
|
||||||
self.beacon_chain.process_block(block).unwrap();
|
self.beacon_chain.process_block(block).unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user