Reimplement fork_name_at_epoch

This commit is contained in:
Michael Sproul
2024-04-22 16:49:04 +10:00
parent e862e5613c
commit 3b92e0bd9a
2 changed files with 7 additions and 15 deletions

View File

@@ -291,23 +291,14 @@ impl ChainSpec {
/// Returns the name of the fork which is active at `epoch`. /// Returns the name of the fork which is active at `epoch`.
pub fn fork_name_at_epoch(&self, epoch: Epoch) -> ForkName { pub fn fork_name_at_epoch(&self, epoch: Epoch) -> ForkName {
match self.electra_fork_epoch { for (fork_name, _) in FORK_ORDER.iter().copied().rev() {
Some(fork_epoch) if epoch >= fork_epoch => ForkName::Electra, match self.fork_epoch(fork_name) {
_ => match self.deneb_fork_epoch { Some(fork_epoch) if epoch >= fork_epoch => return fork_name,
Some(fork_epoch) if epoch >= fork_epoch => ForkName::Deneb, _ => continue,
_ => match self.capella_fork_epoch {
Some(fork_epoch) if epoch >= fork_epoch => ForkName::Capella,
_ => 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,
_ => ForkName::Base,
},
},
},
},
} }
} }
ForkName::Base
}
/// Returns the fork version for a named fork. /// Returns the fork version for a named fork.
pub fn fork_version_for_name(&self, fork_name: ForkName) -> [u8; 4] { pub fn fork_version_for_name(&self, fork_name: ForkName) -> [u8; 4] {

View File

@@ -160,6 +160,7 @@ pub use crate::fork::Fork;
pub use crate::fork_context::ForkContext; pub use crate::fork_context::ForkContext;
pub use crate::fork_data::ForkData; pub use crate::fork_data::ForkData;
pub use crate::fork_name::{ForkName, InconsistentFork}; pub use crate::fork_name::{ForkName, InconsistentFork};
pub use crate::fork_order::FORK_ORDER;
pub use crate::fork_versioned_response::{ForkVersionDeserialize, ForkVersionedResponse}; pub use crate::fork_versioned_response::{ForkVersionDeserialize, ForkVersionedResponse};
pub use crate::graffiti::{Graffiti, GRAFFITI_BYTES_LEN}; pub use crate::graffiti::{Graffiti, GRAFFITI_BYTES_LEN};
pub use crate::historical_batch::HistoricalBatch; pub use crate::historical_batch::HistoricalBatch;