Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

agave-validator: extract exit #4771

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 2 additions & 53 deletions validator/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use {
hidden_unless_forced,
input_validators::{
is_keypair, is_keypair_or_ask_keyword, is_parsable, is_pow2, is_pubkey,
is_pubkey_or_keypair, is_slot, is_url_or_moniker, is_valid_percentage, is_within_range,
is_pubkey_or_keypair, is_slot, is_url_or_moniker, is_within_range,
validate_maximum_full_snapshot_archives_to_retain,
validate_maximum_incremental_snapshot_archives_to_retain,
},
Expand Down Expand Up @@ -1734,58 +1734,7 @@ pub fn app<'a>(version: &'a str, default_args: &'a DefaultArgs) -> App<'a, 'a> {
.args(&thread_args(&default_args.thread_args))
.args(&get_deprecated_arguments())
.after_help("The default subcommand is run")
.subcommand(
SubCommand::with_name("exit")
.about("Send an exit request to the validator")
.arg(
Arg::with_name("force")
.short("f")
.long("force")
.takes_value(false)
.help(
"Request the validator exit immediately instead of waiting for a \
restart window",
),
)
.arg(
Arg::with_name("monitor")
.short("m")
.long("monitor")
.takes_value(false)
.help("Monitor the validator after sending the exit request"),
)
.arg(
Arg::with_name("min_idle_time")
.long("min-idle-time")
.takes_value(true)
.validator(is_parsable::<usize>)
.value_name("MINUTES")
.default_value(&default_args.exit_min_idle_time)
.help(
"Minimum time that the validator should not be leader before \
restarting",
),
)
.arg(
Arg::with_name("max_delinquent_stake")
.long("max-delinquent-stake")
.takes_value(true)
.validator(is_valid_percentage)
.default_value(&default_args.exit_max_delinquent_stake)
.value_name("PERCENT")
.help("The maximum delinquent stake % permitted for an exit"),
)
.arg(
Arg::with_name("skip_new_snapshot_check")
.long("skip-new-snapshot-check")
.help("Skip check for a new snapshot"),
)
.arg(
Arg::with_name("skip_health_check")
.long("skip-health-check")
.help("Skip health check"),
),
)
.subcommand(commands::exit::command(default_args))
.subcommand(commands::authorized_voter::command(default_args))
.subcommand(
SubCommand::with_name("contact-info")
Expand Down
94 changes: 94 additions & 0 deletions validator/src/commands/exit/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
use {
crate::{admin_rpc_service, cli::DefaultArgs, commands},
clap::{value_t_or_exit, App, Arg, ArgMatches, SubCommand},
solana_clap_utils::input_validators::{is_parsable, is_valid_percentage},
std::{path::Path, process::exit},
};

pub fn command(default_args: &DefaultArgs) -> App<'_, '_> {
SubCommand::with_name("exit")
.about("Send an exit request to the validator")
.arg(
Arg::with_name("force")
.short("f")
.long("force")
.takes_value(false)
.help(
"Request the validator exit immediately instead of waiting for a restart window",
),
)
.arg(
Arg::with_name("monitor")
.short("m")
.long("monitor")
.takes_value(false)
.help("Monitor the validator after sending the exit request"),
)
.arg(
Arg::with_name("min_idle_time")
.long("min-idle-time")
.takes_value(true)
.validator(is_parsable::<usize>)
.value_name("MINUTES")
.default_value(&default_args.exit_min_idle_time)
.help(
"Minimum time that the validator should not be leader before restarting",
),
)
.arg(
Arg::with_name("max_delinquent_stake")
.long("max-delinquent-stake")
.takes_value(true)
.validator(is_valid_percentage)
.default_value(&default_args.exit_max_delinquent_stake)
.value_name("PERCENT")
.help("The maximum delinquent stake % permitted for an exit"),
)
.arg(
Arg::with_name("skip_new_snapshot_check")
.long("skip-new-snapshot-check")
.help("Skip check for a new snapshot"),
)
.arg(
Arg::with_name("skip_health_check")
.long("skip-health-check")
.help("Skip health check"),
)
}

pub fn execute(matches: &ArgMatches, ledger_path: &Path) {
let min_idle_time = value_t_or_exit!(matches, "min_idle_time", usize);
let force = matches.is_present("force");
let monitor = matches.is_present("monitor");
let skip_new_snapshot_check = matches.is_present("skip_new_snapshot_check");
let skip_health_check = matches.is_present("skip_health_check");
let max_delinquent_stake = value_t_or_exit!(matches, "max_delinquent_stake", u8);

if !force {
commands::wait_for_restart_window::wait_for_restart_window(
ledger_path,
None,
min_idle_time,
max_delinquent_stake,
skip_new_snapshot_check,
skip_health_check,
)
.unwrap_or_else(|err| {
println!("{err}");
exit(1);
});
}

let admin_client = admin_rpc_service::connect(ledger_path);
admin_rpc_service::runtime()
.block_on(async move { admin_client.await?.exit().await })
.unwrap_or_else(|err| {
println!("exit request failed: {err}");
exit(1);
});
println!("Exit request sent");

if monitor {
commands::monitor::execute(matches, ledger_path);
}
}
1 change: 1 addition & 0 deletions validator/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod authorized_voter;
pub mod exit;
pub mod monitor;
pub mod wait_for_restart_window;
36 changes: 1 addition & 35 deletions validator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,41 +290,7 @@ pub fn main() {
}
("init", _) => Operation::Initialize,
("exit", Some(subcommand_matches)) => {
let min_idle_time = value_t_or_exit!(subcommand_matches, "min_idle_time", usize);
let force = subcommand_matches.is_present("force");
let monitor = subcommand_matches.is_present("monitor");
let skip_new_snapshot_check = subcommand_matches.is_present("skip_new_snapshot_check");
let skip_health_check = subcommand_matches.is_present("skip_health_check");
let max_delinquent_stake =
value_t_or_exit!(subcommand_matches, "max_delinquent_stake", u8);

if !force {
commands::wait_for_restart_window::wait_for_restart_window(
&ledger_path,
None,
min_idle_time,
max_delinquent_stake,
skip_new_snapshot_check,
skip_health_check,
)
.unwrap_or_else(|err| {
println!("{err}");
exit(1);
});
}

let admin_client = admin_rpc_service::connect(&ledger_path);
admin_rpc_service::runtime()
.block_on(async move { admin_client.await?.exit().await })
.unwrap_or_else(|err| {
println!("exit request failed: {err}");
exit(1);
});
println!("Exit request sent");

if monitor {
commands::monitor::monitor_validator(&ledger_path);
}
commands::exit::execute(subcommand_matches, &ledger_path);
return;
}
("monitor", _) => {
Expand Down
Loading