Skip to content

Commit

Permalink
Merge pull request #2405 from sigp/altair-alpha.7
Browse files Browse the repository at this point in the history
Update to spec v1.1.0-alpha.7
  • Loading branch information
michaelsproul authored Jun 16, 2021
2 parents bc68a2d + 17a0431 commit c962b88
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 86 deletions.
7 changes: 7 additions & 0 deletions common/eth2_network_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,13 @@ mod tests {

type E = MainnetEthSpec;

#[test]
fn mainnet_config_eq_chain_spec() {
let config = Eth2NetworkConfig::from_hardcoded_net(&MAINNET).unwrap();
let spec = ChainSpec::mainnet();
assert_eq!(spec, config.chain_spec::<E>().unwrap());
}

#[test]
fn hard_coded_nets_work() {
for net in HARDCODED_NETS {
Expand Down
4 changes: 2 additions & 2 deletions consensus/state_processing/src/per_block_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub use self::verify_attester_slashing::{
get_slashable_indices, get_slashable_indices_modular, verify_attester_slashing,
};
pub use self::verify_proposer_slashing::verify_proposer_slashing;
pub use altair::sync_committee::process_sync_committee;
pub use altair::sync_committee::process_sync_aggregate;
pub use block_signature_verifier::BlockSignatureVerifier;
pub use is_valid_indexed_attestation::is_valid_indexed_attestation;
pub use process_operations::process_operations;
Expand Down Expand Up @@ -130,7 +130,7 @@ pub fn per_block_processing<T: EthSpec>(
process_operations(state, block.body(), verify_signatures, spec)?;

if let BeaconBlockRef::Altair(inner) = block {
process_sync_committee(state, &inner.body.sync_aggregate, proposer_index, spec)?;
process_sync_aggregate(state, &inner.body.sync_aggregate, proposer_index, spec)?;
}

Ok(())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::common::{altair::get_base_reward_per_increment, increase_balance};
use crate::common::{altair::get_base_reward_per_increment, decrease_balance, increase_balance};
use crate::per_block_processing::errors::{BlockProcessingError, SyncAggregateInvalid};
use safe_arith::SafeArith;
use tree_hash::TreeHash;
use types::consts::altair::{PROPOSER_WEIGHT, SYNC_REWARD_WEIGHT, WEIGHT_DENOMINATOR};
use types::{BeaconState, ChainSpec, Domain, EthSpec, SigningData, SyncAggregate, Unsigned};

pub fn process_sync_committee<T: EthSpec>(
pub fn process_sync_aggregate<T: EthSpec>(
state: &mut BeaconState<T>,
aggregate: &SyncAggregate<T>,
proposer_index: u64,
Expand Down Expand Up @@ -68,14 +68,18 @@ pub fn process_sync_committee<T: EthSpec>(
.safe_div(WEIGHT_DENOMINATOR.safe_sub(PROPOSER_WEIGHT)?)?;

// Apply participant and proposer rewards
let participant_indices = state.get_sync_committee_participant_indices(
&current_sync_committee,
&aggregate.sync_committee_bits,
)?;
let committee_indices = state.get_sync_committee_indices(&current_sync_committee)?;

for participant_index in participant_indices {
increase_balance(state, participant_index as usize, participant_reward)?;
increase_balance(state, proposer_index as usize, proposer_reward)?;
for (participant_index, participation_bit) in committee_indices
.into_iter()
.zip(aggregate.sync_committee_bits.iter())
{
if participation_bit {
increase_balance(state, participant_index as usize, participant_reward)?;
increase_balance(state, proposer_index as usize, proposer_reward)?;
} else {
decrease_balance(state, participant_index as usize, participant_reward)?;
}
}

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions consensus/types/presets/mainnet/altair.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ PROPORTIONAL_SLASHING_MULTIPLIER_ALTAIR: 2
# ---------------------------------------------------------------
# 2**9 (= 512)
SYNC_COMMITTEE_SIZE: 512
# 2**9 (= 512)
EPOCHS_PER_SYNC_COMMITTEE_PERIOD: 512
# 2**8 (= 256)
EPOCHS_PER_SYNC_COMMITTEE_PERIOD: 256


# Sync protocol
Expand Down
19 changes: 5 additions & 14 deletions consensus/types/src/beacon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,26 +728,17 @@ impl<T: EthSpec> BeaconState<T> {
Ok(hash(&preimage))
}

/// Get the validator indices of all validators from `sync_committee` identified by
/// `sync_committee_bits`.
pub fn get_sync_committee_participant_indices(
/// Get the validator indices of all validators from `sync_committee`.
pub fn get_sync_committee_indices(
&mut self,
sync_committee: &SyncCommittee<T>,
sync_committee_bits: &BitVector<T::SyncCommitteeSize>,
) -> Result<Vec<usize>, Error> {
sync_committee
.pubkeys
.iter()
.zip(sync_committee_bits.iter())
.flat_map(|(pubkey, bit)| {
if bit {
let validator_index_res = self
.get_validator_index(&pubkey)
.and_then(|opt| opt.ok_or(Error::PubkeyCacheInconsistent));
Some(validator_index_res)
} else {
None
}
.map(|pubkey| {
self.get_validator_index(&pubkey)?
.ok_or(Error::PubkeyCacheInconsistent)
})
.collect()
}
Expand Down
2 changes: 1 addition & 1 deletion consensus/types/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ impl ChainSpec {
inactivity_score_bias: 4,
inactivity_score_recovery_rate: 16,
min_sync_committee_participants: 1,
epochs_per_sync_committee_period: Epoch::new(512),
epochs_per_sync_committee_period: Epoch::new(256),
domain_sync_committee: 7,
domain_sync_committee_selection_proof: 8,
domain_contribution_and_proof: 9,
Expand Down
8 changes: 4 additions & 4 deletions consensus/types/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ pub mod altair {
pub const TIMELY_SOURCE_FLAG_INDEX: usize = 0;
pub const TIMELY_TARGET_FLAG_INDEX: usize = 1;
pub const TIMELY_HEAD_FLAG_INDEX: usize = 2;
pub const TIMELY_SOURCE_WEIGHT: u64 = 12;
pub const TIMELY_TARGET_WEIGHT: u64 = 24;
pub const TIMELY_HEAD_WEIGHT: u64 = 12;
pub const SYNC_REWARD_WEIGHT: u64 = 8;
pub const TIMELY_SOURCE_WEIGHT: u64 = 14;
pub const TIMELY_TARGET_WEIGHT: u64 = 26;
pub const TIMELY_HEAD_WEIGHT: u64 = 14;
pub const SYNC_REWARD_WEIGHT: u64 = 2;
pub const PROPOSER_WEIGHT: u64 = 8;
pub const WEIGHT_DENOMINATOR: u64 = 64;

Expand Down
2 changes: 1 addition & 1 deletion testing/ef_tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TESTS_TAG := v1.1.0-alpha.6
TESTS_TAG := v1.1.0-alpha.7
TESTS = general minimal mainnet
TARBALLS = $(patsubst %,%-$(TESTS_TAG).tar.gz,$(TESTS))

Expand Down
8 changes: 4 additions & 4 deletions testing/ef_tests/check_all_files_accessed.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /bin/python
#!/usr/bin/env python3

# The purpose of this script is to compare a list of file names that were accessed during testing
# against all the file names in the eth2.0-spec-tests repository. It then checks to see which files
Expand Down Expand Up @@ -54,9 +54,9 @@
# SyncCommitteeContribution
"tests/minimal/altair/ssz_static/SyncCommitteeContribution",
"tests/mainnet/altair/ssz_static/SyncCommitteeContribution",
# SyncCommitteeSignature
"tests/minimal/altair/ssz_static/SyncCommitteeSignature",
"tests/mainnet/altair/ssz_static/SyncCommitteeSignature",
# SyncCommitteeMessage
"tests/minimal/altair/ssz_static/SyncCommitteeMessage",
"tests/mainnet/altair/ssz_static/SyncCommitteeMessage",
# SyncCommitteeSigningData
"tests/minimal/altair/ssz_static/SyncCommitteeSigningData",
"tests/mainnet/altair/ssz_static/SyncCommitteeSigningData",
Expand Down
20 changes: 12 additions & 8 deletions testing/ef_tests/src/cases/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use state_processing::per_block_processing::{
altair, base, process_attester_slashings, process_deposits, process_exits,
process_proposer_slashings,
},
process_sync_committee, VerifySignatures,
process_sync_aggregate, VerifySignatures,
};
use std::fmt::Debug;
use std::path::Path;
Expand Down Expand Up @@ -44,6 +44,10 @@ pub trait Operation<E: EthSpec>: TypeName + Debug + Sync + Sized {
format!("{}.ssz_snappy", Self::handler_name())
}

fn is_enabled_for_fork(_fork_name: ForkName) -> bool {
true
}

fn decode(path: &Path, spec: &ChainSpec) -> Result<Self, Error>;

fn apply_to(
Expand Down Expand Up @@ -167,13 +171,17 @@ impl<E: EthSpec> Operation<E> for BeaconBlock<E> {

impl<E: EthSpec> Operation<E> for SyncAggregate<E> {
fn handler_name() -> String {
"sync_committee".into()
"sync_aggregate".into()
}

fn filename() -> String {
"sync_aggregate.ssz_snappy".into()
}

fn is_enabled_for_fork(fork_name: ForkName) -> bool {
fork_name != ForkName::Base
}

fn decode(path: &Path, _spec: &ChainSpec) -> Result<Self, Error> {
ssz_decode_file(path)
}
Expand All @@ -184,7 +192,7 @@ impl<E: EthSpec> Operation<E> for SyncAggregate<E> {
spec: &ChainSpec,
) -> Result<(), BlockProcessingError> {
let proposer_index = state.get_beacon_proposer_index(state.slot(), spec)? as u64;
process_sync_committee(state, self, proposer_index, spec)
process_sync_aggregate(state, self, proposer_index, spec)
}
}

Expand Down Expand Up @@ -239,11 +247,7 @@ impl<E: EthSpec, O: Operation<E>> Case for Operations<E, O> {
}

fn is_enabled_for_fork(fork_name: ForkName) -> bool {
match fork_name {
// Base fork doesn't have sync aggregate tests
ForkName::Base => O::handler_name() != "sync_committee",
_ => true,
}
O::is_enabled_for_fork(fork_name)
}

fn result(&self, _case_index: usize, fork_name: ForkName) -> Result<(), Error> {
Expand Down
41 changes: 0 additions & 41 deletions testing/ef_tests/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,6 @@
use ef_tests::*;
use types::*;

// FIXME(altair): fix these once alpha.7 is released and includes config files
// Check that the config from the Eth2.0 spec tests matches our minimal/mainnet config.
/*
fn config_test<E: EthSpec + TypeName>() {
let config_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("eth2.0-spec-tests")
.join("tests")
.join(E::name())
.join("config");
let phase0_config_path = config_dir.join("phase0.yaml");
let altair_config_path = config_dir.join("altair.yaml");
let phase0_config = BaseConfig::from_file(&phase0_config_path).expect("config file loads OK");
let altair_config = AltairConfig::from_file(&altair_config_path).expect("altair config loads");
let std_config = StandardConfig::from_parts(phase0_config.clone(), altair_config.clone());
let spec = E::default_spec();
log_file_access(&phase0_config_path);
log_file_access(&altair_config_path);
let unified_spec =
ChainSpec::from_standard_config::<E>(&std_config).expect("config unification");
assert_eq!(unified_spec, spec);
let phase0_from_spec = BaseConfig::from_chain_spec::<E>(&spec);
assert_eq!(phase0_from_spec, phase0_config);
let altair_from_spec = AltairConfig::from_chain_spec::<E>(&spec);
assert_eq!(altair_from_spec, altair_config);
}
#[test]
fn mainnet_config_ok() {
config_test::<MainnetEthSpec>();
}
#[test]
fn minimal_config_ok() {
config_test::<MinimalEthSpec>();
}
*/

// Check that the hand-computed multiplications on EthSpec are correctly computed.
// This test lives here because one is most likely to muck these up during a spec update.
fn check_typenum_values<E: EthSpec>() {
Expand Down

0 comments on commit c962b88

Please sign in to comment.