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 repair_whitelist #4783

Merged
merged 1 commit into from
Feb 5, 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
45 changes: 1 addition & 44 deletions validator/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1738,50 +1738,7 @@ pub fn app<'a>(version: &'a str, default_args: &'a DefaultArgs) -> App<'a, 'a> {
.subcommand(commands::authorized_voter::command(default_args))
.subcommand(commands::contact_info::command(default_args))
.subcommand(commands::repair_shred_from_peer::command(default_args))
.subcommand(
SubCommand::with_name("repair-whitelist")
.about("Manage the validator's repair protocol whitelist")
.setting(AppSettings::SubcommandRequiredElseHelp)
.setting(AppSettings::InferSubcommands)
.subcommand(
SubCommand::with_name("get")
.about("Display the validator's repair protocol whitelist")
.arg(
Arg::with_name("output")
.long("output")
.takes_value(true)
.value_name("MODE")
.possible_values(&["json", "json-compact"])
.help("Output display mode"),
),
)
.subcommand(
SubCommand::with_name("set")
.about("Set the validator's repair protocol whitelist")
.setting(AppSettings::ArgRequiredElseHelp)
.arg(
Arg::with_name("whitelist")
.long("whitelist")
.validator(is_pubkey)
.value_name("VALIDATOR IDENTITY")
.multiple(true)
.takes_value(true)
.help("Set the validator's repair protocol whitelist"),
)
.after_help(
"Note: repair protocol whitelist changes only apply to the currently \
running validator instance",
),
)
.subcommand(
SubCommand::with_name("remove-all")
.about("Clear the validator's repair protocol whitelist")
.after_help(
"Note: repair protocol whitelist changes only apply to the currently \
running validator instance",
),
),
)
.subcommand(commands::repair_whitelist::command(default_args))
.subcommand(
SubCommand::with_name("init").about("Initialize the ledger directory then exit"),
)
Expand Down
1 change: 1 addition & 0 deletions validator/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod exit;
pub mod monitor;
pub mod plugin;
pub mod repair_shred_from_peer;
pub mod repair_whitelist;
pub mod set_identity;
pub mod set_log_filter;
pub mod staked_nodes_overrides;
Expand Down
117 changes: 117 additions & 0 deletions validator/src/commands/repair_whitelist/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
use {
crate::{admin_rpc_service, cli::DefaultArgs},
clap::{values_t_or_exit, App, AppSettings, Arg, ArgMatches, SubCommand},
solana_clap_utils::input_validators::is_pubkey,
solana_sdk::pubkey::Pubkey,
std::{collections::HashSet, path::Path, process::exit},
};

pub fn command(_default_args: &DefaultArgs) -> App<'_, '_> {
SubCommand::with_name("repair-whitelist")
.about("Manage the validator's repair protocol whitelist")
.setting(AppSettings::SubcommandRequiredElseHelp)
.setting(AppSettings::InferSubcommands)
.subcommand(
SubCommand::with_name("get")
.about("Display the validator's repair protocol whitelist")
.arg(
Arg::with_name("output")
.long("output")
.takes_value(true)
.value_name("MODE")
.possible_values(&["json", "json-compact"])
.help("Output display mode"),
),
)
.subcommand(
SubCommand::with_name("set")
.about("Set the validator's repair protocol whitelist")
.setting(AppSettings::ArgRequiredElseHelp)
.arg(
Arg::with_name("whitelist")
.long("whitelist")
.validator(is_pubkey)
.value_name("VALIDATOR IDENTITY")
.multiple(true)
.takes_value(true)
.help("Set the validator's repair protocol whitelist"),
)
.after_help(
"Note: repair protocol whitelist changes only apply to the currently running validator instance",
),
)
.subcommand(
SubCommand::with_name("remove-all")
.about("Clear the validator's repair protocol whitelist")
.after_help(
"Note: repair protocol whitelist changes only apply to the currently running validator instance",
),
)
}

pub fn execute(matches: &ArgMatches, ledger_path: &Path) {
match matches.subcommand() {
("get", Some(subcommand_matches)) => {
let output_mode = subcommand_matches.value_of("output");
let admin_client = admin_rpc_service::connect(ledger_path);
let repair_whitelist = admin_rpc_service::runtime()
.block_on(async move { admin_client.await?.repair_whitelist().await })
.unwrap_or_else(|err| {
eprintln!("Repair whitelist query failed: {err}");
exit(1);
});
if let Some(mode) = output_mode {
match mode {
"json" => println!(
"{}",
serde_json::to_string_pretty(&repair_whitelist).unwrap()
),
"json-compact" => {
print!("{}", serde_json::to_string(&repair_whitelist).unwrap())
}
_ => unreachable!(),
}
} else {
print!("{repair_whitelist}");
}
}
("set", Some(subcommand_matches)) => {
let whitelist = if subcommand_matches.is_present("whitelist") {
let validators_set: HashSet<_> =
values_t_or_exit!(subcommand_matches, "whitelist", Pubkey)
.into_iter()
.collect();
validators_set.into_iter().collect::<Vec<_>>()
} else {
return;
};
set_repair_whitelist(ledger_path, whitelist).unwrap_or_else(|err| {
eprintln!("{err}");
exit(1);
});
}
("remove-all", _) => {
set_repair_whitelist(ledger_path, Vec::default()).unwrap_or_else(|err| {
eprintln!("{err}");
exit(1);
});
}
_ => unreachable!(),
}
}

fn set_repair_whitelist(
ledger_path: &Path,
whitelist: Vec<Pubkey>,
) -> Result<(), Box<dyn std::error::Error>> {
let admin_client = admin_rpc_service::connect(ledger_path);
admin_rpc_service::runtime()
.block_on(async move { admin_client.await?.set_repair_whitelist(whitelist).await })
.map_err(|err| {
std::io::Error::new(
std::io::ErrorKind::Other,
format!("setRepairWhitelist request failed: {err}"),
)
})?;
Ok(())
}
69 changes: 2 additions & 67 deletions validator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,6 @@ enum Operation {

const MILLIS_PER_SECOND: u64 = 1000;

fn set_repair_whitelist(
ledger_path: &Path,
whitelist: Vec<Pubkey>,
) -> Result<(), Box<dyn std::error::Error>> {
let admin_client = admin_rpc_service::connect(ledger_path);
admin_rpc_service::runtime()
.block_on(async move { admin_client.await?.set_repair_whitelist(whitelist).await })
.map_err(|err| {
std::io::Error::new(
std::io::ErrorKind::Other,
format!("setRepairWhitelist request failed: {err}"),
)
})?;
Ok(())
}

// This function is duplicated in ledger-tool/src/main.rs...
fn hardforks_of(matches: &ArgMatches<'_>, name: &str) -> Option<Vec<Slot>> {
if matches.is_present(name) {
Expand Down Expand Up @@ -233,57 +217,8 @@ pub fn main() {
return;
}
("repair-whitelist", Some(repair_whitelist_subcommand_matches)) => {
match repair_whitelist_subcommand_matches.subcommand() {
("get", Some(subcommand_matches)) => {
let output_mode = subcommand_matches.value_of("output");
let admin_client = admin_rpc_service::connect(&ledger_path);
let repair_whitelist = admin_rpc_service::runtime()
.block_on(async move { admin_client.await?.repair_whitelist().await })
.unwrap_or_else(|err| {
eprintln!("Repair whitelist query failed: {err}");
exit(1);
});
if let Some(mode) = output_mode {
match mode {
"json" => println!(
"{}",
serde_json::to_string_pretty(&repair_whitelist).unwrap()
),
"json-compact" => {
print!("{}", serde_json::to_string(&repair_whitelist).unwrap())
}
_ => unreachable!(),
}
} else {
print!("{repair_whitelist}");
}
return;
}
("set", Some(subcommand_matches)) => {
let whitelist = if subcommand_matches.is_present("whitelist") {
let validators_set: HashSet<_> =
values_t_or_exit!(subcommand_matches, "whitelist", Pubkey)
.into_iter()
.collect();
validators_set.into_iter().collect::<Vec<_>>()
} else {
return;
};
set_repair_whitelist(&ledger_path, whitelist).unwrap_or_else(|err| {
eprintln!("{err}");
exit(1);
});
return;
}
("remove-all", _) => {
set_repair_whitelist(&ledger_path, Vec::default()).unwrap_or_else(|err| {
eprintln!("{err}");
exit(1);
});
return;
}
_ => unreachable!(),
}
commands::repair_whitelist::execute(repair_whitelist_subcommand_matches, &ledger_path);
return;
}
("set-public-address", Some(subcommand_matches)) => {
let parse_arg_addr = |arg_name: &str, arg_long: &str| -> Option<SocketAddr> {
Expand Down
Loading