2021-03-11 22:22:40 -08:00
|
|
|
use crate::{clock::DEFAULT_TICKS_PER_SECOND, unchecked_div_by_const};
|
2019-05-18 14:01:36 -07:00
|
|
|
use std::time::Duration;
|
|
|
|
|
2020-07-06 04:22:23 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, AbiExample)]
|
2019-05-18 14:01:36 -07:00
|
|
|
pub struct PohConfig {
|
|
|
|
/// The target tick rate of the cluster.
|
|
|
|
pub target_tick_duration: Duration,
|
|
|
|
|
2019-10-16 12:37:27 -07:00
|
|
|
/// The target total tick count to be produced; used for testing only
|
|
|
|
pub target_tick_count: Option<u64>,
|
|
|
|
|
2019-05-18 14:01:36 -07:00
|
|
|
/// How many hashes to roll before emitting the next tick entry.
|
|
|
|
/// None enables "Low power mode", which implies:
|
|
|
|
/// * sleep for `target_tick_duration` instead of hashing
|
|
|
|
/// * the number of hashes per tick will be variable
|
|
|
|
pub hashes_per_tick: Option<u64>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PohConfig {
|
|
|
|
pub fn new_sleep(target_tick_duration: Duration) -> Self {
|
|
|
|
Self {
|
|
|
|
target_tick_duration,
|
|
|
|
hashes_per_tick: None,
|
2019-10-16 12:37:27 -07:00
|
|
|
target_tick_count: None,
|
2019-05-18 14:01:36 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for PohConfig {
|
|
|
|
fn default() -> Self {
|
2021-03-11 22:22:40 -08:00
|
|
|
Self::new_sleep(Duration::from_micros(unchecked_div_by_const!(
|
|
|
|
1000 * 1000,
|
|
|
|
DEFAULT_TICKS_PER_SECOND
|
|
|
|
)))
|
2019-05-18 14:01:36 -07:00
|
|
|
}
|
|
|
|
}
|