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,29 +1,46 @@
use super::*;
use crate::decode::{ssz_decode_file, yaml_decode_file};
use crate::decode::{ssz_decode_state, yaml_decode_file};
use serde_derive::Deserialize;
use state_processing::is_valid_genesis_state;
use std::path::Path;
use types::{BeaconState, EthSpec};
use types::{BeaconState, EthSpec, ForkName};
#[derive(Debug, Clone, Deserialize)]
pub struct Metadata {
description: String,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(bound = "E: EthSpec")]
pub struct GenesisValidity<E: EthSpec> {
pub metadata: Option<Metadata>,
pub genesis: BeaconState<E>,
pub is_valid: bool,
}
impl<E: EthSpec> LoadCase for GenesisValidity<E> {
fn load_from_dir(path: &Path) -> Result<Self, Error> {
let genesis = ssz_decode_file(&path.join("genesis.ssz"))?;
fn load_from_dir(path: &Path, fork_name: ForkName) -> Result<Self, Error> {
let spec = &testing_spec::<E>(fork_name);
let genesis = ssz_decode_state(&path.join("genesis.ssz_snappy"), spec)?;
let is_valid = yaml_decode_file(&path.join("is_valid.yaml"))?;
let meta_path = path.join("meta.yaml");
let metadata = if meta_path.exists() {
Some(yaml_decode_file(&meta_path)?)
} else {
None
};
Ok(Self { genesis, is_valid })
Ok(Self {
metadata,
genesis,
is_valid,
})
}
}
impl<E: EthSpec> Case for GenesisValidity<E> {
fn result(&self, _case_index: usize) -> Result<(), Error> {
let spec = &E::default_spec();
fn result(&self, _case_index: usize, fork_name: ForkName) -> Result<(), Error> {
let spec = &testing_spec::<E>(fork_name);
let is_valid = is_valid_genesis_state(&self.genesis, spec);