diff --git a/clap-utils/src/input_validators.rs b/clap-utils/src/input_validators.rs index 0419abc05..0e6b659a1 100644 --- a/clap-utils/src/input_validators.rs +++ b/clap-utils/src/input_validators.rs @@ -1,6 +1,7 @@ use crate::keypair::{parse_keypair_path, KeypairUrl, ASK_KEYWORD}; use chrono::DateTime; use solana_sdk::{ + clock::Slot, hash::Hash, pubkey::Pubkey, signature::{read_keypair_file, Signature}, @@ -93,6 +94,12 @@ pub fn is_url(string: String) -> Result<(), String> { } } +pub fn is_slot(slot: String) -> Result<(), String> { + slot.parse::() + .map(|_| ()) + .map_err(|e| format!("{:?}", e)) +} + pub fn is_port(port: String) -> Result<(), String> { port.parse::() .map(|_| ()) diff --git a/core/src/validator.rs b/core/src/validator.rs index 51b7a8bd0..821bd0d0a 100644 --- a/core/src/validator.rs +++ b/core/src/validator.rs @@ -72,7 +72,7 @@ pub struct ValidatorConfig { pub broadcast_stage_type: BroadcastStageType, pub enable_partition: Option>, pub fixed_leader_schedule: Option, - pub wait_for_supermajority: bool, + pub wait_for_supermajority: Option, pub new_hard_forks: Option>, pub trusted_validators: Option>, // None = trust all } @@ -95,7 +95,7 @@ impl Default for ValidatorConfig { broadcast_stage_type: BroadcastStageType::Standard, enable_partition: None, fixed_leader_schedule: None, - wait_for_supermajority: false, + wait_for_supermajority: None, new_hard_forks: None, trusted_validators: None, } @@ -631,7 +631,7 @@ fn wait_for_supermajority( bank: &Arc, cluster_info: &Arc>, ) { - if !config.wait_for_supermajority { + if config.wait_for_supermajority != Some(bank.slot()) { return; } diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs index 3839df930..021587b02 100644 --- a/ledger-tool/src/main.rs +++ b/ledger-tool/src/main.rs @@ -4,6 +4,7 @@ use clap::{ }; use histogram; use serde_json::json; +use solana_clap_utils::input_validators::is_slot; use solana_ledger::{ bank_forks::{BankForks, SnapshotConfig}, bank_forks_utils, @@ -576,11 +577,13 @@ fn main() { let halt_at_slot_arg = Arg::with_name("halt_at_slot") .long("halt-at-slot") .value_name("SLOT") + .validator(is_slot) .takes_value(true) .help("Halt processing at the given slot"); let hard_forks_arg = Arg::with_name("hard_forks") .long("hard-fork") .value_name("SLOT") + .validator(is_slot) .multiple(true) .takes_value(true) .help("Add a hard fork at this slot"); @@ -609,6 +612,7 @@ fn main() { Arg::with_name("slots") .index(1) .value_name("SLOTS") + .validator(is_slot) .takes_value(true) .multiple(true) .required(true) @@ -685,6 +689,7 @@ fn main() { Arg::with_name("snapshot_slot") .index(1) .value_name("SLOT") + .validator(is_slot) .takes_value(true) .help("Slot at which to create the snapshot"), ) diff --git a/local-cluster/tests/local_cluster.rs b/local-cluster/tests/local_cluster.rs index 873894c6a..8073187bb 100644 --- a/local-cluster/tests/local_cluster.rs +++ b/local-cluster/tests/local_cluster.rs @@ -158,7 +158,7 @@ fn test_validator_exit_2() { let num_nodes = 2; let mut validator_config = ValidatorConfig::default(); validator_config.rpc_config.enable_validator_exit = true; - validator_config.wait_for_supermajority = true; + validator_config.wait_for_supermajority = Some(0); let config = ClusterConfig { cluster_lamports: 10_000, diff --git a/validator/src/main.rs b/validator/src/main.rs index fb0784f89..428f31923 100644 --- a/validator/src/main.rs +++ b/validator/src/main.rs @@ -8,7 +8,7 @@ use log::*; use rand::{thread_rng, Rng}; use solana_clap_utils::{ input_parsers::pubkey_of, - input_validators::{is_keypair, is_pubkey, is_pubkey_or_keypair}, + input_validators::{is_keypair, is_pubkey, is_pubkey_or_keypair, is_slot}, keypair::{ self, keypair_input, KeypairWithSource, ASK_SEED_PHRASE_ARG, SKIP_SEED_PHRASE_VALIDATION_ARG, @@ -664,6 +664,7 @@ pub fn main() { Arg::with_name("dev_halt_at_slot") .long("dev-halt-at-slot") .value_name("SLOT") + .validator(is_slot) .takes_value(true) .help("Halt the validator when it reaches the given slot"), ) @@ -796,22 +797,17 @@ pub fn main() { .help("Redirect logging to the specified file, '-' for standard error"), ) .arg( - Arg::with_name("no_wait_for_supermajority") - .long("no-wait-for-supermajority") - .takes_value(false) - .help("After processing the ledger, do not wait until a supermajority of stake is visible on gossip before starting PoH"), - ) - .arg( - // Legacy flag that is now enabled by default. Remove this flag a couple months after the 0.23.0 - // release Arg::with_name("wait_for_supermajority") .long("wait-for-supermajority") - .hidden(true) + .value_name("SLOT") + .validator(is_slot) + .help("After processing the ledger and the next slot is SLOT, wait until a supermajority of stake is visible on gossip before starting PoH"), ) .arg( Arg::with_name("hard_forks") .long("hard-fork") .value_name("SLOT") + .validator(is_slot) .multiple(true) .takes_value(true) .help("Add a hard fork at this slot"), @@ -915,7 +911,7 @@ pub fn main() { .ok() .map(|rpc_port| (rpc_port, rpc_port + 1)), voting_disabled: matches.is_present("no_voting"), - wait_for_supermajority: !matches.is_present("no_wait_for_supermajority"), + wait_for_supermajority: value_t!(matches, "wait_for_supermajority", Slot).ok(), trusted_validators, ..ValidatorConfig::default() };