ForkCondition: some small refactors (#10712)

This commit is contained in:
Thomas Coratger
2024-09-05 09:17:29 -07:00
committed by GitHub
parent b0fddef46a
commit 1ec5678081
2 changed files with 5 additions and 4 deletions

View File

@ -522,10 +522,11 @@ impl ChainSpec {
ForkCondition::Timestamp(timestamp) => { ForkCondition::Timestamp(timestamp) => {
// to satisfy every timestamp ForkCondition, we find the last ForkCondition::Block // to satisfy every timestamp ForkCondition, we find the last ForkCondition::Block
// if one exists, and include its block_num in the returned Head // if one exists, and include its block_num in the returned Head
if let Some(last_block_num) = self.last_block_fork_before_merge_or_timestamp() { Head {
return Head { timestamp, number: last_block_num, ..Default::default() } timestamp,
number: self.last_block_fork_before_merge_or_timestamp().unwrap_or_default(),
..Default::default()
} }
Head { timestamp, ..Default::default() }
} }
ForkCondition::TTD { total_difficulty, .. } => { ForkCondition::TTD { total_difficulty, .. } => {
Head { total_difficulty, ..Default::default() } Head { total_difficulty, ..Default::default() }

View File

@ -68,7 +68,7 @@ impl ChainHardforks {
/// Retrieves [`ForkCondition`] from `fork`. If `fork` is not present, returns /// Retrieves [`ForkCondition`] from `fork`. If `fork` is not present, returns
/// [`ForkCondition::Never`]. /// [`ForkCondition::Never`].
pub fn fork<H: Hardfork>(&self, fork: H) -> ForkCondition { pub fn fork<H: Hardfork>(&self, fork: H) -> ForkCondition {
self.get(fork).unwrap_or(ForkCondition::Never) self.get(fork).unwrap_or_default()
} }
/// Retrieves [`ForkCondition`] from `fork` if it exists, otherwise `None`. /// Retrieves [`ForkCondition`] from `fork` if it exists, otherwise `None`.