Skip to content

Commit

Permalink
refactor how a user can get a Clock for the configured network
Browse files Browse the repository at this point in the history
  • Loading branch information
ralexstokes committed Aug 20, 2023
1 parent d1c665f commit 4d4e3fb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions ethereum-consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod deneb;
pub mod domains;
pub mod kzg;
pub mod networking;
pub mod networks;
pub mod phase0;
pub mod primitives;
#[cfg(feature = "serde")]
Expand Down
8 changes: 8 additions & 0 deletions ethereum-consensus/src/networks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/// This module contains support for various Ethereum netowrks.
use crate::state_transition::Context;

// NOTE: the default genesis time here is usually seen on testnets
// where we have control over the genesis details
pub fn typical_genesis_time(context: &Context) -> u64 {
context.min_genesis_time + context.genesis_delay
}
20 changes: 9 additions & 11 deletions ethereum-consensus/src/state_transition/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,18 +286,16 @@ impl Context {
}
}

pub fn clock(&self, genesis_time: Option<u64>) -> Clock<SystemTimeProvider> {
pub fn clock(&self) -> Option<Clock<SystemTimeProvider>> {
match self.name.as_ref() {
"mainnet" => clock::for_mainnet(),
"sepolia" => clock::for_sepolia(),
"goerli" => clock::for_goerli(),
_ => {
// NOTE: the default genesis time here is usually seen on testnets
// where we have control over the genesis details
let genesis_time =
genesis_time.unwrap_or(self.min_genesis_time + self.genesis_delay);
clock::from_system_time(genesis_time, self.seconds_per_slot, self.slots_per_epoch)
}
"mainnet" => Some(clock::for_mainnet()),
"sepolia" => Some(clock::for_sepolia()),
"goerli" => Some(clock::for_goerli()),
_ => None,
}
}

pub fn clock_at(&self, genesis_time: u64) -> Clock<SystemTimeProvider> {
clock::from_system_time(genesis_time, self.seconds_per_slot, self.slots_per_epoch)
}
}

0 comments on commit 4d4e3fb

Please sign in to comment.