Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Use lazy_static! instead of abusing DefaultArgs...
Browse files Browse the repository at this point in the history
  • Loading branch information
ryoqun committed Mar 23, 2023
1 parent 296b909 commit 428fcfd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
29 changes: 19 additions & 10 deletions core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use {
tvu::{Tvu, TvuConfig, TvuSockets},
},
crossbeam_channel::{bounded, unbounded, Receiver},
lazy_static::lazy_static,
rand::{thread_rng, Rng},
solana_client::connection_cache::ConnectionCache,
solana_entry::poh::compute_hash_time_ns,
Expand Down Expand Up @@ -135,11 +136,15 @@ impl BlockVerificationMethod {
Self::VARIANTS
}

pub fn cli_message() -> String {
format!(
"Switch transaction scheduling method for verifying ledger entries [default: {}]",
Self::default()
)
pub fn cli_message() -> &'static str {
lazy_static! {
static ref MESSAGE: String = format!(
"Switch transaction scheduling method for verifying ledger entries [default: {}]",
BlockVerificationMethod::default()
);
};

&MESSAGE
}
}

Expand All @@ -155,11 +160,15 @@ impl BlockProductionMethod {
Self::VARIANTS
}

pub fn cli_message() -> String {
format!(
"Switch transaction scheduling method for producing ledger entries [default: {}]",
Self::default()
)
pub fn cli_message() -> &'static str {
lazy_static! {
static ref MESSAGE: String = format!(
"Switch transaction scheduling method for producing ledger entries [default: {}]",
BlockProductionMethod::default()
);
};

&MESSAGE
}
}

Expand Down
4 changes: 1 addition & 3 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1651,8 +1651,6 @@ fn main() {
.to_string();
let default_graph_vote_account_mode = GraphVoteAccountMode::default();

let block_verification_method_help = &BlockVerificationMethod::cli_message();

let mut measure_total_execution_time = Measure::start("ledger tool");

let matches = App::new(crate_name!())
Expand Down Expand Up @@ -1718,7 +1716,7 @@ fn main() {
.possible_values(BlockVerificationMethod::cli_names())
.global(true)
.hidden(hidden_unless_forced())
.help(block_verification_method_help),
.help(BlockVerificationMethod::cli_message()),
)
.arg(
Arg::with_name("output_format")
Expand Down
8 changes: 2 additions & 6 deletions validator/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ pub fn app<'a>(version: &'a str, default_args: &'a DefaultArgs) -> App<'a, 'a> {
.value_name("METHOD")
.takes_value(true)
.possible_values(BlockVerificationMethod::cli_names())
.help(&default_args.block_verification_method_help),
.help(BlockVerificationMethod::cli_message())
)
.arg(
Arg::with_name("block_production_method")
Expand All @@ -1350,7 +1350,7 @@ pub fn app<'a>(version: &'a str, default_args: &'a DefaultArgs) -> App<'a, 'a> {
.value_name("METHOD")
.takes_value(true)
.possible_values(BlockProductionMethod::cli_names())
.help(&default_args.block_production_method_help),
.help(BlockProductionMethod::cli_message())
)
.args(&get_deprecated_arguments())
.after_help("The default subcommand is run")
Expand Down Expand Up @@ -1781,8 +1781,6 @@ pub struct DefaultArgs {
pub wait_for_restart_window_max_delinquent_stake: String,

pub banking_trace_dir_byte_limit: String,
pub block_verification_method_help: String,
pub block_production_method_help: String,
}

impl DefaultArgs {
Expand Down Expand Up @@ -1862,8 +1860,6 @@ impl DefaultArgs {
wait_for_restart_window_min_idle_time: "10".to_string(),
wait_for_restart_window_max_delinquent_stake: "5".to_string(),
banking_trace_dir_byte_limit: BANKING_TRACE_DIR_DEFAULT_BYTE_LIMIT.to_string(),
block_verification_method_help: BlockVerificationMethod::cli_message(),
block_production_method_help: BlockProductionMethod::cli_message(),
}
}
}
Expand Down

0 comments on commit 428fcfd

Please sign in to comment.