Skip to content

Remove duplicated fork_epoch and fork_version implementation #6953

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

Merged
merged 1 commit into from
Feb 8, 2025
Merged
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
4 changes: 2 additions & 2 deletions consensus/types/src/fork_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ impl ForkContext {
let fork_to_digest: HashMap<ForkName, [u8; 4]> = ForkName::list_all()
.into_iter()
.filter_map(|fork| {
if fork.fork_epoch(spec).is_some() {
if spec.fork_epoch(fork).is_some() {
Some((
fork,
ChainSpec::compute_fork_digest(
ForkName::fork_version(fork, spec),
spec.fork_version_for_name(fork),
genesis_validators_root,
),
))
Expand Down
27 changes: 1 addition & 26 deletions consensus/types/src/fork_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,10 @@ impl ForkName {
.into_iter()
// Skip Base
.skip(1)
.map(|fork| (fork, fork.fork_epoch(spec)))
.map(|fork| (fork, spec.fork_epoch(fork)))
.collect()
}

pub fn fork_epoch(self, spec: &ChainSpec) -> Option<Epoch> {
match self {
Self::Base => Some(Epoch::new(0)),
Self::Altair => spec.altair_fork_epoch,
Self::Bellatrix => spec.bellatrix_fork_epoch,
Self::Capella => spec.capella_fork_epoch,
Self::Deneb => spec.deneb_fork_epoch,
Self::Electra => spec.electra_fork_epoch,
Self::Fulu => spec.fulu_fork_epoch,
}
}

/// Returns the fork version of a fork
pub fn fork_version(self, spec: &ChainSpec) -> [u8; 4] {
match self {
Self::Base => spec.genesis_fork_version,
Self::Altair => spec.altair_fork_version,
Self::Bellatrix => spec.bellatrix_fork_version,
Self::Capella => spec.capella_fork_version,
Self::Deneb => spec.deneb_fork_version,
Self::Electra => spec.electra_fork_version,
Self::Fulu => spec.fulu_fork_version,
}
}

pub fn latest() -> ForkName {
// This unwrap is safe as long as we have 1+ forks. It is tested below.
*ForkName::list_all().last().unwrap()
Expand Down