Skip to main content

cbe_sdk/
poh_config.rs

1//! Definitions of Cartallum CBE's proof of history.
2
3use {
4    crate::{clock::DEFAULT_TICKS_PER_SECOND, unchecked_div_by_const},
5    std::time::Duration,
6};
7
8#[derive(Serialize, Deserialize, Clone, Debug, AbiExample, Eq, PartialEq)]
9pub struct PohConfig {
10    /// The target tick rate of the cluster.
11    pub target_tick_duration: Duration,
12
13    /// The target total tick count to be produced; used for testing only
14    pub target_tick_count: Option<u64>,
15
16    /// How many hashes to roll before emitting the next tick entry.
17    /// None enables "Low power mode", which implies:
18    /// * sleep for `target_tick_duration` instead of hashing
19    /// * the number of hashes per tick will be variable
20    pub hashes_per_tick: Option<u64>,
21}
22
23impl PohConfig {
24    pub fn new_sleep(target_tick_duration: Duration) -> Self {
25        Self {
26            target_tick_duration,
27            hashes_per_tick: None,
28            target_tick_count: None,
29        }
30    }
31}
32
33impl Default for PohConfig {
34    fn default() -> Self {
35        Self::new_sleep(Duration::from_micros(unchecked_div_by_const!(
36            1000 * 1000,
37            DEFAULT_TICKS_PER_SECOND
38        )))
39    }
40}