mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-02 16:21:42 +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:
@@ -209,7 +209,7 @@ impl<E: EthSpec> CandidateBeaconNode<E> {
|
||||
|
||||
/// Checks if the node has the correct specification.
|
||||
async fn is_compatible(&self, spec: &ChainSpec, log: &Logger) -> Result<(), CandidateError> {
|
||||
let yaml_config = self
|
||||
let config_and_preset = self
|
||||
.beacon_node
|
||||
.get_config_spec()
|
||||
.await
|
||||
@@ -224,9 +224,8 @@ impl<E: EthSpec> CandidateBeaconNode<E> {
|
||||
})?
|
||||
.data;
|
||||
|
||||
let beacon_node_spec = yaml_config
|
||||
.apply_to_chain_spec::<E>(&E::default_spec())
|
||||
.ok_or_else(|| {
|
||||
let beacon_node_spec =
|
||||
ChainSpec::from_config::<E>(&config_and_preset.config).ok_or_else(|| {
|
||||
error!(
|
||||
log,
|
||||
"The minimal/mainnet spec type of the beacon node does not match the validator \
|
||||
@@ -236,11 +235,12 @@ impl<E: EthSpec> CandidateBeaconNode<E> {
|
||||
CandidateError::Incompatible
|
||||
})?;
|
||||
|
||||
if !yaml_config.extra_fields.is_empty() {
|
||||
if !config_and_preset.extra_fields.is_empty() {
|
||||
debug!(
|
||||
log,
|
||||
"Beacon spec includes unknown fields";
|
||||
"fields" => ?yaml_config.extra_fields
|
||||
"endpoint" => %self.beacon_node,
|
||||
"fields" => ?config_and_preset.extra_fields,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -289,8 +289,8 @@ impl<T: SlotClock + 'static, E: EthSpec> BlockService<T, E> {
|
||||
info!(
|
||||
log,
|
||||
"Successfully published block";
|
||||
"deposits" => signed_block.message.body.deposits.len(),
|
||||
"attestations" => signed_block.message.body.attestations.len(),
|
||||
"deposits" => signed_block.message().body().deposits().len(),
|
||||
"attestations" => signed_block.message().body().attestations().len(),
|
||||
"graffiti" => ?graffiti.map(|g| g.as_utf8_lossy()),
|
||||
"slot" => signed_block.slot().as_u64(),
|
||||
);
|
||||
|
||||
@@ -16,7 +16,7 @@ use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::{Arc, Weak};
|
||||
use tokio::runtime::Runtime;
|
||||
use types::{ChainSpec, EthSpec, YamlConfig};
|
||||
use types::{ChainSpec, ConfigAndPreset, EthSpec};
|
||||
use validator_dir::Builder as ValidatorDirBuilder;
|
||||
use warp::{
|
||||
http::{
|
||||
@@ -191,9 +191,9 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
.and(signer.clone())
|
||||
.and_then(|spec: Arc<_>, signer| {
|
||||
blocking_signed_json_task(signer, move || {
|
||||
Ok(api_types::GenericResponse::from(
|
||||
YamlConfig::from_spec::<E>(&spec),
|
||||
))
|
||||
let mut config = ConfigAndPreset::from_chain_spec::<E>(&spec);
|
||||
config.make_backwards_compat(&spec);
|
||||
Ok(api_types::GenericResponse::from(config))
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
@@ -150,7 +150,8 @@ impl ApiTester {
|
||||
pub async fn test_get_lighthouse_spec(self) -> Self {
|
||||
let result = self.client.get_lighthouse_spec().await.unwrap().data;
|
||||
|
||||
let expected = YamlConfig::from_spec::<E>(&E::default_spec());
|
||||
let mut expected = ConfigAndPreset::from_chain_spec::<E>(&E::default_spec());
|
||||
expected.make_backwards_compat(&E::default_spec());
|
||||
|
||||
assert_eq!(result, expected);
|
||||
|
||||
|
||||
@@ -168,11 +168,11 @@ impl<T: SlotClock + 'static, E: EthSpec> ValidatorStore<T, E> {
|
||||
current_slot: Slot,
|
||||
) -> Option<SignedBeaconBlock<E>> {
|
||||
// Make sure the block slot is not higher than the current slot to avoid potential attacks.
|
||||
if block.slot > current_slot {
|
||||
if block.slot() > current_slot {
|
||||
warn!(
|
||||
self.log,
|
||||
"Not signing block with slot greater than current slot";
|
||||
"block_slot" => block.slot.as_u64(),
|
||||
"block_slot" => block.slot().as_u64(),
|
||||
"current_slot" => current_slot.as_u64()
|
||||
);
|
||||
return None;
|
||||
|
||||
Reference in New Issue
Block a user