mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 01:05:47 +00:00
Remove duplicated fork_epoch and fork_version implementation (#6953)
This PR adds an implementation to get fork_version and fork_epoch given a `ForkName`. I didn't realize that this is already implemented in the `ChainSpec` sorry - https://github.com/sigp/lighthouse/pull/6933 Remove duplicated fork_epoch and fork_version implementation
This commit is contained in:
@@ -25,11 +25,11 @@ impl ForkContext {
|
|||||||
let fork_to_digest: HashMap<ForkName, [u8; 4]> = ForkName::list_all()
|
let fork_to_digest: HashMap<ForkName, [u8; 4]> = ForkName::list_all()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|fork| {
|
.filter_map(|fork| {
|
||||||
if fork.fork_epoch(spec).is_some() {
|
if spec.fork_epoch(fork).is_some() {
|
||||||
Some((
|
Some((
|
||||||
fork,
|
fork,
|
||||||
ChainSpec::compute_fork_digest(
|
ChainSpec::compute_fork_digest(
|
||||||
ForkName::fork_version(fork, spec),
|
spec.fork_version_for_name(fork),
|
||||||
genesis_validators_root,
|
genesis_validators_root,
|
||||||
),
|
),
|
||||||
))
|
))
|
||||||
|
|||||||
@@ -38,35 +38,10 @@ impl ForkName {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
// Skip Base
|
// Skip Base
|
||||||
.skip(1)
|
.skip(1)
|
||||||
.map(|fork| (fork, fork.fork_epoch(spec)))
|
.map(|fork| (fork, spec.fork_epoch(fork)))
|
||||||
.collect()
|
.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 {
|
pub fn latest() -> ForkName {
|
||||||
// This unwrap is safe as long as we have 1+ forks. It is tested below.
|
// This unwrap is safe as long as we have 1+ forks. It is tested below.
|
||||||
*ForkName::list_all().last().unwrap()
|
*ForkName::list_all().last().unwrap()
|
||||||
|
|||||||
Reference in New Issue
Block a user