diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f354e83fc..cddf23bd5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ Post 1.0.0 release, the changelog format is based on [Keep a Changelog](https:// - mixnode, gateway: attempting to determine reconnection backoff to persistently failing mixnode could result in a crash ([#1260]) - mixnode: the mixnode learned how to shutdown gracefully +- mixnode: listen out for SIGTERM and SIGQUIT too, making it play nicely as a system service. - native & socks5 clients: fail early when clients try to re-init with a different gateway, which is not supported yet ([#1322]) - native & socks5 clients: rerun init will now reuse previous gateway configuration instead of failing ([#1353]) - native & socks5 clients: deduplicate big chunks of init logic diff --git a/Cargo.lock b/Cargo.lock index 54e7b3726d..595c7fe681 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1343,9 +1343,9 @@ dependencies = [ [[package]] name = "dirs" -version = "3.0.2" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30baa043103c9d0c2a57cf537cc2f35623889dc0d405e6c3cccfadbc81c71309" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" dependencies = [ "dirs-sys", ] @@ -3156,7 +3156,6 @@ dependencies = [ "rand 0.7.3", "rocket", "serde", - "serial_test", "sysinfo", "task", "tokio", @@ -5019,28 +5018,6 @@ dependencies = [ "yaml-rust", ] -[[package]] -name = "serial_test" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0bccbcf40c8938196944a3da0e133e031a33f4d6b72db3bda3cc556e361905d" -dependencies = [ - "lazy_static", - "parking_lot 0.11.2", - "serial_test_derive", -] - -[[package]] -name = "serial_test_derive" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2acd6defeddb41eb60bb468f8825d0cfd0c2a76bc03bfd235b6a1dc4f6a1ad5" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "sha-1" version = "0.8.2" diff --git a/clients/client-core/Cargo.toml b/clients/client-core/Cargo.toml index 8d2d453dac..c628d8bd44 100644 --- a/clients/client-core/Cargo.toml +++ b/clients/client-core/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -dirs = "3.0" +dirs = "4.0" futures = "0.3" humantime-serde = "1.0" log = "0.4" diff --git a/clients/native/Cargo.toml b/clients/native/Cargo.toml index 18c156975c..6028be7eb6 100644 --- a/clients/native/Cargo.toml +++ b/clients/native/Cargo.toml @@ -20,7 +20,7 @@ futures = "0.3" # bunch of futures stuff, however, now that I think about it, it url = "2.2" clap = "2.33.0" # for the command line arguments -dirs = "3.0" # for determining default store directories in config +dirs = "4.0" dotenv = "0.15.0" # for obtaining environmental variables (only used for RUST_LOG for time being) log = "0.4" # self explanatory pretty_env_logger = "0.4" # for formatting log messages diff --git a/clients/socks5/Cargo.toml b/clients/socks5/Cargo.toml index 504a5d7518..ec033a79f6 100644 --- a/clients/socks5/Cargo.toml +++ b/clients/socks5/Cargo.toml @@ -11,7 +11,7 @@ path = "src/lib.rs" [dependencies] clap = "2.33.0" -dirs = "3.0" # for determining default store directories in config +dirs = "4.0" dotenv = "0.15.0" futures = "0.3" log = "0.4" diff --git a/common/statistics/Cargo.toml b/common/statistics/Cargo.toml index 2bee2c1c39..1094962c21 100644 --- a/common/statistics/Cargo.toml +++ b/common/statistics/Cargo.toml @@ -18,4 +18,4 @@ sqlx = { version = "0.5", features = ["runtime-tokio-rustls", "chrono"]} thiserror = "1" tokio = { version = "1.19.1", features = [ "time" ] } -network-defaults = { path = "../network-defaults" } \ No newline at end of file +network-defaults = { path = "../network-defaults" } diff --git a/gateway/Cargo.toml b/gateway/Cargo.toml index 5d12664be1..d28f07c38f 100644 --- a/gateway/Cargo.toml +++ b/gateway/Cargo.toml @@ -19,7 +19,7 @@ bs58 = "0.4.0" clap = { version = "3.0.10", features = ["cargo", "derive"] } colored = "2.0" dashmap = "4.0" -dirs = "3.0" +dirs = "4.0" dotenv = "0.15.0" futures = "0.3" humantime-serde = "1.0.1" diff --git a/mixnode/Cargo.toml b/mixnode/Cargo.toml index a0ca74020b..4fb441b0ce 100644 --- a/mixnode/Cargo.toml +++ b/mixnode/Cargo.toml @@ -21,7 +21,7 @@ bs58 = "0.4.0" clap = { version = "3.0.10", features = ["cargo", "derive"] } colored = "2.0" cupid = "0.6.1" -dirs = "3.0" +dirs = "4.0" dotenv = "0.15.0" futures = "0.3.0" humantime-serde = "1.0" @@ -51,7 +51,6 @@ validator-client = { path="../common/client-libs/validator-client" } version-checker = { path="../common/version-checker" } [dev-dependencies] -serial_test = "0.5" tokio = { version="1.19.1", features = ["rt-multi-thread", "net", "signal", "test-util"] } nymsphinx-types = { path = "../common/nymsphinx/types" } diff --git a/mixnode/src/commands/init.rs b/mixnode/src/commands/init.rs index 7df9421e3c..7d848c7849 100644 --- a/mixnode/src/commands/init.rs +++ b/mixnode/src/commands/init.rs @@ -60,7 +60,7 @@ impl From for OverrideConfig { } } -pub(crate) async fn execute(args: &Init) { +pub(crate) fn execute(args: &Init) { let override_config_fields = OverrideConfig::from(args.clone()); let id = &override_config_fields.id; println!("Initialising mixnode {}...", id); diff --git a/mixnode/src/commands/mod.rs b/mixnode/src/commands/mod.rs index e4820aabed..1d924bcf63 100644 --- a/mixnode/src/commands/mod.rs +++ b/mixnode/src/commands/mod.rs @@ -52,7 +52,7 @@ struct OverrideConfig { pub(crate) async fn execute(args: Cli) { match &args.command { Commands::Describe(m) => describe::execute(m), - Commands::Init(m) => init::execute(m).await, + Commands::Init(m) => init::execute(m), Commands::Run(m) => run::execute(m).await, Commands::Sign(m) => sign::execute(m), Commands::Upgrade(m) => upgrade::execute(m), @@ -136,7 +136,9 @@ pub(crate) fn validate_bech32_address_or_exit(address: &str) { pub(crate) fn version_check(cfg: &Config) -> bool { let binary_version = env!("CARGO_PKG_VERSION"); let config_version = cfg.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 version_checker::is_minor_version_compatible(binary_version, config_version) { info!("but they are still semver compatible. However, consider running the `upgrade` command"); @@ -145,7 +147,5 @@ pub(crate) 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/mixnode/src/commands/run.rs b/mixnode/src/commands/run.rs index 983d2c008e..c0106034b9 100644 --- a/mixnode/src/commands/run.rs +++ b/mixnode/src/commands/run.rs @@ -59,7 +59,7 @@ impl From for OverrideConfig { } } -fn show_binding_warning(address: String) { +fn show_binding_warning(address: &str) { println!("\n##### NOTE #####"); println!( "\nYou are trying to bind to {} - you might not be accessible to other nodes\n\ @@ -97,7 +97,7 @@ pub(crate) async fn execute(args: &Run) { } if special_addresses().contains(&&*config.get_listening_address().to_string()) { - show_binding_warning(config.get_listening_address().to_string()); + show_binding_warning(&config.get_listening_address().to_string()); } let mut mixnode = MixNode::new(config); diff --git a/mixnode/src/node/http/hardware.rs b/mixnode/src/node/http/hardware.rs index 18543e9d37..57e2e68bbf 100644 --- a/mixnode/src/node/http/hardware.rs +++ b/mixnode/src/node/http/hardware.rs @@ -10,6 +10,7 @@ pub(crate) struct Hardware { crypto_hardware: Option, } +#[allow(clippy::struct_excessive_bools)] #[derive(Serialize, Debug)] #[serde(crate = "rocket::serde")] pub(crate) struct CryptoHardware { @@ -44,9 +45,9 @@ fn hardware_from_sysinfo(crypto_hardware: Option) -> Option { + log::info!("Received SIGINT"); + }, + _ = sigterm.recv() => { + log::info!("Received SIGTERM"); + } + _ = sigquit.recv() => { + log::info!("Received SIGQUIT"); + } + } +} + +#[cfg(not(unix))] +async fn wait_for_signal() { + tokio::select! { + _ = tokio::signal::ctrl_c() => { + log::info!("Received SIGINT"); + }, + } +} diff --git a/mixnode/src/node/node_statistics.rs b/mixnode/src/node/node_statistics.rs index 21cba5ef96..86f98401ab 100644 --- a/mixnode/src/node/node_statistics.rs +++ b/mixnode/src/node/node_statistics.rs @@ -51,14 +51,14 @@ impl SharedNodeStats { guard.update_time = snapshot_time; guard.packets_received_since_startup += new_received; - for (mix, count) in new_sent.iter() { + for (mix, count) in &new_sent { *guard .packets_sent_since_startup .entry(mix.clone()) .or_insert(0) += *count; } - for (mix, count) in new_dropped.iter() { + for (mix, count) in &new_dropped { *guard .packets_explicitly_dropped_since_last_update .entry(mix.clone()) diff --git a/service-providers/network-requester/Cargo.toml b/service-providers/network-requester/Cargo.toml index 11ff1285aa..983bfe999d 100644 --- a/service-providers/network-requester/Cargo.toml +++ b/service-providers/network-requester/Cargo.toml @@ -12,7 +12,7 @@ edition = "2021" [dependencies] async-trait = { version = "0.1.51" } clap = "2.33.0" -dirs = "3.0" +dirs = "4.0" futures = "0.3" ipnetwork = "0.17" log = "0.4" diff --git a/service-providers/network-statistics/Cargo.toml b/service-providers/network-statistics/Cargo.toml index 94e16ac6fe..d310b31fc4 100644 --- a/service-providers/network-statistics/Cargo.toml +++ b/service-providers/network-statistics/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -dirs = "3.0" +dirs = "4.0" log = "0.4" pretty_env_logger = "0.4" rocket = { version = "0.5.0-rc.2", features = ["json"] } diff --git a/validator-api/Cargo.toml b/validator-api/Cargo.toml index 6bd1f3f22e..e4cb7fc8e4 100644 --- a/validator-api/Cargo.toml +++ b/validator-api/Cargo.toml @@ -17,7 +17,7 @@ rust-version = "1.56" [dependencies] async-trait = "0.1.52" clap = "2.33.0" -dirs = "3.0" +dirs = "4.0" dotenv = "0.15.0" futures = "0.3" humantime-serde = "1.0" diff --git a/validator-api/validator-api-requests/Cargo.toml b/validator-api/validator-api-requests/Cargo.toml index d8c16f4260..1fbb6ab2ec 100644 --- a/validator-api/validator-api-requests/Cargo.toml +++ b/validator-api/validator-api-requests/Cargo.toml @@ -19,4 +19,4 @@ mixnet-contract-common = { path= ".../../../../common/cosmwasm-smart-contracts/m [features] default = [] coconut = ["coconut-interface"] -generate-ts = [] \ No newline at end of file +generate-ts = []