Skip to content

Commit

Permalink
Reimplement fork_name_at_epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsproul committed Apr 22, 2024
1 parent e862e56 commit 3b92e0b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
21 changes: 6 additions & 15 deletions consensus/types/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,22 +291,13 @@ 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.electra_fork_epoch {
Some(fork_epoch) if epoch >= fork_epoch => ForkName::Electra,
_ => match self.deneb_fork_epoch {
Some(fork_epoch) if epoch >= fork_epoch => ForkName::Deneb,
_ => 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,
},
},
},
},
for (fork_name, _) in FORK_ORDER.iter().copied().rev() {
match self.fork_epoch(fork_name) {
Some(fork_epoch) if epoch >= fork_epoch => return fork_name,
_ => continue,
}
}
ForkName::Base
}

/// Returns the fork version for a named fork.
Expand Down
1 change: 1 addition & 0 deletions consensus/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ pub use crate::fork::Fork;
pub use crate::fork_context::ForkContext;
pub use crate::fork_data::ForkData;
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::graffiti::{Graffiti, GRAFFITI_BYTES_LEN};
pub use crate::historical_batch::HistoricalBatch;
Expand Down

0 comments on commit 3b92e0b

Please sign in to comment.