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:
Michael Sproul
2021-07-09 06:15:32 +00:00
parent 89361573d4
commit b4689e20c6
271 changed files with 9652 additions and 8444 deletions

View File

@@ -5,7 +5,7 @@ use eth1::{DepositLog, Eth1Block, Service as Eth1Service};
use slog::{debug, error, info, trace, Logger};
use state_processing::{
eth2_genesis_time, initialize_beacon_state_from_eth1, is_valid_genesis_state,
per_block_processing::process_deposit, process_activations,
per_block_processing::process_operations::process_deposit, process_activations,
};
use std::sync::{
atomic::{AtomicU64, AtomicUsize, Ordering},
@@ -190,7 +190,7 @@ impl Eth1GenesisService {
.get_active_validator_indices(E::genesis_epoch(), &spec)
.map_err(|e| format!("Genesis validators error: {:?}", e))?
.len(),
"genesis_time" => genesis_state.genesis_time,
"genesis_time" => genesis_state.genesis_time(),
);
break Ok(genesis_state);
}

View File

@@ -48,10 +48,12 @@ pub fn interop_genesis_state<T: EthSpec>(
)
.map_err(|e| format!("Unable to initialize genesis state: {:?}", e))?;
state.genesis_time = genesis_time;
*state.genesis_time_mut() = genesis_time;
// Invalid all the caches after all the manual state surgery.
state.drop_all_caches();
// Invalidate all the caches after all the manual state surgery.
state
.drop_all_caches()
.map_err(|e| format!("Unable to drop caches: {:?}", e))?;
Ok(state)
}
@@ -75,24 +77,25 @@ mod test {
.expect("should build state");
assert_eq!(
state.eth1_data.block_hash,
state.eth1_data().block_hash,
Hash256::from_slice(&[0x42; 32]),
"eth1 block hash should be co-ordinated junk"
);
assert_eq!(
state.genesis_time, genesis_time,
state.genesis_time(),
genesis_time,
"genesis time should be as specified"
);
for b in &state.balances {
for b in state.balances() {
assert_eq!(
*b, spec.max_effective_balance,
"validator balances should be max effective balance"
);
}
for v in &state.validators {
for v in state.validators() {
let creds = v.withdrawal_credentials.as_bytes();
assert_eq!(
creds[0], spec.bls_withdrawal_prefix_byte,
@@ -106,13 +109,13 @@ mod test {
}
assert_eq!(
state.balances.len(),
state.balances().len(),
validator_count,
"validator balances len should be correct"
);
assert_eq!(
state.validators.len(),
state.validators().len(),
validator_count,
"validator count should be correct"
);