From 1d1496aa49f754f14fb74c31fb9e17856ae2b899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan-=C8=98tefan=20Neac=C5=9Fu?= Date: Thu, 23 Dec 2021 11:55:01 +0200 Subject: [PATCH] Make the separation between testnet-mode and erc20 bandwidth mode clearer (#994) * Make the separation between testnet-mode and erc20 bandwidth mode more clear * Update Cargo.toml * Remove eth bw from native client under a feature flag * Remove eth bw from socks5 client under a feature flag * Remove eth bw from gateway under a feature flag * Update gateway version * Fix coconut build warnings --- Cargo.lock | 6 ++--- clients/native/Cargo.toml | 3 ++- clients/native/src/commands/init.rs | 35 ++++++++++++++++++----------- clients/native/src/commands/mod.rs | 24 +++++++++++++++++--- clients/native/src/commands/run.rs | 27 ++++++++++++---------- clients/socks5/Cargo.toml | 3 ++- clients/socks5/src/commands/init.rs | 35 ++++++++++++++++++----------- clients/socks5/src/commands/mod.rs | 24 +++++++++++++++++--- clients/socks5/src/commands/run.rs | 27 ++++++++++++---------- gateway/Cargo.toml | 3 ++- gateway/src/commands/init.rs | 12 +++++----- gateway/src/commands/mod.rs | 16 ++++++++++++- 12 files changed, 146 insertions(+), 69 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d3bfd7346c..73ac0b54e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3573,7 +3573,7 @@ dependencies = [ [[package]] name = "nym-client" -version = "0.12.0" +version = "0.12.1" dependencies = [ "clap", "client-core", @@ -3631,7 +3631,7 @@ dependencies = [ [[package]] name = "nym-gateway" -version = "0.12.0" +version = "0.12.1" dependencies = [ "bandwidth-claim-contract", "bip39", @@ -3729,7 +3729,7 @@ dependencies = [ [[package]] name = "nym-socks5-client" -version = "0.12.0" +version = "0.12.1" dependencies = [ "clap", "client-core", diff --git a/clients/native/Cargo.toml b/clients/native/Cargo.toml index 0849bcd698..fcdde9ea1c 100644 --- a/clients/native/Cargo.toml +++ b/clients/native/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "nym-client" -version = "0.12.0" +version = "0.12.1" authors = ["Dave Hrycyszyn ", "Jędrzej Stuczyński "] edition = "2018" rust-version = "1.56" @@ -48,6 +48,7 @@ network-defaults = { path = "../../common/network-defaults" } [features] coconut = ["coconut-interface", "credentials", "gateway-requests/coconut", "gateway-client/coconut"] +eth = [] [dev-dependencies] serde_json = "1.0" # for the "textsend" example diff --git a/clients/native/src/commands/init.rs b/clients/native/src/commands/init.rs index 15027dcb0f..30f202701e 100644 --- a/clients/native/src/commands/init.rs +++ b/clients/native/src/commands/init.rs @@ -30,7 +30,12 @@ use topology::{filter::VersionFilterable, gateway}; use url::Url; use crate::client::config::Config; -use crate::commands::{override_config, TESTNET_MODE_ARG_NAME}; +use crate::commands::override_config; +#[cfg(feature = "eth")] +use crate::commands::{ + DEFAULT_ETH_ENDPOINT, DEFAULT_ETH_PRIVATE_KEY, ETH_ENDPOINT_ARG_NAME, ETH_PRIVATE_KEY_ARG_NAME, + TESTNET_MODE_ARG_NAME, +}; pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> { let app = App::new("init") @@ -65,24 +70,28 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> { .long("fastmode") .hidden(true) // this will prevent this flag from being displayed in `--help` .help("Mostly debug-related option to increase default traffic rate so that you would not need to modify config post init") - ) + ); + #[cfg(feature = "eth")] + let app = app .arg( Arg::with_name(TESTNET_MODE_ARG_NAME) .long(TESTNET_MODE_ARG_NAME) - .help("Set this client to work in a testnet mode that would attempt to use gateway without bandwidth credential requirement") - ); - #[cfg(not(feature = "coconut"))] - let app = app - .arg(Arg::with_name("eth_endpoint") - .long("eth_endpoint") - .help("URL of an Ethereum full node that we want to use for getting bandwidth tokens from ERC20 tokens") + .help("Set this client to work in a testnet mode that would attempt to use gateway without bandwidth credential requirement. If this value is set, --eth_endpoint and --eth_private_key don't need to be set.") + .conflicts_with_all(&[ETH_ENDPOINT_ARG_NAME, ETH_PRIVATE_KEY_ARG_NAME]) + ) + .arg(Arg::with_name(ETH_ENDPOINT_ARG_NAME) + .long(ETH_ENDPOINT_ARG_NAME) + .help("URL of an Ethereum full node that we want to use for getting bandwidth tokens from ERC20 tokens. If you don't want to set this value, use --testnet-mode instead") .takes_value(true) + .default_value_if(TESTNET_MODE_ARG_NAME, None, DEFAULT_ETH_ENDPOINT) .required(true)) - .arg(Arg::with_name("eth_private_key") - .long("eth_private_key") - .help("Ethereum private key used for obtaining bandwidth tokens from ERC20 tokens") + .arg(Arg::with_name(ETH_PRIVATE_KEY_ARG_NAME) + .long(ETH_PRIVATE_KEY_ARG_NAME) + .help("Ethereum private key used for obtaining bandwidth tokens from ERC20 tokens. If you don't want to set this value, use --testnet-mode instead") .takes_value(true) - .required(true)); + .default_value_if(TESTNET_MODE_ARG_NAME, None, DEFAULT_ETH_PRIVATE_KEY) + .required(true) + ); app } diff --git a/clients/native/src/commands/mod.rs b/clients/native/src/commands/mod.rs index d747c76f1e..24351254e0 100644 --- a/clients/native/src/commands/mod.rs +++ b/clients/native/src/commands/mod.rs @@ -6,6 +6,16 @@ use clap::ArgMatches; use url::Url; pub(crate) const TESTNET_MODE_ARG_NAME: &str = "testnet-mode"; +#[cfg(not(feature = "coconut"))] +pub(crate) const ETH_ENDPOINT_ARG_NAME: &str = "eth_endpoint"; +#[cfg(not(feature = "coconut"))] +pub(crate) const ETH_PRIVATE_KEY_ARG_NAME: &str = "eth_private_key"; +#[cfg(not(feature = "coconut"))] +pub(crate) const DEFAULT_ETH_ENDPOINT: &str = + "https://rinkeby.infura.io/v3/00000000000000000000000000000000"; +#[cfg(not(feature = "coconut"))] +pub(crate) const DEFAULT_ETH_PRIVATE_KEY: &str = + "0000000000000000000000000000000000000000000000000000000000000001"; pub(crate) mod init; pub(crate) mod run; @@ -46,15 +56,23 @@ pub(crate) fn override_config(mut config: Config, matches: &ArgMatches) -> Confi } #[cfg(not(feature = "coconut"))] - if let Some(eth_endpoint) = matches.value_of("eth_endpoint") { + if let Some(eth_endpoint) = matches.value_of(ETH_ENDPOINT_ARG_NAME) { config.get_base_mut().with_eth_endpoint(eth_endpoint); + } else { + config + .get_base_mut() + .with_eth_endpoint(DEFAULT_ETH_ENDPOINT); } #[cfg(not(feature = "coconut"))] - if let Some(eth_private_key) = matches.value_of("eth_private_key") { + if let Some(eth_private_key) = matches.value_of(ETH_PRIVATE_KEY_ARG_NAME) { config.get_base_mut().with_eth_private_key(eth_private_key); + } else { + config + .get_base_mut() + .with_eth_private_key(DEFAULT_ETH_PRIVATE_KEY); } - if matches.is_present(TESTNET_MODE_ARG_NAME) { + if !cfg!(feature = "eth") || matches.is_present(TESTNET_MODE_ARG_NAME) { config.get_base_mut().with_testnet_mode(true) } diff --git a/clients/native/src/commands/run.rs b/clients/native/src/commands/run.rs index eaae5aecc2..b82f288293 100644 --- a/clients/native/src/commands/run.rs +++ b/clients/native/src/commands/run.rs @@ -3,7 +3,9 @@ use crate::client::config::Config; use crate::client::NymClient; -use crate::commands::{override_config, TESTNET_MODE_ARG_NAME}; +use crate::commands::override_config; +#[cfg(feature = "eth")] +use crate::commands::{ETH_ENDPOINT_ARG_NAME, ETH_PRIVATE_KEY_ARG_NAME, TESTNET_MODE_ARG_NAME}; use clap::{App, Arg, ArgMatches}; use config::NymConfig; use log::*; @@ -38,21 +40,22 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> { .long("port") .help("Port for the socket (if applicable) to listen on") .takes_value(true) - ) + ); + #[cfg(feature = "eth")] + let app = app .arg( Arg::with_name(TESTNET_MODE_ARG_NAME) .long(TESTNET_MODE_ARG_NAME) - .help("Set this client to work in a testnet mode that would attempt to use gateway without bandwidth credential requirement") - ); - #[cfg(not(feature = "coconut"))] - let app = app - .arg(Arg::with_name("eth_endpoint") - .long("eth_endpoint") - .help("URL of an Ethereum full node that we want to use for getting bandwidth tokens from ERC20 tokens") + .help("Set this client to work in a testnet mode that would attempt to use gateway without bandwidth credential requirement. If this value is set, --eth_endpoint and --eth_private_key don't need to be set.") + .conflicts_with_all(&[ETH_ENDPOINT_ARG_NAME, ETH_PRIVATE_KEY_ARG_NAME]) + ) + .arg(Arg::with_name(ETH_ENDPOINT_ARG_NAME) + .long(ETH_ENDPOINT_ARG_NAME) + .help("URL of an Ethereum full node that we want to use for getting bandwidth tokens from ERC20 tokens. If you don't want to set this value, use --testnet-mode instead") .takes_value(true)) - .arg(Arg::with_name("eth_private_key") - .long("eth_private_key") - .help("Ethereum private key used for obtaining bandwidth tokens from ERC20 tokens") + .arg(Arg::with_name(ETH_PRIVATE_KEY_ARG_NAME) + .long(ETH_PRIVATE_KEY_ARG_NAME) + .help("Ethereum private key used for obtaining bandwidth tokens from ERC20 tokens. If you don't want to set this value, use --testnet-mode instead") .takes_value(true)); app diff --git a/clients/socks5/Cargo.toml b/clients/socks5/Cargo.toml index 832777f1a9..c256c005a0 100644 --- a/clients/socks5/Cargo.toml +++ b/clients/socks5/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "nym-socks5-client" -version = "0.12.0" +version = "0.12.1" authors = ["Dave Hrycyszyn "] edition = "2018" rust-version = "1.56" @@ -43,6 +43,7 @@ network-defaults = { path = "../../common/network-defaults" } [features] coconut = ["coconut-interface", "credentials", "gateway-requests/coconut", "gateway-client/coconut"] +eth = [] [build-dependencies] vergen = { version = "5", default-features = false, features = ["build", "git", "rustc", "cargo"] } \ No newline at end of file diff --git a/clients/socks5/src/commands/init.rs b/clients/socks5/src/commands/init.rs index 574c1edab5..d58654f89e 100644 --- a/clients/socks5/src/commands/init.rs +++ b/clients/socks5/src/commands/init.rs @@ -28,7 +28,12 @@ use topology::{filter::VersionFilterable, gateway}; use url::Url; use crate::client::config::Config; -use crate::commands::{override_config, TESTNET_MODE_ARG_NAME}; +use crate::commands::override_config; +#[cfg(feature = "eth")] +use crate::commands::{ + DEFAULT_ETH_ENDPOINT, DEFAULT_ETH_PRIVATE_KEY, ETH_ENDPOINT_ARG_NAME, ETH_PRIVATE_KEY_ARG_NAME, + TESTNET_MODE_ARG_NAME, +}; pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> { let app = App::new("init") @@ -65,24 +70,28 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> { .long("fastmode") .hidden(true) // this will prevent this flag from being displayed in `--help` .help("Mostly debug-related option to increase default traffic rate so that you would not need to modify config post init") - ) + ); + #[cfg(feature = "eth")] + let app = app .arg( Arg::with_name(TESTNET_MODE_ARG_NAME) .long(TESTNET_MODE_ARG_NAME) - .help("Set this client to work in a testnet mode that would attempt to use gateway without bandwidth credential requirement") - ); - #[cfg(not(feature = "coconut"))] - let app = app - .arg(Arg::with_name("eth_endpoint") - .long("eth_endpoint") - .help("URL of an Ethereum full node that we want to use for getting bandwidth tokens from ERC20 tokens") + .help("Set this client to work in a testnet mode that would attempt to use gateway without bandwidth credential requirement. If this value is set, --eth_endpoint and --eth_private_key don't need to be set.") + .conflicts_with_all(&[ETH_ENDPOINT_ARG_NAME, ETH_PRIVATE_KEY_ARG_NAME]) + ) + .arg(Arg::with_name(ETH_ENDPOINT_ARG_NAME) + .long(ETH_ENDPOINT_ARG_NAME) + .help("URL of an Ethereum full node that we want to use for getting bandwidth tokens from ERC20 tokens. If you don't want to set this value, use --testnet-mode instead") .takes_value(true) + .default_value_if(TESTNET_MODE_ARG_NAME, None, DEFAULT_ETH_ENDPOINT) .required(true)) - .arg(Arg::with_name("eth_private_key") - .long("eth_private_key") - .help("Ethereum private key used for obtaining bandwidth tokens from ERC20 tokens") + .arg(Arg::with_name(ETH_PRIVATE_KEY_ARG_NAME) + .long(ETH_PRIVATE_KEY_ARG_NAME) + .help("Ethereum private key used for obtaining bandwidth tokens from ERC20 tokens. If you don't want to set this value, use --testnet-mode instead") .takes_value(true) - .required(true)); + .default_value_if(TESTNET_MODE_ARG_NAME, None, DEFAULT_ETH_PRIVATE_KEY) + .required(true) + ); app } diff --git a/clients/socks5/src/commands/mod.rs b/clients/socks5/src/commands/mod.rs index 09bb081f70..9804d90704 100644 --- a/clients/socks5/src/commands/mod.rs +++ b/clients/socks5/src/commands/mod.rs @@ -10,6 +10,16 @@ pub(crate) mod run; pub(crate) mod upgrade; pub(crate) const TESTNET_MODE_ARG_NAME: &str = "testnet-mode"; +#[cfg(not(feature = "coconut"))] +pub(crate) const ETH_ENDPOINT_ARG_NAME: &str = "eth_endpoint"; +#[cfg(not(feature = "coconut"))] +pub(crate) const ETH_PRIVATE_KEY_ARG_NAME: &str = "eth_private_key"; +#[cfg(not(feature = "coconut"))] +pub(crate) const DEFAULT_ETH_ENDPOINT: &str = + "https://rinkeby.infura.io/v3/00000000000000000000000000000000"; +#[cfg(not(feature = "coconut"))] +pub(crate) const DEFAULT_ETH_PRIVATE_KEY: &str = + "0000000000000000000000000000000000000000000000000000000000000001"; fn parse_validators(raw: &str) -> Vec { raw.split(',') @@ -42,15 +52,23 @@ pub(crate) fn override_config(mut config: Config, matches: &ArgMatches) -> Confi } #[cfg(not(feature = "coconut"))] - if let Some(eth_endpoint) = matches.value_of("eth_endpoint") { + if let Some(eth_endpoint) = matches.value_of(ETH_ENDPOINT_ARG_NAME) { config.get_base_mut().with_eth_endpoint(eth_endpoint); + } else { + config + .get_base_mut() + .with_eth_endpoint(DEFAULT_ETH_ENDPOINT); } #[cfg(not(feature = "coconut"))] - if let Some(eth_private_key) = matches.value_of("eth_private_key") { + if let Some(eth_private_key) = matches.value_of(ETH_PRIVATE_KEY_ARG_NAME) { config.get_base_mut().with_eth_private_key(eth_private_key); + } else { + config + .get_base_mut() + .with_eth_private_key(DEFAULT_ETH_PRIVATE_KEY); } - if matches.is_present(TESTNET_MODE_ARG_NAME) { + if !cfg!(feature = "eth") || matches.is_present(TESTNET_MODE_ARG_NAME) { config.get_base_mut().with_testnet_mode(true) } diff --git a/clients/socks5/src/commands/run.rs b/clients/socks5/src/commands/run.rs index 1880cc0ecf..befdd3997e 100644 --- a/clients/socks5/src/commands/run.rs +++ b/clients/socks5/src/commands/run.rs @@ -3,7 +3,9 @@ use crate::client::config::Config; use crate::client::NymClient; -use crate::commands::{override_config, TESTNET_MODE_ARG_NAME}; +use crate::commands::override_config; +#[cfg(feature = "eth")] +use crate::commands::{ETH_ENDPOINT_ARG_NAME, ETH_PRIVATE_KEY_ARG_NAME, TESTNET_MODE_ARG_NAME}; use clap::{App, Arg, ArgMatches}; use config::NymConfig; use log::*; @@ -44,21 +46,22 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> { .long("port") .help("Port for the socket to listen on") .takes_value(true) - ) + ); + #[cfg(feature = "eth")] + let app = app .arg( Arg::with_name(TESTNET_MODE_ARG_NAME) .long(TESTNET_MODE_ARG_NAME) - .help("Set this client to work in a testnet mode that would attempt to use gateway without bandwidth credential requirement") - ); - #[cfg(not(feature = "coconut"))] - let app = app - .arg(Arg::with_name("eth_endpoint") - .long("eth_endpoint") - .help("URL of an Ethereum full node that we want to use for getting bandwidth tokens from ERC20 tokens") + .help("Set this client to work in a testnet mode that would attempt to use gateway without bandwidth credential requirement. If this value is set, --eth_endpoint and --eth_private_key don't need to be set.") + .conflicts_with_all(&[ETH_ENDPOINT_ARG_NAME, ETH_PRIVATE_KEY_ARG_NAME]) + ) + .arg(Arg::with_name(ETH_ENDPOINT_ARG_NAME) + .long(ETH_ENDPOINT_ARG_NAME) + .help("URL of an Ethereum full node that we want to use for getting bandwidth tokens from ERC20 tokens. If you don't want to set this value, use --testnet-mode instead") .takes_value(true)) - .arg(Arg::with_name("eth_private_key") - .long("eth_private_key") - .help("Ethereum private key used for obtaining bandwidth tokens from ERC20 tokens") + .arg(Arg::with_name(ETH_PRIVATE_KEY_ARG_NAME) + .long(ETH_PRIVATE_KEY_ARG_NAME) + .help("Ethereum private key used for obtaining bandwidth tokens from ERC20 tokens. If you don't want to set this value, use --testnet-mode instead") .takes_value(true)); app diff --git a/gateway/Cargo.toml b/gateway/Cargo.toml index f316b3201c..19aca0a7b9 100644 --- a/gateway/Cargo.toml +++ b/gateway/Cargo.toml @@ -3,7 +3,7 @@ [package] name = "nym-gateway" -version = "0.12.0" +version = "0.12.1" authors = ["Dave Hrycyszyn ", "Jędrzej Stuczyński "] edition = "2018" rust-version = "1.56" @@ -52,6 +52,7 @@ version-checker = { path = "../common/version-checker" } [features] coconut = ["coconut-interface", "gateway-requests/coconut", "gateway-client/coconut"] +eth = [] [build-dependencies] tokio = { version = "1.4", features = ["rt-multi-thread", "macros"] } diff --git a/gateway/src/commands/init.rs b/gateway/src/commands/init.rs index a7464e2b0c..d73314a055 100644 --- a/gateway/src/commands/init.rs +++ b/gateway/src/commands/init.rs @@ -56,11 +56,6 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> { .help("Comma separated list of endpoints of the validators APIs") .takes_value(true), ) - .arg( - Arg::with_name(TESTNET_MODE_ARG_NAME) - .long(TESTNET_MODE_ARG_NAME) - .help("Set this gateway to work in a testnet mode that would allow clients to bypass bandwidth credential requirement") - ) .arg( Arg::with_name(WALLET_ADDRESS) .long(WALLET_ADDRESS) @@ -69,8 +64,13 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> { .required(true) ); - #[cfg(not(feature = "coconut"))] + #[cfg(feature = "eth")] let app = app + .arg( + Arg::with_name(TESTNET_MODE_ARG_NAME) + .long(TESTNET_MODE_ARG_NAME) + .help("Set this gateway to work in a testnet mode that would allow clients to bypass bandwidth credential requirement") + ) .arg(Arg::with_name(ETH_ENDPOINT) .long(ETH_ENDPOINT) .help("URL of an Ethereum full node that we want to use for getting bandwidth tokens from ERC20 tokens") diff --git a/gateway/src/commands/mod.rs b/gateway/src/commands/mod.rs index 09f0d7e0c6..aeb072c7eb 100644 --- a/gateway/src/commands/mod.rs +++ b/gateway/src/commands/mod.rs @@ -31,6 +31,14 @@ pub(crate) const DATASTORE_PATH: &str = "datastore"; pub(crate) const TESTNET_MODE_ARG_NAME: &str = "testnet-mode"; pub(crate) const WALLET_ADDRESS: &str = "wallet-address"; +#[cfg(not(feature = "coconut"))] +const DEFAULT_ETH_ENDPOINT: &str = "https://rinkeby.infura.io/v3/00000000000000000000000000000000"; +#[cfg(not(feature = "coconut"))] +const DEFAULT_VALIDATOR_ENDPOINT: &str = "http://localhost:26657"; +// A dummy mnemonic +#[cfg(not(feature = "coconut"))] +const DEFAULT_MNEMONIC: &str = "typical regret aware used tennis noise resource crisp defy join donate orient army item immense clean emerge globe gift chronic loan flat enter egg"; + fn parse_validators(raw: &str) -> Vec { raw.split(',') .map(|raw_validator| { @@ -85,11 +93,15 @@ pub(crate) fn override_config(mut config: Config, matches: &ArgMatches) -> Confi #[cfg(not(feature = "coconut"))] if let Some(raw_validators) = matches.value_of(VALIDATORS_ARG_NAME) { config = config.with_custom_validator_nymd(parse_validators(raw_validators)); + } else { + config = config.with_custom_validator_nymd(parse_validators(DEFAULT_VALIDATOR_ENDPOINT)); } #[cfg(not(feature = "coconut"))] if let Some(cosmos_mnemonic) = matches.value_of(COSMOS_MNEMONIC) { config = config.with_cosmos_mnemonic(String::from(cosmos_mnemonic)); + } else { + config = config.with_cosmos_mnemonic(String::from(DEFAULT_MNEMONIC)); } if let Some(datastore_path) = matches.value_of(DATASTORE_PATH) { @@ -99,6 +111,8 @@ pub(crate) fn override_config(mut config: Config, matches: &ArgMatches) -> Confi #[cfg(not(feature = "coconut"))] if let Some(eth_endpoint) = matches.value_of(ETH_ENDPOINT) { config = config.with_eth_endpoint(String::from(eth_endpoint)); + } else { + config = config.with_eth_endpoint(String::from(DEFAULT_ETH_ENDPOINT)); } if let Some(wallet_address) = matches.value_of(WALLET_ADDRESS) { @@ -107,7 +121,7 @@ pub(crate) fn override_config(mut config: Config, matches: &ArgMatches) -> Confi config = config.with_wallet_address(trimmed); } - if matches.is_present(TESTNET_MODE_ARG_NAME) { + if !cfg!(feature = "eth") || matches.is_present(TESTNET_MODE_ARG_NAME) { config.with_testnet_mode(true) } else { config