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    solana_clock::DEFAULT_TICKS_PER_SECOND
13);
14
15#[cfg_attr(feature = "frozen-abi", derive(solana_frozen_abi_macro::AbiExample))]
16#[cfg_attr(
17    feature = "serde",
18    derive(serde_derive::Deserialize, serde_derive::Serialize)
19)]
20#[derive(Clone, Debug, Eq, PartialEq)]
21pub struct PohConfig {
22    /// The target tick rate of the cluster.
23    pub target_tick_duration: Duration,
24
25    /// The target total tick count to be produced; used for testing only
26    pub target_tick_count: Option<u64>,
27
28    /// How many hashes to roll before emitting the next tick entry.
29    /// None enables "Low power mode", which makes the validator sleep
30    /// for `target_tick_duration` instead of hashing
31    pub hashes_per_tick: Option<u64>,
32}
33
34impl PohConfig {
35    pub fn new_sleep(target_tick_duration: Duration) -> Self {
36        Self {
37            target_tick_duration,
38            hashes_per_tick: None,
39            target_tick_count: None,
40        }
41    }
42}
43
44// the !=0 check was previously done by the unchecked_div_by_const macro
45#[cfg(test)]
46static_assertions::const_assert!(DEFAULT_TICKS_PER_SECOND != 0);
47const DEFAULT_SLEEP_MICROS: u64 = (1000 * 1000) / DEFAULT_TICKS_PER_SECOND;
48
49impl Default for PohConfig {
50    fn default() -> Self {
51        Self::new_sleep(Duration::from_micros(DEFAULT_SLEEP_MICROS))
52    }
53}