2021-07-09 06:15:32 +00:00
|
|
|
use beacon_chain::store::StoreConfig;
|
|
|
|
use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType};
|
2019-08-05 08:06:50 +00:00
|
|
|
use types::{BeaconState, EthSpec, MainnetEthSpec};
|
|
|
|
|
|
|
|
const TREE_HASH_LOOPS: usize = 1_000;
|
|
|
|
const VALIDATOR_COUNT: usize = 1_000;
|
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
fn get_harness<T: EthSpec>() -> BeaconChainHarness<EphemeralHarnessType<T>> {
|
|
|
|
let harness = BeaconChainHarness::new_with_store_config(
|
|
|
|
T::default(),
|
|
|
|
None,
|
|
|
|
types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT),
|
|
|
|
StoreConfig::default(),
|
|
|
|
);
|
2019-08-05 08:06:50 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
harness.advance_slot();
|
|
|
|
|
|
|
|
harness
|
|
|
|
}
|
|
|
|
|
|
|
|
fn build_state<T: EthSpec>() -> BeaconState<T> {
|
|
|
|
let state = get_harness::<T>().chain.head_beacon_state().unwrap();
|
|
|
|
|
|
|
|
assert_eq!(state.as_base().unwrap().validators.len(), VALIDATOR_COUNT);
|
|
|
|
assert_eq!(state.as_base().unwrap().balances.len(), VALIDATOR_COUNT);
|
|
|
|
assert!(state
|
|
|
|
.as_base()
|
|
|
|
.unwrap()
|
|
|
|
.previous_epoch_attestations
|
|
|
|
.is_empty());
|
|
|
|
assert!(state
|
|
|
|
.as_base()
|
|
|
|
.unwrap()
|
|
|
|
.current_epoch_attestations
|
|
|
|
.is_empty());
|
|
|
|
assert!(state.as_base().unwrap().eth1_data_votes.is_empty());
|
|
|
|
assert!(state.as_base().unwrap().historical_roots.is_empty());
|
2019-08-05 08:06:50 +00:00
|
|
|
|
|
|
|
state
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2021-07-09 06:15:32 +00:00
|
|
|
let state = build_state::<MainnetEthSpec>();
|
2019-08-05 08:06:50 +00:00
|
|
|
|
|
|
|
// This vec is an attempt to ensure the compiler doesn't optimize-out the hashing.
|
|
|
|
let mut vec = Vec::with_capacity(TREE_HASH_LOOPS);
|
|
|
|
|
|
|
|
for _ in 0..TREE_HASH_LOOPS {
|
2019-08-08 01:39:47 +00:00
|
|
|
let root = state.canonical_root();
|
2019-08-05 08:06:50 +00:00
|
|
|
vec.push(root[0]);
|
|
|
|
}
|
|
|
|
}
|