diff --git a/entry/src/poh.rs b/entry/src/poh.rs index c2b6c0820f..573b1ab606 100644 --- a/entry/src/poh.rs +++ b/entry/src/poh.rs @@ -5,6 +5,8 @@ use { std::time::{Duration, Instant}, }; +const LOW_POWER_MODE: u64 = std::u64::MAX; + pub struct Poh { pub hash: Hash, num_hashes: u64, @@ -26,7 +28,7 @@ impl Poh { } pub fn new_with_slot_info(hash: Hash, hashes_per_tick: Option, tick_number: u64) -> Self { - let hashes_per_tick = hashes_per_tick.unwrap_or(std::u64::MAX); + let hashes_per_tick = hashes_per_tick.unwrap_or(LOW_POWER_MODE); assert!(hashes_per_tick > 1); let now = Instant::now(); Poh { @@ -90,9 +92,9 @@ impl Poh { self.num_hashes += 1; self.remaining_hashes -= 1; - // If the hashes_per_tick is variable (std::u64::MAX) then always generate a tick. + // If we are in low power mode then always generate a tick. // Otherwise only tick if there are no remaining hashes - if self.hashes_per_tick < std::u64::MAX && self.remaining_hashes != 0 { + if self.hashes_per_tick != LOW_POWER_MODE && self.remaining_hashes != 0 { return None; } @@ -118,8 +120,8 @@ pub fn compute_hash_time_ns(hashes_sample_size: u64) -> u64 { } pub fn compute_hashes_per_tick(duration: Duration, hashes_sample_size: u64) -> u64 { - let elapsed = compute_hash_time_ns(hashes_sample_size) / (1000 * 1000); - duration.as_millis() as u64 * hashes_sample_size / elapsed + let elapsed_ms = compute_hash_time_ns(hashes_sample_size) / (1000 * 1000); + duration.as_millis() as u64 * hashes_sample_size / elapsed_ms } #[cfg(test)] diff --git a/poh/src/poh_service.rs b/poh/src/poh_service.rs index 34d773cfec..9a72ad837b 100644 --- a/poh/src/poh_service.rs +++ b/poh/src/poh_service.rs @@ -111,14 +111,14 @@ impl PohService { solana_sys_tuner::request_realtime_poh(); if poh_config.hashes_per_tick.is_none() { if poh_config.target_tick_count.is_none() { - Self::sleepy_tick_producer( + Self::low_power_tick_producer( poh_recorder, &poh_config, &poh_exit_, record_receiver, ); } else { - Self::short_lived_sleepy_tick_producer( + Self::short_lived_low_power_tick_producer( poh_recorder, &poh_config, &poh_exit_, @@ -162,7 +162,7 @@ impl PohService { target_tick_duration_ns.saturating_sub(adjustment_per_tick) } - fn sleepy_tick_producer( + fn low_power_tick_producer( poh_recorder: Arc>, poh_config: &PohConfig, poh_exit: &AtomicBool, @@ -206,7 +206,7 @@ impl PohService { } } - fn short_lived_sleepy_tick_producer( + fn short_lived_low_power_tick_producer( poh_recorder: Arc>, poh_config: &PohConfig, poh_exit: &AtomicBool, diff --git a/sdk/src/poh_config.rs b/sdk/src/poh_config.rs index 864004f11b..20176326cf 100644 --- a/sdk/src/poh_config.rs +++ b/sdk/src/poh_config.rs @@ -14,9 +14,8 @@ pub struct PohConfig { pub target_tick_count: Option, /// 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 + /// None enables "Low power mode", which makes the validator sleep + /// for `target_tick_duration` instead of hashing pub hashes_per_tick: Option, }