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.
This commit is contained in:
Michael Sproul
2022-01-19 00:24:19 +00:00
parent 9ed92d6e78
commit ef7351ddfe
29 changed files with 214 additions and 172 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -69,7 +69,7 @@ impl<'a, T: EthSpec> SignedRoot for BeaconBlockRef<'a, T> {}
impl<T: EthSpec> BeaconBlock<T> {
/// 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))

View File

@@ -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<Epoch>,
pub bellatrix_fork_epoch: Option<Epoch>,
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<MaybeQuoted<Epoch>>,
#[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<MaybeQuoted<Epoch>>,
pub bellatrix_fork_epoch: Option<MaybeQuoted<Epoch>>,
#[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,

View File

@@ -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::<T>(spec);
let base_preset = BasePreset::from_chain_spec::<T>(spec);
let altair_preset = AltairPreset::from_chain_spec::<T>(spec);
let bellatrix_preset = BellatrixPreset::from_chain_spec::<T>(spec);
let extra_fields = HashMap::new();
Self {
config,
base_preset,
altair_preset,
bellatrix_preset,
extra_fields,
}
}

View File

@@ -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,
),
));
}

View File

@@ -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");
}
}

View File

@@ -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;

View File

@@ -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<T: EthSpec>(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::<E>(&spec));
let bellatrix: BellatrixPreset = preset_from_file(&preset_name, "bellatrix.yaml");
assert_eq!(bellatrix, BellatrixPreset::from_chain_spec::<E>(&spec));
}
#[test]