From be938cf4f06a41602a8f56bbde99307c76796c0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Wed, 8 Jun 2022 21:51:00 +0200 Subject: [PATCH] client/native: tidy some logging (#1320) * client/native: some logging refinement * client/native: fix pedantic clippy warn * client/native: another pedantic clippy warn * rustfmt --- clients/native/src/commands/init.rs | 13 +++++++++++-- clients/native/src/commands/mod.rs | 2 +- clients/native/src/commands/run.rs | 6 +++--- clients/native/src/commands/upgrade.rs | 14 +++++++------- clients/native/src/main.rs | 2 ++ common/config/src/lib.rs | 4 ---- common/topology/src/gateway.rs | 10 ++++++++++ 7 files changed, 34 insertions(+), 17 deletions(-) diff --git a/clients/native/src/commands/init.rs b/clients/native/src/commands/init.rs index 63ac522634..4810365526 100644 --- a/clients/native/src/commands/init.rs +++ b/clients/native/src/commands/init.rs @@ -119,6 +119,7 @@ async fn gateway_details( .expect("The list of validator apis is empty"); let validator_client = validator_client::ApiClient::new(validator_api.clone()); + log::trace!("Fetching list of gateways from: {}", validator_api); let gateways = validator_client.get_cached_gateways().await.unwrap(); let valid_gateways = gateways .into_iter() @@ -213,12 +214,14 @@ pub async fn execute(matches: ArgMatches<'static>) { let mut key_manager = KeyManager::new(&mut rng); let chosen_gateway_id = matches.value_of("gateway"); + log::trace!("Chosen gateway: {:?}", chosen_gateway_id); let gateway_details = gateway_details( config.get_base().get_validator_api_endpoints(), chosen_gateway_id, ) .await; + log::trace!("Used gateway: {}", gateway_details); let shared_keys = register_with_gateway(&gateway_details, key_manager.identity_keypair()).await; @@ -241,8 +244,14 @@ pub async fn execute(matches: ArgMatches<'static>) { .save_to_file(None) .expect("Failed to save the config file"); println!("Saved configuration file to {:?}", config_save_location); - println!("Using gateway: {}", config.get_base().get_gateway_id(),); - println!("Client configuration completed.\n\n\n"); + println!("Using gateway: {}", config.get_base().get_gateway_id()); + log::debug!("Gateway id: {}", config.get_base().get_gateway_id()); + log::debug!("Gateway owner: {}", config.get_base().get_gateway_owner()); + log::debug!( + "Gateway listener: {}", + config.get_base().get_gateway_listener() + ); + println!("Client configuration completed."); show_address(&config); } diff --git a/clients/native/src/commands/mod.rs b/clients/native/src/commands/mod.rs index 79e8f0e00d..f48e9fb9d7 100644 --- a/clients/native/src/commands/mod.rs +++ b/clients/native/src/commands/mod.rs @@ -43,7 +43,7 @@ pub(crate) fn override_config(mut config: Config, matches: &ArgMatches<'_>) -> C config = config.with_socket(SocketType::None); } - if let Some(port) = matches.value_of("port").map(|port| port.parse::()) { + if let Some(port) = matches.value_of("port").map(str::parse) { if let Err(err) = port { // if port was overridden, it must be parsable panic!("Invalid port value provided - {:?}", err); diff --git a/clients/native/src/commands/run.rs b/clients/native/src/commands/run.rs index 1ccbcc9ed9..14c3fe14a2 100644 --- a/clients/native/src/commands/run.rs +++ b/clients/native/src/commands/run.rs @@ -70,7 +70,9 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> { fn version_check(cfg: &Config) -> bool { let binary_version = env!("CARGO_PKG_VERSION"); let config_version = cfg.get_base().get_version(); - if binary_version != config_version { + if binary_version == config_version { + true + } else { warn!("The mixnode binary has different version than what is specified in config file! {} and {}", binary_version, config_version); if is_minor_version_compatible(binary_version, config_version) { info!("but they are still semver compatible. However, consider running the `upgrade` command"); @@ -79,8 +81,6 @@ fn version_check(cfg: &Config) -> bool { error!("and they are semver incompatible! - please run the `upgrade` command before attempting `run` again"); false } - } else { - true } } diff --git a/clients/native/src/commands/upgrade.rs b/clients/native/src/commands/upgrade.rs index 2c90840f31..446f110d47 100644 --- a/clients/native/src/commands/upgrade.rs +++ b/clients/native/src/commands/upgrade.rs @@ -131,22 +131,22 @@ fn minor_0_12_upgrade( config } -fn do_upgrade(mut config: Config, matches: &ArgMatches<'_>, package_version: Version) { +fn do_upgrade(mut config: Config, matches: &ArgMatches<'_>, package_version: &Version) { loop { let config_version = parse_config_version(&config); - if config_version == package_version { + if &config_version == package_version { println!("You're using the most recent version!"); return; } config = match config_version.major { 0 => match config_version.minor { - 9 | 10 => outdated_upgrade(&config_version, &package_version), - 11 => minor_0_12_upgrade(config, matches, &config_version, &package_version), - _ => unsupported_upgrade(&config_version, &package_version), + 9 | 10 => outdated_upgrade(&config_version, package_version), + 11 => minor_0_12_upgrade(config, matches, &config_version, package_version), + _ => unsupported_upgrade(&config_version, package_version), }, - _ => unsupported_upgrade(&config_version, &package_version), + _ => unsupported_upgrade(&config_version, package_version), } } } @@ -167,5 +167,5 @@ pub fn execute(matches: &ArgMatches<'_>) { } // here be upgrade path to 0.9.X and beyond based on version number from config - do_upgrade(existing_config, matches, package_version) + do_upgrade(existing_config, matches, &package_version) } diff --git a/clients/native/src/main.rs b/clients/native/src/main.rs index fc9a475b9b..7b3af045f5 100644 --- a/clients/native/src/main.rs +++ b/clients/native/src/main.rs @@ -108,5 +108,7 @@ fn setup_logging() { .filter_module("want", log::LevelFilter::Warn) .filter_module("tungstenite", log::LevelFilter::Warn) .filter_module("tokio_tungstenite", log::LevelFilter::Warn) + .filter_module("handlebars", log::LevelFilter::Warn) + .filter_module("sled", log::LevelFilter::Warn) .init(); } diff --git a/common/config/src/lib.rs b/common/config/src/lib.rs index 39427d5a85..10cff06548 100644 --- a/common/config/src/lib.rs +++ b/common/config/src/lib.rs @@ -15,7 +15,6 @@ pub trait NymConfig: Default + Serialize + DeserializeOwned { fn template() -> &'static str; fn config_file_name() -> String { - log::trace!("NymdConfig::config_file_name"); "config.toml".to_string() } @@ -23,7 +22,6 @@ pub trait NymConfig: Default + Serialize + DeserializeOwned { // default, most probable, implementations; can be easily overridden where required fn default_config_directory(id: Option<&str>) -> PathBuf { - log::trace!("NymdConfig::default_config_directory"); if let Some(id) = id { Self::default_root_directory().join(id).join("config") } else { @@ -32,7 +30,6 @@ pub trait NymConfig: Default + Serialize + DeserializeOwned { } fn default_data_directory(id: Option<&str>) -> PathBuf { - log::trace!("NymdConfig::default_data_path"); if let Some(id) = id { Self::default_root_directory().join(id).join("data") } else { @@ -41,7 +38,6 @@ pub trait NymConfig: Default + Serialize + DeserializeOwned { } fn default_config_file_path(id: Option<&str>) -> PathBuf { - log::trace!("NymdConfig::default_config_file_path"); Self::default_config_directory(id).join(Self::config_file_name()) } diff --git a/common/topology/src/gateway.rs b/common/topology/src/gateway.rs index bc9a569df8..57b34146e6 100644 --- a/common/topology/src/gateway.rs +++ b/common/topology/src/gateway.rs @@ -93,6 +93,16 @@ impl Node { } } +impl fmt::Display for Node { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "Node(id: {}, owner: {}, stake: {}, location: {}, host: {})", + self.identity_key, self.owner, self.stake, self.location, self.host, + ) + } +} + impl filter::Versioned for Node { fn version(&self) -> String { self.version.clone()