Rename enum Config to enum PohServiceConfig

This commit is contained in:
Michael Vines
2019-02-09 09:25:11 -08:00
committed by Grimes
parent ab3dd2a1b3
commit a6aaca814c
3 changed files with 20 additions and 23 deletions

View File

@ -8,7 +8,7 @@ use crate::counter::Counter;
use crate::entry::Entry; use crate::entry::Entry;
use crate::packet::Packets; use crate::packet::Packets;
use crate::poh_recorder::{PohRecorder, PohRecorderError}; use crate::poh_recorder::{PohRecorder, PohRecorderError};
use crate::poh_service::{Config, PohService}; use crate::poh_service::{PohService, PohServiceConfig};
use crate::result::{Error, Result}; use crate::result::{Error, Result};
use crate::service::Service; use crate::service::Service;
use crate::sigverify_stage::VerifiedPackets; use crate::sigverify_stage::VerifiedPackets;
@ -51,7 +51,7 @@ impl BankingStage {
pub fn new( pub fn new(
bank: &Arc<Bank>, bank: &Arc<Bank>,
verified_receiver: Receiver<VerifiedPackets>, verified_receiver: Receiver<VerifiedPackets>,
config: Config, config: PohServiceConfig,
last_entry_id: &Hash, last_entry_id: &Hash,
max_tick_height: u64, max_tick_height: u64,
leader_id: Pubkey, leader_id: Pubkey,
@ -338,7 +338,7 @@ mod tests {
let (banking_stage, entry_receiver) = BankingStage::new( let (banking_stage, entry_receiver) = BankingStage::new(
&bank, &bank,
verified_receiver, verified_receiver,
Config::Sleep(Duration::from_millis(1)), PohServiceConfig::Sleep(Duration::from_millis(1)),
&bank.last_id(), &bank.last_id(),
std::u64::MAX, std::u64::MAX,
genesis_block.bootstrap_leader_id, genesis_block.bootstrap_leader_id,

View File

@ -15,7 +15,7 @@ use std::time::Duration;
pub const NUM_TICKS_PER_SECOND: usize = 10; pub const NUM_TICKS_PER_SECOND: usize = 10;
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub enum Config { pub enum PohServiceConfig {
/// * `Tick` - Run full PoH thread. Tick is a rough estimate of how many hashes to roll before /// * `Tick` - Run full PoH thread. Tick is a rough estimate of how many hashes to roll before
/// transmitting a new entry. /// transmitting a new entry.
Tick(usize), Tick(usize),
@ -24,10 +24,10 @@ pub enum Config {
Sleep(Duration), Sleep(Duration),
} }
impl Default for Config { impl Default for PohServiceConfig {
fn default() -> Config { fn default() -> PohServiceConfig {
// TODO: Change this to Tick to enable PoH // TODO: Change this to Tick to enable PoH
Config::Sleep(Duration::from_millis(1000 / NUM_TICKS_PER_SECOND as u64)) PohServiceConfig::Sleep(Duration::from_millis(1000 / NUM_TICKS_PER_SECOND as u64))
} }
} }
@ -48,7 +48,7 @@ impl PohService {
pub fn new( pub fn new(
poh_recorder: PohRecorder, poh_recorder: PohRecorder,
config: Config, config: PohServiceConfig,
to_validator_sender: TpuRotationSender, to_validator_sender: TpuRotationSender,
) -> Self { ) -> Self {
// PohService is a headless producer, so when it exits it should notify the banking stage. // PohService is a headless producer, so when it exits it should notify the banking stage.
@ -80,14 +80,14 @@ impl PohService {
fn tick_producer( fn tick_producer(
poh: &mut PohRecorder, poh: &mut PohRecorder,
config: Config, config: PohServiceConfig,
poh_exit: &AtomicBool, poh_exit: &AtomicBool,
to_validator_sender: &TpuRotationSender, to_validator_sender: &TpuRotationSender,
) -> Result<()> { ) -> Result<()> {
let max_tick_height = poh.max_tick_height(); let max_tick_height = poh.max_tick_height();
loop { loop {
match config { match config {
Config::Tick(num) => { PohServiceConfig::Tick(num) => {
for _ in 1..num { for _ in 1..num {
let res = poh.hash(); let res = poh.hash();
if let Err(e) = res { if let Err(e) = res {
@ -99,7 +99,7 @@ impl PohService {
} }
} }
} }
Config::Sleep(duration) => { PohServiceConfig::Sleep(duration) => {
sleep(duration); sleep(duration);
} }
} }
@ -128,18 +128,12 @@ impl Service for PohService {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::{Config, PohService}; use super::*;
use crate::bank::Bank; use crate::bank::Bank;
use crate::genesis_block::GenesisBlock; use crate::genesis_block::GenesisBlock;
use crate::poh_recorder::PohRecorder;
use crate::result::Result;
use crate::service::Service;
use crate::test_tx::test_tx; use crate::test_tx::test_tx;
use solana_sdk::hash::hash; use solana_sdk::hash::hash;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::channel; use std::sync::mpsc::channel;
use std::sync::Arc;
use std::thread::{Builder, JoinHandle};
#[test] #[test]
fn test_poh_service() { fn test_poh_service() {
@ -173,8 +167,11 @@ mod tests {
const HASHES_PER_TICK: u64 = 2; const HASHES_PER_TICK: u64 = 2;
let (sender, _) = channel(); let (sender, _) = channel();
let poh_service = let poh_service = PohService::new(
PohService::new(poh_recorder, Config::Tick(HASHES_PER_TICK as usize), sender); poh_recorder,
PohServiceConfig::Tick(HASHES_PER_TICK as usize),
sender,
);
// get some events // get some events
let mut hashes = 0; let mut hashes = 0;

View File

@ -7,7 +7,7 @@ use crate::broadcast_service::BroadcastService;
use crate::cluster_info::ClusterInfo; use crate::cluster_info::ClusterInfo;
use crate::cluster_info_vote_listener::ClusterInfoVoteListener; use crate::cluster_info_vote_listener::ClusterInfoVoteListener;
use crate::fetch_stage::FetchStage; use crate::fetch_stage::FetchStage;
use crate::poh_service::Config; use crate::poh_service::PohServiceConfig;
use crate::service::Service; use crate::service::Service;
use crate::sigverify_stage::SigVerifyStage; use crate::sigverify_stage::SigVerifyStage;
use crate::streamer::BlobSender; use crate::streamer::BlobSender;
@ -77,7 +77,7 @@ impl Tpu {
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn new( pub fn new(
bank: &Arc<Bank>, bank: &Arc<Bank>,
tick_duration: Config, tick_duration: PohServiceConfig,
transactions_sockets: Vec<UdpSocket>, transactions_sockets: Vec<UdpSocket>,
broadcast_socket: UdpSocket, broadcast_socket: UdpSocket,
cluster_info: Arc<RwLock<ClusterInfo>>, cluster_info: Arc<RwLock<ClusterInfo>>,
@ -143,7 +143,7 @@ impl Tpu {
pub fn switch_to_leader( pub fn switch_to_leader(
&mut self, &mut self,
bank: &Arc<Bank>, bank: &Arc<Bank>,
tick_duration: Config, tick_duration: PohServiceConfig,
transactions_sockets: Vec<UdpSocket>, transactions_sockets: Vec<UdpSocket>,
broadcast_socket: UdpSocket, broadcast_socket: UdpSocket,
cluster_info: Arc<RwLock<ClusterInfo>>, cluster_info: Arc<RwLock<ClusterInfo>>,