clone_solana_poh_config/
lib.rs

1//! Definitions of Solana's proof of history.
2#![cfg_attr(docsrs, feature(doc_auto_cfg))]
3#![cfg_attr(feature = "frozen-abi", feature(min_specialization))]
4
5use std::time::Duration;
6
7// inlined to avoid solana-clock dep
8const DEFAULT_TICKS_PER_SECOND: u64 = 160;
9#[cfg(test)]
10static_assertions::const_assert_eq!(
11    DEFAULT_TICKS_PER_SECOND,
12    clone_solana_clock::DEFAULT_TICKS_PER_SECOND
13);
14
15#[cfg_attr(
16    feature = "frozen-abi",
17    derive(clone_solana_frozen_abi_macro::AbiExample)
18)]
19#[cfg_attr(
20    feature = "serde",
21    derive(serde_derive::Deserialize, serde_derive::Serialize)
22)]
23#[derive(Clone, Debug, Eq, PartialEq)]
24pub struct PohConfig {
25    /// The target tick rate of the cluster.
26    pub target_tick_duration: Duration,
27
28    /// The target total tick count to be produced; used for testing only
29    pub target_tick_count: Option<u64>,
30
31    /// How many hashes to roll before emitting the next tick entry.
32    /// None enables "Low power mode", which makes the validator sleep
33    /// for `target_tick_duration` instead of hashing
34    pub hashes_per_tick: Option<u64>,
35}
36
37impl PohConfig {
38    pub fn new_sleep(target_tick_duration: Duration) -> Self {
39        Self {
40            target_tick_duration,
41            hashes_per_tick: None,
42            target_tick_count: None,
43        }
44    }
45}
46
47// the !=0 check was previously done by the unchecked_div_by_const macro
48#[cfg(test)]
49static_assertions::const_assert!(DEFAULT_TICKS_PER_SECOND != 0);
50const DEFAULT_SLEEP_MICROS: u64 = (1000 * 1000) / DEFAULT_TICKS_PER_SECOND;
51
52impl Default for PohConfig {
53    fn default() -> Self {
54        Self::new_sleep(Duration::from_micros(DEFAULT_SLEEP_MICROS))
55    }
56}