From 02a12afe0ff2d6c9fa0c63462f253ef468d2517a Mon Sep 17 00:00:00 2001 From: yihau Date: Thu, 12 Dec 2024 12:39:15 +0800 Subject: [PATCH 1/3] extract monitor --- validator/src/cli.rs | 2 +- validator/src/commands/mod.rs | 1 + validator/src/commands/monitor/mod.rs | 29 +++++++++++++++++++++++++++ validator/src/main.rs | 14 +------------ 4 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 validator/src/commands/monitor/mod.rs diff --git a/validator/src/cli.rs b/validator/src/cli.rs index e2486067daec05..6f78291e84f5e2 100644 --- a/validator/src/cli.rs +++ b/validator/src/cli.rs @@ -1875,7 +1875,7 @@ pub fn app<'a>(version: &'a str, default_args: &'a DefaultArgs) -> App<'a, 'a> { .subcommand( SubCommand::with_name("init").about("Initialize the ledger directory then exit"), ) - .subcommand(SubCommand::with_name("monitor").about("Monitor the validator")) + .subcommand(commands::monitor::command(default_args)) .subcommand(SubCommand::with_name("run").about("Run the validator")) .subcommand( SubCommand::with_name("plugin") diff --git a/validator/src/commands/mod.rs b/validator/src/commands/mod.rs index 36cfab38299922..09817822ff6be2 100644 --- a/validator/src/commands/mod.rs +++ b/validator/src/commands/mod.rs @@ -1,2 +1,3 @@ pub mod authorized_voter; +pub mod monitor; pub mod wait_for_restart_window; diff --git a/validator/src/commands/monitor/mod.rs b/validator/src/commands/monitor/mod.rs new file mode 100644 index 00000000000000..61fa5a097aa8fa --- /dev/null +++ b/validator/src/commands/monitor/mod.rs @@ -0,0 +1,29 @@ +use { + crate::{cli::DefaultArgs, dashboard::Dashboard}, + clap::{App, ArgMatches, SubCommand}, + std::{ + path::{Path, PathBuf}, + process::exit, + time::Duration, + }, +}; + +pub fn command<'a>(_default_args: &'a DefaultArgs) -> App<'a, 'a> { + SubCommand::with_name("monitor").about("Monitor the validator") +} + +pub fn execute(_matches: &ArgMatches, ledger_path: &PathBuf) { + monitor_validator(&ledger_path); +} + +pub fn monitor_validator(ledger_path: &Path) { + let dashboard = Dashboard::new(ledger_path, None, None).unwrap_or_else(|err| { + println!( + "Error: Unable to connect to validator at {}: {:?}", + ledger_path.display(), + err, + ); + exit(1); + }); + dashboard.run(Duration::from_secs(2)); +} diff --git a/validator/src/main.rs b/validator/src/main.rs index c0fdbf720180ea..ae9a71d5e2ec3b 100644 --- a/validator/src/main.rs +++ b/validator/src/main.rs @@ -98,18 +98,6 @@ enum Operation { const MILLIS_PER_SECOND: u64 = 1000; -fn monitor_validator(ledger_path: &Path) { - let dashboard = Dashboard::new(ledger_path, None, None).unwrap_or_else(|err| { - println!( - "Error: Unable to connect to validator at {}: {:?}", - ledger_path.display(), - err, - ); - exit(1); - }); - dashboard.run(Duration::from_secs(2)); -} - fn set_repair_whitelist( ledger_path: &Path, whitelist: Vec, @@ -342,7 +330,7 @@ pub fn main() { return; } ("monitor", _) => { - monitor_validator(&ledger_path); + commands::monitor::execute(&matches, &ledger_path); return; } ("staked-nodes-overrides", Some(subcommand_matches)) => { From 1f34fb90fbc79817419e51646a0b184b37638f2d Mon Sep 17 00:00:00 2001 From: yihau Date: Tue, 4 Feb 2025 02:40:03 +0800 Subject: [PATCH 2/3] lint --- validator/src/commands/monitor/mod.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/validator/src/commands/monitor/mod.rs b/validator/src/commands/monitor/mod.rs index 61fa5a097aa8fa..3505b98851e057 100644 --- a/validator/src/commands/monitor/mod.rs +++ b/validator/src/commands/monitor/mod.rs @@ -1,19 +1,15 @@ use { crate::{cli::DefaultArgs, dashboard::Dashboard}, clap::{App, ArgMatches, SubCommand}, - std::{ - path::{Path, PathBuf}, - process::exit, - time::Duration, - }, + std::{path::Path, process::exit, time::Duration}, }; -pub fn command<'a>(_default_args: &'a DefaultArgs) -> App<'a, 'a> { +pub fn command(_default_args: &DefaultArgs) -> App<'_, '_> { SubCommand::with_name("monitor").about("Monitor the validator") } -pub fn execute(_matches: &ArgMatches, ledger_path: &PathBuf) { - monitor_validator(&ledger_path); +pub fn execute(_matches: &ArgMatches, ledger_path: &Path) { + monitor_validator(ledger_path); } pub fn monitor_validator(ledger_path: &Path) { From 779deb072e3c1ef520e23a332a6031971b2ec489 Mon Sep 17 00:00:00 2001 From: yihau Date: Tue, 4 Feb 2025 10:56:50 +0800 Subject: [PATCH 3/3] lint --- validator/src/main.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/validator/src/main.rs b/validator/src/main.rs index ae9a71d5e2ec3b..cb7c698fbeae97 100644 --- a/validator/src/main.rs +++ b/validator/src/main.rs @@ -7,9 +7,7 @@ use { admin_rpc_service::{load_staked_nodes_overrides, StakedNodesOverrides}, bootstrap, cli::{self, app, warn_for_deprecated_arguments, DefaultArgs}, - commands, - dashboard::Dashboard, - ledger_lockfile, lock_ledger, redirect_stderr_to_file, + commands, ledger_lockfile, lock_ledger, redirect_stderr_to_file, }, clap::{crate_name, value_t, value_t_or_exit, values_t, values_t_or_exit, ArgMatches}, crossbeam_channel::unbounded, @@ -325,7 +323,7 @@ pub fn main() { println!("Exit request sent"); if monitor { - monitor_validator(&ledger_path); + commands::monitor::monitor_validator(&ledger_path); } return; }