connection-tester: refine log statements
This commit is contained in:
Generated
+1
@@ -6068,6 +6068,7 @@ dependencies = [
|
||||
"base64",
|
||||
"bip39",
|
||||
"coconut-interface",
|
||||
"colored",
|
||||
"config",
|
||||
"cosmrs",
|
||||
"cosmwasm-std",
|
||||
|
||||
@@ -9,6 +9,7 @@ rust-version = "1.56"
|
||||
|
||||
[dependencies]
|
||||
base64 = "0.13"
|
||||
colored = "2.0"
|
||||
mixnet-contract-common = { path= "../../cosmwasm-smart-contracts/mixnet-contract" }
|
||||
vesting-contract-common = { path= "../../cosmwasm-smart-contracts/vesting-contract" }
|
||||
vesting-contract = { path = "../../../contracts/vesting" }
|
||||
|
||||
@@ -3,6 +3,7 @@ use crate::nymd::{NymdClient, QueryNymdClient};
|
||||
use crate::ApiClient;
|
||||
use network_defaults::all::Network;
|
||||
|
||||
use colored::Colorize;
|
||||
use core::fmt;
|
||||
use itertools::Itertools;
|
||||
use std::collections::HashMap;
|
||||
@@ -84,7 +85,6 @@ async fn test_nymd_connection(
|
||||
url: &Url,
|
||||
client: &NymdClient<QueryNymdClient>,
|
||||
) -> ConnectionResult {
|
||||
log::info!("{network}: {url}: checking nymd connection");
|
||||
let result = match timeout(
|
||||
Duration::from_secs(CONNECTION_TEST_TIMEOUT_SEC),
|
||||
client.get_mixnet_contract_version(),
|
||||
@@ -93,30 +93,39 @@ async fn test_nymd_connection(
|
||||
{
|
||||
Ok(Err(NymdError::TendermintError(e))) => {
|
||||
// If we get a tendermint-rpc error, we classify the node as not contactable
|
||||
log::debug!("{network}: {url}: nymd connection test failed: {}", e);
|
||||
log::debug!("Checking: nymd_url: {network}: {url}: failed: {}", e);
|
||||
false
|
||||
}
|
||||
Ok(Err(NymdError::AbciError(code, log))) => {
|
||||
// We accept the mixnet contract not found as ok from a connection standpoint. This happens
|
||||
// for example on a pre-launch network.
|
||||
log::debug!("{network}: {url}: nymd abci error: {code}: {log}");
|
||||
log::debug!(
|
||||
"Checking: nymd_url: {network}: {url}: {}, but with abci error: {code}: {log}",
|
||||
"success".green()
|
||||
);
|
||||
code == 18
|
||||
}
|
||||
Ok(Err(error @ NymdError::NoContractAddressAvailable)) => {
|
||||
log::debug!("{network}: {url}: nymd connection test failed: {error}");
|
||||
log::debug!(
|
||||
"Checking: nymd_url: {network}: {url}: {}: {error}",
|
||||
"failed".red()
|
||||
);
|
||||
false
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
// For any other error, we're optimistic and just try anyway.
|
||||
log::debug!("{network}: {url}: nymd connection test response ok, but with error: {e}");
|
||||
log::debug!(
|
||||
"Checking: nymd_url: {network}: {url}: {}, but with error: {e}",
|
||||
"success".green()
|
||||
);
|
||||
true
|
||||
}
|
||||
Ok(Ok(_)) => {
|
||||
log::debug!("{network}: {url}: nymd connection test successful");
|
||||
log::debug!("Checking: nymd_url: {network}: {url}: {}", "success".green());
|
||||
true
|
||||
}
|
||||
Err(e) => {
|
||||
log::debug!("{network}: {url}: nymd connection test failed: {e}");
|
||||
log::debug!("Checking: nymd_url: {network}: {url}: {}: {e}", "failed".red());
|
||||
false
|
||||
}
|
||||
};
|
||||
@@ -124,7 +133,6 @@ async fn test_nymd_connection(
|
||||
}
|
||||
|
||||
async fn test_api_connection(network: Network, url: &Url, client: &ApiClient) -> ConnectionResult {
|
||||
log::info!("{network}: {url}: checking api connection");
|
||||
let result = match timeout(
|
||||
Duration::from_secs(CONNECTION_TEST_TIMEOUT_SEC),
|
||||
client.get_cached_mixnodes(),
|
||||
@@ -132,15 +140,21 @@ async fn test_api_connection(network: Network, url: &Url, client: &ApiClient) ->
|
||||
.await
|
||||
{
|
||||
Ok(Ok(_)) => {
|
||||
log::debug!("{network}: {url}: api connection test successful");
|
||||
log::debug!("Checking: api_url: {network}: {url}: {}", "success".green());
|
||||
true
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
log::debug!("{network}: {url}: api connection test failed: {e}");
|
||||
log::debug!(
|
||||
"Checking: api_url: {network}: {url}: {}: {e}",
|
||||
"failed".red()
|
||||
);
|
||||
false
|
||||
}
|
||||
Err(e) => {
|
||||
log::debug!("{network}: {url}: api connection test failed: {e}");
|
||||
log::debug!(
|
||||
"Checking: api_url: {network}: {url}: {}: {e}",
|
||||
"failed".red()
|
||||
);
|
||||
false
|
||||
}
|
||||
};
|
||||
|
||||
Generated
+13
@@ -551,6 +551,17 @@ dependencies = [
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "colored"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"lazy_static",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "config"
|
||||
version = "0.1.0"
|
||||
@@ -2755,6 +2766,7 @@ dependencies = [
|
||||
"bip39",
|
||||
"cfg-if",
|
||||
"coconut-interface",
|
||||
"colored",
|
||||
"config",
|
||||
"cosmrs",
|
||||
"cosmwasm-std",
|
||||
@@ -5114,6 +5126,7 @@ dependencies = [
|
||||
"base64",
|
||||
"bip39",
|
||||
"coconut-interface",
|
||||
"colored",
|
||||
"config",
|
||||
"cosmrs",
|
||||
"cosmwasm-std",
|
||||
|
||||
@@ -21,6 +21,7 @@ tauri-macros = "=1.0.0-rc.1"
|
||||
[dependencies]
|
||||
bip39 = "1.0"
|
||||
cfg-if = "1.0.0"
|
||||
colored = "2.0"
|
||||
dirs = "4.0"
|
||||
dotenv = "0.15.0"
|
||||
eyre = "0.6.5"
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
use crate::{error::BackendError, network::Network as WalletNetwork};
|
||||
use config::defaults::{all::SupportedNetworks, ValidatorDetails};
|
||||
use config::NymConfig;
|
||||
use core::fmt;
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::time::Duration;
|
||||
@@ -173,6 +174,7 @@ impl Config {
|
||||
.send()
|
||||
.await?;
|
||||
self.base.fetched_validators = serde_json::from_str(&response.text().await?)?;
|
||||
log::debug!("Received validator urls: \n{}", self.base.fetched_validators);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -197,6 +199,14 @@ impl TryFrom<ValidatorDetails> for ValidatorUrl {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ValidatorUrl {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let s1 = format!("nymd_url: {}", self.nymd_url);
|
||||
let s2 = self.api_url.as_ref().map(|url| format!(", api_url: {}", url));
|
||||
write!(f, " {}{},", s1, s2.unwrap_or_default())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct OptionalValidators {
|
||||
@@ -219,6 +229,27 @@ impl OptionalValidators {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for OptionalValidators {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let s1 = self
|
||||
.mainnet
|
||||
.as_ref()
|
||||
.map(|validators| format!("mainnet: [\n{}\n]", validators.iter().format("\n")))
|
||||
.unwrap_or_default();
|
||||
let s2 = self
|
||||
.sandbox
|
||||
.as_ref()
|
||||
.map(|validators| format!(",\nsandbox: [\n{}\n]", validators.iter().format("\n")))
|
||||
.unwrap_or_default();
|
||||
let s3 = self
|
||||
.qa
|
||||
.as_ref()
|
||||
.map(|validators| format!(",\nqa: [\n{}\n]", validators.iter().format("\n")))
|
||||
.unwrap_or_default();
|
||||
write!(f, "{}{}{}", s1, s2, s3)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -10,6 +10,7 @@ use bip39::{Language, Mnemonic};
|
||||
use config::defaults::all::Network;
|
||||
use config::defaults::COSMOS_DERIVATION_PATH;
|
||||
use cosmrs::bip32::DerivationPath;
|
||||
use itertools::Itertools;
|
||||
use rand::seq::SliceRandom;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
@@ -163,6 +164,13 @@ async fn _connect_with_mnemonic(
|
||||
update_validator_urls(state.clone()).await?;
|
||||
let config = state.read().await.config();
|
||||
|
||||
for network in WalletNetwork::iter() {
|
||||
log::debug!(
|
||||
"List of validators for {network}: [\n{}\n]",
|
||||
config.get_validators(network).format(",\n")
|
||||
);
|
||||
}
|
||||
|
||||
// Run connection tests on all nymd and validator-api endpoints
|
||||
let (nymd_urls, api_urls) = {
|
||||
let mixnet_contract_address = WalletNetwork::iter()
|
||||
@@ -226,7 +234,7 @@ fn select_random_responding_nymd_url(
|
||||
nymd_urls.choose(&mut rand::thread_rng()).cloned()
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
log::debug!("{network}: nymd_url: using default");
|
||||
log::debug!("No passing nymd_urls for {network}: using default");
|
||||
config
|
||||
.get_nymd_urls(network)
|
||||
.next()
|
||||
@@ -249,7 +257,7 @@ fn select_first_responding_api_url(
|
||||
.find_map(|(url, result)| if *result { Some(url.clone()) } else { None })
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
log::debug!("{network}: api_url: using default");
|
||||
log::debug!("No passing api_urls for {network}: using default");
|
||||
config
|
||||
.get_api_urls(network)
|
||||
.next()
|
||||
@@ -268,8 +276,8 @@ fn create_clients(
|
||||
let nymd_url = select_random_responding_nymd_url(nymd_urls, network, config);
|
||||
let api_url = select_first_responding_api_url(api_urls, network, config);
|
||||
|
||||
log::info!("{network}: nymd_url: using: {nymd_url}");
|
||||
log::info!("{network}: api_url: using: {api_url}");
|
||||
log::info!("Connecting to: nymd_url: {nymd_url} for {network}");
|
||||
log::info!("Connecting to: api_url: {api_url} for {network}");
|
||||
|
||||
let client = validator_client::Client::new_signing(
|
||||
validator_client::Config::new(
|
||||
|
||||
Reference in New Issue
Block a user