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

merge queue: embarking unstable (d527d12) and #5531 together #5550

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
61 changes: 29 additions & 32 deletions consensus/types/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,12 @@ impl ChainSpec {
}

pub fn inactivity_penalty_quotient_for_fork(&self, fork_name: ForkName) -> u64 {
match fork_name {
ForkName::Base => self.inactivity_penalty_quotient,
ForkName::Altair => self.inactivity_penalty_quotient_altair,
ForkName::Merge => self.inactivity_penalty_quotient_bellatrix,
ForkName::Capella => self.inactivity_penalty_quotient_bellatrix,
ForkName::Deneb | ForkName::Electra => self.inactivity_penalty_quotient_bellatrix,
if fork_name >= ForkName::Merge {
self.inactivity_penalty_quotient_bellatrix
} else if fork_name >= ForkName::Altair {
self.inactivity_penalty_quotient_altair
} else {
self.inactivity_penalty_quotient
}
}

Expand All @@ -348,13 +348,13 @@ impl ChainSpec {
&self,
state: &BeaconState<E>,
) -> u64 {
match state {
BeaconState::Base(_) => self.proportional_slashing_multiplier,
BeaconState::Altair(_) => self.proportional_slashing_multiplier_altair,
BeaconState::Merge(_) => self.proportional_slashing_multiplier_bellatrix,
BeaconState::Capella(_) => self.proportional_slashing_multiplier_bellatrix,
BeaconState::Deneb(_) => self.proportional_slashing_multiplier_bellatrix,
BeaconState::Electra(_) => self.proportional_slashing_multiplier_bellatrix,
let fork_name = state.fork_name_unchecked();
if fork_name >= ForkName::Merge {
self.proportional_slashing_multiplier_bellatrix
} else if fork_name >= ForkName::Altair {
self.proportional_slashing_multiplier_altair
} else {
self.proportional_slashing_multiplier
}
}

Expand All @@ -363,13 +363,13 @@ impl ChainSpec {
&self,
state: &BeaconState<E>,
) -> u64 {
match state {
BeaconState::Base(_) => self.min_slashing_penalty_quotient,
BeaconState::Altair(_) => self.min_slashing_penalty_quotient_altair,
BeaconState::Merge(_) => self.min_slashing_penalty_quotient_bellatrix,
BeaconState::Capella(_) => self.min_slashing_penalty_quotient_bellatrix,
BeaconState::Deneb(_) => self.min_slashing_penalty_quotient_bellatrix,
BeaconState::Electra(_) => self.min_slashing_penalty_quotient_bellatrix,
let fork_name = state.fork_name_unchecked();
if fork_name >= ForkName::Merge {
self.min_slashing_penalty_quotient_bellatrix
} else if fork_name >= ForkName::Altair {
self.min_slashing_penalty_quotient_altair
} else {
self.min_slashing_penalty_quotient
}
}

Expand Down Expand Up @@ -531,22 +531,19 @@ impl ChainSpec {
}

pub fn max_blocks_by_root_request(&self, fork_name: ForkName) -> usize {
match fork_name {
ForkName::Base | ForkName::Altair | ForkName::Merge | ForkName::Capella => {
self.max_blocks_by_root_request
}
ForkName::Deneb | ForkName::Electra => self.max_blocks_by_root_request_deneb,
if fork_name >= ForkName::Deneb {
self.max_blocks_by_root_request_deneb
} else {
self.max_blocks_by_root_request
}
}

pub fn max_request_blocks(&self, fork_name: ForkName) -> usize {
let max_request_blocks = match fork_name {
ForkName::Base | ForkName::Altair | ForkName::Merge | ForkName::Capella => {
self.max_request_blocks
}
ForkName::Deneb | ForkName::Electra => self.max_request_blocks_deneb,
};
max_request_blocks as usize
if fork_name >= ForkName::Deneb {
self.max_request_blocks_deneb as usize
} else {
self.max_request_blocks as usize
}
}

/// Returns a `ChainSpec` compatible with the Ethereum Foundation specification.
Expand Down
13 changes: 12 additions & 1 deletion consensus/types/src/fork_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use ssz_derive::{Decode, Encode};
use std::fmt::{self, Display, Formatter};
use std::str::FromStr;

#[derive(Debug, Clone, Copy, Decode, Encode, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(
Debug, Clone, Copy, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
)]
#[serde(try_from = "String")]
#[serde(into = "String")]
#[ssz(enum_behaviour = "tag")]
Expand Down Expand Up @@ -272,4 +274,13 @@ mod test {
}
assert_eq!(ForkName::latest(), fork);
}

#[test]
fn fork_ord_consistent() {
for (prev_fork, fork) in ForkName::list_all().into_iter().tuple_windows() {
assert_eq!(prev_fork.next_fork(), Some(fork));
assert_eq!(fork.previous_fork(), Some(prev_fork));
assert!(prev_fork < fork);
}
}
}
Loading