Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
13 changes: 8 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 27 additions & 42 deletions core/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ fn fill_network_configuration(
Ok(())
}

fn input_keystore_password() -> Result<String, String> {
rpassword::read_password_from_tty(Some("Keystore password: "))
fn input_password(prompt: &str) -> Result<String, String> {
rpassword::read_password_from_tty(Some(prompt))
.map_err(|e| format!("{:?}", e))
}

Expand All @@ -375,9 +375,6 @@ where
{
let spec = load_spec(&cli.shared_params, spec_factory)?;
let mut config = service::Configuration::default_with_spec(spec.clone());
if cli.interactive_password {
config.password = input_keystore_password()?.into()
}

config.impl_name = impl_name;
config.impl_commit = version.commit;
Expand All @@ -401,8 +398,6 @@ where

let base_path = base_path(&cli.shared_params, version);

config.keystore_path = cli.keystore_path.or_else(|| Some(keystore_path(&base_path, config.chain_spec.id())));

config.database_path = db_path(&base_path, config.chain_spec.id());
config.database_cache_size = cli.database_cache_size;
config.state_cache_size = cli.state_cache_size;
Expand All @@ -414,15 +409,6 @@ 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 exec = cli.execution_strategies;
let exec_all_or = |strat: params::ExecutionStrategy| exec.execution.unwrap_or(strat).into();
config.execution_strategies = ExecutionStrategies {
Expand All @@ -433,19 +419,30 @@ where
other: exec_all_or(exec.execution_other),
};

config.offchain_worker = match (cli.offchain_worker, role) {
(params::OffchainWorkerEnabled::WhenValidating, service::Roles::AUTHORITY) => true,
let is_dev = cli.shared_params.dev;

config.aura = cli.aura || cli.validator || is_dev;
config.grandpa_voter = cli.grandpa_voter || cli.validator || is_dev;

config.roles = if cli.light {
service::Roles::LIGHT
} else if config.aura {
service::Roles::AUTHORITY
} else {
service::Roles::FULL
};

config.offchain_worker = match (cli.offchain_worker, config.aura) {
(params::OffchainWorkerEnabled::WhenValidating, true) => true,
(params::OffchainWorkerEnabled::Always, _) => true,
(params::OffchainWorkerEnabled::Never, _) => false,
(params::OffchainWorkerEnabled::WhenValidating, _) => false,
};

config.roles = role;
config.disable_grandpa = cli.no_grandpa;
config.grandpa_voter = cli.grandpa_voter;


let is_dev = cli.shared_params.dev;
if cli.offchain_worker_password {
config.offchain_worker_password =
input_password("Offchain worker password: ")?.into()
}

let client_id = config.client_id();
fill_network_configuration(
Expand All @@ -462,16 +459,12 @@ where
cli.pool_config,
)?;

if let Some(key) = cli.key {
config.keys.push(key);
config.key = cli.key;
if config.key.is_none() {
config.key = cli.keyring.account.map(|account| format!("//{}", account));
}

if cli.shared_params.dev && cli.keyring.account.is_none() {
config.keys.push("//Alice".into());
}

if let Some(account) = cli.keyring.account {
config.keys.push(format!("//{}", account));
if is_dev && config.key.is_none() {
config.key = Some("//Alice".into());
}

let rpc_interface: &str = if cli.rpc_external { "0.0.0.0" } else { "127.0.0.1" };
Expand Down Expand Up @@ -506,7 +499,7 @@ where
}

// Imply forced authoring on --dev
config.force_authoring = cli.shared_params.dev || cli.force_authoring;
config.force_authoring = cli.force_authoring || is_dev;

Ok(config)
}
Expand Down Expand Up @@ -721,14 +714,6 @@ fn parse_address(
Ok(address)
}

fn keystore_path(base_path: &Path, chain_id: &str) -> PathBuf {
let mut path = base_path.to_owned();
path.push("chains");
path.push(chain_id);
path.push("keystore");
path
}

fn db_path(base_path: &Path, chain_id: &str) -> PathBuf {
let mut path = base_path.to_owned();
path.push("chains");
Expand Down
21 changes: 8 additions & 13 deletions core/cli/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,24 +305,19 @@ pub struct ExecutionStrategies {
/// The `run` command used to run a node.
#[derive(Debug, StructOpt, Clone)]
pub struct RunCmd {
/// Specify custom keystore path
#[structopt(long = "keystore-path", value_name = "PATH", parse(from_os_str))]
pub keystore_path: Option<PathBuf>,

/// Specify additional key seed
#[structopt(long = "key", value_name = "STRING")]
pub key: Option<String>,

/// Enable validator mode
/// Shortcut for `--aura` and `--grandpa-voter`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this switch on --babe instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These flags should me moved to the node and not be in core

#[structopt(long = "validator")]
pub validator: bool,

/// Disable GRANDPA when running in validator mode
#[structopt(long = "no-grandpa")]
pub no_grandpa: bool,
/// Enable AURA.
#[structopt(long = "aura")]
pub aura: 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.
/// Enable GRANDPA voter.
#[structopt(long = "grandpa-voter")]
pub grandpa_voter: bool,

Expand Down Expand Up @@ -421,9 +416,9 @@ pub struct RunCmd {
#[structopt(long = "force-authoring")]
pub force_authoring: bool,

/// Interactive password for validator key.
#[structopt(short = "i")]
pub interactive_password: bool,
/// Interactive password for offchain worker keys
#[structopt(long = "offchain-worker-password")]
pub offchain_worker_password: bool,
}

/// Stores all required Cli values for a keyring test account.
Expand Down
2 changes: 2 additions & 0 deletions core/consensus/aura/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ futures = "0.1.17"
tokio-timer = "0.2.11"
parking_lot = "0.8.0"
log = "0.4"
keystore = { package = "substrate-keystore", path = "../../keystore" }
offchain = { package = "substrate-offchain", path = "../../offchain" }

[dev-dependencies]
futures03 = { package = "futures-preview", version = "0.3.0-alpha.17", features = ["compat"] }
Expand Down
Loading