From 60269d65c6d375d43a4cebb1de14e0ae5026c7d7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bastian=20K=C3=B6cher?= <bkchr@users.noreply.github.com>
Date: Thu, 8 Aug 2019 09:33:45 +0200
Subject: [PATCH] Clean up CLI interface (#3334)

* Clean up CLI interface

- Removes `--validator` and `--grandpa-voter`
- Make `--alice` etc work without `--dev`

* Style fixes
---
 substrate/core/cli/src/lib.rs          | 34 ++++++---------------
 substrate/core/cli/src/params.rs       | 10 ------
 substrate/core/service/src/config.rs   |  4 ---
 substrate/core/service/test/src/lib.rs |  1 -
 substrate/node/cli/src/service.rs      | 42 ++++++++++++++------------
 5 files changed, 32 insertions(+), 59 deletions(-)

diff --git a/substrate/core/cli/src/lib.rs b/substrate/core/cli/src/lib.rs
index 6be285ee371..6c2a36121ee 100644
--- a/substrate/core/cli/src/lib.rs
+++ b/substrate/core/cli/src/lib.rs
@@ -433,14 +433,11 @@ where
 		),
 	};
 
-	let role =
-		if cli.light {
-			service::Roles::LIGHT
-		} else if cli.validator || cli.shared_params.dev {
-			service::Roles::AUTHORITY
-		} else {
-			service::Roles::FULL
-		};
+	let role = if cli.light {
+		service::Roles::LIGHT
+	} else {
+		service::Roles::AUTHORITY
+	};
 
 	let exec = cli.execution_strategies;
 	let exec_all_or = |strat: params::ExecutionStrategy| exec.execution.unwrap_or(strat).into();
@@ -461,7 +458,6 @@ where
 
 	config.roles = role;
 	config.disable_grandpa = cli.no_grandpa;
-	config.grandpa_voter = cli.grandpa_voter;
 
 	let is_dev = cli.shared_params.dev;
 
@@ -475,26 +471,16 @@ where
 		is_dev,
 	)?;
 
-	fill_transaction_pool_configuration::<F>(
-		&mut config,
-		cli.pool_config,
-	)?;
+	fill_transaction_pool_configuration::<F>(&mut config, cli.pool_config)?;
 
-	if cli.shared_params.dev {
-		config.dev_key_seed = cli.keyring.account
-			.map(|a| format!("//{}", a))
-			.or_else(|| Some("//Alice".into()));
-	}
+	config.dev_key_seed = cli.keyring.account.map(|a| format!("//{}", a));
 
 	let rpc_interface: &str = if cli.rpc_external { "0.0.0.0" } else { "127.0.0.1" };
 	let ws_interface: &str = if cli.ws_external { "0.0.0.0" } else { "127.0.0.1" };
 
-	config.rpc_http = Some(
-		parse_address(&format!("{}:{}", rpc_interface, 9933), cli.rpc_port)?
-	);
-	config.rpc_ws = Some(
-		parse_address(&format!("{}:{}", ws_interface, 9944), cli.ws_port)?
-	);
+	config.rpc_http = Some(parse_address(&format!("{}:{}", rpc_interface, 9933), cli.rpc_port)?);
+	config.rpc_ws = Some(parse_address(&format!("{}:{}", ws_interface, 9944), cli.ws_port)?);
+
 	config.rpc_ws_max_connections = cli.ws_max_connections;
 	config.rpc_cors = cli.rpc_cors.unwrap_or_else(|| if is_dev {
 		log::warn!("Running in --dev mode, RPC CORS has been disabled.");
diff --git a/substrate/core/cli/src/params.rs b/substrate/core/cli/src/params.rs
index 6f92e8c9b4d..702416aa0c4 100644
--- a/substrate/core/cli/src/params.rs
+++ b/substrate/core/cli/src/params.rs
@@ -311,19 +311,10 @@ pub struct ExecutionStrategies {
 /// The `run` command used to run a node.
 #[derive(Debug, StructOpt, Clone)]
 pub struct RunCmd {
-	/// Enable validator mode
-	#[structopt(long = "validator")]
-	pub validator: bool,
-
 	/// Disable GRANDPA when running in validator mode
 	#[structopt(long = "no-grandpa")]
 	pub no_grandpa: bool,
 
-	/// Run GRANDPA voter even when no additional key seed via `--key` is specified. This can for example be of interest
-	/// when running a sentry node in front of a validator, thus needing to forward GRANDPA gossip messages.
-	#[structopt(long = "grandpa-voter")]
-	pub grandpa_voter: bool,
-
 	/// Experimental: Run in light client mode
 	#[structopt(long = "light")]
 	pub light: bool,
@@ -505,7 +496,6 @@ impl AugmentClap for Keyring {
 					.long(&a.name)
 					.help(&a.help)
 					.conflicts_with_all(&conflicts_with_strs)
-					.requires("dev")
 					.takes_value(false)
 			)
 		})
diff --git a/substrate/core/service/src/config.rs b/substrate/core/service/src/config.rs
index b5019c82637..97eba357e3f 100644
--- a/substrate/core/service/src/config.rs
+++ b/substrate/core/service/src/config.rs
@@ -85,9 +85,6 @@ pub struct Configuration<C, G> {
 	pub force_authoring: bool,
 	/// Disable GRANDPA when running in validator mode
 	pub disable_grandpa: bool,
-	/// Run GRANDPA voter even when no additional key seed is specified. This can for example be of interest when
-	/// running a sentry node in front of a validator, thus needing to forward GRANDPA gossip messages.
-	pub grandpa_voter: bool,
 	/// Node keystore's password
 	pub keystore_password: Option<Protected<String>>,
 	/// Development key seed.
@@ -128,7 +125,6 @@ impl<C: Default, G: Serialize + DeserializeOwned + BuildStorage> Configuration<C
 			offchain_worker: Default::default(),
 			force_authoring: false,
 			disable_grandpa: false,
-			grandpa_voter: false,
 			keystore_password: None,
 			dev_key_seed: None,
 		};
diff --git a/substrate/core/service/test/src/lib.rs b/substrate/core/service/test/src/lib.rs
index b9f05af2c7f..851ed8e5ec2 100644
--- a/substrate/core/service/test/src/lib.rs
+++ b/substrate/core/service/test/src/lib.rs
@@ -190,7 +190,6 @@ fn node_config<F: ServiceFactory> (
 		offchain_worker: false,
 		force_authoring: false,
 		disable_grandpa: false,
-		grandpa_voter: false,
 		dev_key_seed: key_seed,
 	}
 }
diff --git a/substrate/node/cli/src/service.rs b/substrate/node/cli/src/service.rs
index 86247668f75..0fc97e99d5b 100644
--- a/substrate/node/cli/src/service.rs
+++ b/substrate/node/cli/src/service.rs
@@ -146,26 +146,28 @@ construct_service_factory! {
 					keystore: Some(service.keystore()),
 				};
 
-				if service.config.roles.is_authority() {
-					let telemetry_on_connect = TelemetryOnConnect {
-						telemetry_connection_sinks: service.telemetry_on_connect_stream(),
-					};
-					let grandpa_config = grandpa::GrandpaParams {
-						config: config,
-						link: link_half,
-						network: service.network(),
-						inherent_data_providers: service.config.custom.inherent_data_providers.clone(),
-						on_exit: service.on_exit(),
-						telemetry_on_connect: Some(telemetry_on_connect),
-					};
-					service.spawn_task(Box::new(grandpa::run_grandpa_voter(grandpa_config)?));
-				} else if !service.config.grandpa_voter {
-					service.spawn_task(Box::new(grandpa::run_grandpa_observer(
-						config,
-						link_half,
-						service.network(),
-						service.on_exit(),
-					)?));
+				if !service.config.disable_grandpa {
+					if service.config.roles.is_authority() {
+						let telemetry_on_connect = TelemetryOnConnect {
+							telemetry_connection_sinks: service.telemetry_on_connect_stream(),
+						};
+						let grandpa_config = grandpa::GrandpaParams {
+							config: config,
+							link: link_half,
+							network: service.network(),
+							inherent_data_providers: service.config.custom.inherent_data_providers.clone(),
+							on_exit: service.on_exit(),
+							telemetry_on_connect: Some(telemetry_on_connect),
+						};
+						service.spawn_task(Box::new(grandpa::run_grandpa_voter(grandpa_config)?));
+					} else {
+						service.spawn_task(Box::new(grandpa::run_grandpa_observer(
+							config,
+							link_half,
+							service.network(),
+							service.on_exit(),
+						)?));
+					}
 				}
 
 				Ok(service)
-- 
GitLab