Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Altair] Update to latest spec v1.1.0-alpha.6 #2373

Merged
merged 10 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 62 additions & 56 deletions beacon_node/beacon_chain/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,65 +640,71 @@ where
slot,
);

let aggregated_attestations: Vec<Option<SignedAggregateAndProof<E>>> = unaggregated_attestations
.iter()
.map(|committee_attestations| {
// If there are any attestations in this committee, create an aggregate.
if let Some((attestation, _)) = committee_attestations.first() {
let bc = state.get_beacon_committee(attestation.data.slot, attestation.data.index)
.unwrap();

let aggregator_index = bc.committee
.iter()
.find(|&validator_index| {
if !attesting_validators.contains(validator_index) {
return false
}

let selection_proof = SelectionProof::new::<E>(
state.slot(),
&self.validator_keypairs[*validator_index].sk,
&state.fork(),
state.genesis_validators_root(),
&self.spec,
);
let aggregated_attestations: Vec<Option<SignedAggregateAndProof<E>>> =
unaggregated_attestations
.iter()
.map(|committee_attestations| {
// If there are any attestations in this committee, create an aggregate.
if let Some((attestation, _)) = committee_attestations.first() {
let bc = state
.get_beacon_committee(attestation.data.slot, attestation.data.index)
.unwrap();

selection_proof.is_aggregator(bc.committee.len(), &self.spec).unwrap_or(false)
})
.copied()
.unwrap_or_else(|| panic!(
"Committee {} at slot {} with {} attesting validators does not have any aggregators",
bc.index, state.slot(), bc.committee.len()
));

// If the chain is able to produce an aggregate, use that. Otherwise, build an
// aggregate locally.
let aggregate = self
.chain
.get_aggregated_attestation(&attestation.data)
.unwrap_or_else(|| {
committee_attestations.iter().skip(1).fold(attestation.clone(), |mut agg, (att, _)| {
agg.aggregate(att);
agg
// Find an aggregator if one exists. Return `None` if there are no
// aggregators.
let aggregator_index = bc
.committee
.iter()
.find(|&validator_index| {
if !attesting_validators.contains(validator_index) {
return false;
}

let selection_proof = SelectionProof::new::<E>(
state.slot(),
&self.validator_keypairs[*validator_index].sk,
&state.fork(),
state.genesis_validators_root(),
&self.spec,
);

selection_proof
.is_aggregator(bc.committee.len(), &self.spec)
.unwrap_or(false)
})
});

let signed_aggregate = SignedAggregateAndProof::from_aggregate(
aggregator_index as u64,
aggregate,
None,
&self.validator_keypairs[aggregator_index].sk,
&state.fork(),
state.genesis_validators_root(),
&self.spec,
);
.copied()?;

Some(signed_aggregate)
}
else {
None
}
}).collect();
// If the chain is able to produce an aggregate, use that. Otherwise, build an
// aggregate locally.
let aggregate = self
.chain
.get_aggregated_attestation(&attestation.data)
.unwrap_or_else(|| {
committee_attestations.iter().skip(1).fold(
attestation.clone(),
|mut agg, (att, _)| {
agg.aggregate(att);
agg
},
)
});

let signed_aggregate = SignedAggregateAndProof::from_aggregate(
aggregator_index as u64,
aggregate,
None,
&self.validator_keypairs[aggregator_index].sk,
&state.fork(),
state.genesis_validators_root(),
&self.spec,
);

Some(signed_aggregate)
} else {
None
}
})
.collect();

unaggregated_attestations
.into_iter()
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/beacon_chain/tests/block_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ fn add_base_block_to_altair_chain() {
let slots_per_epoch = MainnetEthSpec::slots_per_epoch();

// The Altair fork happens at epoch 1.
spec.altair_fork_slot = Some(Epoch::new(1).start_slot(slots_per_epoch));
spec.altair_fork_epoch = Some(Epoch::new(1));

let harness = BeaconChainHarness::new_with_chain_config(
MainnetEthSpec,
Expand Down Expand Up @@ -986,7 +986,7 @@ fn add_altair_block_to_base_chain() {
let mut spec = MainnetEthSpec::default_spec();

// Altair never happens.
spec.altair_fork_slot = None;
spec.altair_fork_epoch = None;

let harness = BeaconChainHarness::new_with_chain_config(
MainnetEthSpec,
Expand Down
22 changes: 15 additions & 7 deletions beacon_node/http_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ use std::sync::Arc;
use tokio::sync::mpsc::UnboundedSender;
use tokio_stream::{wrappers::BroadcastStream, StreamExt};
use types::{
Attestation, AttesterSlashing, CommitteeCache, Epoch, EthSpec, ProposerSlashing, RelativeEpoch,
SignedAggregateAndProof, SignedBeaconBlock, SignedVoluntaryExit, Slot, StandardConfig,
Attestation, AttesterSlashing, CommitteeCache, ConfigAndPreset, Epoch, EthSpec,
ProposerSlashing, RelativeEpoch, SignedAggregateAndProof, SignedBeaconBlock,
SignedVoluntaryExit, Slot,
};
use warp::http::StatusCode;
use warp::sse::Event;
Expand Down Expand Up @@ -74,6 +75,7 @@ pub struct Config {
pub listen_addr: Ipv4Addr,
pub listen_port: u16,
pub allow_origin: Option<String>,
pub serve_legacy_spec: bool,
}

impl Default for Config {
Expand All @@ -83,6 +85,7 @@ impl Default for Config {
listen_addr: Ipv4Addr::new(127, 0, 0, 1),
listen_port: 5052,
allow_origin: None,
serve_legacy_spec: true,
}
}
}
Expand Down Expand Up @@ -331,7 +334,8 @@ pub fn serve<T: BeaconChainTypes>(
.untuple_one();

// Create a `warp` filter that provides access to the logger.
let log_filter = warp::any().map(move || ctx.log.clone());
let inner_ctx = ctx.clone();
let log_filter = warp::any().map(move || inner_ctx.log.clone());

/*
*
Expand Down Expand Up @@ -1267,16 +1271,20 @@ pub fn serve<T: BeaconChainTypes>(
});

// GET config/spec
let serve_legacy_spec = ctx.config.serve_legacy_spec;
let get_config_spec = config_path
.clone()
.and(warp::path("spec"))
.and(warp::path::end())
.and(chain_filter.clone())
.and_then(|chain: Arc<BeaconChain<T>>| {
.and_then(move |chain: Arc<BeaconChain<T>>| {
blocking_json_task(move || {
Ok(api_types::GenericResponse::from(
StandardConfig::from_chain_spec::<T::EthSpec>(&chain.spec),
))
let mut config_and_preset =
ConfigAndPreset::from_chain_spec::<T::EthSpec>(&chain.spec);
if serve_legacy_spec {
config_and_preset.make_backwards_compat(&chain.spec);
}
Ok(api_types::GenericResponse::from(config_and_preset))
})
});

Expand Down
5 changes: 4 additions & 1 deletion beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ impl ApiTester {
listen_addr: Ipv4Addr::new(127, 0, 0, 1),
listen_port: 0,
allow_origin: None,
serve_legacy_spec: true,
},
chain: Some(chain.clone()),
network_tx: Some(network_tx),
Expand Down Expand Up @@ -294,6 +295,7 @@ impl ApiTester {
listen_addr: Ipv4Addr::new(127, 0, 0, 1),
listen_port: 0,
allow_origin: None,
serve_legacy_spec: true,
},
chain: Some(chain.clone()),
network_tx: Some(network_tx),
Expand Down Expand Up @@ -1253,7 +1255,8 @@ impl ApiTester {
pub async fn test_get_config_spec(self) -> Self {
let result = self.client.get_config_spec().await.unwrap().data;

let expected = StandardConfig::from_chain_spec::<E>(&self.chain.spec);
let mut expected = ConfigAndPreset::from_chain_spec::<E>(&self.chain.spec);
expected.make_backwards_compat(&self.chain.spec);

assert_eq!(result, expected);

Expand Down
8 changes: 4 additions & 4 deletions beacon_node/operation_pool/src/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use state_processing::common::{
use std::collections::HashMap;
use types::{
beacon_state::BeaconStateBase,
consts::altair::{FLAG_INDICES_AND_WEIGHTS, WEIGHT_DENOMINATOR},
consts::altair::{PARTICIPATION_FLAG_WEIGHTS, WEIGHT_DENOMINATOR},
Attestation, BeaconState, BitList, ChainSpec, EthSpec,
};

Expand Down Expand Up @@ -100,9 +100,9 @@ impl<'a, T: EthSpec> AttMaxCover<'a, T> {
let base_reward =
altair::get_base_reward(state, index, total_active_balance, spec).ok()?;

for (flag_index, weight) in &FLAG_INDICES_AND_WEIGHTS {
if att_participation_flags.contains(flag_index)
&& !participation.has_flag(*flag_index).ok()?
for (flag_index, weight) in PARTICIPATION_FLAG_WEIGHTS.iter().enumerate() {
if att_participation_flags.contains(&flag_index)
&& !participation.has_flag(flag_index).ok()?
{
proposer_reward_numerator += base_reward.checked_mul(*weight)?;
}
Expand Down
6 changes: 6 additions & 0 deletions beacon_node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
address of this server (e.g., http://localhost:5052).")
.takes_value(true),
)
.arg(
Arg::with_name("http-disable-legacy-spec")
.long("http-disable-legacy-spec")
.help("Disable serving of legacy data on the /config/spec endpoint. May be \
disabled by default in a future release.")
)
/* Prometheus metrics HTTP server related arguments */
.arg(
Arg::with_name("metrics")
Expand Down
4 changes: 4 additions & 0 deletions beacon_node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ pub fn get_config<E: EthSpec>(
client_config.http_api.allow_origin = Some(allow_origin.to_string());
}

if cli_args.is_present("http-disable-legacy-spec") {
client_config.http_api.serve_legacy_spec = false;
}

/*
* Prometheus metrics HTTP server
*/
Expand Down
5 changes: 3 additions & 2 deletions beacon_node/store/src/partial_beacon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,11 @@ impl<T: EthSpec> PartialBeaconState<T> {
)?;

let slot = Slot::from_ssz_bytes(slot_bytes)?;
let epoch = slot.epoch(T::slots_per_epoch());

if spec
.altair_fork_slot
.map_or(true, |altair_slot| slot < altair_slot)
.altair_fork_epoch
.map_or(true, |altair_epoch| epoch < altair_epoch)
{
PartialBeaconStateBase::from_ssz_bytes(bytes).map(Self::Base)
} else {
Expand Down
2 changes: 1 addition & 1 deletion common/eth2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ impl BeaconNodeHttpClient {
}

/// `GET config/spec`
pub async fn get_config_spec(&self) -> Result<GenericResponse<StandardConfig>, Error> {
pub async fn get_config_spec(&self) -> Result<GenericResponse<ConfigAndPreset>, Error> {
let mut path = self.eth_path()?;

path.path_segments_mut()
Expand Down
2 changes: 1 addition & 1 deletion common/eth2/src/lighthouse_vc/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl ValidatorClientHttpClient {
}

/// `GET lighthouse/spec`
pub async fn get_lighthouse_spec(&self) -> Result<GenericResponse<StandardConfig>, Error> {
pub async fn get_lighthouse_spec(&self) -> Result<GenericResponse<ConfigAndPreset>, Error> {
let mut path = self.server.full.clone();

path.path_segments_mut()
Expand Down
2 changes: 0 additions & 2 deletions common/eth2_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,4 @@ define_net!(pyrmont, include_pyrmont_file, "pyrmont", true);

define_net!(mainnet, include_mainnet_file, "mainnet", true);

define_net!(toledo, include_toledo_file, "toledo", true);

define_net!(prater, include_prater_file, "prater", true);
5 changes: 1 addition & 4 deletions common/eth2_network_config/build.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
//! Extracts zipped genesis states on first run.
use eth2_config::{
mainnet, prater, pyrmont, toledo, Eth2NetArchiveAndDirectory, GENESIS_FILE_NAME,
};
use eth2_config::{mainnet, prater, pyrmont, Eth2NetArchiveAndDirectory, GENESIS_FILE_NAME};
use std::fs::File;
use std::io;
use zip::ZipArchive;

const ETH2_NET_DIRS: &[Eth2NetArchiveAndDirectory<'static>] = &[
mainnet::ETH2_NET_DIR,
pyrmont::ETH2_NET_DIR,
toledo::ETH2_NET_DIR,
prater::ETH2_NET_DIR,
];

Expand Down

This file was deleted.

Loading