Clean up Validator::new()

This commit is contained in:
Michael Vines 2020-01-30 10:26:27 -07:00
parent 81ba18eea6
commit e218f4e56e
1 changed files with 50 additions and 43 deletions

View File

@ -127,7 +127,6 @@ pub struct Validator {
} }
impl Validator { impl Validator {
#[allow(clippy::cognitive_complexity)]
pub fn new( pub fn new(
mut node: Node, mut node: Node,
keypair: &Arc<Keypair>, keypair: &Arc<Keypair>,
@ -312,23 +311,28 @@ impl Validator {
.set_entrypoint(entrypoint_info.clone()); .set_entrypoint(entrypoint_info.clone());
} }
if config.wait_for_supermajority { wait_for_supermajority(config, &bank, &cluster_info);
info!(
"Waiting for more than 75% of activated stake at slot {} to be in gossip...", let voting_keypair = if config.voting_disabled {
bank.slot() None
} else {
Some(voting_keypair.clone())
};
let poh_service = PohService::new(poh_recorder.clone(), &poh_config, &exit);
assert_eq!(
blockstore.new_shreds_signals.len(),
1,
"New shred signal for the TVU should be the same as the clear bank signal."
); );
loop {
let gossip_stake_percent = get_stake_percent_in_gossip(&bank, &cluster_info);
info!("{}% of activated stake in gossip", gossip_stake_percent,); let tvu = Tvu::new(
if gossip_stake_percent > 75 { vote_account,
break; voting_keypair,
} storage_keypair,
sleep(Duration::new(1, 0)); &bank_forks,
} &cluster_info,
} Sockets {
let sockets = Sockets {
repair: node repair: node
.sockets .sockets
.repair .repair
@ -352,28 +356,7 @@ impl Validator {
.iter() .iter()
.map(|s| s.try_clone().expect("Failed to clone TVU forwards Sockets")) .map(|s| s.try_clone().expect("Failed to clone TVU forwards Sockets"))
.collect(), .collect(),
}; },
let voting_keypair = if config.voting_disabled {
None
} else {
Some(voting_keypair.clone())
};
let poh_service = PohService::new(poh_recorder.clone(), &poh_config, &exit);
assert_eq!(
blockstore.new_shreds_signals.len(),
1,
"New shred signal for the TVU should be the same as the clear bank signal."
);
let tvu = Tvu::new(
vote_account,
voting_keypair,
storage_keypair,
&bank_forks,
&cluster_info,
sockets,
blockstore.clone(), blockstore.clone(),
&storage_state, &storage_state,
config.blockstream_unix_socket.as_ref(), config.blockstream_unix_socket.as_ref(),
@ -567,6 +550,30 @@ fn new_banks_from_blockstore(
) )
} }
fn wait_for_supermajority(
config: &ValidatorConfig,
bank: &Arc<Bank>,
cluster_info: &Arc<RwLock<ClusterInfo>>,
) {
if !config.wait_for_supermajority {
return;
}
info!(
"Waiting for more than 75% of activated stake at slot {} to be in gossip...",
bank.slot()
);
loop {
let gossip_stake_percent = get_stake_percent_in_gossip(&bank, &cluster_info);
info!("{}% of activated stake in gossip", gossip_stake_percent,);
if gossip_stake_percent > 75 {
break;
}
sleep(Duration::new(1, 0));
}
}
pub fn new_validator_for_tests() -> (Validator, ContactInfo, Keypair, PathBuf) { pub fn new_validator_for_tests() -> (Validator, ContactInfo, Keypair, PathBuf) {
use crate::genesis_utils::{create_genesis_config_with_leader, GenesisConfigInfo}; use crate::genesis_utils::{create_genesis_config_with_leader, GenesisConfigInfo};