Poh subsystem cleanup, genesis plumbing, enable real PoH on edge testnet (#4292)

* Remove unused PohServiceConfig::Step

* Clarify variable name

* Poh::hash() now takes an iteration counter

* man -> max

* Inline functions with single call site

* Move PohServiceConfig into GenesisBlock

* Add plumbing to enable real PoH on testnets

* Batch hashes to improve PoH hash rate

* Ensure a constant hashes_per_tick

* Remove PohEntry mixin field

* Poh/PohEntry no longer maintains tick_height

* Ensure a constant hashes_per_tick

* ci/localnet-sanity.sh: Use real PoH

* Rework Poh/PohService to keep PohRecorder unlocked as much as possible while hashing
This commit is contained in:
Michael Vines
2019-05-18 14:01:36 -07:00
committed by GitHub
parent 7e1a7862db
commit 392a39dd54
26 changed files with 625 additions and 319 deletions

View File

@ -3,6 +3,7 @@
use crate::account::Account;
use crate::fee_calculator::FeeCalculator;
use crate::hash::{hash, Hash};
use crate::poh_config::PohConfig;
use crate::pubkey::Pubkey;
use crate::signature::{Keypair, KeypairUtil};
use crate::system_program;
@ -21,6 +22,7 @@ pub struct GenesisBlock {
pub slots_per_epoch: u64,
pub stakers_slot_offset: u64,
pub ticks_per_slot: u64,
pub poh_config: PohConfig,
}
// useful for basic tests
@ -54,6 +56,7 @@ impl GenesisBlock {
slots_per_epoch: DEFAULT_SLOTS_PER_EPOCH,
stakers_slot_offset: DEFAULT_SLOTS_PER_EPOCH,
ticks_per_slot: DEFAULT_TICKS_PER_SLOT,
poh_config: PohConfig::default(),
}
}

View File

@ -10,6 +10,7 @@ pub mod loader_instruction;
pub mod message;
pub mod native_loader;
pub mod packet;
pub mod poh_config;
pub mod pubkey;
pub mod rpc_port;
pub mod short_vec;

29
sdk/src/poh_config.rs Normal file
View File

@ -0,0 +1,29 @@
use crate::timing::DEFAULT_NUM_TICKS_PER_SECOND;
use std::time::Duration;
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct PohConfig {
/// The target tick rate of the cluster.
pub target_tick_duration: Duration,
/// 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,
}
}
}
impl Default for PohConfig {
fn default() -> Self {
Self::new_sleep(Duration::from_millis(1000 / DEFAULT_NUM_TICKS_PER_SECOND))
}
}

View File

@ -2,7 +2,9 @@
use std::time::Duration;
use std::time::{SystemTime, UNIX_EPOCH};
pub const NUM_TICKS_PER_SECOND: u64 = 10;
// The default tick rate that the cluster attempts to achieve. Note that the actual tick
// rate at any given time should be expected to drift
pub const DEFAULT_NUM_TICKS_PER_SECOND: u64 = 10;
// At 10 ticks/s, 8 ticks per slot implies that leader rotation and voting will happen
// every 800 ms. A fast voting cadence ensures faster finality and convergence