diff --git a/Cargo.lock b/Cargo.lock index bfccc53419..8c264231f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4679,6 +4679,7 @@ dependencies = [ "reqwest 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)", "solana-clap-utils 1.0.5", + "solana-cli-config 1.0.5", "solana-client 1.0.5", "solana-logger 1.0.5", "solana-metrics 1.0.5", diff --git a/watchtower/Cargo.toml b/watchtower/Cargo.toml index be2fb8b9c6..201a96af6a 100644 --- a/watchtower/Cargo.toml +++ b/watchtower/Cargo.toml @@ -14,6 +14,7 @@ log = "0.4.8" reqwest = { version = "0.10.1", default-features = false, features = ["blocking", "rustls-tls"] } serde_json = "1.0" solana-clap-utils = { path = "../clap-utils", version = "1.0.5" } +solana-cli-config = { path = "../cli-config", version = "1.0.5" } solana-client = { path = "../client", version = "1.0.5" } solana-logger = { path = "../logger", version = "1.0.5" } solana-metrics = { path = "../metrics", version = "1.0.5" } diff --git a/watchtower/src/main.rs b/watchtower/src/main.rs index e29e9e15fe..e466857739 100644 --- a/watchtower/src/main.rs +++ b/watchtower/src/main.rs @@ -3,12 +3,13 @@ mod notifier; use crate::notifier::Notifier; -use clap::{crate_description, crate_name, value_t_or_exit, App, Arg}; +use clap::{crate_description, crate_name, value_t, value_t_or_exit, App, Arg}; use log::*; use solana_clap_utils::{ input_parsers::pubkey_of, input_validators::{is_pubkey_or_keypair, is_url}, }; +use solana_cli_config::{Config, CONFIG_FILE}; use solana_client::rpc_client::RpcClient; use solana_metrics::{datapoint_error, datapoint_info}; use std::{error, io, thread::sleep, time::Duration}; @@ -17,12 +18,25 @@ fn main() -> Result<(), Box> { let matches = App::new(crate_name!()) .about(crate_description!()) .version(solana_clap_utils::version!()) + .arg({ + let arg = Arg::with_name("config_file") + .short("C") + .long("config") + .value_name("PATH") + .takes_value(true) + .global(true) + .help("Configuration file to use"); + if let Some(ref config_file) = *CONFIG_FILE { + arg.default_value(&config_file) + } else { + arg + } + }) .arg( Arg::with_name("json_rpc_url") .long("url") .value_name("URL") .takes_value(true) - .required(true) .validator(is_url) .help("JSON RPC URL for the cluster"), ) @@ -44,13 +58,21 @@ fn main() -> Result<(), Box> { ) .get_matches(); + let config = if let Some(config_file) = matches.value_of("config_file") { + Config::load(config_file).unwrap_or_default() + } else { + Config::default() + }; + let interval = Duration::from_secs(value_t_or_exit!(matches, "interval", u64)); - let json_rpc_url = value_t_or_exit!(matches, "json_rpc_url", String); + let json_rpc_url = + value_t!(matches, "json_rpc_url", String).unwrap_or_else(|_| config.json_rpc_url); let validator_identity = pubkey_of(&matches, "validator_identity").map(|i| i.to_string()); solana_logger::setup_with_default("solana=info"); solana_metrics::set_panic_hook("watchtower"); + info!("RPC URL: {}", json_rpc_url); let rpc_client = RpcClient::new(json_rpc_url); let notifier = Notifier::new();