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

@@ -21,7 +21,6 @@ use reqwest::{IntoUrl, Response};
pub use reqwest::{StatusCode, Url};
use sensitive_url::SensitiveUrl;
use serde::{de::DeserializeOwned, Serialize};
use ssz::Decode;
use std::convert::TryFrom;
use std::fmt;
use std::iter::Iterator;
@@ -498,6 +497,7 @@ impl BeaconNodeHttpClient {
pub async fn get_beacon_blocks_ssz<T: EthSpec>(
&self,
block_id: BlockId,
spec: &ChainSpec,
) -> Result<Option<SignedBeaconBlock<T>>, Error> {
let mut path = self.eth_path()?;
@@ -509,7 +509,7 @@ impl BeaconNodeHttpClient {
self.get_bytes_opt_accept_header(path, Accept::Ssz)
.await?
.map(|bytes| SignedBeaconBlock::from_ssz_bytes(&bytes).map_err(Error::InvalidSsz))
.map(|bytes| SignedBeaconBlock::from_ssz_bytes(&bytes, spec).map_err(Error::InvalidSsz))
.transpose()
}
@@ -715,7 +715,7 @@ impl BeaconNodeHttpClient {
}
/// `GET config/spec`
pub async fn get_config_spec(&self) -> Result<GenericResponse<YamlConfig>, Error> {
pub async fn get_config_spec(&self) -> Result<GenericResponse<ConfigAndPreset>, Error> {
let mut path = self.eth_path()?;
path.path_segments_mut()
@@ -883,6 +883,7 @@ impl BeaconNodeHttpClient {
pub async fn get_debug_beacon_states_ssz<T: EthSpec>(
&self,
state_id: StateId,
spec: &ChainSpec,
) -> Result<Option<BeaconState<T>>, Error> {
let mut path = self.eth_path()?;
@@ -895,7 +896,7 @@ impl BeaconNodeHttpClient {
self.get_bytes_opt_accept_header(path, Accept::Ssz)
.await?
.map(|bytes| BeaconState::from_ssz_bytes(&bytes).map_err(Error::InvalidSsz))
.map(|bytes| BeaconState::from_ssz_bytes(&bytes, spec).map_err(Error::InvalidSsz))
.transpose()
}

View File

@@ -2,13 +2,12 @@
use crate::{
ok_or_error,
types::{BeaconState, Epoch, EthSpec, GenericResponse, ValidatorId},
types::{BeaconState, ChainSpec, Epoch, EthSpec, GenericResponse, ValidatorId},
BeaconNodeHttpClient, DepositData, Error, Eth1Data, Hash256, StateId, StatusCode,
};
use proto_array::core::ProtoArray;
use reqwest::IntoUrl;
use serde::{Deserialize, Serialize};
use ssz::Decode;
use ssz_derive::{Decode, Encode};
pub use eth2_libp2p::{types::SyncState, PeerInfo};
@@ -470,6 +469,7 @@ impl BeaconNodeHttpClient {
pub async fn get_lighthouse_beacon_states_ssz<E: EthSpec>(
&self,
state_id: &StateId,
spec: &ChainSpec,
) -> Result<Option<BeaconState<E>>, Error> {
let mut path = self.server.full.clone();
@@ -483,7 +483,7 @@ impl BeaconNodeHttpClient {
self.get_bytes_opt(path)
.await?
.map(|bytes| BeaconState::from_ssz_bytes(&bytes).map_err(Error::InvalidSsz))
.map(|bytes| BeaconState::from_ssz_bytes(&bytes, spec).map_err(Error::InvalidSsz))
.transpose()
}

View File

@@ -211,7 +211,7 @@ impl ValidatorClientHttpClient {
}
/// `GET lighthouse/spec`
pub async fn get_lighthouse_spec(&self) -> Result<GenericResponse<YamlConfig>, Error> {
pub async fn get_lighthouse_spec(&self) -> Result<GenericResponse<ConfigAndPreset>, Error> {
let mut path = self.server.full.clone();
path.path_segments_mut()