mirror of
https://github.com/sigp/lighthouse.git
synced 2026-06-29 10:54:24 +00:00
Altair consensus changes and refactors (#2279)
## Proposed Changes Implement the consensus changes necessary for the upcoming Altair hard fork. ## Additional Info This is quite a heavy refactor, with pivotal types like the `BeaconState` and `BeaconBlock` changing from structs to enums. This ripples through the whole codebase with field accesses changing to methods, e.g. `state.slot` => `state.slot()`. Co-authored-by: realbigsean <seananderson33@gmail.com>
This commit is contained in:
@@ -1,26 +1,46 @@
|
||||
use types::test_utils::TestingBeaconStateBuilder;
|
||||
use beacon_chain::store::StoreConfig;
|
||||
use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType};
|
||||
use types::{BeaconState, EthSpec, MainnetEthSpec};
|
||||
|
||||
const TREE_HASH_LOOPS: usize = 1_000;
|
||||
const VALIDATOR_COUNT: usize = 1_000;
|
||||
|
||||
fn build_state<T: EthSpec>(validator_count: usize) -> BeaconState<T> {
|
||||
let (state, _keypairs) =
|
||||
TestingBeaconStateBuilder::from_deterministic_keypairs(validator_count, &T::default_spec())
|
||||
.build();
|
||||
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(),
|
||||
);
|
||||
|
||||
assert_eq!(state.validators.len(), validator_count);
|
||||
assert_eq!(state.balances.len(), validator_count);
|
||||
assert!(state.previous_epoch_attestations.is_empty());
|
||||
assert!(state.current_epoch_attestations.is_empty());
|
||||
assert!(state.eth1_data_votes.is_empty());
|
||||
assert!(state.historical_roots.is_empty());
|
||||
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());
|
||||
|
||||
state
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let state = build_state::<MainnetEthSpec>(VALIDATOR_COUNT);
|
||||
let state = build_state::<MainnetEthSpec>();
|
||||
|
||||
// This vec is an attempt to ensure the compiler doesn't optimize-out the hashing.
|
||||
let mut vec = Vec::with_capacity(TREE_HASH_LOOPS);
|
||||
|
||||
Reference in New Issue
Block a user