From ef7351ddfecbb35cd23dde11835d58d4d4e689a8 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Wed, 19 Jan 2022 00:24:19 +0000 Subject: [PATCH] Update to spec v1.1.8 (#2893) ## Proposed Changes Change the canonical fork name for the merge to Bellatrix. Keep other merge naming the same to avoid churn. I've also fixed and enabled the `fork` and `transition` tests for Bellatrix, and the v1.1.7 fork choice tests. Additionally, the `BellatrixPreset` has been added with tests. It gets served via the `/config/spec` API endpoint along with the other presets. --- beacon_node/beacon_chain/tests/merge.rs | 10 +- .../lighthouse_network/tests/common/mod.rs | 2 +- beacon_node/src/config.rs | 2 +- .../mainnet/config.yaml | 4 +- .../prater/config.yaml | 4 +- .../pyrmont/config.yaml | 4 +- consensus/state_processing/src/genesis.rs | 8 +- .../src/per_slot_processing.rs | 6 +- consensus/state_processing/src/upgrade.rs | 2 +- .../state_processing/src/upgrade/merge.rs | 4 +- .../types/presets/mainnet/bellatrix.yaml | 21 ++++ .../types/presets/minimal/bellatrix.yaml | 21 ++++ consensus/types/src/beacon_block.rs | 2 +- consensus/types/src/chain_spec.rs | 54 +++++----- consensus/types/src/config_and_preset.rs | 6 +- consensus/types/src/fork_context.rs | 9 +- consensus/types/src/fork_name.rs | 17 +++- consensus/types/src/lib.rs | 2 +- consensus/types/src/preset.rs | 37 +++++++ lcli/src/new_testnet.rs | 2 +- .../environment/tests/testnet_dir/config.yaml | 4 +- testing/ef_tests/Makefile | 2 +- testing/ef_tests/check_all_files_accessed.py | 15 +-- testing/ef_tests/src/cases/fork.rs | 10 +- testing/ef_tests/src/cases/fork_choice.rs | 13 +-- testing/ef_tests/src/cases/operations.rs | 1 - testing/ef_tests/src/cases/transition.rs | 8 +- testing/ef_tests/src/handler.rs | 98 ++++++------------- testing/ef_tests/tests/tests.rs | 18 ++-- 29 files changed, 214 insertions(+), 172 deletions(-) create mode 100644 consensus/types/presets/mainnet/bellatrix.yaml create mode 100644 consensus/types/presets/minimal/bellatrix.yaml diff --git a/beacon_node/beacon_chain/tests/merge.rs b/beacon_node/beacon_chain/tests/merge.rs index 35dda493e..43ee2372b 100644 --- a/beacon_node/beacon_chain/tests/merge.rs +++ b/beacon_node/beacon_chain/tests/merge.rs @@ -30,11 +30,11 @@ fn verify_execution_payload_chain(chain: &[ExecutionPayload]) { #[should_panic] fn merge_with_terminal_block_hash_override() { let altair_fork_epoch = Epoch::new(0); - let merge_fork_epoch = Epoch::new(0); + let bellatrix_fork_epoch = Epoch::new(0); let mut spec = E::default_spec(); spec.altair_fork_epoch = Some(altair_fork_epoch); - spec.merge_fork_epoch = Some(merge_fork_epoch); + spec.bellatrix_fork_epoch = Some(bellatrix_fork_epoch); let genesis_pow_block_hash = generate_pow_block( spec.terminal_total_difficulty, @@ -95,12 +95,12 @@ fn merge_with_terminal_block_hash_override() { fn base_altair_merge_with_terminal_block_after_fork() { let altair_fork_epoch = Epoch::new(4); let altair_fork_slot = altair_fork_epoch.start_slot(E::slots_per_epoch()); - let merge_fork_epoch = Epoch::new(8); - let merge_fork_slot = merge_fork_epoch.start_slot(E::slots_per_epoch()); + let bellatrix_fork_epoch = Epoch::new(8); + let merge_fork_slot = bellatrix_fork_epoch.start_slot(E::slots_per_epoch()); let mut spec = E::default_spec(); spec.altair_fork_epoch = Some(altair_fork_epoch); - spec.merge_fork_epoch = Some(merge_fork_epoch); + spec.bellatrix_fork_epoch = Some(bellatrix_fork_epoch); let mut execution_payloads = vec![]; diff --git a/beacon_node/lighthouse_network/tests/common/mod.rs b/beacon_node/lighthouse_network/tests/common/mod.rs index 7397fe7ea..7deb2108b 100644 --- a/beacon_node/lighthouse_network/tests/common/mod.rs +++ b/beacon_node/lighthouse_network/tests/common/mod.rs @@ -29,7 +29,7 @@ pub fn fork_context() -> ForkContext { // Set fork_epoch to `Some` to ensure that the `ForkContext` object // includes altair in the list of forks chain_spec.altair_fork_epoch = Some(types::Epoch::new(42)); - chain_spec.merge_fork_epoch = Some(types::Epoch::new(84)); + chain_spec.bellatrix_fork_epoch = Some(types::Epoch::new(84)); ForkContext::new::(types::Slot::new(0), Hash256::zero(), &chain_spec) } diff --git a/beacon_node/src/config.rs b/beacon_node/src/config.rs index df5cf1437..204082293 100644 --- a/beacon_node/src/config.rs +++ b/beacon_node/src/config.rs @@ -469,7 +469,7 @@ pub fn get_config( } client_config.chain.max_network_size = - lighthouse_network::gossip_max_size(spec.merge_fork_epoch.is_some()); + lighthouse_network::gossip_max_size(spec.bellatrix_fork_epoch.is_some()); if cli_args.is_present("slasher") { let slasher_dir = if let Some(slasher_dir) = cli_args.value_of("slasher-dir") { diff --git a/common/eth2_network_config/built_in_network_configs/mainnet/config.yaml b/common/eth2_network_config/built_in_network_configs/mainnet/config.yaml index 4d17356ce..b889b8288 100644 --- a/common/eth2_network_config/built_in_network_configs/mainnet/config.yaml +++ b/common/eth2_network_config/built_in_network_configs/mainnet/config.yaml @@ -33,8 +33,8 @@ GENESIS_DELAY: 604800 ALTAIR_FORK_VERSION: 0x01000000 ALTAIR_FORK_EPOCH: 74240 # Merge -MERGE_FORK_VERSION: 0x02000000 -MERGE_FORK_EPOCH: 18446744073709551615 +BELLATRIX_FORK_VERSION: 0x02000000 +BELLATRIX_FORK_EPOCH: 18446744073709551615 # Sharding SHARDING_FORK_VERSION: 0x03000000 SHARDING_FORK_EPOCH: 18446744073709551615 diff --git a/common/eth2_network_config/built_in_network_configs/prater/config.yaml b/common/eth2_network_config/built_in_network_configs/prater/config.yaml index aa375ab2e..72a106f36 100644 --- a/common/eth2_network_config/built_in_network_configs/prater/config.yaml +++ b/common/eth2_network_config/built_in_network_configs/prater/config.yaml @@ -33,8 +33,8 @@ GENESIS_DELAY: 1919188 ALTAIR_FORK_VERSION: 0x01001020 ALTAIR_FORK_EPOCH: 36660 # Merge -MERGE_FORK_VERSION: 0x02001020 -MERGE_FORK_EPOCH: 18446744073709551615 +BELLATRIX_FORK_VERSION: 0x02001020 +BELLATRIX_FORK_EPOCH: 18446744073709551615 # Sharding SHARDING_FORK_VERSION: 0x03001020 SHARDING_FORK_EPOCH: 18446744073709551615 diff --git a/common/eth2_network_config/built_in_network_configs/pyrmont/config.yaml b/common/eth2_network_config/built_in_network_configs/pyrmont/config.yaml index b5f841580..913671c2b 100644 --- a/common/eth2_network_config/built_in_network_configs/pyrmont/config.yaml +++ b/common/eth2_network_config/built_in_network_configs/pyrmont/config.yaml @@ -33,8 +33,8 @@ GENESIS_DELAY: 432000 ALTAIR_FORK_VERSION: 0x01002009 ALTAIR_FORK_EPOCH: 61650 # Merge -MERGE_FORK_VERSION: 0x02002009 -MERGE_FORK_EPOCH: 18446744073709551615 +BELLATRIX_FORK_VERSION: 0x02002009 +BELLATRIX_FORK_EPOCH: 18446744073709551615 # Sharding SHARDING_FORK_VERSION: 0x03002009 SHARDING_FORK_EPOCH: 18446744073709551615 diff --git a/consensus/state_processing/src/genesis.rs b/consensus/state_processing/src/genesis.rs index 1bb88c84d..fb2c9bfa7 100644 --- a/consensus/state_processing/src/genesis.rs +++ b/consensus/state_processing/src/genesis.rs @@ -2,7 +2,7 @@ use super::per_block_processing::{ errors::BlockProcessingError, process_operations::process_deposit, }; use crate::common::DepositDataTree; -use crate::upgrade::{upgrade_to_altair, upgrade_to_merge}; +use crate::upgrade::{upgrade_to_altair, upgrade_to_bellatrix}; use safe_arith::{ArithError, SafeArith}; use tree_hash::TreeHash; use types::DEPOSIT_TREE_DEPTH; @@ -58,13 +58,13 @@ pub fn initialize_beacon_state_from_eth1( // Similarly, perform an upgrade to the merge if configured from genesis. if spec - .merge_fork_epoch + .bellatrix_fork_epoch .map_or(false, |fork_epoch| fork_epoch == T::genesis_epoch()) { - upgrade_to_merge(&mut state, spec)?; + upgrade_to_bellatrix(&mut state, spec)?; // Remove intermediate Altair fork from `state.fork`. - state.fork_mut().previous_version = spec.merge_fork_version; + state.fork_mut().previous_version = spec.bellatrix_fork_version; // Override latest execution payload header. // See https://github.com/ethereum/consensus-specs/blob/v1.1.0/specs/merge/beacon-chain.md#testing diff --git a/consensus/state_processing/src/per_slot_processing.rs b/consensus/state_processing/src/per_slot_processing.rs index 454cee5ff..9018db65b 100644 --- a/consensus/state_processing/src/per_slot_processing.rs +++ b/consensus/state_processing/src/per_slot_processing.rs @@ -1,4 +1,4 @@ -use crate::upgrade::{upgrade_to_altair, upgrade_to_merge}; +use crate::upgrade::{upgrade_to_altair, upgrade_to_bellatrix}; use crate::{per_epoch_processing::EpochProcessingSummary, *}; use safe_arith::{ArithError, SafeArith}; use types::*; @@ -52,8 +52,8 @@ pub fn per_slot_processing( upgrade_to_altair(state, spec)?; } // If the Merge fork epoch is reached, perform an irregular state upgrade. - if spec.merge_fork_epoch == Some(state.current_epoch()) { - upgrade_to_merge(state, spec)?; + if spec.bellatrix_fork_epoch == Some(state.current_epoch()) { + upgrade_to_bellatrix(state, spec)?; } } diff --git a/consensus/state_processing/src/upgrade.rs b/consensus/state_processing/src/upgrade.rs index fda1a714a..fdf13c828 100644 --- a/consensus/state_processing/src/upgrade.rs +++ b/consensus/state_processing/src/upgrade.rs @@ -2,4 +2,4 @@ pub mod altair; pub mod merge; pub use altair::upgrade_to_altair; -pub use merge::upgrade_to_merge; +pub use merge::upgrade_to_bellatrix; diff --git a/consensus/state_processing/src/upgrade/merge.rs b/consensus/state_processing/src/upgrade/merge.rs index c41987609..2e4ed441a 100644 --- a/consensus/state_processing/src/upgrade/merge.rs +++ b/consensus/state_processing/src/upgrade/merge.rs @@ -5,7 +5,7 @@ use types::{ }; /// Transform a `Altair` state into an `Merge` state. -pub fn upgrade_to_merge( +pub fn upgrade_to_bellatrix( pre_state: &mut BeaconState, spec: &ChainSpec, ) -> Result<(), Error> { @@ -24,7 +24,7 @@ pub fn upgrade_to_merge( slot: pre.slot, fork: Fork { previous_version: pre.fork.current_version, - current_version: spec.merge_fork_version, + current_version: spec.bellatrix_fork_version, epoch, }, // History diff --git a/consensus/types/presets/mainnet/bellatrix.yaml b/consensus/types/presets/mainnet/bellatrix.yaml new file mode 100644 index 000000000..7ae61b732 --- /dev/null +++ b/consensus/types/presets/mainnet/bellatrix.yaml @@ -0,0 +1,21 @@ +# Mainnet preset - Bellatrix + +# Updated penalty values +# --------------------------------------------------------------- +# 2**24 (= 16,777,216) +INACTIVITY_PENALTY_QUOTIENT_BELLATRIX: 16777216 +# 2**5 (= 32) +MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX: 32 +# 3 +PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX: 3 + +# Execution +# --------------------------------------------------------------- +# 2**30 (= 1,073,741,824) +MAX_BYTES_PER_TRANSACTION: 1073741824 +# 2**20 (= 1,048,576) +MAX_TRANSACTIONS_PER_PAYLOAD: 1048576 +# 2**8 (= 256) +BYTES_PER_LOGS_BLOOM: 256 +# 2**5 (= 32) +MAX_EXTRA_DATA_BYTES: 32 diff --git a/consensus/types/presets/minimal/bellatrix.yaml b/consensus/types/presets/minimal/bellatrix.yaml new file mode 100644 index 000000000..3417985fa --- /dev/null +++ b/consensus/types/presets/minimal/bellatrix.yaml @@ -0,0 +1,21 @@ +# Minimal preset - Bellatrix + +# Updated penalty values +# --------------------------------------------------------------- +# 2**24 (= 16,777,216) +INACTIVITY_PENALTY_QUOTIENT_BELLATRIX: 16777216 +# 2**5 (= 32) +MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX: 32 +# 3 +PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX: 3 + +# Execution +# --------------------------------------------------------------- +# 2**30 (= 1,073,741,824) +MAX_BYTES_PER_TRANSACTION: 1073741824 +# 2**20 (= 1,048,576) +MAX_TRANSACTIONS_PER_PAYLOAD: 1048576 +# 2**8 (= 256) +BYTES_PER_LOGS_BLOOM: 256 +# 2**5 (= 32) +MAX_EXTRA_DATA_BYTES: 32 diff --git a/consensus/types/src/beacon_block.rs b/consensus/types/src/beacon_block.rs index e524f0c12..0026db0ee 100644 --- a/consensus/types/src/beacon_block.rs +++ b/consensus/types/src/beacon_block.rs @@ -69,7 +69,7 @@ impl<'a, T: EthSpec> SignedRoot for BeaconBlockRef<'a, T> {} impl BeaconBlock { /// Returns an empty block to be used during genesis. pub fn empty(spec: &ChainSpec) -> Self { - if spec.merge_fork_epoch == Some(T::genesis_epoch()) { + if spec.bellatrix_fork_epoch == Some(T::genesis_epoch()) { Self::Merge(BeaconBlockMerge::empty(spec)) } else if spec.altair_fork_epoch == Some(T::genesis_epoch()) { Self::Altair(BeaconBlockAltair::empty(spec)) diff --git a/consensus/types/src/chain_spec.rs b/consensus/types/src/chain_spec.rs index 70845877d..f5ed2717c 100644 --- a/consensus/types/src/chain_spec.rs +++ b/consensus/types/src/chain_spec.rs @@ -132,12 +132,12 @@ pub struct ChainSpec { /* * Merge hard fork params */ - pub inactivity_penalty_quotient_merge: u64, - pub min_slashing_penalty_quotient_merge: u64, - pub proportional_slashing_multiplier_merge: u64, - pub merge_fork_version: [u8; 4], + pub inactivity_penalty_quotient_bellatrix: u64, + pub min_slashing_penalty_quotient_bellatrix: u64, + pub proportional_slashing_multiplier_bellatrix: u64, + pub bellatrix_fork_version: [u8; 4], /// The Merge fork epoch is optional, with `None` representing "Merge never happens". - pub merge_fork_epoch: Option, + pub bellatrix_fork_epoch: Option, pub terminal_total_difficulty: Uint256, pub terminal_block_hash: Hash256, pub terminal_block_hash_activation_epoch: Epoch, @@ -217,7 +217,7 @@ impl ChainSpec { /// Returns the name of the fork which is active at `epoch`. pub fn fork_name_at_epoch(&self, epoch: Epoch) -> ForkName { - match self.merge_fork_epoch { + match self.bellatrix_fork_epoch { Some(fork_epoch) if epoch >= fork_epoch => ForkName::Merge, _ => match self.altair_fork_epoch { Some(fork_epoch) if epoch >= fork_epoch => ForkName::Altair, @@ -231,7 +231,7 @@ impl ChainSpec { match fork_name { ForkName::Base => self.genesis_fork_version, ForkName::Altair => self.altair_fork_version, - ForkName::Merge => self.merge_fork_version, + ForkName::Merge => self.bellatrix_fork_version, } } @@ -240,7 +240,7 @@ impl ChainSpec { match fork_name { ForkName::Base => Some(Epoch::new(0)), ForkName::Altair => self.altair_fork_epoch, - ForkName::Merge => self.merge_fork_epoch, + ForkName::Merge => self.bellatrix_fork_epoch, } } @@ -249,7 +249,7 @@ impl ChainSpec { match state { BeaconState::Base(_) => self.inactivity_penalty_quotient, BeaconState::Altair(_) => self.inactivity_penalty_quotient_altair, - BeaconState::Merge(_) => self.inactivity_penalty_quotient_merge, + BeaconState::Merge(_) => self.inactivity_penalty_quotient_bellatrix, } } @@ -261,7 +261,7 @@ impl ChainSpec { match state { BeaconState::Base(_) => self.proportional_slashing_multiplier, BeaconState::Altair(_) => self.proportional_slashing_multiplier_altair, - BeaconState::Merge(_) => self.proportional_slashing_multiplier_merge, + BeaconState::Merge(_) => self.proportional_slashing_multiplier_bellatrix, } } @@ -273,7 +273,7 @@ impl ChainSpec { match state { BeaconState::Base(_) => self.min_slashing_penalty_quotient, BeaconState::Altair(_) => self.min_slashing_penalty_quotient_altair, - BeaconState::Merge(_) => self.min_slashing_penalty_quotient_merge, + BeaconState::Merge(_) => self.min_slashing_penalty_quotient_bellatrix, } } @@ -526,13 +526,13 @@ impl ChainSpec { /* * Merge hard fork params */ - inactivity_penalty_quotient_merge: u64::checked_pow(2, 24) + inactivity_penalty_quotient_bellatrix: u64::checked_pow(2, 24) .expect("pow does not overflow"), - min_slashing_penalty_quotient_merge: u64::checked_pow(2, 5) + min_slashing_penalty_quotient_bellatrix: u64::checked_pow(2, 5) .expect("pow does not overflow"), - proportional_slashing_multiplier_merge: 3, - merge_fork_version: [0x02, 0x00, 0x00, 0x00], - merge_fork_epoch: None, + proportional_slashing_multiplier_bellatrix: 3, + bellatrix_fork_version: [0x02, 0x00, 0x00, 0x00], + bellatrix_fork_epoch: None, terminal_total_difficulty: Uint256::MAX .checked_sub(Uint256::from(2u64.pow(10))) .expect("subtraction does not overflow") @@ -583,8 +583,8 @@ impl ChainSpec { altair_fork_version: [0x01, 0x00, 0x00, 0x01], altair_fork_epoch: None, // Merge - merge_fork_version: [0x02, 0x00, 0x00, 0x01], - merge_fork_epoch: None, + bellatrix_fork_version: [0x02, 0x00, 0x00, 0x01], + bellatrix_fork_epoch: None, // Other network_id: 2, // lighthouse testnet network id deposit_chain_id: 5, @@ -632,10 +632,10 @@ pub struct Config { pub altair_fork_epoch: Option>, #[serde(with = "eth2_serde_utils::bytes_4_hex")] - merge_fork_version: [u8; 4], + bellatrix_fork_version: [u8; 4], #[serde(serialize_with = "serialize_fork_epoch")] #[serde(deserialize_with = "deserialize_fork_epoch")] - pub merge_fork_epoch: Option>, + pub bellatrix_fork_epoch: Option>, #[serde(with = "eth2_serde_utils::quoted_u64")] seconds_per_slot: u64, @@ -734,9 +734,9 @@ impl Config { altair_fork_epoch: spec .altair_fork_epoch .map(|epoch| MaybeQuoted { value: epoch }), - merge_fork_version: spec.merge_fork_version, - merge_fork_epoch: spec - .merge_fork_epoch + bellatrix_fork_version: spec.bellatrix_fork_version, + bellatrix_fork_epoch: spec + .bellatrix_fork_epoch .map(|epoch| MaybeQuoted { value: epoch }), seconds_per_slot: spec.seconds_per_slot, @@ -779,8 +779,8 @@ impl Config { genesis_delay, altair_fork_version, altair_fork_epoch, - merge_fork_epoch, - merge_fork_version, + bellatrix_fork_epoch, + bellatrix_fork_version, seconds_per_slot, seconds_per_eth1_block, min_validator_withdrawability_delay, @@ -808,8 +808,8 @@ impl Config { genesis_delay, altair_fork_version, altair_fork_epoch: altair_fork_epoch.map(|q| q.value), - merge_fork_epoch: merge_fork_epoch.map(|q| q.value), - merge_fork_version, + bellatrix_fork_epoch: bellatrix_fork_epoch.map(|q| q.value), + bellatrix_fork_version, seconds_per_slot, seconds_per_eth1_block, min_validator_withdrawability_delay, diff --git a/consensus/types/src/config_and_preset.rs b/consensus/types/src/config_and_preset.rs index 16d36c850..18c559ca2 100644 --- a/consensus/types/src/config_and_preset.rs +++ b/consensus/types/src/config_and_preset.rs @@ -1,4 +1,4 @@ -use crate::{AltairPreset, BasePreset, ChainSpec, Config, EthSpec}; +use crate::{AltairPreset, BasePreset, BellatrixPreset, ChainSpec, Config, EthSpec}; use serde_derive::{Deserialize, Serialize}; use std::collections::HashMap; @@ -14,6 +14,8 @@ pub struct ConfigAndPreset { pub base_preset: BasePreset, #[serde(flatten)] pub altair_preset: AltairPreset, + #[serde(flatten)] + pub bellatrix_preset: BellatrixPreset, /// The `extra_fields` map allows us to gracefully decode fields intended for future hard forks. #[serde(flatten)] @@ -25,12 +27,14 @@ impl ConfigAndPreset { let config = Config::from_chain_spec::(spec); let base_preset = BasePreset::from_chain_spec::(spec); let altair_preset = AltairPreset::from_chain_spec::(spec); + let bellatrix_preset = BellatrixPreset::from_chain_spec::(spec); let extra_fields = HashMap::new(); Self { config, base_preset, altair_preset, + bellatrix_preset, extra_fields, } } diff --git a/consensus/types/src/fork_context.rs b/consensus/types/src/fork_context.rs index 88a2f3126..52b9294c8 100644 --- a/consensus/types/src/fork_context.rs +++ b/consensus/types/src/fork_context.rs @@ -36,11 +36,14 @@ impl ForkContext { } // Only add Merge to list of forks if it's enabled - // Note: `merge_fork_epoch == None` implies merge hasn't been activated yet on the config. - if spec.merge_fork_epoch.is_some() { + // Note: `bellatrix_fork_epoch == None` implies merge hasn't been activated yet on the config. + if spec.bellatrix_fork_epoch.is_some() { fork_to_digest.push(( ForkName::Merge, - ChainSpec::compute_fork_digest(spec.merge_fork_version, genesis_validators_root), + ChainSpec::compute_fork_digest( + spec.bellatrix_fork_version, + genesis_validators_root, + ), )); } diff --git a/consensus/types/src/fork_name.rs b/consensus/types/src/fork_name.rs index 54cc7a245..4a2e76208 100644 --- a/consensus/types/src/fork_name.rs +++ b/consensus/types/src/fork_name.rs @@ -25,17 +25,17 @@ impl ForkName { match self { ForkName::Base => { spec.altair_fork_epoch = None; - spec.merge_fork_epoch = None; + spec.bellatrix_fork_epoch = None; spec } ForkName::Altair => { spec.altair_fork_epoch = Some(Epoch::new(0)); - spec.merge_fork_epoch = None; + spec.bellatrix_fork_epoch = None; spec } ForkName::Merge => { spec.altair_fork_epoch = Some(Epoch::new(0)); - spec.merge_fork_epoch = Some(Epoch::new(0)); + spec.bellatrix_fork_epoch = Some(Epoch::new(0)); spec } } @@ -112,7 +112,7 @@ impl FromStr for ForkName { Ok(match fork_name.to_lowercase().as_ref() { "phase0" | "base" => ForkName::Base, "altair" => ForkName::Altair, - "merge" => ForkName::Merge, + "bellatrix" | "merge" => ForkName::Merge, _ => return Err(()), }) } @@ -123,7 +123,7 @@ impl Display for ForkName { match self { ForkName::Base => "phase0".fmt(f), ForkName::Altair => "altair".fmt(f), - ForkName::Merge => "merge".fmt(f), + ForkName::Merge => "bellatrix".fmt(f), } } } @@ -181,4 +181,11 @@ mod test { assert_eq!(ForkName::from_str("NO_NAME"), Err(())); assert_eq!(ForkName::from_str("no_name"), Err(())); } + + #[test] + fn fork_name_bellatrix_or_merge() { + assert_eq!(ForkName::from_str("bellatrix"), Ok(ForkName::Merge)); + assert_eq!(ForkName::from_str("merge"), Ok(ForkName::Merge)); + assert_eq!(ForkName::Merge.to_string(), "bellatrix"); + } } diff --git a/consensus/types/src/lib.rs b/consensus/types/src/lib.rs index 5b1d3707a..5e27b6674 100644 --- a/consensus/types/src/lib.rs +++ b/consensus/types/src/lib.rs @@ -125,7 +125,7 @@ pub use crate::indexed_attestation::IndexedAttestation; pub use crate::participation_flags::ParticipationFlags; pub use crate::participation_list::ParticipationList; pub use crate::pending_attestation::PendingAttestation; -pub use crate::preset::{AltairPreset, BasePreset}; +pub use crate::preset::{AltairPreset, BasePreset, BellatrixPreset}; pub use crate::proposer_slashing::ProposerSlashing; pub use crate::relative_epoch::{Error as RelativeEpochError, RelativeEpoch}; pub use crate::selection_proof::SelectionProof; diff --git a/consensus/types/src/preset.rs b/consensus/types/src/preset.rs index 030c12340..ccda1a06a 100644 --- a/consensus/types/src/preset.rs +++ b/consensus/types/src/preset.rs @@ -150,6 +150,40 @@ impl AltairPreset { } } +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[serde(rename_all = "UPPERCASE")] +pub struct BellatrixPreset { + #[serde(with = "eth2_serde_utils::quoted_u64")] + pub inactivity_penalty_quotient_bellatrix: u64, + #[serde(with = "eth2_serde_utils::quoted_u64")] + pub min_slashing_penalty_quotient_bellatrix: u64, + #[serde(with = "eth2_serde_utils::quoted_u64")] + pub proportional_slashing_multiplier_bellatrix: u64, + #[serde(with = "eth2_serde_utils::quoted_u64")] + pub max_bytes_per_transaction: u64, + #[serde(with = "eth2_serde_utils::quoted_u64")] + pub max_transactions_per_payload: u64, + #[serde(with = "eth2_serde_utils::quoted_u64")] + pub bytes_per_logs_bloom: u64, + #[serde(with = "eth2_serde_utils::quoted_u64")] + pub max_extra_data_bytes: u64, +} + +impl BellatrixPreset { + pub fn from_chain_spec(spec: &ChainSpec) -> Self { + Self { + inactivity_penalty_quotient_bellatrix: spec.inactivity_penalty_quotient_bellatrix, + min_slashing_penalty_quotient_bellatrix: spec.min_slashing_penalty_quotient_bellatrix, + proportional_slashing_multiplier_bellatrix: spec + .proportional_slashing_multiplier_bellatrix, + max_bytes_per_transaction: T::max_bytes_per_transaction() as u64, + max_transactions_per_payload: T::max_transactions_per_payload() as u64, + bytes_per_logs_bloom: T::bytes_per_logs_bloom() as u64, + max_extra_data_bytes: T::max_extra_data_bytes() as u64, + } + } +} + #[cfg(test)] mod test { use super::*; @@ -182,6 +216,9 @@ mod test { let altair: AltairPreset = preset_from_file(&preset_name, "altair.yaml"); assert_eq!(altair, AltairPreset::from_chain_spec::(&spec)); + + let bellatrix: BellatrixPreset = preset_from_file(&preset_name, "bellatrix.yaml"); + assert_eq!(bellatrix, BellatrixPreset::from_chain_spec::(&spec)); } #[test] diff --git a/lcli/src/new_testnet.rs b/lcli/src/new_testnet.rs index 630d65963..83dcc2e71 100644 --- a/lcli/src/new_testnet.rs +++ b/lcli/src/new_testnet.rs @@ -63,7 +63,7 @@ pub fn run(testnet_dir_path: PathBuf, matches: &ArgMatches) -> Resul } if let Some(fork_epoch) = parse_optional(matches, "merge-fork-epoch")? { - spec.merge_fork_epoch = Some(fork_epoch); + spec.bellatrix_fork_epoch = Some(fork_epoch); } let genesis_state_bytes = if matches.is_present("interop-genesis-state") { diff --git a/lighthouse/environment/tests/testnet_dir/config.yaml b/lighthouse/environment/tests/testnet_dir/config.yaml index ac5403efd..8424a2fdc 100644 --- a/lighthouse/environment/tests/testnet_dir/config.yaml +++ b/lighthouse/environment/tests/testnet_dir/config.yaml @@ -33,8 +33,8 @@ GENESIS_DELAY: 604800 ALTAIR_FORK_VERSION: 0x01000000 ALTAIR_FORK_EPOCH: 18446744073709551615 # Merge -MERGE_FORK_VERSION: 0x02000000 -MERGE_FORK_EPOCH: 18446744073709551615 +BELLATRIX_FORK_VERSION: 0x02000000 +BELLATRIX_FORK_EPOCH: 18446744073709551615 # Sharding SHARDING_FORK_VERSION: 0x03000000 SHARDING_FORK_EPOCH: 18446744073709551615 diff --git a/testing/ef_tests/Makefile b/testing/ef_tests/Makefile index 8c2a0f10e..3cd6d17c0 100644 --- a/testing/ef_tests/Makefile +++ b/testing/ef_tests/Makefile @@ -1,4 +1,4 @@ -TESTS_TAG := v1.1.6 +TESTS_TAG := v1.1.8 TESTS = general minimal mainnet TARBALLS = $(patsubst %,%-$(TESTS_TAG).tar.gz,$(TESTS)) diff --git a/testing/ef_tests/check_all_files_accessed.py b/testing/ef_tests/check_all_files_accessed.py index ce9e1d6b4..2eb4ce540 100755 --- a/testing/ef_tests/check_all_files_accessed.py +++ b/testing/ef_tests/check_all_files_accessed.py @@ -30,18 +30,11 @@ excluded_paths = [ # LightClientUpdate "tests/.*/.*/ssz_static/LightClientUpdate", # LightClientSnapshot - "tests/minimal/altair/ssz_static/LightClientSnapshot", - "tests/mainnet/altair/ssz_static/LightClientSnapshot", - "tests/minimal/merge/ssz_static/LightClientSnapshot", - "tests/mainnet/merge/ssz_static/LightClientSnapshot", + "tests/.*/.*/ssz_static/LightClientSnapshot", # Merkle-proof tests for light clients - "tests/mainnet/altair/merkle/single_proof", - "tests/minimal/altair/merkle/single_proof", - "tests/mainnet/merge/merkle/single_proof", - "tests/minimal/merge/merkle/single_proof", - # FIXME(merge): Merge transition tests are now available but not yet passing - "tests/mainnet/merge/transition/", - "tests/minimal/merge/transition/", + "tests/.*/.*/merkle/single_proof", + # One of the EF researchers likes to pack the tarballs on a Mac + ".*\.DS_Store.*" ] def normalize_path(path): diff --git a/testing/ef_tests/src/cases/fork.rs b/testing/ef_tests/src/cases/fork.rs index 868e4a0c5..ae12447ab 100644 --- a/testing/ef_tests/src/cases/fork.rs +++ b/testing/ef_tests/src/cases/fork.rs @@ -3,7 +3,7 @@ use crate::case_result::compare_beacon_state_results_without_caches; use crate::cases::common::previous_fork; use crate::decode::{ssz_decode_state, yaml_decode_file}; use serde_derive::Deserialize; -use state_processing::upgrade::upgrade_to_altair; +use state_processing::upgrade::{upgrade_to_altair, upgrade_to_bellatrix}; use types::{BeaconState, ForkName}; #[derive(Debug, Clone, Default, Deserialize)] @@ -49,10 +49,7 @@ impl Case for ForkTest { fn is_enabled_for_fork(fork_name: ForkName) -> bool { // Upgrades exist targeting all forks except phase0/base. // Fork tests also need BLS. - // FIXME(merge): enable merge tests once available - cfg!(not(feature = "fake_crypto")) - && fork_name != ForkName::Base - && fork_name != ForkName::Merge + cfg!(not(feature = "fake_crypto")) && fork_name != ForkName::Base } fn result(&self, _case_index: usize, fork_name: ForkName) -> Result<(), Error> { @@ -61,8 +58,9 @@ impl Case for ForkTest { let spec = &E::default_spec(); let mut result = match fork_name { + ForkName::Base => panic!("phase0 not supported"), ForkName::Altair => upgrade_to_altair(&mut result_state, spec).map(|_| result_state), - _ => panic!("unknown fork: {:?}", fork_name), + ForkName::Merge => upgrade_to_bellatrix(&mut result_state, spec).map(|_| result_state), }; compare_beacon_state_results_without_caches(&mut result, &mut expected) diff --git a/testing/ef_tests/src/cases/fork_choice.rs b/testing/ef_tests/src/cases/fork_choice.rs index ecdfebc28..608429a9c 100644 --- a/testing/ef_tests/src/cases/fork_choice.rs +++ b/testing/ef_tests/src/cases/fork_choice.rs @@ -154,15 +154,10 @@ impl Case for ForkChoiceTest { fn result(&self, _case_index: usize, fork_name: ForkName) -> Result<(), Error> { let tester = Tester::new(self, fork_choice_spec::(fork_name))?; - // TODO(merge): enable these tests before production. - // This test will fail until this PR is merged and released: - // - // https://github.com/ethereum/consensus-specs/pull/2760 - if self.description == "shorter_chain_but_heavier_weight" - // This test is skipped until we can do retrospective confirmations of the terminal - // block after an optimistic sync. - || self.description == "block_lookup_failed" - { + // TODO(merge): re-enable this test before production. + // This test is skipped until we can do retrospective confirmations of the terminal + // block after an optimistic sync. + if self.description == "block_lookup_failed" { return Err(Error::SkippedKnownFailure); }; diff --git a/testing/ef_tests/src/cases/operations.rs b/testing/ef_tests/src/cases/operations.rs index d833846e4..195df7f38 100644 --- a/testing/ef_tests/src/cases/operations.rs +++ b/testing/ef_tests/src/cases/operations.rs @@ -239,7 +239,6 @@ impl Operation for ExecutionPayload { spec: &ChainSpec, extra: &Operations, ) -> Result<(), BlockProcessingError> { - // FIXME(merge): we may want to plumb the validity bool into state processing let valid = extra .execution_metadata .as_ref() diff --git a/testing/ef_tests/src/cases/transition.rs b/testing/ef_tests/src/cases/transition.rs index 8e6ba2267..d2b1bb2c6 100644 --- a/testing/ef_tests/src/cases/transition.rs +++ b/testing/ef_tests/src/cases/transition.rs @@ -39,7 +39,8 @@ impl LoadCase for TransitionTest { spec.altair_fork_epoch = Some(metadata.fork_epoch); } ForkName::Merge => { - spec.merge_fork_epoch = Some(metadata.fork_epoch); + spec.altair_fork_epoch = Some(Epoch::new(0)); + spec.bellatrix_fork_epoch = Some(metadata.fork_epoch); } } @@ -73,10 +74,7 @@ impl Case for TransitionTest { fn is_enabled_for_fork(fork_name: ForkName) -> bool { // Upgrades exist targeting all forks except phase0/base. // Transition tests also need BLS. - // FIXME(merge): Merge transition tests are now available but not yet passing - cfg!(not(feature = "fake_crypto")) - && fork_name != ForkName::Base - && fork_name != ForkName::Merge + cfg!(not(feature = "fake_crypto")) && fork_name != ForkName::Base } fn result(&self, _case_index: usize, _fork_name: ForkName) -> Result<(), Error> { diff --git a/testing/ef_tests/src/handler.rs b/testing/ef_tests/src/handler.rs index a1d5b0916..636119cdb 100644 --- a/testing/ef_tests/src/handler.rs +++ b/testing/ef_tests/src/handler.rs @@ -2,7 +2,7 @@ use crate::cases::{self, Case, Cases, EpochTransition, LoadCase, Operation}; use crate::type_name; use crate::type_name::TypeName; use derivative::Derivative; -use std::fs; +use std::fs::{self, DirEntry}; use std::marker::PhantomData; use std::path::PathBuf; use types::{BeaconState, EthSpec, ForkName}; @@ -31,30 +31,27 @@ pub trait Handler { } fn run_for_fork(&self, fork_name: ForkName) { - let fork_name_str = match fork_name { - ForkName::Base => "phase0", - ForkName::Altair => "altair", - ForkName::Merge => "merge", - }; + let fork_name_str = fork_name.to_string(); let handler_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) .join("consensus-spec-tests") .join("tests") .join(Self::config_name()) - .join(fork_name_str) + .join(&fork_name_str) .join(Self::runner_name()) .join(self.handler_name()); // Iterate through test suites + let as_directory = |entry: Result| -> Option { + entry + .ok() + .filter(|e| e.file_type().map(|ty| ty.is_dir()).unwrap_or(false)) + }; let test_cases = fs::read_dir(&handler_path) .expect("handler dir exists") - .flat_map(|entry| { - entry - .ok() - .filter(|e| e.file_type().map(|ty| ty.is_dir()).unwrap_or(false)) - }) + .filter_map(as_directory) .flat_map(|suite| fs::read_dir(suite.path()).expect("suite dir exists")) - .flat_map(Result::ok) + .filter_map(as_directory) .map(|test_case_dir| { let path = test_case_dir.path(); let case = Self::Case::load_from_dir(&path, fork_name).expect("test should load"); @@ -439,37 +436,21 @@ impl Handler for FinalityHandler { } } -#[derive(Derivative)] -#[derivative(Default(bound = ""))] -pub struct ForkChoiceGetHeadHandler(PhantomData); +pub struct ForkChoiceHandler { + handler_name: String, + _phantom: PhantomData, +} -impl Handler for ForkChoiceGetHeadHandler { - type Case = cases::ForkChoiceTest; - - fn config_name() -> &'static str { - E::name() - } - - fn runner_name() -> &'static str { - "fork_choice" - } - - fn handler_name(&self) -> String { - "get_head".into() - } - - fn is_enabled_for_fork(&self, _fork_name: ForkName) -> bool { - // These tests check block validity (which may include signatures) and there is no need to - // run them with fake crypto. - cfg!(not(feature = "fake_crypto")) +impl ForkChoiceHandler { + pub fn new(handler_name: &str) -> Self { + Self { + handler_name: handler_name.into(), + _phantom: PhantomData, + } } } -#[derive(Derivative)] -#[derivative(Default(bound = ""))] -pub struct ForkChoiceOnBlockHandler(PhantomData); - -impl Handler for ForkChoiceOnBlockHandler { +impl Handler for ForkChoiceHandler { type Case = cases::ForkChoiceTest; fn config_name() -> &'static str { @@ -481,41 +462,20 @@ impl Handler for ForkChoiceOnBlockHandler { } fn handler_name(&self) -> String { - "on_block".into() - } - - fn is_enabled_for_fork(&self, _fork_name: ForkName) -> bool { - // These tests check block validity (which may include signatures) and there is no need to - // run them with fake crypto. - cfg!(not(feature = "fake_crypto")) - } -} - -#[derive(Derivative)] -#[derivative(Default(bound = ""))] -pub struct ForkChoiceOnMergeBlockHandler(PhantomData); - -impl Handler for ForkChoiceOnMergeBlockHandler { - type Case = cases::ForkChoiceTest; - - fn config_name() -> &'static str { - E::name() - } - - fn runner_name() -> &'static str { - "fork_choice" - } - - fn handler_name(&self) -> String { - "on_merge_block".into() + self.handler_name.clone() } fn is_enabled_for_fork(&self, fork_name: ForkName) -> bool { + // Merge block tests are only enabled for Bellatrix or later. + if self.handler_name == "on_merge_block" + && (fork_name == ForkName::Base || fork_name == ForkName::Altair) + { + return false; + } + // These tests check block validity (which may include signatures) and there is no need to // run them with fake crypto. cfg!(not(feature = "fake_crypto")) - // These tests only exist for the merge. - && fork_name == ForkName::Merge } } diff --git a/testing/ef_tests/tests/tests.rs b/testing/ef_tests/tests/tests.rs index 2201bc5ee..bdefec001 100644 --- a/testing/ef_tests/tests/tests.rs +++ b/testing/ef_tests/tests/tests.rs @@ -413,20 +413,26 @@ fn finality() { #[test] fn fork_choice_get_head() { - ForkChoiceGetHeadHandler::::default().run(); - ForkChoiceGetHeadHandler::::default().run(); + ForkChoiceHandler::::new("get_head").run(); + ForkChoiceHandler::::new("get_head").run(); } #[test] fn fork_choice_on_block() { - ForkChoiceOnBlockHandler::::default().run(); - ForkChoiceOnBlockHandler::::default().run(); + ForkChoiceHandler::::new("on_block").run(); + ForkChoiceHandler::::new("on_block").run(); } #[test] fn fork_choice_on_merge_block() { - ForkChoiceOnMergeBlockHandler::::default().run(); - ForkChoiceOnMergeBlockHandler::::default().run(); + ForkChoiceHandler::::new("on_merge_block").run(); + ForkChoiceHandler::::new("on_merge_block").run(); +} + +#[test] +fn fork_choice_ex_ante() { + ForkChoiceHandler::::new("ex_ante").run(); + ForkChoiceHandler::::new("ex_ante").run(); } #[test]