2019-08-19 11:02:34 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
|
|
|
|
|
|
|
mod metrics;
|
2019-02-14 01:09:18 +00:00
|
|
|
mod system_time_slot_clock;
|
|
|
|
mod testing_slot_clock;
|
|
|
|
|
2019-09-21 01:21:47 +00:00
|
|
|
use std::time::Duration;
|
2019-08-19 11:02:34 +00:00
|
|
|
|
2019-08-29 02:46:18 +00:00
|
|
|
pub use crate::system_time_slot_clock::SystemTimeSlotClock;
|
|
|
|
pub use crate::testing_slot_clock::TestingSlotClock;
|
2019-08-19 11:02:34 +00:00
|
|
|
pub use metrics::scrape_for_metrics;
|
2019-02-14 01:09:18 +00:00
|
|
|
pub use types::Slot;
|
|
|
|
|
2019-09-21 01:21:47 +00:00
|
|
|
/// A clock that reports the current slot.
|
|
|
|
///
|
|
|
|
/// The clock is not required to be monotonically increasing and may go backwards.
|
2019-05-27 05:12:51 +00:00
|
|
|
pub trait SlotClock: Send + Sync + Sized {
|
2019-09-21 01:21:47 +00:00
|
|
|
/// Creates a new slot clock where the first slot is `genesis_slot`, genesis occured
|
|
|
|
/// `genesis_duration` after the `UNIX_EPOCH` and each slot is `slot_duration` apart.
|
|
|
|
fn new(genesis_slot: Slot, genesis_duration: Duration, slot_duration: Duration) -> Self;
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-09-21 01:21:47 +00:00
|
|
|
/// Returns the slot at this present time.
|
2019-08-29 04:26:30 +00:00
|
|
|
fn now(&self) -> Option<Slot>;
|
2019-05-27 05:12:51 +00:00
|
|
|
|
2019-09-21 01:21:47 +00:00
|
|
|
/// Returns the duration between slots
|
2019-08-29 02:46:18 +00:00
|
|
|
fn slot_duration(&self) -> Duration;
|
2019-09-21 01:21:47 +00:00
|
|
|
|
|
|
|
/// Returns the duration until the next slot.
|
|
|
|
fn duration_to_next_slot(&self) -> Option<Duration>;
|
2019-11-25 04:48:24 +00:00
|
|
|
|
|
|
|
/// Returns the duration until the first slot of the next epoch.
|
|
|
|
fn duration_to_next_epoch(&self, slots_per_epoch: u64) -> Option<Duration>;
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|