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

@@ -1,16 +1,22 @@
use super::*;
use crate::case_result::compare_beacon_state_results_without_caches;
use crate::decode::{ssz_decode_file, yaml_decode_file};
use crate::decode::{ssz_decode_file, ssz_decode_state, yaml_decode_file};
use serde_derive::Deserialize;
use state_processing::initialize_beacon_state_from_eth1;
use std::path::PathBuf;
use types::{BeaconState, Deposit, EthSpec, Hash256};
use types::{BeaconState, Deposit, EthSpec, ForkName, Hash256};
#[derive(Debug, Clone, Deserialize)]
struct Metadata {
deposits_count: usize,
}
#[derive(Debug, Clone, Deserialize)]
struct Eth1 {
eth1_block_hash: Hash256,
eth1_timestamp: u64,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(bound = "E: EthSpec")]
pub struct GenesisInitialization<E: EthSpec> {
@@ -22,17 +28,20 @@ pub struct GenesisInitialization<E: EthSpec> {
}
impl<E: EthSpec> LoadCase for GenesisInitialization<E> {
fn load_from_dir(path: &Path) -> Result<Self, Error> {
let eth1_block_hash = ssz_decode_file(&path.join("eth1_block_hash.ssz"))?;
let eth1_timestamp = yaml_decode_file(&path.join("eth1_timestamp.yaml"))?;
fn load_from_dir(path: &Path, fork_name: ForkName) -> Result<Self, Error> {
let Eth1 {
eth1_block_hash,
eth1_timestamp,
} = yaml_decode_file(&path.join("eth1.yaml"))?;
let meta: Metadata = yaml_decode_file(&path.join("meta.yaml"))?;
let deposits: Vec<Deposit> = (0..meta.deposits_count)
.map(|i| {
let filename = format!("deposits_{}.ssz", i);
let filename = format!("deposits_{}.ssz_snappy", i);
ssz_decode_file(&path.join(filename))
})
.collect::<Result<_, _>>()?;
let state = ssz_decode_file(&path.join("state.ssz"))?;
let spec = &testing_spec::<E>(fork_name);
let state = ssz_decode_state(&path.join("state.ssz_snappy"), spec)?;
Ok(Self {
path: path.into(),
@@ -45,8 +54,13 @@ impl<E: EthSpec> LoadCase for GenesisInitialization<E> {
}
impl<E: EthSpec> Case for GenesisInitialization<E> {
fn result(&self, _case_index: usize) -> Result<(), Error> {
let spec = &E::default_spec();
fn is_enabled_for_fork(fork_name: ForkName) -> bool {
// Altair genesis and later requires real crypto.
fork_name == ForkName::Base || cfg!(not(feature = "fake_crypto"))
}
fn result(&self, _case_index: usize, fork_name: ForkName) -> Result<(), Error> {
let spec = &testing_spec::<E>(fork_name);
let mut result = initialize_beacon_state_from_eth1(
self.eth1_block_hash,