2019-01-07 11:33:07 +01:00
|
|
|
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
|
|
|
// This file is part of Parity Ethereum.
|
2016-04-21 16:45:04 +02:00
|
|
|
|
2019-01-07 11:33:07 +01:00
|
|
|
// Parity Ethereum is free software: you can redistribute it and/or modify
|
2016-04-21 16:45:04 +02:00
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
2019-01-07 11:33:07 +01:00
|
|
|
// Parity Ethereum is distributed in the hope that it will be useful,
|
2016-04-21 16:45:04 +02:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
2019-01-07 11:33:07 +01:00
|
|
|
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
2016-04-21 16:45:04 +02:00
|
|
|
|
2016-06-29 16:26:19 +02:00
|
|
|
use std::time::Duration;
|
2017-10-10 17:42:20 +02:00
|
|
|
use std::io::Read;
|
2019-07-03 09:44:32 +02:00
|
|
|
use std::net::{SocketAddr, ToSocketAddrs};
|
2018-07-11 12:19:54 +02:00
|
|
|
use std::path::PathBuf;
|
2019-01-28 11:26:11 +01:00
|
|
|
use std::collections::{HashSet, BTreeMap};
|
|
|
|
use std::iter::FromIterator;
|
2018-04-13 17:34:27 +02:00
|
|
|
use std::cmp;
|
2016-09-11 11:52:12 +02:00
|
|
|
use cli::{Args, ArgsError};
|
2017-08-31 11:35:41 +02:00
|
|
|
use hash::keccak;
|
2018-01-10 13:35:18 +01:00
|
|
|
use ethereum_types::{U256, H256, Address};
|
2017-12-22 14:37:39 +01:00
|
|
|
use parity_version::{version_data, version};
|
2017-09-06 20:47:45 +02:00
|
|
|
use bytes::Bytes;
|
2017-09-01 16:57:57 +02:00
|
|
|
use ansi_term::Colour;
|
2018-04-10 12:13:49 +02:00
|
|
|
use sync::{NetworkConfiguration, validate_node_url, self};
|
2019-10-23 13:03:46 +02:00
|
|
|
use parity_crypto::publickey::{Secret, Public};
|
2018-04-13 17:34:27 +02:00
|
|
|
use ethcore::miner::{stratum, MinerOptions};
|
2019-09-03 11:29:25 +02:00
|
|
|
use snapshot::SnapshotConfiguration;
|
2018-04-13 17:34:27 +02:00
|
|
|
use miner::pool;
|
2019-08-28 10:09:42 +02:00
|
|
|
use verification::queue::VerifierSettings;
|
2016-07-25 16:09:47 +02:00
|
|
|
|
2018-06-06 10:05:52 +02:00
|
|
|
use rpc::{IpcConfiguration, HttpConfiguration, WsConfiguration};
|
2017-04-13 16:32:07 +02:00
|
|
|
use parity_rpc::NetworkSettings;
|
2016-07-25 16:09:47 +02:00
|
|
|
use cache::CacheConfig;
|
2019-02-07 14:34:24 +01:00
|
|
|
use helpers::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_price, geth_ipc_path, parity_ipc_path, to_bootnodes, to_addresses, to_address, to_queue_strategy, to_queue_penalization};
|
2017-12-24 09:34:43 +01:00
|
|
|
use dir::helpers::{replace_home, replace_home_and_local};
|
2017-10-24 12:25:34 +02:00
|
|
|
use params::{ResealPolicy, AccountsConfig, GasPricerConfig, MinerExtras, SpecType};
|
2016-07-25 16:09:47 +02:00
|
|
|
use ethcore_logger::Config as LogConfig;
|
2017-01-18 18:45:30 +01:00
|
|
|
use dir::{self, Directories, default_hypervisor_path, default_local_path, default_data_path};
|
2017-02-16 14:41:33 +01:00
|
|
|
use ipfs::Configuration as IpfsConfiguration;
|
2018-04-09 16:14:33 +02:00
|
|
|
use ethcore_private_tx::{ProviderConfig, EncryptorConfig};
|
2017-11-24 10:33:33 +01:00
|
|
|
use secretstore::{NodeSecretKey, Configuration as SecretStoreConfiguration, ContractAddress as SecretStoreContractAddress};
|
2016-12-15 18:51:59 +01:00
|
|
|
use updater::{UpdatePolicy, UpdateFilter, ReleaseTrack};
|
2016-07-25 16:09:47 +02:00
|
|
|
use run::RunCmd;
|
2019-09-09 13:46:05 +02:00
|
|
|
use types::data_format::DataFormat;
|
|
|
|
use blockchain::{BlockchainCmd, ImportBlockchain, ExportBlockchain, KillBlockchain, ExportState, ResetBlockchain};
|
2018-03-27 13:56:59 +02:00
|
|
|
use export_hardcoded_sync::ExportHsyncCmd;
|
2016-07-25 16:09:47 +02:00
|
|
|
use presale::ImportWallet;
|
2016-12-12 16:51:07 +01:00
|
|
|
use account::{AccountCmd, NewAccount, ListAccounts, ImportAccounts, ImportFromGethAccounts};
|
2019-09-03 11:29:25 +02:00
|
|
|
use snapshot_cmd::{self, SnapshotCommand};
|
2017-07-28 19:06:39 +02:00
|
|
|
use network::{IpFilter};
|
2016-07-25 16:09:47 +02:00
|
|
|
|
2018-04-03 16:51:57 +02:00
|
|
|
const DEFAULT_MAX_PEERS: u16 = 50;
|
|
|
|
const DEFAULT_MIN_PEERS: u16 = 25;
|
2019-10-29 12:18:30 +01:00
|
|
|
pub const ETHERSCAN_ETH_PRICE_ENDPOINT: &str = "https://api.etherscan.io/api?module=stats&action=ethprice";
|
2018-04-03 16:51:57 +02:00
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub enum Cmd {
|
|
|
|
Run(RunCmd),
|
|
|
|
Version,
|
|
|
|
Account(AccountCmd),
|
|
|
|
ImportPresaleWallet(ImportWallet),
|
|
|
|
Blockchain(BlockchainCmd),
|
2018-06-06 10:05:52 +02:00
|
|
|
SignerToken(WsConfiguration, LogConfig),
|
2016-09-20 12:19:07 +02:00
|
|
|
SignerSign {
|
|
|
|
id: Option<usize>,
|
|
|
|
pwfile: Option<PathBuf>,
|
|
|
|
port: u16,
|
|
|
|
authfile: PathBuf,
|
|
|
|
},
|
|
|
|
SignerList {
|
|
|
|
port: u16,
|
|
|
|
authfile: PathBuf
|
|
|
|
},
|
|
|
|
SignerReject {
|
2016-09-30 15:30:17 +02:00
|
|
|
id: Option<usize>,
|
2016-09-20 12:19:07 +02:00
|
|
|
port: u16,
|
|
|
|
authfile: PathBuf
|
|
|
|
},
|
2016-08-05 17:00:46 +02:00
|
|
|
Snapshot(SnapshotCommand),
|
2016-09-23 15:28:09 +02:00
|
|
|
Hash(Option<String>),
|
2018-03-27 13:56:59 +02:00
|
|
|
ExportHardcodedSync(ExportHsyncCmd),
|
2016-04-21 16:45:04 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 19:42:21 +01:00
|
|
|
pub struct Execute {
|
|
|
|
pub logger: LogConfig,
|
|
|
|
pub cmd: Cmd,
|
|
|
|
}
|
|
|
|
|
2018-05-09 08:47:21 +02:00
|
|
|
/// Configuration for the Parity client.
|
2016-07-25 16:09:47 +02:00
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub struct Configuration {
|
2018-05-09 08:47:21 +02:00
|
|
|
/// Arguments to be interpreted.
|
2016-07-25 16:09:47 +02:00
|
|
|
pub args: Args,
|
2016-05-13 17:32:32 +02:00
|
|
|
}
|
|
|
|
|
2016-04-21 16:45:04 +02:00
|
|
|
impl Configuration {
|
2018-05-09 08:47:21 +02:00
|
|
|
/// Parses a configuration from a list of command line arguments.
|
|
|
|
///
|
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
/// ```
|
2018-07-11 13:35:10 +02:00
|
|
|
/// let _cfg = parity_ethereum::Configuration::parse_cli(&["--light", "--chain", "kovan"]).unwrap();
|
2018-05-09 08:47:21 +02:00
|
|
|
/// ```
|
|
|
|
pub fn parse_cli<S: AsRef<str>>(command: &[S]) -> Result<Self, ArgsError> {
|
2016-07-25 16:09:47 +02:00
|
|
|
let config = Configuration {
|
2018-05-09 08:47:21 +02:00
|
|
|
args: Args::parse(command)?,
|
2016-07-25 16:09:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Ok(config)
|
|
|
|
}
|
|
|
|
|
2018-05-09 08:47:21 +02:00
|
|
|
pub(crate) fn into_command(self) -> Result<Execute, String> {
|
2016-07-25 16:09:47 +02:00
|
|
|
let dirs = self.directories();
|
2017-09-05 13:30:22 +02:00
|
|
|
let pruning = self.args.arg_pruning.parse()?;
|
|
|
|
let pruning_history = self.args.arg_pruning_history;
|
2017-10-24 12:25:34 +02:00
|
|
|
let spec = self.chain()?;
|
2017-09-05 13:30:22 +02:00
|
|
|
let mode = match self.args.arg_mode.as_ref() {
|
2017-03-13 12:10:53 +01:00
|
|
|
"last" => None,
|
2017-09-05 13:30:22 +02:00
|
|
|
mode => Some(to_mode(&mode, self.args.arg_mode_timeout, self.args.arg_mode_alarm)?),
|
2017-03-13 12:10:53 +01:00
|
|
|
};
|
2016-12-27 12:53:56 +01:00
|
|
|
let update_policy = self.update_policy()?;
|
2016-07-25 16:09:47 +02:00
|
|
|
let logger_config = self.logger_config();
|
2017-04-13 16:32:07 +02:00
|
|
|
let ws_conf = self.ws_config()?;
|
2018-09-13 12:58:49 +02:00
|
|
|
let snapshot_conf = self.snapshot_config()?;
|
2016-12-27 12:53:56 +01:00
|
|
|
let http_conf = self.http_config()?;
|
|
|
|
let ipc_conf = self.ipc_config()?;
|
|
|
|
let net_conf = self.net_config()?;
|
2016-11-03 22:22:25 +01:00
|
|
|
let network_id = self.network_id();
|
2016-07-25 16:09:47 +02:00
|
|
|
let cache_config = self.cache_config();
|
2017-09-05 13:30:22 +02:00
|
|
|
let tracing = self.args.arg_tracing.parse()?;
|
|
|
|
let fat_db = self.args.arg_fat_db.parse()?;
|
|
|
|
let compaction = self.args.arg_db_compaction.parse()?;
|
2017-10-10 17:42:20 +02:00
|
|
|
let warp_sync = !self.args.flag_no_warp;
|
2016-07-25 16:09:47 +02:00
|
|
|
let geth_compatibility = self.args.flag_geth;
|
2018-11-16 14:00:34 +01:00
|
|
|
let experimental_rpcs = self.args.flag_jsonrpc_experimental;
|
2017-02-16 14:41:33 +01:00
|
|
|
let ipfs_conf = self.ipfs_config();
|
2017-04-08 11:26:16 +02:00
|
|
|
let secretstore_conf = self.secretstore_config()?;
|
2016-12-27 12:53:56 +01:00
|
|
|
let format = self.format()?;
|
2019-05-28 07:50:10 +02:00
|
|
|
|
|
|
|
let key_iterations = self.args.arg_keys_iterations;
|
|
|
|
if key_iterations == 0 {
|
|
|
|
return Err("--key-iterations must be non-zero".into());
|
|
|
|
}
|
2016-07-25 16:09:47 +02:00
|
|
|
|
|
|
|
let cmd = if self.args.flag_version {
|
|
|
|
Cmd::Version
|
2016-09-20 12:19:07 +02:00
|
|
|
} else if self.args.cmd_signer {
|
2017-05-24 12:24:07 +02:00
|
|
|
let authfile = ::signer::codes_path(&ws_conf.signer_path);
|
2016-09-20 12:19:07 +02:00
|
|
|
|
2017-09-05 13:30:22 +02:00
|
|
|
if self.args.cmd_signer_new_token {
|
2018-06-06 10:05:52 +02:00
|
|
|
Cmd::SignerToken(ws_conf, logger_config.clone())
|
2017-09-05 13:30:22 +02:00
|
|
|
} else if self.args.cmd_signer_sign {
|
2018-04-09 16:34:47 +02:00
|
|
|
let pwfile = self.accounts_config()?.password_files.first().map(|pwfile| {
|
2016-09-30 15:30:17 +02:00
|
|
|
PathBuf::from(pwfile)
|
|
|
|
});
|
2016-09-20 12:19:07 +02:00
|
|
|
Cmd::SignerSign {
|
2017-09-05 13:30:22 +02:00
|
|
|
id: self.args.arg_signer_sign_id,
|
2016-09-20 12:19:07 +02:00
|
|
|
pwfile: pwfile,
|
2017-05-24 12:24:07 +02:00
|
|
|
port: ws_conf.port,
|
2016-09-20 12:19:07 +02:00
|
|
|
authfile: authfile,
|
|
|
|
}
|
2018-09-12 11:47:01 +02:00
|
|
|
} else if self.args.cmd_signer_reject {
|
2016-09-20 12:19:07 +02:00
|
|
|
Cmd::SignerReject {
|
2017-09-05 13:30:22 +02:00
|
|
|
id: self.args.arg_signer_reject_id,
|
2017-05-24 12:24:07 +02:00
|
|
|
port: ws_conf.port,
|
2016-09-20 12:19:07 +02:00
|
|
|
authfile: authfile,
|
|
|
|
}
|
2018-09-12 11:47:01 +02:00
|
|
|
} else if self.args.cmd_signer_list {
|
2016-09-20 12:19:07 +02:00
|
|
|
Cmd::SignerList {
|
2017-05-24 12:24:07 +02:00
|
|
|
port: ws_conf.port,
|
2016-09-20 12:19:07 +02:00
|
|
|
authfile: authfile,
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
unreachable!();
|
|
|
|
}
|
2017-09-05 13:30:22 +02:00
|
|
|
} else if self.args.cmd_tools && self.args.cmd_tools_hash {
|
|
|
|
Cmd::Hash(self.args.arg_tools_hash_file)
|
2019-01-16 16:37:26 +01:00
|
|
|
} else if self.args.cmd_db && self.args.cmd_db_reset {
|
|
|
|
Cmd::Blockchain(BlockchainCmd::Reset(ResetBlockchain {
|
|
|
|
dirs,
|
|
|
|
spec,
|
|
|
|
pruning,
|
|
|
|
pruning_history,
|
|
|
|
pruning_memory: self.args.arg_pruning_memory,
|
|
|
|
tracing,
|
|
|
|
fat_db,
|
|
|
|
compaction,
|
|
|
|
cache_config,
|
|
|
|
num: self.args.arg_db_reset_num,
|
|
|
|
}))
|
2017-09-05 13:30:22 +02:00
|
|
|
} else if self.args.cmd_db && self.args.cmd_db_kill {
|
2016-12-12 17:19:41 +01:00
|
|
|
Cmd::Blockchain(BlockchainCmd::Kill(KillBlockchain {
|
|
|
|
spec: spec,
|
|
|
|
dirs: dirs,
|
|
|
|
pruning: pruning,
|
|
|
|
}))
|
2016-07-25 16:09:47 +02:00
|
|
|
} else if self.args.cmd_account {
|
2017-09-05 13:30:22 +02:00
|
|
|
let account_cmd = if self.args.cmd_account_new {
|
2016-07-25 16:09:47 +02:00
|
|
|
let new_acc = NewAccount {
|
2019-05-28 07:50:10 +02:00
|
|
|
iterations: key_iterations,
|
2016-07-25 16:09:47 +02:00
|
|
|
path: dirs.keys,
|
2016-12-12 16:51:07 +01:00
|
|
|
spec: spec,
|
2018-04-09 16:34:47 +02:00
|
|
|
password_file: self.accounts_config()?.password_files.first().map(|x| x.to_owned()),
|
2016-07-25 16:09:47 +02:00
|
|
|
};
|
|
|
|
AccountCmd::New(new_acc)
|
2017-09-05 13:30:22 +02:00
|
|
|
} else if self.args.cmd_account_list {
|
2016-12-12 16:51:07 +01:00
|
|
|
let list_acc = ListAccounts {
|
|
|
|
path: dirs.keys,
|
|
|
|
spec: spec,
|
|
|
|
};
|
|
|
|
AccountCmd::List(list_acc)
|
2017-09-05 13:30:22 +02:00
|
|
|
} else if self.args.cmd_account_import {
|
2016-07-25 16:09:47 +02:00
|
|
|
let import_acc = ImportAccounts {
|
2017-09-05 13:30:22 +02:00
|
|
|
from: self.args.arg_account_import_path.expect("CLI argument is required; qed").clone(),
|
2016-07-25 16:09:47 +02:00
|
|
|
to: dirs.keys,
|
2016-12-12 16:51:07 +01:00
|
|
|
spec: spec,
|
2016-07-25 16:09:47 +02:00
|
|
|
};
|
|
|
|
AccountCmd::Import(import_acc)
|
|
|
|
} else {
|
|
|
|
unreachable!();
|
|
|
|
};
|
|
|
|
Cmd::Account(account_cmd)
|
2016-10-04 10:44:47 +02:00
|
|
|
} else if self.args.flag_import_geth_keys {
|
2018-09-12 11:47:01 +02:00
|
|
|
let account_cmd = AccountCmd::ImportFromGeth(
|
2016-10-04 10:44:47 +02:00
|
|
|
ImportFromGethAccounts {
|
2016-12-12 16:51:07 +01:00
|
|
|
spec: spec,
|
2016-10-04 10:44:47 +02:00
|
|
|
to: dirs.keys,
|
|
|
|
testnet: self.args.flag_testnet
|
2016-10-06 10:20:05 +02:00
|
|
|
}
|
2016-10-04 10:44:47 +02:00
|
|
|
);
|
|
|
|
Cmd::Account(account_cmd)
|
2016-07-25 16:09:47 +02:00
|
|
|
} else if self.args.cmd_wallet {
|
|
|
|
let presale_cmd = ImportWallet {
|
2019-05-28 07:50:10 +02:00
|
|
|
iterations: key_iterations,
|
2016-07-25 16:09:47 +02:00
|
|
|
path: dirs.keys,
|
2016-12-12 16:51:07 +01:00
|
|
|
spec: spec,
|
2018-04-09 16:34:47 +02:00
|
|
|
wallet_path: self.args.arg_wallet_import_path.clone().unwrap(),
|
|
|
|
password_file: self.accounts_config()?.password_files.first().map(|x| x.to_owned()),
|
2016-07-25 16:09:47 +02:00
|
|
|
};
|
|
|
|
Cmd::ImportPresaleWallet(presale_cmd)
|
|
|
|
} else if self.args.cmd_import {
|
|
|
|
let import_cmd = ImportBlockchain {
|
|
|
|
spec: spec,
|
|
|
|
cache_config: cache_config,
|
|
|
|
dirs: dirs,
|
2017-09-05 13:30:22 +02:00
|
|
|
file_path: self.args.arg_import_file.clone(),
|
2016-08-04 09:22:54 +02:00
|
|
|
format: format,
|
2016-07-25 16:09:47 +02:00
|
|
|
pruning: pruning,
|
2016-10-14 14:44:56 +02:00
|
|
|
pruning_history: pruning_history,
|
2017-09-05 13:30:22 +02:00
|
|
|
pruning_memory: self.args.arg_pruning_memory,
|
2016-07-25 16:09:47 +02:00
|
|
|
compaction: compaction,
|
|
|
|
tracing: tracing,
|
2016-10-03 11:13:10 +02:00
|
|
|
fat_db: fat_db,
|
2016-10-24 15:09:13 +02:00
|
|
|
check_seal: !self.args.flag_no_seal_check,
|
2016-11-02 19:42:21 +01:00
|
|
|
with_color: logger_config.color,
|
2016-12-02 18:21:54 +01:00
|
|
|
verifier_settings: self.verifier_settings(),
|
2017-07-27 13:50:12 +02:00
|
|
|
light: self.args.flag_light,
|
2018-10-26 13:21:36 +02:00
|
|
|
max_round_blocks_to_import: self.args.arg_max_round_blocks_to_import,
|
2016-07-25 16:09:47 +02:00
|
|
|
};
|
|
|
|
Cmd::Blockchain(BlockchainCmd::Import(import_cmd))
|
|
|
|
} else if self.args.cmd_export {
|
2017-09-05 13:30:22 +02:00
|
|
|
if self.args.cmd_export_blocks {
|
2016-11-27 11:11:56 +01:00
|
|
|
let export_cmd = ExportBlockchain {
|
|
|
|
spec: spec,
|
|
|
|
cache_config: cache_config,
|
|
|
|
dirs: dirs,
|
2017-09-05 13:30:22 +02:00
|
|
|
file_path: self.args.arg_export_blocks_file.clone(),
|
2016-11-27 11:11:56 +01:00
|
|
|
format: format,
|
|
|
|
pruning: pruning,
|
|
|
|
pruning_history: pruning_history,
|
2017-09-05 13:30:22 +02:00
|
|
|
pruning_memory: self.args.arg_pruning_memory,
|
2016-11-27 11:11:56 +01:00
|
|
|
compaction: compaction,
|
|
|
|
tracing: tracing,
|
|
|
|
fat_db: fat_db,
|
2017-09-05 13:30:22 +02:00
|
|
|
from_block: to_block_id(&self.args.arg_export_blocks_from)?,
|
|
|
|
to_block: to_block_id(&self.args.arg_export_blocks_to)?,
|
2016-11-27 11:11:56 +01:00
|
|
|
check_seal: !self.args.flag_no_seal_check,
|
2018-10-26 13:21:36 +02:00
|
|
|
max_round_blocks_to_import: self.args.arg_max_round_blocks_to_import,
|
2016-11-27 11:11:56 +01:00
|
|
|
};
|
|
|
|
Cmd::Blockchain(BlockchainCmd::Export(export_cmd))
|
2017-09-05 13:30:22 +02:00
|
|
|
} else if self.args.cmd_export_state {
|
2016-11-27 11:11:56 +01:00
|
|
|
let export_cmd = ExportState {
|
|
|
|
spec: spec,
|
|
|
|
cache_config: cache_config,
|
|
|
|
dirs: dirs,
|
2017-09-05 13:30:22 +02:00
|
|
|
file_path: self.args.arg_export_state_file.clone(),
|
2016-11-27 11:11:56 +01:00
|
|
|
format: format,
|
|
|
|
pruning: pruning,
|
|
|
|
pruning_history: pruning_history,
|
2017-09-05 13:30:22 +02:00
|
|
|
pruning_memory: self.args.arg_pruning_memory,
|
2016-11-27 11:11:56 +01:00
|
|
|
compaction: compaction,
|
|
|
|
tracing: tracing,
|
|
|
|
fat_db: fat_db,
|
2017-09-05 13:30:22 +02:00
|
|
|
at: to_block_id(&self.args.arg_export_state_at)?,
|
|
|
|
storage: !self.args.flag_export_state_no_storage,
|
|
|
|
code: !self.args.flag_export_state_no_code,
|
|
|
|
min_balance: self.args.arg_export_state_min_balance.and_then(|s| to_u256(&s).ok()),
|
|
|
|
max_balance: self.args.arg_export_state_max_balance.and_then(|s| to_u256(&s).ok()),
|
2018-10-26 13:21:36 +02:00
|
|
|
max_round_blocks_to_import: self.args.arg_max_round_blocks_to_import,
|
2016-11-27 11:11:56 +01:00
|
|
|
};
|
|
|
|
Cmd::Blockchain(BlockchainCmd::ExportState(export_cmd))
|
|
|
|
} else {
|
|
|
|
unreachable!();
|
|
|
|
}
|
2016-08-05 17:00:46 +02:00
|
|
|
} else if self.args.cmd_snapshot {
|
|
|
|
let snapshot_cmd = SnapshotCommand {
|
|
|
|
cache_config: cache_config,
|
|
|
|
dirs: dirs,
|
|
|
|
spec: spec,
|
|
|
|
pruning: pruning,
|
2016-10-14 14:44:56 +02:00
|
|
|
pruning_history: pruning_history,
|
2017-09-05 13:30:22 +02:00
|
|
|
pruning_memory: self.args.arg_pruning_memory,
|
2016-08-05 17:00:46 +02:00
|
|
|
tracing: tracing,
|
2016-10-03 11:13:10 +02:00
|
|
|
fat_db: fat_db,
|
2016-08-05 17:00:46 +02:00
|
|
|
compaction: compaction,
|
2017-09-05 13:30:22 +02:00
|
|
|
file_path: self.args.arg_snapshot_file.clone(),
|
2019-09-03 11:29:25 +02:00
|
|
|
kind: snapshot_cmd::Kind::Take,
|
2017-09-05 13:30:22 +02:00
|
|
|
block_at: to_block_id(&self.args.arg_snapshot_at)?,
|
2018-10-26 13:21:36 +02:00
|
|
|
max_round_blocks_to_import: self.args.arg_max_round_blocks_to_import,
|
2018-09-13 12:58:49 +02:00
|
|
|
snapshot_conf: snapshot_conf,
|
2016-08-05 17:00:46 +02:00
|
|
|
};
|
|
|
|
Cmd::Snapshot(snapshot_cmd)
|
|
|
|
} else if self.args.cmd_restore {
|
|
|
|
let restore_cmd = SnapshotCommand {
|
|
|
|
cache_config: cache_config,
|
|
|
|
dirs: dirs,
|
|
|
|
spec: spec,
|
|
|
|
pruning: pruning,
|
2016-10-14 14:44:56 +02:00
|
|
|
pruning_history: pruning_history,
|
2017-09-05 13:30:22 +02:00
|
|
|
pruning_memory: self.args.arg_pruning_memory,
|
2016-08-05 17:00:46 +02:00
|
|
|
tracing: tracing,
|
2016-10-03 11:13:10 +02:00
|
|
|
fat_db: fat_db,
|
2016-08-05 17:00:46 +02:00
|
|
|
compaction: compaction,
|
2017-09-05 13:30:22 +02:00
|
|
|
file_path: self.args.arg_restore_file.clone(),
|
2019-09-03 11:29:25 +02:00
|
|
|
kind: snapshot_cmd::Kind::Restore,
|
2016-12-27 12:53:56 +01:00
|
|
|
block_at: to_block_id("latest")?, // unimportant.
|
2018-10-26 13:21:36 +02:00
|
|
|
max_round_blocks_to_import: self.args.arg_max_round_blocks_to_import,
|
2018-09-13 12:58:49 +02:00
|
|
|
snapshot_conf: snapshot_conf,
|
2016-08-05 17:00:46 +02:00
|
|
|
};
|
|
|
|
Cmd::Snapshot(restore_cmd)
|
2018-03-27 13:56:59 +02:00
|
|
|
} else if self.args.cmd_export_hardcoded_sync {
|
|
|
|
let export_hs_cmd = ExportHsyncCmd {
|
|
|
|
cache_config: cache_config,
|
|
|
|
dirs: dirs,
|
|
|
|
spec: spec,
|
|
|
|
pruning: pruning,
|
|
|
|
compaction: compaction,
|
|
|
|
};
|
|
|
|
Cmd::ExportHardcodedSync(export_hs_cmd)
|
2016-07-25 16:09:47 +02:00
|
|
|
} else {
|
|
|
|
let daemon = if self.args.cmd_daemon {
|
2017-09-05 13:30:22 +02:00
|
|
|
Some(self.args.arg_daemon_pid_file.clone().expect("CLI argument is required; qed"))
|
2016-07-25 16:09:47 +02:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2016-12-02 18:21:54 +01:00
|
|
|
let verifier_settings = self.verifier_settings();
|
2018-04-09 16:14:33 +02:00
|
|
|
let (private_provider_conf, private_enc_conf, private_tx_enabled) = self.private_provider_config()?;
|
2016-12-02 18:21:54 +01:00
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
let run_cmd = RunCmd {
|
2019-11-18 19:40:48 +01:00
|
|
|
cache_config,
|
|
|
|
dirs,
|
|
|
|
spec,
|
|
|
|
pruning,
|
|
|
|
pruning_history,
|
2017-09-05 13:30:22 +02:00
|
|
|
pruning_memory: self.args.arg_pruning_memory,
|
2019-11-18 19:40:48 +01:00
|
|
|
daemon,
|
2016-11-02 19:42:21 +01:00
|
|
|
logger_config: logger_config.clone(),
|
2017-10-24 12:25:34 +02:00
|
|
|
miner_options: self.miner_options()?,
|
2018-01-09 12:43:36 +01:00
|
|
|
gas_price_percentile: self.args.arg_gas_price_percentile,
|
2018-06-18 13:42:54 +02:00
|
|
|
poll_lifetime: self.args.arg_poll_lifetime,
|
2019-11-18 19:40:48 +01:00
|
|
|
ws_conf,
|
|
|
|
snapshot_conf,
|
|
|
|
http_conf,
|
|
|
|
ipc_conf,
|
|
|
|
net_conf,
|
|
|
|
network_id,
|
2016-12-27 12:53:56 +01:00
|
|
|
acc_conf: self.accounts_config()?,
|
2017-07-17 08:33:26 +02:00
|
|
|
gas_pricer_conf: self.gas_pricer_config()?,
|
2016-12-27 12:53:56 +01:00
|
|
|
miner_extras: self.miner_extras()?,
|
2017-01-25 11:03:36 +01:00
|
|
|
stratum: self.stratum_options()?,
|
2019-11-18 19:40:48 +01:00
|
|
|
update_policy,
|
2018-11-26 19:58:27 +01:00
|
|
|
allow_missing_blocks: self.args.flag_jsonrpc_allow_missing_blocks,
|
2019-11-18 19:40:48 +01:00
|
|
|
mode,
|
|
|
|
tracing,
|
|
|
|
fat_db,
|
|
|
|
compaction,
|
|
|
|
warp_sync,
|
2018-03-29 11:20:27 +02:00
|
|
|
warp_barrier: self.args.arg_warp_barrier,
|
2019-11-18 19:40:48 +01:00
|
|
|
geth_compatibility,
|
2018-11-16 14:00:34 +01:00
|
|
|
experimental_rpcs,
|
2017-05-23 12:24:32 +02:00
|
|
|
net_settings: self.network_settings()?,
|
2019-11-18 19:40:48 +01:00
|
|
|
ipfs_conf,
|
|
|
|
secretstore_conf,
|
|
|
|
private_provider_conf,
|
2018-04-09 16:14:33 +02:00
|
|
|
private_encryptor_conf: private_enc_conf,
|
|
|
|
private_tx_enabled,
|
2017-09-05 13:30:22 +02:00
|
|
|
name: self.args.arg_identity,
|
|
|
|
custom_bootnodes: self.args.arg_bootnodes.is_some(),
|
2016-10-24 15:09:13 +02:00
|
|
|
check_seal: !self.args.flag_no_seal_check,
|
2016-11-22 18:03:35 +01:00
|
|
|
download_old_blocks: !self.args.flag_no_ancient_blocks,
|
2019-11-18 19:40:48 +01:00
|
|
|
verifier_settings,
|
2017-03-22 16:45:50 +01:00
|
|
|
serve_light: !self.args.flag_no_serve_light,
|
|
|
|
light: self.args.flag_light,
|
2017-05-04 12:13:50 +02:00
|
|
|
no_persistent_txqueue: self.args.flag_no_persistent_txqueue,
|
2018-03-27 13:56:59 +02:00
|
|
|
no_hardcoded_sync: self.args.flag_no_hardcoded_sync,
|
2018-10-26 13:21:36 +02:00
|
|
|
max_round_blocks_to_import: self.args.arg_max_round_blocks_to_import,
|
2018-12-05 10:36:53 +01:00
|
|
|
on_demand_response_time_window: self.args.arg_on_demand_response_time_window,
|
|
|
|
on_demand_request_backoff_start: self.args.arg_on_demand_request_backoff_start,
|
|
|
|
on_demand_request_backoff_max: self.args.arg_on_demand_request_backoff_max,
|
|
|
|
on_demand_request_backoff_rounds_max: self.args.arg_on_demand_request_backoff_rounds_max,
|
|
|
|
on_demand_request_consecutive_failures: self.args.arg_on_demand_request_consecutive_failures,
|
2016-07-25 16:09:47 +02:00
|
|
|
};
|
|
|
|
Cmd::Run(run_cmd)
|
|
|
|
};
|
|
|
|
|
2016-11-02 19:42:21 +01:00
|
|
|
Ok(Execute {
|
|
|
|
logger: logger_config,
|
2019-11-18 19:40:48 +01:00
|
|
|
cmd,
|
2016-11-02 19:42:21 +01:00
|
|
|
})
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn miner_extras(&self) -> Result<MinerExtras, String> {
|
2018-04-13 17:34:27 +02:00
|
|
|
let floor = to_u256(&self.args.arg_gas_floor_target)?;
|
|
|
|
let ceil = to_u256(&self.args.arg_gas_cap)?;
|
2016-07-25 16:09:47 +02:00
|
|
|
let extras = MinerExtras {
|
2016-12-27 12:53:56 +01:00
|
|
|
author: self.author()?,
|
|
|
|
extra_data: self.extra_data()?,
|
2018-04-13 17:34:27 +02:00
|
|
|
gas_range_target: (floor, ceil),
|
2016-12-27 12:53:56 +01:00
|
|
|
engine_signer: self.engine_signer()?,
|
2018-04-13 17:34:27 +02:00
|
|
|
work_notify: self.work_notify(),
|
2019-02-07 14:34:24 +01:00
|
|
|
local_accounts: HashSet::from_iter(to_addresses(&self.args.arg_tx_queue_locals)?.into_iter()),
|
2016-07-25 16:09:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Ok(extras)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn author(&self) -> Result<Address, String> {
|
2017-09-05 13:30:22 +02:00
|
|
|
to_address(self.args.arg_etherbase.clone().or(self.args.arg_author.clone()))
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
|
|
|
|
2016-12-05 22:31:38 +01:00
|
|
|
fn engine_signer(&self) -> Result<Address, String> {
|
2017-09-05 13:30:22 +02:00
|
|
|
to_address(self.args.arg_engine_signer.clone())
|
2016-12-05 20:23:03 +01:00
|
|
|
}
|
|
|
|
|
2016-08-04 09:22:54 +02:00
|
|
|
fn format(&self) -> Result<Option<DataFormat>, String> {
|
2017-09-05 13:30:22 +02:00
|
|
|
match self.args.arg_import_format.clone()
|
|
|
|
.or(self.args.arg_export_blocks_format.clone())
|
|
|
|
.or(self.args.arg_export_state_format.clone()) {
|
2016-12-27 12:53:56 +01:00
|
|
|
Some(ref f) => Ok(Some(f.parse()?)),
|
2016-08-04 09:22:54 +02:00
|
|
|
None => Ok(None),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
fn cache_config(&self) -> CacheConfig {
|
2017-09-05 13:30:22 +02:00
|
|
|
match self.args.arg_cache_size.or(self.args.arg_cache) {
|
2016-07-25 16:09:47 +02:00
|
|
|
Some(size) => CacheConfig::new_with_total_cache_size(size),
|
2016-10-07 00:28:42 +02:00
|
|
|
None => CacheConfig::new(
|
2017-09-05 13:30:22 +02:00
|
|
|
self.args.arg_cache_size_db,
|
|
|
|
self.args.arg_cache_size_blocks,
|
|
|
|
self.args.arg_cache_size_queue,
|
|
|
|
self.args.arg_cache_size_state,
|
2016-10-07 00:28:42 +02:00
|
|
|
),
|
2016-07-05 17:50:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-01 19:31:02 +01:00
|
|
|
/// returns logger config
|
|
|
|
pub fn logger_config(&self) -> LogConfig {
|
2016-07-25 16:09:47 +02:00
|
|
|
LogConfig {
|
2017-09-05 13:30:22 +02:00
|
|
|
mode: self.args.arg_logging.clone(),
|
2016-07-25 16:09:47 +02:00
|
|
|
color: !self.args.flag_no_color && !cfg!(windows),
|
2018-04-09 16:34:47 +02:00
|
|
|
file: self.args.arg_log_file.as_ref().map(|log_file| replace_home(&self.directories().base, log_file)),
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
2016-04-30 19:58:28 +02:00
|
|
|
}
|
|
|
|
|
2017-10-24 12:25:34 +02:00
|
|
|
fn chain(&self) -> Result<SpecType, String> {
|
2018-04-13 14:21:15 +02:00
|
|
|
let name = if self.args.flag_testnet {
|
2017-03-02 20:24:27 +01:00
|
|
|
"testnet".to_owned()
|
2016-04-30 19:58:28 +02:00
|
|
|
} else {
|
2017-09-05 13:30:22 +02:00
|
|
|
self.args.arg_chain.clone()
|
2017-10-24 12:25:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Ok(name.parse()?)
|
2016-04-30 19:58:28 +02:00
|
|
|
}
|
|
|
|
|
2018-11-07 09:30:34 +01:00
|
|
|
fn is_dev_chain(&self) -> Result<bool, String> {
|
|
|
|
Ok(self.chain()? == SpecType::Dev)
|
|
|
|
}
|
|
|
|
|
2016-04-30 19:58:28 +02:00
|
|
|
fn max_peers(&self) -> u32 {
|
2018-04-03 16:51:57 +02:00
|
|
|
self.args.arg_max_peers
|
2018-04-13 17:34:27 +02:00
|
|
|
.or(cmp::max(self.args.arg_min_peers, Some(DEFAULT_MAX_PEERS)))
|
2018-04-03 16:51:57 +02:00
|
|
|
.unwrap_or(DEFAULT_MAX_PEERS) as u32
|
2016-07-29 17:30:02 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 19:06:39 +02:00
|
|
|
fn ip_filter(&self) -> Result<IpFilter, String> {
|
2017-09-05 13:30:22 +02:00
|
|
|
match IpFilter::parse(self.args.arg_allow_ips.as_str()) {
|
2017-07-28 19:06:39 +02:00
|
|
|
Ok(allow_ip) => Ok(allow_ip),
|
|
|
|
Err(_) => Err("Invalid IP filter value".to_owned()),
|
2016-10-24 18:25:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-29 17:30:02 +02:00
|
|
|
fn min_peers(&self) -> u32 {
|
2018-04-03 16:51:57 +02:00
|
|
|
self.args.arg_min_peers
|
2018-04-13 17:34:27 +02:00
|
|
|
.or(cmp::min(self.args.arg_max_peers, Some(DEFAULT_MIN_PEERS)))
|
2018-04-03 16:51:57 +02:00
|
|
|
.unwrap_or(DEFAULT_MIN_PEERS) as u32
|
2016-04-30 19:58:28 +02:00
|
|
|
}
|
|
|
|
|
2016-10-24 18:25:27 +02:00
|
|
|
fn max_pending_peers(&self) -> u32 {
|
2017-09-05 13:30:22 +02:00
|
|
|
self.args.arg_max_pending_peers as u32
|
2016-10-24 18:25:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn snapshot_peers(&self) -> u32 {
|
2017-09-05 13:30:22 +02:00
|
|
|
self.args.arg_snapshot_peers as u32
|
2016-10-24 18:25:27 +02:00
|
|
|
}
|
|
|
|
|
2016-06-29 20:07:21 +02:00
|
|
|
fn work_notify(&self) -> Vec<String> {
|
2017-09-05 13:30:22 +02:00
|
|
|
self.args.arg_notify_work.as_ref().map_or_else(Vec::new, |s| s.split(',').map(|s| s.to_owned()).collect())
|
2016-06-29 15:37:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
fn accounts_config(&self) -> Result<AccountsConfig, String> {
|
|
|
|
let cfg = AccountsConfig {
|
2019-05-28 07:50:10 +02:00
|
|
|
iterations: self.args.arg_keys_iterations,
|
2017-12-22 04:33:49 +01:00
|
|
|
refresh_time: self.args.arg_accounts_refresh,
|
2016-07-25 16:09:47 +02:00
|
|
|
testnet: self.args.flag_testnet,
|
2018-04-09 16:34:47 +02:00
|
|
|
password_files: self.args.arg_password.iter().map(|s| replace_home(&self.directories().base, s)).collect(),
|
2017-09-05 13:30:22 +02:00
|
|
|
unlocked_accounts: to_addresses(&self.args.arg_unlock)?,
|
2017-06-06 18:06:40 +02:00
|
|
|
enable_fast_unlock: self.args.flag_fast_unlock,
|
2016-06-27 17:23:54 +02:00
|
|
|
};
|
2016-07-25 16:09:47 +02:00
|
|
|
|
|
|
|
Ok(cfg)
|
|
|
|
}
|
|
|
|
|
2018-04-13 17:34:27 +02:00
|
|
|
fn stratum_options(&self) -> Result<Option<stratum::Options>, String> {
|
2017-01-25 11:03:36 +01:00
|
|
|
if self.args.flag_stratum {
|
2018-04-13 17:34:27 +02:00
|
|
|
Ok(Some(stratum::Options {
|
2017-01-25 11:03:36 +01:00
|
|
|
io_path: self.directories().db,
|
|
|
|
listen_addr: self.stratum_interface(),
|
2017-09-05 13:30:22 +02:00
|
|
|
port: self.args.arg_ports_shift + self.args.arg_stratum_port,
|
|
|
|
secret: self.args.arg_stratum_secret.as_ref().map(|s| s.parse::<H256>().unwrap_or_else(|_| keccak(s))),
|
2017-01-25 11:03:36 +01:00
|
|
|
}))
|
|
|
|
} else { Ok(None) }
|
|
|
|
}
|
|
|
|
|
2017-10-24 12:25:34 +02:00
|
|
|
fn miner_options(&self) -> Result<MinerOptions, String> {
|
2018-11-07 09:30:34 +01:00
|
|
|
let is_dev_chain = self.is_dev_chain()?;
|
2017-10-24 12:25:34 +02:00
|
|
|
if is_dev_chain && self.args.flag_force_sealing && self.args.arg_reseal_min_period == 0 {
|
2017-07-01 17:20:49 +02:00
|
|
|
return Err("Force sealing can't be used with reseal_min_period = 0".into());
|
|
|
|
}
|
|
|
|
|
2017-09-05 13:30:22 +02:00
|
|
|
let reseal = self.args.arg_reseal_on_txs.parse::<ResealPolicy>()?;
|
2016-07-25 16:09:47 +02:00
|
|
|
|
|
|
|
let options = MinerOptions {
|
2016-06-27 17:23:54 +02:00
|
|
|
force_sealing: self.args.flag_force_sealing,
|
2016-07-25 16:09:47 +02:00
|
|
|
reseal_on_external_tx: reseal.external,
|
|
|
|
reseal_on_own_tx: reseal.own,
|
2017-07-10 13:36:42 +02:00
|
|
|
reseal_on_uncle: self.args.flag_reseal_on_uncle,
|
2017-10-24 12:25:34 +02:00
|
|
|
reseal_min_period: Duration::from_millis(self.args.arg_reseal_min_period),
|
2017-09-05 13:30:22 +02:00
|
|
|
reseal_max_period: Duration::from_millis(self.args.arg_reseal_max_period),
|
2018-04-13 17:34:27 +02:00
|
|
|
|
|
|
|
pending_set: to_pending_set(&self.args.arg_relay_set)?,
|
2017-09-05 13:30:22 +02:00
|
|
|
work_queue_size: self.args.arg_work_queue_size,
|
2016-06-30 12:56:58 +02:00
|
|
|
enable_resubmission: !self.args.flag_remove_solved,
|
2017-11-03 15:20:20 +01:00
|
|
|
infinite_pending_block: self.args.flag_infinite_pending_block,
|
2018-04-13 17:34:27 +02:00
|
|
|
|
|
|
|
tx_queue_penalization: to_queue_penalization(self.args.arg_tx_time_limit)?,
|
|
|
|
tx_queue_strategy: to_queue_strategy(&self.args.arg_tx_queue_strategy)?,
|
2018-06-18 15:32:18 +02:00
|
|
|
tx_queue_no_unfamiliar_locals: self.args.flag_tx_queue_no_unfamiliar_locals,
|
2018-04-13 17:34:27 +02:00
|
|
|
refuse_service_transactions: self.args.flag_refuse_service_transactions,
|
|
|
|
|
|
|
|
pool_limits: self.pool_limits()?,
|
|
|
|
pool_verification_options: self.pool_verification_options()?,
|
2016-07-25 16:09:47 +02:00
|
|
|
};
|
2016-04-21 16:45:04 +02:00
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
Ok(options)
|
2016-06-23 14:29:16 +02:00
|
|
|
}
|
2016-06-19 13:20:14 +02:00
|
|
|
|
2018-04-13 17:34:27 +02:00
|
|
|
fn pool_limits(&self) -> Result<pool::Options, String> {
|
|
|
|
let max_count = self.args.arg_tx_queue_size;
|
|
|
|
|
|
|
|
Ok(pool::Options {
|
|
|
|
max_count,
|
|
|
|
max_per_sender: self.args.arg_tx_queue_per_sender.unwrap_or_else(|| cmp::max(16, max_count / 100)),
|
|
|
|
max_mem_usage: if self.args.arg_tx_queue_mem_limit > 0 {
|
|
|
|
self.args.arg_tx_queue_mem_limit as usize * 1024 * 1024
|
|
|
|
} else {
|
|
|
|
usize::max_value()
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn pool_verification_options(&self) -> Result<pool::verifier::Options, String>{
|
|
|
|
Ok(pool::verifier::Options {
|
|
|
|
// NOTE min_gas_price and block_gas_limit will be overwritten right after start.
|
|
|
|
minimal_gas_price: U256::from(20_000_000) * 1_000u32,
|
|
|
|
block_gas_limit: U256::max_value(),
|
|
|
|
tx_gas_limit: match self.args.arg_tx_gas_limit {
|
|
|
|
Some(ref d) => to_u256(d)?,
|
|
|
|
None => U256::max_value(),
|
|
|
|
},
|
2018-07-24 15:04:48 +02:00
|
|
|
no_early_reject: self.args.flag_tx_queue_no_early_reject,
|
2018-04-13 17:34:27 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-04-08 11:26:16 +02:00
|
|
|
fn secretstore_config(&self) -> Result<SecretStoreConfiguration, String> {
|
|
|
|
Ok(SecretStoreConfiguration {
|
2017-02-20 16:13:21 +01:00
|
|
|
enabled: self.secretstore_enabled(),
|
2017-07-27 12:29:09 +02:00
|
|
|
http_enabled: self.secretstore_http_enabled(),
|
2018-01-10 11:33:45 +01:00
|
|
|
auto_migrate_enabled: self.secretstore_auto_migrate_enabled(),
|
2018-06-14 09:01:52 +02:00
|
|
|
acl_check_contract_address: self.secretstore_acl_check_contract_address()?,
|
2017-11-24 10:33:33 +01:00
|
|
|
service_contract_address: self.secretstore_service_contract_address()?,
|
2018-04-03 16:54:34 +02:00
|
|
|
service_contract_srv_gen_address: self.secretstore_service_contract_srv_gen_address()?,
|
|
|
|
service_contract_srv_retr_address: self.secretstore_service_contract_srv_retr_address()?,
|
|
|
|
service_contract_doc_store_address: self.secretstore_service_contract_doc_store_address()?,
|
|
|
|
service_contract_doc_sretr_address: self.secretstore_service_contract_doc_sretr_address()?,
|
2017-04-08 11:26:16 +02:00
|
|
|
self_secret: self.secretstore_self_secret()?,
|
|
|
|
nodes: self.secretstore_nodes()?,
|
2018-06-14 09:01:52 +02:00
|
|
|
key_server_set_contract_address: self.secretstore_key_server_set_contract_address()?,
|
2017-02-20 16:13:21 +01:00
|
|
|
interface: self.secretstore_interface(),
|
2017-09-05 13:30:22 +02:00
|
|
|
port: self.args.arg_ports_shift + self.args.arg_secretstore_port,
|
2017-04-08 11:26:16 +02:00
|
|
|
http_interface: self.secretstore_http_interface(),
|
2017-09-05 13:30:22 +02:00
|
|
|
http_port: self.args.arg_ports_shift + self.args.arg_secretstore_http_port,
|
2017-02-20 16:13:21 +01:00
|
|
|
data_path: self.directories().secretstore,
|
2017-10-02 15:27:31 +02:00
|
|
|
admin_public: self.secretstore_admin_public()?,
|
2019-04-20 07:31:37 +02:00
|
|
|
cors: self.secretstore_cors()
|
2017-04-08 11:26:16 +02:00
|
|
|
})
|
2017-02-20 16:13:21 +01:00
|
|
|
}
|
|
|
|
|
2017-02-16 14:41:33 +01:00
|
|
|
fn ipfs_config(&self) -> IpfsConfiguration {
|
|
|
|
IpfsConfiguration {
|
|
|
|
enabled: self.args.flag_ipfs_api,
|
2017-09-05 13:30:22 +02:00
|
|
|
port: self.args.arg_ports_shift + self.args.arg_ipfs_api_port,
|
2017-02-24 10:32:42 +01:00
|
|
|
interface: self.ipfs_interface(),
|
|
|
|
cors: self.ipfs_cors(),
|
|
|
|
hosts: self.ipfs_hosts(),
|
2017-02-16 14:41:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
fn gas_pricer_config(&self) -> Result<GasPricerConfig, String> {
|
2017-01-18 19:44:24 +01:00
|
|
|
fn wei_per_gas(usd_per_tx: f32, usd_per_eth: f32) -> U256 {
|
|
|
|
let wei_per_usd: f32 = 1.0e18 / usd_per_eth;
|
|
|
|
let gas_per_tx: f32 = 21000.0;
|
|
|
|
let wei_per_gas: f32 = wei_per_usd * usd_per_tx / gas_per_tx;
|
|
|
|
U256::from_dec_str(&format!("{:.0}", wei_per_gas)).unwrap()
|
|
|
|
}
|
|
|
|
|
2017-09-05 13:30:22 +02:00
|
|
|
if let Some(dec) = self.args.arg_gasprice.as_ref() {
|
2017-07-13 14:25:41 +02:00
|
|
|
return Ok(GasPricerConfig::Fixed(to_u256(dec)?));
|
2017-09-05 13:30:22 +02:00
|
|
|
} else if let Some(dec) = self.args.arg_min_gas_price {
|
2017-07-14 04:40:47 +02:00
|
|
|
return Ok(GasPricerConfig::Fixed(U256::from(dec)));
|
2017-10-25 11:42:48 +02:00
|
|
|
} else if self.chain()? != SpecType::Foundation {
|
|
|
|
return Ok(GasPricerConfig::Fixed(U256::zero()));
|
2016-04-21 16:45:04 +02:00
|
|
|
}
|
|
|
|
|
2017-09-05 13:30:22 +02:00
|
|
|
let usd_per_tx = to_price(&self.args.arg_usd_per_tx)?;
|
2019-10-29 12:18:30 +01:00
|
|
|
|
|
|
|
if "auto" == self.args.arg_usd_per_eth {
|
|
|
|
Ok(GasPricerConfig::Calibrated {
|
2016-07-25 16:09:47 +02:00
|
|
|
usd_per_tx: usd_per_tx,
|
2017-09-05 13:30:22 +02:00
|
|
|
recalibration_period: to_duration(self.args.arg_price_update_period.as_str())?,
|
2019-10-29 12:18:30 +01:00
|
|
|
api_endpoint: ETHERSCAN_ETH_PRICE_ENDPOINT.to_string(),
|
|
|
|
})
|
|
|
|
} else if let Ok(usd_per_eth_parsed) = to_price(&self.args.arg_usd_per_eth) {
|
|
|
|
let wei_per_gas = wei_per_gas(usd_per_tx, usd_per_eth_parsed);
|
|
|
|
|
|
|
|
info!(
|
|
|
|
"Using a fixed conversion rate of Ξ1 = {} ({} wei/gas)",
|
|
|
|
Colour::White.bold().paint(format!("US${:.2}", usd_per_eth_parsed)),
|
|
|
|
Colour::Yellow.bold().paint(format!("{}", wei_per_gas))
|
|
|
|
);
|
2016-07-25 16:09:47 +02:00
|
|
|
|
2019-10-29 12:18:30 +01:00
|
|
|
Ok(GasPricerConfig::Fixed(wei_per_gas))
|
|
|
|
} else {
|
|
|
|
Ok(GasPricerConfig::Calibrated {
|
|
|
|
usd_per_tx: usd_per_tx,
|
|
|
|
recalibration_period: to_duration(self.args.arg_price_update_period.as_str())?,
|
|
|
|
api_endpoint: self.args.arg_usd_per_eth.clone(),
|
|
|
|
})
|
|
|
|
}
|
2016-04-21 16:45:04 +02:00
|
|
|
}
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
fn extra_data(&self) -> Result<Bytes, String> {
|
2017-09-05 13:30:22 +02:00
|
|
|
match self.args.arg_extradata.as_ref().or(self.args.arg_extra_data.as_ref()) {
|
2016-08-17 16:06:41 +02:00
|
|
|
Some(x) if x.len() <= 32 => Ok(x.as_bytes().to_owned()),
|
2016-07-25 16:09:47 +02:00
|
|
|
None => Ok(version_data()),
|
|
|
|
Some(_) => Err("Extra data must be at most 32 characters".into()),
|
2016-04-21 16:45:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
fn init_reserved_nodes(&self) -> Result<Vec<String>, String> {
|
2016-06-20 14:13:33 +02:00
|
|
|
use std::fs::File;
|
|
|
|
|
2017-09-05 13:30:22 +02:00
|
|
|
match self.args.arg_reserved_peers {
|
2016-07-25 16:09:47 +02:00
|
|
|
Some(ref path) => {
|
2018-04-09 16:34:47 +02:00
|
|
|
let path = replace_home(&self.directories().base, path);
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
let mut buffer = String::new();
|
2018-04-09 16:34:47 +02:00
|
|
|
let mut node_file = File::open(&path).map_err(|e| format!("Error opening reserved nodes file: {}", e))?;
|
2016-12-27 12:53:56 +01:00
|
|
|
node_file.read_to_string(&mut buffer).map_err(|_| "Error reading reserved node file")?;
|
2017-07-10 13:24:40 +02:00
|
|
|
let lines = buffer.lines().map(|s| s.trim().to_owned()).filter(|s| !s.is_empty() && !s.starts_with("#")).collect::<Vec<_>>();
|
2017-10-31 05:09:31 +01:00
|
|
|
|
|
|
|
for line in &lines {
|
2017-11-13 14:37:08 +01:00
|
|
|
match validate_node_url(line).map(Into::into) {
|
2017-10-31 05:09:31 +01:00
|
|
|
None => continue,
|
2019-06-17 08:44:59 +02:00
|
|
|
Some(sync::Error::AddressResolve(_)) => return Err(format!("Failed to resolve hostname of a boot node: {}", line)),
|
2017-10-31 05:09:31 +01:00
|
|
|
Some(_) => return Err(format!("Invalid node address format given for a boot node: {}", line)),
|
|
|
|
}
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
2017-10-31 05:09:31 +01:00
|
|
|
|
2016-07-29 10:22:51 +02:00
|
|
|
Ok(lines)
|
2016-07-25 16:09:47 +02:00
|
|
|
},
|
|
|
|
None => Ok(Vec::new())
|
2016-06-20 14:13:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-23 12:24:32 +02:00
|
|
|
fn net_addresses(&self) -> Result<(SocketAddr, Option<SocketAddr>), String> {
|
2017-09-05 13:30:22 +02:00
|
|
|
let port = self.args.arg_ports_shift + self.args.arg_port;
|
2018-05-31 13:36:47 +02:00
|
|
|
let listen_address = SocketAddr::new(self.interface(&self.args.arg_interface).parse().unwrap(), port);
|
2017-09-05 13:30:22 +02:00
|
|
|
let public_address = if self.args.arg_nat.starts_with("extip:") {
|
2019-07-03 09:44:32 +02:00
|
|
|
let host = self.args.arg_nat[6..].split(':').next().expect("split has at least one part; qed");
|
|
|
|
let host = format!("{}:{}", host, port);
|
|
|
|
match host.to_socket_addrs() {
|
|
|
|
Ok(mut addr_iter) => {
|
|
|
|
if let Some(addr) = addr_iter.next() {
|
|
|
|
Some(addr)
|
|
|
|
} else {
|
|
|
|
return Err(format!("Invalid host given with `--nat extip:{}`", &self.args.arg_nat[6..]))
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Err(_) => return Err(format!("Invalid host given with `--nat extip:{}`", &self.args.arg_nat[6..]))
|
|
|
|
}
|
2016-04-21 16:45:04 +02:00
|
|
|
} else {
|
2016-07-04 18:21:22 +02:00
|
|
|
None
|
2016-04-21 16:45:04 +02:00
|
|
|
};
|
2016-07-25 16:09:47 +02:00
|
|
|
Ok((listen_address, public_address))
|
2016-04-21 16:45:04 +02:00
|
|
|
}
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
fn net_config(&self) -> Result<NetworkConfiguration, String> {
|
2016-04-21 16:45:04 +02:00
|
|
|
let mut ret = NetworkConfiguration::new();
|
2017-09-05 13:30:22 +02:00
|
|
|
ret.nat_enabled = self.args.arg_nat == "any" || self.args.arg_nat == "upnp";
|
|
|
|
ret.boot_nodes = to_bootnodes(&self.args.arg_bootnodes)?;
|
2016-12-27 12:53:56 +01:00
|
|
|
let (listen, public) = self.net_addresses()?;
|
2017-05-23 12:24:32 +02:00
|
|
|
ret.listen_address = Some(format!("{}", listen));
|
2016-08-05 10:32:04 +02:00
|
|
|
ret.public_address = public.map(|p| format!("{}", p));
|
2017-09-05 13:30:22 +02:00
|
|
|
ret.use_secret = match self.args.arg_node_key.as_ref()
|
2019-10-23 13:03:46 +02:00
|
|
|
.map(|s| s.parse::<Secret>().or_else(|_| Secret::import_key(keccak(s).as_bytes())).map_err(|e| format!("Invalid key: {:?}", e))
|
2017-01-11 12:16:47 +01:00
|
|
|
) {
|
|
|
|
None => None,
|
|
|
|
Some(Ok(key)) => Some(key),
|
|
|
|
Some(Err(err)) => return Err(err),
|
|
|
|
};
|
2016-04-21 16:45:04 +02:00
|
|
|
ret.discovery_enabled = !self.args.flag_no_discovery && !self.args.flag_nodiscover;
|
2016-07-29 17:30:02 +02:00
|
|
|
ret.max_peers = self.max_peers();
|
|
|
|
ret.min_peers = self.min_peers();
|
2016-10-24 18:25:27 +02:00
|
|
|
ret.snapshot_peers = self.snapshot_peers();
|
2017-07-28 19:06:39 +02:00
|
|
|
ret.ip_filter = self.ip_filter()?;
|
2016-10-24 18:25:27 +02:00
|
|
|
ret.max_pending_peers = self.max_pending_peers();
|
2016-12-15 21:56:45 +01:00
|
|
|
let mut net_path = PathBuf::from(self.directories().base);
|
2016-04-21 16:45:04 +02:00
|
|
|
net_path.push("network");
|
|
|
|
ret.config_path = Some(net_path.to_str().unwrap().to_owned());
|
2016-12-27 12:53:56 +01:00
|
|
|
ret.reserved_nodes = self.init_reserved_nodes()?;
|
2016-08-05 10:32:04 +02:00
|
|
|
ret.allow_non_reserved = !self.args.flag_reserved_only;
|
2018-06-18 15:50:17 +02:00
|
|
|
ret.client_version = {
|
|
|
|
let mut client_version = version();
|
|
|
|
if !self.args.arg_identity.is_empty() {
|
2018-07-11 13:35:10 +02:00
|
|
|
// Insert name after the "Parity-Ethereum/" at the beginning of version string.
|
2018-06-18 15:50:17 +02:00
|
|
|
let idx = client_version.find('/').unwrap_or(client_version.len());
|
|
|
|
client_version.insert_str(idx, &format!("/{}", self.args.arg_identity));
|
|
|
|
}
|
|
|
|
client_version
|
|
|
|
};
|
2016-07-25 16:09:47 +02:00
|
|
|
Ok(ret)
|
2016-04-21 16:45:04 +02:00
|
|
|
}
|
|
|
|
|
2016-12-05 15:54:31 +01:00
|
|
|
fn network_id(&self) -> Option<u64> {
|
2017-09-05 13:30:22 +02:00
|
|
|
self.args.arg_network_id.or(self.args.arg_networkid)
|
2016-07-11 09:46:33 +02:00
|
|
|
}
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
fn rpc_apis(&self) -> String {
|
2017-09-05 13:30:22 +02:00
|
|
|
let mut apis: Vec<&str> = self.args.arg_rpcapi
|
2017-03-29 17:07:58 +02:00
|
|
|
.as_ref()
|
2017-09-05 13:30:22 +02:00
|
|
|
.unwrap_or(&self.args.arg_jsonrpc_apis)
|
2017-03-29 17:07:58 +02:00
|
|
|
.split(",")
|
|
|
|
.collect();
|
|
|
|
|
2016-11-06 12:51:53 +01:00
|
|
|
if self.args.flag_geth {
|
2017-04-06 19:38:33 +02:00
|
|
|
apis.insert(0, "personal");
|
2017-03-29 17:07:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
apis.join(",")
|
2016-04-30 19:58:28 +02:00
|
|
|
}
|
|
|
|
|
2017-12-27 18:56:06 +01:00
|
|
|
fn cors(cors: &str) -> Option<Vec<String>> {
|
|
|
|
match cors {
|
|
|
|
"none" => return Some(Vec::new()),
|
|
|
|
"*" | "all" | "any" => return None,
|
|
|
|
_ => {},
|
|
|
|
}
|
|
|
|
|
|
|
|
Some(cors.split(',').map(Into::into).collect())
|
2017-02-24 10:32:42 +01:00
|
|
|
}
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
fn rpc_cors(&self) -> Option<Vec<String>> {
|
2017-12-27 18:56:06 +01:00
|
|
|
let cors = self.args.arg_rpccorsdomain.clone().unwrap_or_else(|| self.args.arg_jsonrpc_cors.to_owned());
|
|
|
|
Self::cors(&cors)
|
2016-07-20 12:34:17 +02:00
|
|
|
}
|
|
|
|
|
2017-02-24 10:32:42 +01:00
|
|
|
fn ipfs_cors(&self) -> Option<Vec<String>> {
|
2017-09-05 13:30:22 +02:00
|
|
|
Self::cors(self.args.arg_ipfs_api_cors.as_ref())
|
2017-02-24 10:32:42 +01:00
|
|
|
}
|
|
|
|
|
2017-05-23 12:24:32 +02:00
|
|
|
fn hosts(&self, hosts: &str, interface: &str) -> Option<Vec<String>> {
|
|
|
|
if self.args.flag_unsafe_expose {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
if interface == "0.0.0.0" && hosts == "none" {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
Self::parse_hosts(hosts)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn parse_hosts(hosts: &str) -> Option<Vec<String>> {
|
2017-02-24 10:32:42 +01:00
|
|
|
match hosts {
|
2016-07-20 12:34:17 +02:00
|
|
|
"none" => return Some(Vec::new()),
|
2017-04-03 10:27:37 +02:00
|
|
|
"*" | "all" | "any" => return None,
|
2016-07-20 12:34:17 +02:00
|
|
|
_ => {}
|
|
|
|
}
|
2017-02-24 10:32:42 +01:00
|
|
|
let hosts = hosts.split(',').map(Into::into).collect();
|
2016-07-20 12:34:17 +02:00
|
|
|
Some(hosts)
|
2016-04-30 19:58:28 +02:00
|
|
|
}
|
2016-05-13 12:53:33 +02:00
|
|
|
|
2017-02-24 10:32:42 +01:00
|
|
|
fn rpc_hosts(&self) -> Option<Vec<String>> {
|
2017-09-05 13:30:22 +02:00
|
|
|
self.hosts(&self.args.arg_jsonrpc_hosts, &self.rpc_interface())
|
2017-02-24 10:32:42 +01:00
|
|
|
}
|
|
|
|
|
2017-04-13 16:32:07 +02:00
|
|
|
fn ws_hosts(&self) -> Option<Vec<String>> {
|
2017-09-05 13:30:22 +02:00
|
|
|
self.hosts(&self.args.arg_ws_hosts, &self.ws_interface())
|
2017-04-13 16:32:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn ws_origins(&self) -> Option<Vec<String>> {
|
2018-06-06 10:05:52 +02:00
|
|
|
if self.args.flag_unsafe_expose {
|
2017-06-03 14:41:42 +02:00
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2017-09-05 13:30:22 +02:00
|
|
|
Self::parse_hosts(&self.args.arg_ws_origins)
|
2017-04-13 16:32:07 +02:00
|
|
|
}
|
|
|
|
|
2017-02-24 10:32:42 +01:00
|
|
|
fn ipfs_hosts(&self) -> Option<Vec<String>> {
|
2017-09-05 13:30:22 +02:00
|
|
|
self.hosts(&self.args.arg_ipfs_api_hosts, &self.ipfs_interface())
|
2016-08-25 08:57:13 +02:00
|
|
|
}
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
fn ipc_config(&self) -> Result<IpcConfiguration, String> {
|
|
|
|
let conf = IpcConfiguration {
|
|
|
|
enabled: !(self.args.flag_ipcdisable || self.args.flag_ipc_off || self.args.flag_no_ipc),
|
|
|
|
socket_addr: self.ipc_path(),
|
2016-11-06 12:51:53 +01:00
|
|
|
apis: {
|
2017-09-05 13:30:22 +02:00
|
|
|
let mut apis = self.args.arg_ipcapi.clone().unwrap_or(self.args.arg_ipc_apis.clone());
|
2016-11-06 12:51:53 +01:00
|
|
|
if self.args.flag_geth {
|
2016-11-08 21:45:22 +01:00
|
|
|
if !apis.is_empty() {
|
|
|
|
apis.push_str(",");
|
|
|
|
}
|
2016-11-06 12:51:53 +01:00
|
|
|
apis.push_str("personal");
|
|
|
|
}
|
2016-12-27 12:53:56 +01:00
|
|
|
apis.parse()?
|
2016-11-06 12:51:53 +01:00
|
|
|
},
|
2016-07-25 16:09:47 +02:00
|
|
|
};
|
2016-05-13 12:53:33 +02:00
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
Ok(conf)
|
2016-05-14 19:43:29 +02:00
|
|
|
}
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
fn http_config(&self) -> Result<HttpConfiguration, String> {
|
2019-11-18 19:40:48 +01:00
|
|
|
let mut conf = HttpConfiguration::default();
|
|
|
|
conf.enabled = self.rpc_enabled();
|
|
|
|
conf.interface = self.rpc_interface();
|
|
|
|
conf.port = self.args.arg_ports_shift + self.args.arg_rpcport.unwrap_or(self.args.arg_jsonrpc_port);
|
|
|
|
conf.apis = self.rpc_apis().parse()?;
|
|
|
|
conf.hosts = self.rpc_hosts();
|
|
|
|
conf.cors = self.rpc_cors();
|
|
|
|
if let Some(threads) = self.args.arg_jsonrpc_server_threads {
|
|
|
|
conf.server_threads = std::cmp::max(1, threads);
|
|
|
|
}
|
|
|
|
if let Some(max_payload) = self.args.arg_jsonrpc_max_payload {
|
|
|
|
conf.max_payload = std::cmp::max(1, max_payload);
|
|
|
|
}
|
|
|
|
conf.keep_alive = !self.args.flag_jsonrpc_no_keep_alive;
|
2016-07-25 16:09:47 +02:00
|
|
|
|
|
|
|
Ok(conf)
|
2016-05-04 15:37:09 +02:00
|
|
|
}
|
|
|
|
|
2017-04-13 16:32:07 +02:00
|
|
|
fn ws_config(&self) -> Result<WsConfiguration, String> {
|
2018-03-20 18:57:37 +01:00
|
|
|
let support_token_api =
|
2018-06-01 16:49:55 +02:00
|
|
|
// enabled when not unlocking
|
2019-12-05 09:38:14 +01:00
|
|
|
self.args.arg_unlock.is_none() && self.args.arg_enable_signing_queue;
|
2018-03-20 18:57:37 +01:00
|
|
|
|
2017-04-13 16:32:07 +02:00
|
|
|
let conf = WsConfiguration {
|
|
|
|
enabled: self.ws_enabled(),
|
|
|
|
interface: self.ws_interface(),
|
2017-09-05 13:30:22 +02:00
|
|
|
port: self.args.arg_ports_shift + self.args.arg_ws_port,
|
|
|
|
apis: self.args.arg_ws_apis.parse()?,
|
2017-04-13 16:32:07 +02:00
|
|
|
hosts: self.ws_hosts(),
|
2017-05-24 12:24:07 +02:00
|
|
|
origins: self.ws_origins(),
|
|
|
|
signer_path: self.directories().signer.into(),
|
2018-03-20 18:57:37 +01:00
|
|
|
support_token_api,
|
2018-04-02 12:33:09 +02:00
|
|
|
max_connections: self.args.arg_ws_max_connections,
|
2017-04-13 16:32:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Ok(conf)
|
|
|
|
}
|
|
|
|
|
2018-04-09 16:14:33 +02:00
|
|
|
fn private_provider_config(&self) -> Result<(ProviderConfig, EncryptorConfig, bool), String> {
|
2019-05-14 11:21:22 +02:00
|
|
|
let dirs = self.directories();
|
2018-04-09 16:14:33 +02:00
|
|
|
let provider_conf = ProviderConfig {
|
|
|
|
validator_accounts: to_addresses(&self.args.arg_private_validators)?,
|
|
|
|
signer_account: self.args.arg_private_signer.clone().and_then(|account| to_address(Some(account)).ok()),
|
2019-06-19 16:28:31 +02:00
|
|
|
logs_path: match self.args.flag_private_enabled {
|
|
|
|
true => Some(dirs.base),
|
|
|
|
false => None,
|
2019-08-16 14:45:52 +02:00
|
|
|
},
|
|
|
|
use_offchain_storage: self.args.flag_private_state_offchain,
|
2018-04-09 16:14:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
let encryptor_conf = EncryptorConfig {
|
|
|
|
base_url: self.args.arg_private_sstore_url.clone(),
|
|
|
|
threshold: self.args.arg_private_sstore_threshold.unwrap_or(0),
|
|
|
|
key_server_account: self.args.arg_private_account.clone().and_then(|account| to_address(Some(account)).ok()),
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok((provider_conf, encryptor_conf, self.args.flag_private_enabled))
|
|
|
|
}
|
|
|
|
|
2018-09-13 12:58:49 +02:00
|
|
|
fn snapshot_config(&self) -> Result<SnapshotConfiguration, String> {
|
2019-06-29 10:43:57 +02:00
|
|
|
let mut conf = SnapshotConfiguration::default();
|
|
|
|
conf.no_periodic = self.args.flag_no_periodic_snapshot;
|
|
|
|
if let Some(threads) = self.args.arg_snapshot_threads {
|
|
|
|
if threads > 0 {
|
|
|
|
conf.processing_threads = threads;
|
|
|
|
}
|
|
|
|
}
|
2018-09-13 12:58:49 +02:00
|
|
|
|
|
|
|
Ok(conf)
|
|
|
|
}
|
|
|
|
|
2017-05-23 12:24:32 +02:00
|
|
|
fn network_settings(&self) -> Result<NetworkSettings, String> {
|
|
|
|
let http_conf = self.http_config()?;
|
|
|
|
let net_addresses = self.net_addresses()?;
|
|
|
|
Ok(NetworkSettings {
|
2017-09-05 13:30:22 +02:00
|
|
|
name: self.args.arg_identity.clone(),
|
2017-10-24 12:25:34 +02:00
|
|
|
chain: format!("{}", self.chain()?),
|
2018-11-07 09:30:34 +01:00
|
|
|
is_dev_chain: self.is_dev_chain()?,
|
2017-05-23 12:24:32 +02:00
|
|
|
network_port: net_addresses.0.port(),
|
|
|
|
rpc_enabled: http_conf.enabled,
|
|
|
|
rpc_interface: http_conf.interface,
|
|
|
|
rpc_port: http_conf.port,
|
|
|
|
})
|
2016-04-21 19:19:42 +02:00
|
|
|
}
|
2016-05-13 17:32:32 +02:00
|
|
|
|
2016-11-23 20:35:21 +01:00
|
|
|
fn update_policy(&self) -> Result<UpdatePolicy, String> {
|
|
|
|
Ok(UpdatePolicy {
|
|
|
|
enable_downloading: !self.args.flag_no_download,
|
2016-12-11 16:52:41 +01:00
|
|
|
require_consensus: !self.args.flag_no_consensus,
|
2017-09-05 13:30:22 +02:00
|
|
|
filter: match self.args.arg_auto_update.as_ref() {
|
2016-11-23 20:35:21 +01:00
|
|
|
"none" => UpdateFilter::None,
|
|
|
|
"critical" => UpdateFilter::Critical,
|
|
|
|
"all" => UpdateFilter::All,
|
2016-12-16 21:45:51 +01:00
|
|
|
_ => return Err("Invalid value for `--auto-update`. See `--help` for more information.".into()),
|
2016-11-23 20:35:21 +01:00
|
|
|
},
|
2017-09-05 13:30:22 +02:00
|
|
|
track: match self.args.arg_release_track.as_ref() {
|
2016-12-15 18:51:59 +01:00
|
|
|
"stable" => ReleaseTrack::Stable,
|
|
|
|
"beta" => ReleaseTrack::Beta,
|
|
|
|
"nightly" => ReleaseTrack::Nightly,
|
|
|
|
"testing" => ReleaseTrack::Testing,
|
|
|
|
"current" => ReleaseTrack::Unknown,
|
2016-12-16 21:45:51 +01:00
|
|
|
_ => return Err("Invalid value for `--releases-track`. See `--help` for more information.".into()),
|
2016-12-15 18:51:59 +01:00
|
|
|
},
|
2016-12-15 19:53:13 +01:00
|
|
|
path: default_hypervisor_path(),
|
2018-03-14 13:40:54 +01:00
|
|
|
max_size: 128 * 1024 * 1024,
|
2018-04-03 16:49:23 +02:00
|
|
|
max_delay: self.args.arg_auto_update_delay as u64,
|
|
|
|
frequency: self.args.arg_auto_update_check_frequency as u64,
|
2016-11-23 20:35:21 +01:00
|
|
|
})
|
2016-11-23 16:29:15 +01:00
|
|
|
}
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
fn directories(&self) -> Directories {
|
2017-01-05 14:12:54 +01:00
|
|
|
let local_path = default_local_path();
|
2017-09-05 13:30:22 +02:00
|
|
|
let base_path = self.args.arg_base_path.as_ref().or_else(|| self.args.arg_datadir.as_ref()).map_or_else(|| default_data_path(), |s| s.clone());
|
2017-05-29 15:15:54 +02:00
|
|
|
let data_path = replace_home("", &base_path);
|
2017-09-05 13:30:22 +02:00
|
|
|
let is_using_base_path = self.args.arg_base_path.is_some();
|
2017-07-10 12:57:40 +02:00
|
|
|
// If base_path is set and db_path is not we default to base path subdir instead of LOCAL.
|
2017-09-05 13:30:22 +02:00
|
|
|
let base_db_path = if is_using_base_path && self.args.arg_db_path.is_none() {
|
2018-07-11 16:17:35 +02:00
|
|
|
if self.args.flag_light {
|
|
|
|
"$BASE/chains_light"
|
|
|
|
} else {
|
|
|
|
"$BASE/chains"
|
|
|
|
}
|
|
|
|
} else if self.args.flag_light {
|
|
|
|
self.args.arg_db_path.as_ref().map_or(dir::CHAINS_PATH_LIGHT, |s| &s)
|
2017-01-05 14:12:54 +01:00
|
|
|
} else {
|
2017-09-05 13:30:22 +02:00
|
|
|
self.args.arg_db_path.as_ref().map_or(dir::CHAINS_PATH, |s| &s)
|
2017-01-05 14:12:54 +01:00
|
|
|
};
|
2017-08-02 12:38:58 +02:00
|
|
|
let cache_path = if is_using_base_path { "$BASE/cache" } else { dir::CACHE_PATH };
|
2017-01-18 18:45:30 +01:00
|
|
|
|
2017-07-10 12:57:40 +02:00
|
|
|
let db_path = replace_home_and_local(&data_path, &local_path, &base_db_path);
|
2017-08-02 12:38:58 +02:00
|
|
|
let cache_path = replace_home_and_local(&data_path, &local_path, cache_path);
|
2017-09-05 13:30:22 +02:00
|
|
|
let keys_path = replace_home(&data_path, &self.args.arg_keys_path);
|
|
|
|
let secretstore_path = replace_home(&data_path, &self.args.arg_secretstore_path);
|
|
|
|
let ui_path = replace_home(&data_path, &self.args.arg_ui_path);
|
2016-05-13 17:32:32 +02:00
|
|
|
|
|
|
|
Directories {
|
|
|
|
keys: keys_path,
|
2016-12-15 21:56:45 +01:00
|
|
|
base: data_path,
|
2017-07-10 12:57:40 +02:00
|
|
|
cache: cache_path,
|
2016-12-15 21:56:45 +01:00
|
|
|
db: db_path,
|
2016-11-07 17:40:53 +01:00
|
|
|
signer: ui_path,
|
2017-02-20 16:13:21 +01:00
|
|
|
secretstore: secretstore_path,
|
2016-05-13 17:32:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn ipc_path(&self) -> String {
|
2016-06-15 00:57:49 +02:00
|
|
|
if self.args.flag_geth {
|
2016-07-25 16:09:47 +02:00
|
|
|
geth_ipc_path(self.args.flag_testnet)
|
2016-06-15 00:57:49 +02:00
|
|
|
} else {
|
2017-05-23 12:24:32 +02:00
|
|
|
parity_ipc_path(
|
|
|
|
&self.directories().base,
|
2017-09-05 13:30:22 +02:00
|
|
|
&self.args.arg_ipcpath.clone().unwrap_or(self.args.arg_ipc_path.clone()),
|
|
|
|
self.args.arg_ports_shift,
|
2017-05-23 12:24:32 +02:00
|
|
|
)
|
2016-06-13 18:55:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-23 12:24:32 +02:00
|
|
|
fn interface(&self, interface: &str) -> String {
|
|
|
|
if self.args.flag_unsafe_expose {
|
|
|
|
return "0.0.0.0".into();
|
|
|
|
}
|
|
|
|
|
2017-02-24 10:32:42 +01:00
|
|
|
match interface {
|
2016-06-24 12:10:36 +02:00
|
|
|
"all" => "0.0.0.0",
|
|
|
|
"local" => "127.0.0.1",
|
|
|
|
x => x,
|
|
|
|
}.into()
|
|
|
|
}
|
|
|
|
|
2017-02-24 10:32:42 +01:00
|
|
|
fn rpc_interface(&self) -> String {
|
2017-09-05 13:30:22 +02:00
|
|
|
let rpc_interface = self.args.arg_rpcaddr.clone().unwrap_or(self.args.arg_jsonrpc_interface.clone());
|
2017-05-23 12:24:32 +02:00
|
|
|
self.interface(&rpc_interface)
|
2017-02-24 10:32:42 +01:00
|
|
|
}
|
|
|
|
|
2017-04-13 16:32:07 +02:00
|
|
|
fn ws_interface(&self) -> String {
|
2017-09-05 13:30:22 +02:00
|
|
|
self.interface(&self.args.arg_ws_interface)
|
2017-04-13 16:32:07 +02:00
|
|
|
}
|
|
|
|
|
2017-02-24 10:32:42 +01:00
|
|
|
fn ipfs_interface(&self) -> String {
|
2017-09-05 13:30:22 +02:00
|
|
|
self.interface(&self.args.arg_ipfs_api_interface)
|
2017-02-24 10:32:42 +01:00
|
|
|
}
|
|
|
|
|
2017-02-20 16:13:21 +01:00
|
|
|
fn secretstore_interface(&self) -> String {
|
2017-09-05 13:30:22 +02:00
|
|
|
self.interface(&self.args.arg_secretstore_interface)
|
2017-04-08 11:26:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn secretstore_http_interface(&self) -> String {
|
2017-09-05 13:30:22 +02:00
|
|
|
self.interface(&self.args.arg_secretstore_http_interface)
|
2017-04-08 11:26:16 +02:00
|
|
|
}
|
|
|
|
|
2019-04-20 07:31:37 +02:00
|
|
|
fn secretstore_cors(&self) -> Option<Vec<String>> {
|
|
|
|
Self::cors(self.args.arg_secretstore_http_cors.as_ref())
|
|
|
|
}
|
|
|
|
|
2017-08-09 11:09:40 +02:00
|
|
|
fn secretstore_self_secret(&self) -> Result<Option<NodeSecretKey>, String> {
|
2017-09-05 13:30:22 +02:00
|
|
|
match self.args.arg_secretstore_secret {
|
2017-08-09 11:09:40 +02:00
|
|
|
Some(ref s) if s.len() == 64 => Ok(Some(NodeSecretKey::Plain(s.parse()
|
|
|
|
.map_err(|e| format!("Invalid secret store secret: {}. Error: {:?}", s, e))?))),
|
2019-02-07 14:34:24 +01:00
|
|
|
#[cfg(feature = "accounts")]
|
2017-08-09 11:09:40 +02:00
|
|
|
Some(ref s) if s.len() == 40 => Ok(Some(NodeSecretKey::KeyStore(s.parse()
|
|
|
|
.map_err(|e| format!("Invalid secret store secret address: {}. Error: {:?}", s, e))?))),
|
|
|
|
Some(_) => Err(format!("Invalid secret store secret. Must be either existing account address, or hex-encoded private key")),
|
2017-04-08 11:26:16 +02:00
|
|
|
None => Ok(None),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-02 15:27:31 +02:00
|
|
|
fn secretstore_admin_public(&self) -> Result<Option<Public>, String> {
|
|
|
|
match self.args.arg_secretstore_admin_public.as_ref() {
|
|
|
|
Some(admin_public) => Ok(Some(admin_public.parse().map_err(|e| format!("Invalid secret store admin public: {}", e))?)),
|
|
|
|
None => Ok(None),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-08 11:26:16 +02:00
|
|
|
fn secretstore_nodes(&self) -> Result<BTreeMap<Public, (String, u16)>, String> {
|
|
|
|
let mut nodes = BTreeMap::new();
|
2017-09-05 13:30:22 +02:00
|
|
|
for node in self.args.arg_secretstore_nodes.split(',').filter(|n| n != &"") {
|
2017-04-08 11:26:16 +02:00
|
|
|
let public_and_addr: Vec<_> = node.split('@').collect();
|
|
|
|
if public_and_addr.len() != 2 {
|
|
|
|
return Err(format!("Invalid secret store node: {}", node));
|
|
|
|
}
|
|
|
|
|
|
|
|
let ip_and_port: Vec<_> = public_and_addr[1].split(':').collect();
|
|
|
|
if ip_and_port.len() != 2 {
|
|
|
|
return Err(format!("Invalid secret store node: {}", node));
|
|
|
|
}
|
|
|
|
|
|
|
|
let public = public_and_addr[0].parse()
|
|
|
|
.map_err(|e| format!("Invalid public key in secret store node: {}. Error: {:?}", public_and_addr[0], e))?;
|
|
|
|
let port = ip_and_port[1].parse()
|
|
|
|
.map_err(|e| format!("Invalid port in secret store node: {}. Error: {:?}", ip_and_port[1], e))?;
|
|
|
|
|
|
|
|
nodes.insert(public, (ip_and_port[0].into(), port));
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(nodes)
|
2017-02-20 16:13:21 +01:00
|
|
|
}
|
|
|
|
|
2017-01-25 11:03:36 +01:00
|
|
|
fn stratum_interface(&self) -> String {
|
2017-09-05 13:30:22 +02:00
|
|
|
self.interface(&self.args.arg_stratum_interface)
|
2017-01-25 11:03:36 +01:00
|
|
|
}
|
|
|
|
|
2017-04-03 10:27:37 +02:00
|
|
|
fn rpc_enabled(&self) -> bool {
|
|
|
|
!self.args.flag_jsonrpc_off && !self.args.flag_no_jsonrpc
|
|
|
|
}
|
|
|
|
|
2017-04-13 16:32:07 +02:00
|
|
|
fn ws_enabled(&self) -> bool {
|
|
|
|
!self.args.flag_no_ws
|
|
|
|
}
|
|
|
|
|
2017-02-20 16:13:21 +01:00
|
|
|
fn secretstore_enabled(&self) -> bool {
|
|
|
|
!self.args.flag_no_secretstore && cfg!(feature = "secretstore")
|
|
|
|
}
|
|
|
|
|
2017-07-27 12:29:09 +02:00
|
|
|
fn secretstore_http_enabled(&self) -> bool {
|
|
|
|
!self.args.flag_no_secretstore_http && cfg!(feature = "secretstore")
|
|
|
|
}
|
|
|
|
|
2018-01-10 11:33:45 +01:00
|
|
|
fn secretstore_auto_migrate_enabled(&self) -> bool {
|
|
|
|
!self.args.flag_no_secretstore_auto_migrate
|
|
|
|
}
|
|
|
|
|
2018-06-14 09:01:52 +02:00
|
|
|
fn secretstore_acl_check_contract_address(&self) -> Result<Option<SecretStoreContractAddress>, String> {
|
|
|
|
into_secretstore_service_contract_address(self.args.arg_secretstore_acl_contract.as_ref())
|
|
|
|
}
|
|
|
|
|
2017-11-24 10:33:33 +01:00
|
|
|
fn secretstore_service_contract_address(&self) -> Result<Option<SecretStoreContractAddress>, String> {
|
2018-04-03 16:54:34 +02:00
|
|
|
into_secretstore_service_contract_address(self.args.arg_secretstore_contract.as_ref())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn secretstore_service_contract_srv_gen_address(&self) -> Result<Option<SecretStoreContractAddress>, String> {
|
|
|
|
into_secretstore_service_contract_address(self.args.arg_secretstore_srv_gen_contract.as_ref())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn secretstore_service_contract_srv_retr_address(&self) -> Result<Option<SecretStoreContractAddress>, String> {
|
|
|
|
into_secretstore_service_contract_address(self.args.arg_secretstore_srv_retr_contract.as_ref())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn secretstore_service_contract_doc_store_address(&self) -> Result<Option<SecretStoreContractAddress>, String> {
|
|
|
|
into_secretstore_service_contract_address(self.args.arg_secretstore_doc_store_contract.as_ref())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn secretstore_service_contract_doc_sretr_address(&self) -> Result<Option<SecretStoreContractAddress>, String> {
|
|
|
|
into_secretstore_service_contract_address(self.args.arg_secretstore_doc_sretr_contract.as_ref())
|
2017-11-24 10:33:33 +01:00
|
|
|
}
|
|
|
|
|
2018-06-14 09:01:52 +02:00
|
|
|
fn secretstore_key_server_set_contract_address(&self) -> Result<Option<SecretStoreContractAddress>, String> {
|
|
|
|
into_secretstore_service_contract_address(self.args.arg_secretstore_server_set_contract.as_ref())
|
|
|
|
}
|
|
|
|
|
2016-12-02 18:21:54 +01:00
|
|
|
fn verifier_settings(&self) -> VerifierSettings {
|
|
|
|
let mut settings = VerifierSettings::default();
|
|
|
|
settings.scale_verifiers = self.args.flag_scale_verifiers;
|
2017-09-05 13:30:22 +02:00
|
|
|
if let Some(num_verifiers) = self.args.arg_num_verifiers {
|
2016-12-02 18:21:54 +01:00
|
|
|
settings.num_verifiers = num_verifiers;
|
|
|
|
}
|
|
|
|
|
|
|
|
settings
|
|
|
|
}
|
2016-04-21 16:45:04 +02:00
|
|
|
}
|
|
|
|
|
2018-06-14 09:01:52 +02:00
|
|
|
fn into_secretstore_service_contract_address(s: Option<&String>) -> Result<Option<SecretStoreContractAddress>, String> {
|
|
|
|
match s.map(String::as_str) {
|
|
|
|
None | Some("none") => Ok(None),
|
|
|
|
Some("registry") => Ok(Some(SecretStoreContractAddress::Registry)),
|
|
|
|
Some(a) => Ok(Some(SecretStoreContractAddress::Address(a.parse().map_err(|e| format!("{}", e))?))),
|
2018-04-03 16:54:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-30 19:58:28 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2017-05-24 12:24:07 +02:00
|
|
|
use std::io::Write;
|
2018-01-19 17:32:53 +01:00
|
|
|
use std::fs::File;
|
2017-07-28 19:06:39 +02:00
|
|
|
use std::str::FromStr;
|
2017-05-24 12:24:07 +02:00
|
|
|
|
2018-01-19 17:32:53 +01:00
|
|
|
use tempdir::TempDir;
|
2018-01-11 17:49:10 +01:00
|
|
|
use ethcore::miner::MinerOptions;
|
2018-04-13 17:34:27 +02:00
|
|
|
use miner::pool::PrioritizationStrategy;
|
2017-05-24 12:24:07 +02:00
|
|
|
use parity_rpc::NetworkSettings;
|
|
|
|
use updater::{UpdatePolicy, UpdateFilter, ReleaseTrack};
|
2019-08-13 12:33:34 +02:00
|
|
|
use types::ids::BlockId;
|
2019-09-09 13:46:05 +02:00
|
|
|
use types::data_format::DataFormat;
|
2017-05-24 12:24:07 +02:00
|
|
|
use account::{AccountCmd, NewAccount, ImportAccounts, ListAccounts};
|
2019-09-09 13:46:05 +02:00
|
|
|
use blockchain::{BlockchainCmd, ImportBlockchain, ExportBlockchain, ExportState};
|
2017-05-24 12:24:07 +02:00
|
|
|
use cli::Args;
|
|
|
|
use dir::{Directories, default_hypervisor_path};
|
|
|
|
use helpers::{default_network_config};
|
2016-12-12 17:53:17 +01:00
|
|
|
use params::SpecType;
|
2017-05-24 12:24:07 +02:00
|
|
|
use presale::ImportWallet;
|
2018-06-06 10:05:52 +02:00
|
|
|
use rpc::WsConfiguration;
|
2018-06-01 16:49:55 +02:00
|
|
|
use rpc_apis::ApiSet;
|
2017-05-24 12:24:07 +02:00
|
|
|
use run::RunCmd;
|
|
|
|
|
2017-07-28 19:06:39 +02:00
|
|
|
use network::{AllowIP, IpFilter};
|
|
|
|
|
|
|
|
extern crate ipnetwork;
|
|
|
|
use self::ipnetwork::IpNetwork;
|
|
|
|
|
2017-05-24 12:24:07 +02:00
|
|
|
use super::*;
|
2016-07-25 16:09:47 +02:00
|
|
|
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
struct TestPasswordReader(&'static str);
|
2016-04-30 19:58:28 +02:00
|
|
|
|
|
|
|
fn parse(args: &[&str]) -> Configuration {
|
|
|
|
Configuration {
|
2016-09-11 11:52:12 +02:00
|
|
|
args: Args::parse_without_config(args).unwrap(),
|
2016-04-30 19:58:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
#[test]
|
|
|
|
fn test_command_version() {
|
|
|
|
let args = vec!["parity", "--version"];
|
2016-09-12 14:11:30 +02:00
|
|
|
let conf = parse(&args);
|
2016-11-02 19:42:21 +01:00
|
|
|
assert_eq!(conf.into_command().unwrap().cmd, Cmd::Version);
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_command_account_new() {
|
|
|
|
let args = vec!["parity", "account", "new"];
|
2016-09-12 14:11:30 +02:00
|
|
|
let conf = parse(&args);
|
2016-11-02 19:42:21 +01:00
|
|
|
assert_eq!(conf.into_command().unwrap().cmd, Cmd::Account(AccountCmd::New(NewAccount {
|
2019-05-28 07:50:10 +02:00
|
|
|
iterations: 10240,
|
2016-12-13 23:38:29 +01:00
|
|
|
path: Directories::default().keys,
|
2016-07-25 16:09:47 +02:00
|
|
|
password_file: None,
|
2016-12-12 17:53:17 +01:00
|
|
|
spec: SpecType::default(),
|
2016-07-25 16:09:47 +02:00
|
|
|
})));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_command_account_list() {
|
|
|
|
let args = vec!["parity", "account", "list"];
|
2016-09-12 14:11:30 +02:00
|
|
|
let conf = parse(&args);
|
2016-11-02 19:42:21 +01:00
|
|
|
assert_eq!(conf.into_command().unwrap().cmd, Cmd::Account(
|
2016-12-12 17:53:17 +01:00
|
|
|
AccountCmd::List(ListAccounts {
|
2016-12-13 23:38:29 +01:00
|
|
|
path: Directories::default().keys,
|
2016-12-12 17:53:17 +01:00
|
|
|
spec: SpecType::default(),
|
|
|
|
})
|
2016-11-02 19:42:21 +01:00
|
|
|
));
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_command_account_import() {
|
|
|
|
let args = vec!["parity", "account", "import", "my_dir", "another_dir"];
|
2016-09-12 14:11:30 +02:00
|
|
|
let conf = parse(&args);
|
2016-11-02 19:42:21 +01:00
|
|
|
assert_eq!(conf.into_command().unwrap().cmd, Cmd::Account(AccountCmd::Import(ImportAccounts {
|
2016-07-25 16:09:47 +02:00
|
|
|
from: vec!["my_dir".into(), "another_dir".into()],
|
2016-12-13 23:38:29 +01:00
|
|
|
to: Directories::default().keys,
|
2016-12-12 17:53:17 +01:00
|
|
|
spec: SpecType::default(),
|
2016-07-25 16:09:47 +02:00
|
|
|
})));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_command_wallet_import() {
|
|
|
|
let args = vec!["parity", "wallet", "import", "my_wallet.json", "--password", "pwd"];
|
2016-09-12 14:11:30 +02:00
|
|
|
let conf = parse(&args);
|
2016-11-02 19:42:21 +01:00
|
|
|
assert_eq!(conf.into_command().unwrap().cmd, Cmd::ImportPresaleWallet(ImportWallet {
|
2019-05-28 07:50:10 +02:00
|
|
|
iterations: 10240,
|
2016-12-13 23:38:29 +01:00
|
|
|
path: Directories::default().keys,
|
2016-07-25 16:09:47 +02:00
|
|
|
wallet_path: "my_wallet.json".into(),
|
|
|
|
password_file: Some("pwd".into()),
|
2016-12-12 17:53:17 +01:00
|
|
|
spec: SpecType::default(),
|
2016-07-25 16:09:47 +02:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_command_blockchain_import() {
|
|
|
|
let args = vec!["parity", "import", "blockchain.json"];
|
2016-09-12 14:11:30 +02:00
|
|
|
let conf = parse(&args);
|
2016-11-02 19:42:21 +01:00
|
|
|
assert_eq!(conf.into_command().unwrap().cmd, Cmd::Blockchain(BlockchainCmd::Import(ImportBlockchain {
|
2016-07-25 16:09:47 +02:00
|
|
|
spec: Default::default(),
|
|
|
|
cache_config: Default::default(),
|
|
|
|
dirs: Default::default(),
|
|
|
|
file_path: Some("blockchain.json".into()),
|
2016-08-04 09:22:54 +02:00
|
|
|
format: Default::default(),
|
2016-07-25 16:09:47 +02:00
|
|
|
pruning: Default::default(),
|
2017-02-13 17:15:25 +01:00
|
|
|
pruning_history: 64,
|
2017-05-02 11:40:03 +02:00
|
|
|
pruning_memory: 32,
|
2016-07-25 16:09:47 +02:00
|
|
|
compaction: Default::default(),
|
|
|
|
tracing: Default::default(),
|
2016-10-03 11:13:10 +02:00
|
|
|
fat_db: Default::default(),
|
2016-10-24 15:09:13 +02:00
|
|
|
check_seal: true,
|
2016-11-03 16:11:08 +01:00
|
|
|
with_color: !cfg!(windows),
|
2016-12-02 18:36:00 +01:00
|
|
|
verifier_settings: Default::default(),
|
2017-07-27 13:50:12 +02:00
|
|
|
light: false,
|
2018-10-26 13:21:36 +02:00
|
|
|
max_round_blocks_to_import: 12,
|
2016-07-25 16:09:47 +02:00
|
|
|
})));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_command_blockchain_export() {
|
2016-11-28 12:08:12 +01:00
|
|
|
let args = vec!["parity", "export", "blocks", "blockchain.json"];
|
2016-09-12 14:11:30 +02:00
|
|
|
let conf = parse(&args);
|
2016-11-02 19:42:21 +01:00
|
|
|
assert_eq!(conf.into_command().unwrap().cmd, Cmd::Blockchain(BlockchainCmd::Export(ExportBlockchain {
|
2016-07-25 16:09:47 +02:00
|
|
|
spec: Default::default(),
|
|
|
|
cache_config: Default::default(),
|
|
|
|
dirs: Default::default(),
|
|
|
|
file_path: Some("blockchain.json".into()),
|
|
|
|
pruning: Default::default(),
|
2017-02-13 17:15:25 +01:00
|
|
|
pruning_history: 64,
|
2017-05-02 11:40:03 +02:00
|
|
|
pruning_memory: 32,
|
2016-07-25 16:09:47 +02:00
|
|
|
format: Default::default(),
|
|
|
|
compaction: Default::default(),
|
|
|
|
tracing: Default::default(),
|
2016-10-03 11:13:10 +02:00
|
|
|
fat_db: Default::default(),
|
2016-11-22 10:24:22 +01:00
|
|
|
from_block: BlockId::Number(1),
|
|
|
|
to_block: BlockId::Latest,
|
2016-10-24 15:09:13 +02:00
|
|
|
check_seal: true,
|
2018-10-26 13:21:36 +02:00
|
|
|
max_round_blocks_to_import: 12,
|
2016-07-25 16:09:47 +02:00
|
|
|
})));
|
|
|
|
}
|
|
|
|
|
2016-11-28 12:08:12 +01:00
|
|
|
#[test]
|
|
|
|
fn test_command_state_export() {
|
|
|
|
let args = vec!["parity", "export", "state", "state.json"];
|
|
|
|
let conf = parse(&args);
|
|
|
|
assert_eq!(conf.into_command().unwrap().cmd, Cmd::Blockchain(BlockchainCmd::ExportState(ExportState {
|
|
|
|
spec: Default::default(),
|
|
|
|
cache_config: Default::default(),
|
|
|
|
dirs: Default::default(),
|
|
|
|
file_path: Some("state.json".into()),
|
|
|
|
pruning: Default::default(),
|
2017-02-13 17:15:25 +01:00
|
|
|
pruning_history: 64,
|
2017-05-02 11:40:03 +02:00
|
|
|
pruning_memory: 32,
|
2016-11-28 12:08:12 +01:00
|
|
|
format: Default::default(),
|
|
|
|
compaction: Default::default(),
|
|
|
|
tracing: Default::default(),
|
|
|
|
fat_db: Default::default(),
|
2016-12-04 18:13:23 +01:00
|
|
|
at: BlockId::Latest,
|
2016-11-28 12:08:12 +01:00
|
|
|
storage: true,
|
|
|
|
code: true,
|
|
|
|
min_balance: None,
|
|
|
|
max_balance: None,
|
2018-10-26 13:21:36 +02:00
|
|
|
max_round_blocks_to_import: 12,
|
2016-11-28 12:08:12 +01:00
|
|
|
})));
|
|
|
|
}
|
|
|
|
|
2016-08-04 09:22:54 +02:00
|
|
|
#[test]
|
|
|
|
fn test_command_blockchain_export_with_custom_format() {
|
2016-11-28 12:08:12 +01:00
|
|
|
let args = vec!["parity", "export", "blocks", "--format", "hex", "blockchain.json"];
|
2016-09-12 14:11:30 +02:00
|
|
|
let conf = parse(&args);
|
2016-11-02 19:42:21 +01:00
|
|
|
assert_eq!(conf.into_command().unwrap().cmd, Cmd::Blockchain(BlockchainCmd::Export(ExportBlockchain {
|
2016-08-04 09:22:54 +02:00
|
|
|
spec: Default::default(),
|
|
|
|
cache_config: Default::default(),
|
|
|
|
dirs: Default::default(),
|
|
|
|
file_path: Some("blockchain.json".into()),
|
|
|
|
pruning: Default::default(),
|
2017-02-13 17:15:25 +01:00
|
|
|
pruning_history: 64,
|
2017-05-02 11:40:03 +02:00
|
|
|
pruning_memory: 32,
|
2016-08-04 09:22:54 +02:00
|
|
|
format: Some(DataFormat::Hex),
|
|
|
|
compaction: Default::default(),
|
|
|
|
tracing: Default::default(),
|
2016-10-03 11:13:10 +02:00
|
|
|
fat_db: Default::default(),
|
2016-11-22 10:24:22 +01:00
|
|
|
from_block: BlockId::Number(1),
|
|
|
|
to_block: BlockId::Latest,
|
2016-10-24 15:09:13 +02:00
|
|
|
check_seal: true,
|
2018-10-26 13:21:36 +02:00
|
|
|
max_round_blocks_to_import: 12,
|
2016-08-04 09:22:54 +02:00
|
|
|
})));
|
|
|
|
}
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
#[test]
|
|
|
|
fn test_command_signer_new_token() {
|
|
|
|
let args = vec!["parity", "signer", "new-token"];
|
2016-09-12 14:11:30 +02:00
|
|
|
let conf = parse(&args);
|
2016-12-13 23:38:29 +01:00
|
|
|
let expected = Directories::default().signer;
|
2017-05-24 12:24:07 +02:00
|
|
|
assert_eq!(conf.into_command().unwrap().cmd, Cmd::SignerToken(WsConfiguration {
|
|
|
|
enabled: true,
|
|
|
|
interface: "127.0.0.1".into(),
|
|
|
|
port: 8546,
|
|
|
|
apis: ApiSet::UnsafeContext,
|
2018-03-02 10:26:49 +01:00
|
|
|
origins: Some(vec!["parity://*".into(),"chrome-extension://*".into(), "moz-extension://*".into()]),
|
2017-05-24 12:24:07 +02:00
|
|
|
hosts: Some(vec![]),
|
|
|
|
signer_path: expected.into(),
|
2019-12-05 09:38:14 +01:00
|
|
|
support_token_api: false,
|
2018-04-02 12:33:09 +02:00
|
|
|
max_connections: 100,
|
2017-07-28 19:07:38 +02:00
|
|
|
}, LogConfig {
|
2018-10-31 11:50:38 +01:00
|
|
|
color: !cfg!(windows),
|
2018-09-12 11:47:01 +02:00
|
|
|
mode: None,
|
|
|
|
file: None,
|
|
|
|
} ));
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
|
|
|
|
2018-04-02 12:33:09 +02:00
|
|
|
#[test]
|
|
|
|
fn test_ws_max_connections() {
|
|
|
|
let args = vec!["parity", "--ws-max-connections", "1"];
|
|
|
|
let conf = parse(&args);
|
|
|
|
|
|
|
|
assert_eq!(conf.ws_config().unwrap(), WsConfiguration {
|
|
|
|
max_connections: 1,
|
|
|
|
..Default::default()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
#[test]
|
|
|
|
fn test_run_cmd() {
|
|
|
|
let args = vec!["parity"];
|
2016-09-12 14:11:30 +02:00
|
|
|
let conf = parse(&args);
|
2017-02-20 16:13:21 +01:00
|
|
|
let mut expected = RunCmd {
|
2018-11-26 19:58:27 +01:00
|
|
|
allow_missing_blocks: false,
|
2016-07-25 16:09:47 +02:00
|
|
|
cache_config: Default::default(),
|
|
|
|
dirs: Default::default(),
|
|
|
|
spec: Default::default(),
|
|
|
|
pruning: Default::default(),
|
2017-02-13 17:15:25 +01:00
|
|
|
pruning_history: 64,
|
2017-05-02 11:40:03 +02:00
|
|
|
pruning_memory: 32,
|
2016-07-25 16:09:47 +02:00
|
|
|
daemon: None,
|
|
|
|
logger_config: Default::default(),
|
|
|
|
miner_options: Default::default(),
|
2018-01-09 12:43:36 +01:00
|
|
|
gas_price_percentile: 50,
|
2018-06-18 13:42:54 +02:00
|
|
|
poll_lifetime: 60,
|
2017-04-13 16:32:07 +02:00
|
|
|
ws_conf: Default::default(),
|
2016-07-25 16:09:47 +02:00
|
|
|
http_conf: Default::default(),
|
|
|
|
ipc_conf: Default::default(),
|
|
|
|
net_conf: default_network_config(),
|
|
|
|
network_id: None,
|
2017-03-02 20:04:17 +01:00
|
|
|
warp_sync: true,
|
2018-03-29 11:20:27 +02:00
|
|
|
warp_barrier: None,
|
2016-07-25 16:09:47 +02:00
|
|
|
acc_conf: Default::default(),
|
2017-07-16 18:22:45 +02:00
|
|
|
gas_pricer_conf: Default::default(),
|
2016-07-25 16:09:47 +02:00
|
|
|
miner_extras: Default::default(),
|
2018-02-09 09:32:06 +01:00
|
|
|
update_policy: UpdatePolicy {
|
|
|
|
enable_downloading: true,
|
|
|
|
require_consensus: true,
|
|
|
|
filter: UpdateFilter::Critical,
|
|
|
|
track: ReleaseTrack::Unknown,
|
2018-03-14 13:40:54 +01:00
|
|
|
path: default_hypervisor_path(),
|
|
|
|
max_size: 128 * 1024 * 1024,
|
2018-04-03 16:49:23 +02:00
|
|
|
max_delay: 100,
|
|
|
|
frequency: 20,
|
2018-02-09 09:32:06 +01:00
|
|
|
},
|
2016-07-25 16:09:47 +02:00
|
|
|
mode: Default::default(),
|
|
|
|
tracing: Default::default(),
|
|
|
|
compaction: Default::default(),
|
|
|
|
geth_compatibility: false,
|
2018-11-16 14:00:34 +01:00
|
|
|
experimental_rpcs: false,
|
2016-07-25 16:09:47 +02:00
|
|
|
net_settings: Default::default(),
|
2017-02-16 14:41:33 +01:00
|
|
|
ipfs_conf: Default::default(),
|
2017-02-20 16:13:21 +01:00
|
|
|
secretstore_conf: Default::default(),
|
2019-06-19 16:28:31 +02:00
|
|
|
private_provider_conf: Default::default(),
|
2018-04-09 16:14:33 +02:00
|
|
|
private_encryptor_conf: Default::default(),
|
|
|
|
private_tx_enabled: false,
|
2016-07-25 16:09:47 +02:00
|
|
|
name: "".into(),
|
|
|
|
custom_bootnodes: false,
|
2016-10-03 11:13:10 +02:00
|
|
|
fat_db: Default::default(),
|
2018-09-13 12:58:49 +02:00
|
|
|
snapshot_conf: Default::default(),
|
2017-01-25 11:03:36 +01:00
|
|
|
stratum: None,
|
2016-10-24 15:09:13 +02:00
|
|
|
check_seal: true,
|
2016-11-22 18:03:35 +01:00
|
|
|
download_old_blocks: true,
|
2016-12-02 18:36:00 +01:00
|
|
|
verifier_settings: Default::default(),
|
2017-03-22 16:45:50 +01:00
|
|
|
serve_light: true,
|
|
|
|
light: false,
|
2018-03-27 13:56:59 +02:00
|
|
|
no_hardcoded_sync: false,
|
2017-05-04 12:13:50 +02:00
|
|
|
no_persistent_txqueue: false,
|
2018-10-26 13:21:36 +02:00
|
|
|
max_round_blocks_to_import: 12,
|
2018-12-05 10:36:53 +01:00
|
|
|
on_demand_response_time_window: None,
|
|
|
|
on_demand_request_backoff_start: None,
|
|
|
|
on_demand_request_backoff_max: None,
|
|
|
|
on_demand_request_backoff_rounds_max: None,
|
|
|
|
on_demand_request_consecutive_failures: None,
|
2017-02-20 16:13:21 +01:00
|
|
|
};
|
|
|
|
expected.secretstore_conf.enabled = cfg!(feature = "secretstore");
|
2017-07-27 12:29:09 +02:00
|
|
|
expected.secretstore_conf.http_enabled = cfg!(feature = "secretstore");
|
2017-02-20 16:13:21 +01:00
|
|
|
assert_eq!(conf.into_command().unwrap().cmd, Cmd::Run(expected));
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
|
|
|
|
2016-10-15 14:46:33 +02:00
|
|
|
#[test]
|
|
|
|
fn should_parse_mining_options() {
|
|
|
|
// given
|
|
|
|
let mut mining_options = MinerOptions::default();
|
|
|
|
|
|
|
|
// when
|
|
|
|
let conf0 = parse(&["parity"]);
|
|
|
|
let conf2 = parse(&["parity", "--tx-queue-strategy", "gas_price"]);
|
|
|
|
|
|
|
|
// then
|
2017-10-24 12:25:34 +02:00
|
|
|
assert_eq!(conf0.miner_options().unwrap(), mining_options);
|
2016-10-15 14:46:33 +02:00
|
|
|
mining_options.tx_queue_strategy = PrioritizationStrategy::GasPriceOnly;
|
2017-10-24 12:25:34 +02:00
|
|
|
assert_eq!(conf2.miner_options().unwrap(), mining_options);
|
2016-10-15 14:46:33 +02:00
|
|
|
}
|
|
|
|
|
2017-07-01 17:20:49 +02:00
|
|
|
#[test]
|
|
|
|
fn should_fail_on_force_reseal_and_reseal_min_period() {
|
2017-10-24 12:25:34 +02:00
|
|
|
let conf = parse(&["parity", "--chain", "dev", "--force-sealing", "--reseal-min-period", "0"]);
|
2017-07-01 17:20:49 +02:00
|
|
|
|
2017-10-24 12:25:34 +02:00
|
|
|
assert!(conf.miner_options().is_err());
|
2017-07-01 17:20:49 +02:00
|
|
|
}
|
|
|
|
|
2016-11-23 20:35:21 +01:00
|
|
|
#[test]
|
|
|
|
fn should_parse_updater_options() {
|
|
|
|
// when
|
2016-12-15 19:17:44 +01:00
|
|
|
let conf0 = parse(&["parity", "--release-track=testing"]);
|
2018-04-03 16:49:23 +02:00
|
|
|
let conf1 = parse(&["parity", "--auto-update", "all", "--no-consensus", "--auto-update-delay", "300"]);
|
|
|
|
let conf2 = parse(&["parity", "--no-download", "--auto-update=all", "--release-track=beta", "--auto-update-delay=300", "--auto-update-check-frequency=100"]);
|
2016-12-15 19:19:50 +01:00
|
|
|
let conf3 = parse(&["parity", "--auto-update=xxx"]);
|
2016-11-23 20:35:21 +01:00
|
|
|
|
|
|
|
// then
|
2018-03-14 13:40:54 +01:00
|
|
|
assert_eq!(conf0.update_policy().unwrap(), UpdatePolicy {
|
|
|
|
enable_downloading: true,
|
|
|
|
require_consensus: true,
|
|
|
|
filter: UpdateFilter::Critical,
|
|
|
|
track: ReleaseTrack::Testing,
|
|
|
|
path: default_hypervisor_path(),
|
|
|
|
max_size: 128 * 1024 * 1024,
|
2018-04-03 16:49:23 +02:00
|
|
|
max_delay: 100,
|
|
|
|
frequency: 20,
|
2018-03-14 13:40:54 +01:00
|
|
|
});
|
|
|
|
assert_eq!(conf1.update_policy().unwrap(), UpdatePolicy {
|
|
|
|
enable_downloading: true,
|
|
|
|
require_consensus: false,
|
|
|
|
filter: UpdateFilter::All,
|
|
|
|
track: ReleaseTrack::Unknown,
|
|
|
|
path: default_hypervisor_path(),
|
|
|
|
max_size: 128 * 1024 * 1024,
|
2018-04-03 16:49:23 +02:00
|
|
|
max_delay: 300,
|
|
|
|
frequency: 20,
|
2018-03-14 13:40:54 +01:00
|
|
|
});
|
|
|
|
assert_eq!(conf2.update_policy().unwrap(), UpdatePolicy {
|
|
|
|
enable_downloading: false,
|
|
|
|
require_consensus: true,
|
|
|
|
filter: UpdateFilter::All,
|
|
|
|
track: ReleaseTrack::Beta,
|
|
|
|
path: default_hypervisor_path(),
|
|
|
|
max_size: 128 * 1024 * 1024,
|
2018-04-03 16:49:23 +02:00
|
|
|
max_delay: 300,
|
|
|
|
frequency: 100,
|
2018-03-14 13:40:54 +01:00
|
|
|
});
|
2016-11-23 20:35:21 +01:00
|
|
|
assert!(conf3.update_policy().is_err());
|
|
|
|
}
|
|
|
|
|
2016-04-30 19:58:28 +02:00
|
|
|
#[test]
|
|
|
|
fn should_parse_network_settings() {
|
|
|
|
// given
|
|
|
|
|
|
|
|
// when
|
|
|
|
let conf = parse(&["parity", "--testnet", "--identity", "testname"]);
|
|
|
|
|
|
|
|
// then
|
2017-05-23 12:24:32 +02:00
|
|
|
assert_eq!(conf.network_settings(), Ok(NetworkSettings {
|
2016-04-30 19:58:28 +02:00
|
|
|
name: "testname".to_owned(),
|
2019-11-02 12:26:38 +01:00
|
|
|
chain: "goerli".to_owned(),
|
2018-11-07 09:30:34 +01:00
|
|
|
is_dev_chain: false,
|
2016-04-30 19:58:28 +02:00
|
|
|
network_port: 30303,
|
2016-05-04 22:09:30 +02:00
|
|
|
rpc_enabled: true,
|
2017-05-23 12:24:32 +02:00
|
|
|
rpc_interface: "127.0.0.1".to_owned(),
|
2016-04-30 19:58:28 +02:00
|
|
|
rpc_port: 8545,
|
2017-05-23 12:24:32 +02:00
|
|
|
}));
|
2016-04-30 19:58:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_parse_rpc_settings_with_geth_compatiblity() {
|
|
|
|
// given
|
|
|
|
fn assert(conf: Configuration) {
|
2017-05-23 12:24:32 +02:00
|
|
|
let net = conf.network_settings().unwrap();
|
2016-04-30 19:58:28 +02:00
|
|
|
assert_eq!(net.rpc_enabled, true);
|
2017-05-23 12:24:32 +02:00
|
|
|
assert_eq!(net.rpc_interface, "0.0.0.0".to_owned());
|
2016-04-30 19:58:28 +02:00
|
|
|
assert_eq!(net.rpc_port, 8000);
|
2017-12-27 18:56:06 +01:00
|
|
|
assert_eq!(conf.rpc_cors(), None);
|
2016-04-30 19:58:28 +02:00
|
|
|
assert_eq!(conf.rpc_apis(), "web3,eth".to_owned());
|
|
|
|
}
|
|
|
|
|
|
|
|
// when
|
|
|
|
let conf1 = parse(&["parity", "-j",
|
|
|
|
"--jsonrpc-port", "8000",
|
|
|
|
"--jsonrpc-interface", "all",
|
|
|
|
"--jsonrpc-cors", "*",
|
|
|
|
"--jsonrpc-apis", "web3,eth"
|
|
|
|
]);
|
|
|
|
let conf2 = parse(&["parity", "--rpc",
|
2018-09-12 11:47:01 +02:00
|
|
|
"--rpcport", "8000",
|
|
|
|
"--rpcaddr", "all",
|
|
|
|
"--rpccorsdomain", "*",
|
|
|
|
"--rpcapi", "web3,eth"
|
|
|
|
]);
|
2016-04-30 19:58:28 +02:00
|
|
|
|
|
|
|
// then
|
|
|
|
assert(conf1);
|
|
|
|
assert(conf2);
|
|
|
|
}
|
2016-07-20 12:34:17 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_parse_rpc_hosts() {
|
|
|
|
// given
|
|
|
|
|
|
|
|
// when
|
|
|
|
let conf0 = parse(&["parity"]);
|
|
|
|
let conf1 = parse(&["parity", "--jsonrpc-hosts", "none"]);
|
|
|
|
let conf2 = parse(&["parity", "--jsonrpc-hosts", "all"]);
|
2017-05-02 11:41:09 +02:00
|
|
|
let conf3 = parse(&["parity", "--jsonrpc-hosts", "parity.io,something.io"]);
|
2016-07-20 12:34:17 +02:00
|
|
|
|
|
|
|
// then
|
|
|
|
assert_eq!(conf0.rpc_hosts(), Some(Vec::new()));
|
|
|
|
assert_eq!(conf1.rpc_hosts(), Some(Vec::new()));
|
|
|
|
assert_eq!(conf2.rpc_hosts(), None);
|
2017-05-02 11:41:09 +02:00
|
|
|
assert_eq!(conf3.rpc_hosts(), Some(vec!["parity.io".into(), "something.io".into()]));
|
2016-07-20 12:34:17 +02:00
|
|
|
}
|
2016-07-22 14:47:31 +02:00
|
|
|
|
2019-11-18 19:40:48 +01:00
|
|
|
#[test]
|
|
|
|
fn ensures_sane_http_settings() {
|
|
|
|
// given incorrect settings
|
|
|
|
let conf = parse(&["parity",
|
|
|
|
"--jsonrpc-server-threads=0",
|
|
|
|
"--jsonrpc-max-payload=0",
|
|
|
|
]);
|
|
|
|
|
|
|
|
// then things are adjusted to Just Work.
|
|
|
|
let http_conf = conf.http_config().unwrap();
|
|
|
|
assert_eq!(http_conf.server_threads, 1);
|
|
|
|
assert_eq!(http_conf.max_payload, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn jsonrpc_threading_defaults() {
|
|
|
|
let conf = parse(&["parity"]);
|
|
|
|
let http_conf = conf.http_config().unwrap();
|
|
|
|
assert_eq!(http_conf.server_threads, 4);
|
|
|
|
assert_eq!(http_conf.max_payload, 5);
|
|
|
|
}
|
|
|
|
|
2017-02-24 10:32:42 +01:00
|
|
|
#[test]
|
|
|
|
fn should_parse_ipfs_hosts() {
|
|
|
|
// given
|
|
|
|
|
|
|
|
// when
|
|
|
|
let conf0 = parse(&["parity"]);
|
|
|
|
let conf1 = parse(&["parity", "--ipfs-api-hosts", "none"]);
|
|
|
|
let conf2 = parse(&["parity", "--ipfs-api-hosts", "all"]);
|
2017-05-02 11:41:09 +02:00
|
|
|
let conf3 = parse(&["parity", "--ipfs-api-hosts", "parity.io,something.io"]);
|
2017-02-24 10:32:42 +01:00
|
|
|
|
|
|
|
// then
|
|
|
|
assert_eq!(conf0.ipfs_hosts(), Some(Vec::new()));
|
|
|
|
assert_eq!(conf1.ipfs_hosts(), Some(Vec::new()));
|
|
|
|
assert_eq!(conf2.ipfs_hosts(), None);
|
2017-05-02 11:41:09 +02:00
|
|
|
assert_eq!(conf3.ipfs_hosts(), Some(vec!["parity.io".into(), "something.io".into()]));
|
2017-02-24 10:32:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_parse_ipfs_cors() {
|
|
|
|
// given
|
|
|
|
|
|
|
|
// when
|
|
|
|
let conf0 = parse(&["parity"]);
|
|
|
|
let conf1 = parse(&["parity", "--ipfs-api-cors", "*"]);
|
2017-05-02 11:41:09 +02:00
|
|
|
let conf2 = parse(&["parity", "--ipfs-api-cors", "http://parity.io,http://something.io"]);
|
2017-02-24 10:32:42 +01:00
|
|
|
|
|
|
|
// then
|
2017-12-27 18:56:06 +01:00
|
|
|
assert_eq!(conf0.ipfs_cors(), Some(vec![]));
|
|
|
|
assert_eq!(conf1.ipfs_cors(), None);
|
2017-05-02 11:41:09 +02:00
|
|
|
assert_eq!(conf2.ipfs_cors(), Some(vec!["http://parity.io".into(),"http://something.io".into()]));
|
2017-02-24 10:32:42 +01:00
|
|
|
}
|
|
|
|
|
2016-08-02 18:53:53 +02:00
|
|
|
#[test]
|
2017-05-24 12:24:07 +02:00
|
|
|
fn should_parse_ui_configuration() {
|
2016-08-02 18:53:53 +02:00
|
|
|
// given
|
|
|
|
|
|
|
|
// when
|
2017-09-05 13:30:22 +02:00
|
|
|
let conf0 = parse(&["parity", "--ui-path=signer"]);
|
|
|
|
let conf1 = parse(&["parity", "--ui-path=signer", "--ui-no-validation"]);
|
|
|
|
let conf2 = parse(&["parity", "--ui-path=signer", "--ui-port", "3123"]);
|
|
|
|
let conf3 = parse(&["parity", "--ui-path=signer", "--ui-interface", "test"]);
|
2018-03-19 18:11:00 +01:00
|
|
|
let conf4 = parse(&["parity", "--ui-path=signer", "--force-ui"]);
|
2016-08-02 18:53:53 +02:00
|
|
|
|
|
|
|
// then
|
2017-05-24 12:24:07 +02:00
|
|
|
assert_eq!(conf0.directories().signer, "signer".to_owned());
|
2018-04-10 16:14:15 +02:00
|
|
|
|
|
|
|
assert!(conf1.ws_config().unwrap().hosts.is_some());
|
2018-06-06 10:05:52 +02:00
|
|
|
assert_eq!(conf1.ws_config().unwrap().origins, Some(vec!["parity://*".into(), "chrome-extension://*".into(), "moz-extension://*".into()]));
|
2017-05-24 12:24:07 +02:00
|
|
|
assert_eq!(conf1.directories().signer, "signer".to_owned());
|
2018-04-10 16:14:15 +02:00
|
|
|
|
|
|
|
assert!(conf2.ws_config().unwrap().hosts.is_some());
|
2017-05-24 12:24:07 +02:00
|
|
|
assert_eq!(conf2.directories().signer, "signer".to_owned());
|
2018-04-10 16:14:15 +02:00
|
|
|
|
|
|
|
assert!(conf3.ws_config().unwrap().hosts.is_some());
|
2017-05-24 12:24:07 +02:00
|
|
|
assert_eq!(conf3.directories().signer, "signer".to_owned());
|
2018-04-10 16:14:15 +02:00
|
|
|
|
|
|
|
assert!(conf4.ws_config().unwrap().hosts.is_some());
|
|
|
|
assert_eq!(conf4.directories().signer, "signer".to_owned());
|
2016-08-02 18:53:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-29 10:48:05 +02:00
|
|
|
#[test]
|
|
|
|
fn should_not_bail_on_empty_line_in_reserved_peers() {
|
2018-01-19 17:32:53 +01:00
|
|
|
let tempdir = TempDir::new("").unwrap();
|
|
|
|
let filename = tempdir.path().join("peers");
|
|
|
|
File::create(&filename).unwrap().write_all(b" \n\t\n").unwrap();
|
|
|
|
let args = vec!["parity", "--reserved-peers", filename.to_str().unwrap()];
|
2018-05-09 08:47:21 +02:00
|
|
|
let conf = Configuration::parse_cli(&args).unwrap();
|
2016-07-29 10:48:05 +02:00
|
|
|
assert!(conf.init_reserved_nodes().is_ok());
|
|
|
|
}
|
2017-02-24 17:36:52 +01:00
|
|
|
|
2017-07-10 13:24:40 +02:00
|
|
|
#[test]
|
|
|
|
fn should_ignore_comments_in_reserved_peers() {
|
2018-01-19 17:32:53 +01:00
|
|
|
let tempdir = TempDir::new("").unwrap();
|
|
|
|
let filename = tempdir.path().join("peers_comments");
|
|
|
|
File::create(&filename).unwrap().write_all(b"# Sample comment\nenode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@172.0.0.1:30303\n").unwrap();
|
|
|
|
let args = vec!["parity", "--reserved-peers", filename.to_str().unwrap()];
|
2018-05-09 08:47:21 +02:00
|
|
|
let conf = Configuration::parse_cli(&args).unwrap();
|
2017-07-10 13:24:40 +02:00
|
|
|
let reserved_nodes = conf.init_reserved_nodes();
|
|
|
|
assert!(reserved_nodes.is_ok());
|
|
|
|
assert_eq!(reserved_nodes.unwrap().len(), 1);
|
|
|
|
}
|
|
|
|
|
2017-02-24 17:36:52 +01:00
|
|
|
#[test]
|
2017-07-13 14:25:41 +02:00
|
|
|
fn test_dev_preset() {
|
2017-07-22 05:37:38 +02:00
|
|
|
let args = vec!["parity", "--config", "dev"];
|
2018-05-09 08:47:21 +02:00
|
|
|
let conf = Configuration::parse_cli(&args).unwrap();
|
2017-02-24 17:36:52 +01:00
|
|
|
match conf.into_command().unwrap().cmd {
|
|
|
|
Cmd::Run(c) => {
|
2017-07-17 08:03:57 +02:00
|
|
|
assert_eq!(c.net_settings.chain, "dev");
|
2017-07-16 18:22:45 +02:00
|
|
|
assert_eq!(c.gas_pricer_conf, GasPricerConfig::Fixed(0.into()));
|
2017-02-24 17:36:52 +01:00
|
|
|
assert_eq!(c.miner_options.reseal_min_period, Duration::from_millis(0));
|
|
|
|
},
|
|
|
|
_ => panic!("Should be Cmd::Run"),
|
|
|
|
}
|
|
|
|
}
|
2017-05-23 12:24:32 +02:00
|
|
|
|
2017-07-14 05:15:39 +02:00
|
|
|
#[test]
|
|
|
|
fn test_mining_preset() {
|
2017-07-22 05:37:38 +02:00
|
|
|
let args = vec!["parity", "--config", "mining"];
|
2018-05-09 08:47:21 +02:00
|
|
|
let conf = Configuration::parse_cli(&args).unwrap();
|
2017-07-14 05:15:39 +02:00
|
|
|
match conf.into_command().unwrap().cmd {
|
|
|
|
Cmd::Run(c) => {
|
|
|
|
assert_eq!(c.net_conf.min_peers, 50);
|
|
|
|
assert_eq!(c.net_conf.max_peers, 100);
|
|
|
|
assert_eq!(c.ipc_conf.enabled, false);
|
|
|
|
assert_eq!(c.miner_options.force_sealing, true);
|
|
|
|
assert_eq!(c.miner_options.reseal_on_external_tx, true);
|
|
|
|
assert_eq!(c.miner_options.reseal_on_own_tx, true);
|
|
|
|
assert_eq!(c.miner_options.reseal_min_period, Duration::from_millis(4000));
|
2018-04-13 17:34:27 +02:00
|
|
|
assert_eq!(c.miner_options.pool_limits.max_count, 8192);
|
|
|
|
assert_eq!(c.cache_config, CacheConfig::new_with_total_cache_size(1024));
|
2017-07-14 05:15:39 +02:00
|
|
|
assert_eq!(c.logger_config.mode.unwrap(), "miner=trace,own_tx=trace");
|
|
|
|
},
|
|
|
|
_ => panic!("Should be Cmd::Run"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-14 05:42:56 +02:00
|
|
|
#[test]
|
|
|
|
fn test_non_standard_ports_preset() {
|
2017-07-22 05:37:38 +02:00
|
|
|
let args = vec!["parity", "--config", "non-standard-ports"];
|
2018-05-09 08:47:21 +02:00
|
|
|
let conf = Configuration::parse_cli(&args).unwrap();
|
2017-07-14 05:42:56 +02:00
|
|
|
match conf.into_command().unwrap().cmd {
|
|
|
|
Cmd::Run(c) => {
|
|
|
|
assert_eq!(c.net_settings.network_port, 30305);
|
|
|
|
assert_eq!(c.net_settings.rpc_port, 8645);
|
|
|
|
},
|
|
|
|
_ => panic!("Should be Cmd::Run"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-17 08:03:57 +02:00
|
|
|
#[test]
|
|
|
|
fn test_insecure_preset() {
|
2017-07-22 05:37:38 +02:00
|
|
|
let args = vec!["parity", "--config", "insecure"];
|
2018-05-09 08:47:21 +02:00
|
|
|
let conf = Configuration::parse_cli(&args).unwrap();
|
2017-07-17 08:03:57 +02:00
|
|
|
match conf.into_command().unwrap().cmd {
|
|
|
|
Cmd::Run(c) => {
|
|
|
|
assert_eq!(c.update_policy.require_consensus, false);
|
|
|
|
assert_eq!(c.net_settings.rpc_interface, "0.0.0.0");
|
|
|
|
match c.http_conf.apis {
|
|
|
|
ApiSet::List(set) => assert_eq!(set, ApiSet::All.list_apis()),
|
|
|
|
_ => panic!("Incorrect rpc apis"),
|
|
|
|
}
|
|
|
|
// "web3,eth,net,personal,parity,parity_set,traces,rpc,parity_accounts");
|
|
|
|
assert_eq!(c.http_conf.hosts, None);
|
|
|
|
assert_eq!(c.ipfs_conf.hosts, None);
|
|
|
|
},
|
|
|
|
_ => panic!("Should be Cmd::Run"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_dev_insecure_preset() {
|
2017-07-22 05:37:38 +02:00
|
|
|
let args = vec!["parity", "--config", "dev-insecure"];
|
2018-05-09 08:47:21 +02:00
|
|
|
let conf = Configuration::parse_cli(&args).unwrap();
|
2017-07-17 08:03:57 +02:00
|
|
|
match conf.into_command().unwrap().cmd {
|
|
|
|
Cmd::Run(c) => {
|
|
|
|
assert_eq!(c.net_settings.chain, "dev");
|
2017-07-17 08:33:26 +02:00
|
|
|
assert_eq!(c.gas_pricer_conf, GasPricerConfig::Fixed(0.into()));
|
2017-07-17 08:03:57 +02:00
|
|
|
assert_eq!(c.miner_options.reseal_min_period, Duration::from_millis(0));
|
|
|
|
assert_eq!(c.update_policy.require_consensus, false);
|
|
|
|
assert_eq!(c.net_settings.rpc_interface, "0.0.0.0");
|
|
|
|
match c.http_conf.apis {
|
|
|
|
ApiSet::List(set) => assert_eq!(set, ApiSet::All.list_apis()),
|
|
|
|
_ => panic!("Incorrect rpc apis"),
|
|
|
|
}
|
|
|
|
// "web3,eth,net,personal,parity,parity_set,traces,rpc,parity_accounts");
|
|
|
|
assert_eq!(c.http_conf.hosts, None);
|
|
|
|
assert_eq!(c.ipfs_conf.hosts, None);
|
|
|
|
},
|
|
|
|
_ => panic!("Should be Cmd::Run"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-14 05:42:56 +02:00
|
|
|
#[test]
|
|
|
|
fn test_override_preset() {
|
2017-07-22 05:37:38 +02:00
|
|
|
let args = vec!["parity", "--config", "mining", "--min-peers=99"];
|
2018-05-09 08:47:21 +02:00
|
|
|
let conf = Configuration::parse_cli(&args).unwrap();
|
2017-07-14 05:42:56 +02:00
|
|
|
match conf.into_command().unwrap().cmd {
|
|
|
|
Cmd::Run(c) => {
|
|
|
|
assert_eq!(c.net_conf.min_peers, 99);
|
|
|
|
},
|
|
|
|
_ => panic!("Should be Cmd::Run"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-18 15:50:17 +02:00
|
|
|
#[test]
|
|
|
|
fn test_identity_arg() {
|
|
|
|
let args = vec!["parity", "--identity", "Somebody"];
|
|
|
|
let conf = Configuration::parse_cli(&args).unwrap();
|
|
|
|
match conf.into_command().unwrap().cmd {
|
|
|
|
Cmd::Run(c) => {
|
|
|
|
assert_eq!(c.name, "Somebody");
|
2018-07-11 13:35:10 +02:00
|
|
|
assert!(c.net_conf.client_version.starts_with("Parity-Ethereum/Somebody/"));
|
2018-06-18 15:50:17 +02:00
|
|
|
}
|
|
|
|
_ => panic!("Should be Cmd::Run"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-23 12:24:32 +02:00
|
|
|
#[test]
|
|
|
|
fn should_apply_ports_shift() {
|
|
|
|
// given
|
|
|
|
|
|
|
|
// when
|
|
|
|
let conf0 = parse(&["parity", "--ports-shift", "1", "--stratum"]);
|
|
|
|
let conf1 = parse(&["parity", "--ports-shift", "1", "--jsonrpc-port", "8544"]);
|
|
|
|
|
|
|
|
// then
|
|
|
|
assert_eq!(conf0.net_addresses().unwrap().0.port(), 30304);
|
|
|
|
assert_eq!(conf0.network_settings().unwrap().network_port, 30304);
|
|
|
|
assert_eq!(conf0.network_settings().unwrap().rpc_port, 8546);
|
|
|
|
assert_eq!(conf0.http_config().unwrap().port, 8546);
|
|
|
|
assert_eq!(conf0.ws_config().unwrap().port, 8547);
|
|
|
|
assert_eq!(conf0.secretstore_config().unwrap().port, 8084);
|
|
|
|
assert_eq!(conf0.secretstore_config().unwrap().http_port, 8083);
|
|
|
|
assert_eq!(conf0.ipfs_config().port, 5002);
|
|
|
|
assert_eq!(conf0.stratum_options().unwrap().unwrap().port, 8009);
|
|
|
|
|
|
|
|
assert_eq!(conf1.net_addresses().unwrap().0.port(), 30304);
|
|
|
|
assert_eq!(conf1.network_settings().unwrap().network_port, 30304);
|
|
|
|
assert_eq!(conf1.network_settings().unwrap().rpc_port, 8545);
|
|
|
|
assert_eq!(conf1.http_config().unwrap().port, 8545);
|
|
|
|
assert_eq!(conf1.ws_config().unwrap().port, 8547);
|
|
|
|
assert_eq!(conf1.secretstore_config().unwrap().port, 8084);
|
|
|
|
assert_eq!(conf1.secretstore_config().unwrap().http_port, 8083);
|
|
|
|
assert_eq!(conf1.ipfs_config().port, 5002);
|
|
|
|
}
|
|
|
|
|
2019-07-03 09:44:32 +02:00
|
|
|
#[test]
|
|
|
|
fn should_resolve_external_nat_hosts() {
|
|
|
|
// Ip works
|
|
|
|
let conf = parse(&["parity", "--nat", "extip:1.1.1.1"]);
|
|
|
|
assert_eq!(conf.net_addresses().unwrap().1.unwrap().ip().to_string(), "1.1.1.1");
|
|
|
|
assert_eq!(conf.net_addresses().unwrap().1.unwrap().port(), 30303);
|
|
|
|
|
|
|
|
// Ip with port works, port is discarded
|
|
|
|
let conf = parse(&["parity", "--nat", "extip:192.168.1.1:123"]);
|
|
|
|
assert_eq!(conf.net_addresses().unwrap().1.unwrap().ip().to_string(), "192.168.1.1");
|
|
|
|
assert_eq!(conf.net_addresses().unwrap().1.unwrap().port(), 30303);
|
|
|
|
|
|
|
|
// Hostname works
|
|
|
|
let conf = parse(&["parity", "--nat", "extip:ethereum.org"]);
|
|
|
|
assert!(conf.net_addresses().unwrap().1.is_some());
|
|
|
|
assert_eq!(conf.net_addresses().unwrap().1.unwrap().port(), 30303);
|
|
|
|
|
|
|
|
// Hostname works, garbage at the end is discarded
|
|
|
|
let conf = parse(&["parity", "--nat", "extip:ethereum.org:whatever bla bla 123"]);
|
|
|
|
assert!(conf.net_addresses().unwrap().1.is_some());
|
|
|
|
assert_eq!(conf.net_addresses().unwrap().1.unwrap().port(), 30303);
|
|
|
|
|
|
|
|
// Garbage is error
|
|
|
|
let conf = parse(&["parity", "--nat", "extip:blabla"]);
|
|
|
|
assert!(conf.net_addresses().is_err());
|
|
|
|
}
|
|
|
|
|
2017-05-23 12:24:32 +02:00
|
|
|
#[test]
|
|
|
|
fn should_expose_all_servers() {
|
|
|
|
// given
|
|
|
|
|
|
|
|
// when
|
|
|
|
let conf0 = parse(&["parity", "--unsafe-expose"]);
|
|
|
|
|
|
|
|
// then
|
|
|
|
assert_eq!(&conf0.network_settings().unwrap().rpc_interface, "0.0.0.0");
|
|
|
|
assert_eq!(&conf0.http_config().unwrap().interface, "0.0.0.0");
|
|
|
|
assert_eq!(conf0.http_config().unwrap().hosts, None);
|
|
|
|
assert_eq!(&conf0.ws_config().unwrap().interface, "0.0.0.0");
|
|
|
|
assert_eq!(conf0.ws_config().unwrap().hosts, None);
|
2017-06-03 14:41:42 +02:00
|
|
|
assert_eq!(conf0.ws_config().unwrap().origins, None);
|
2017-05-23 12:24:32 +02:00
|
|
|
assert_eq!(&conf0.secretstore_config().unwrap().interface, "0.0.0.0");
|
|
|
|
assert_eq!(&conf0.secretstore_config().unwrap().http_interface, "0.0.0.0");
|
|
|
|
assert_eq!(&conf0.ipfs_config().interface, "0.0.0.0");
|
|
|
|
assert_eq!(conf0.ipfs_config().hosts, None);
|
|
|
|
}
|
2017-07-28 19:06:39 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn allow_ips() {
|
|
|
|
let all = parse(&["parity", "--allow-ips", "all"]);
|
|
|
|
let private = parse(&["parity", "--allow-ips", "private"]);
|
|
|
|
let block_custom = parse(&["parity", "--allow-ips", "-10.0.0.0/8"]);
|
|
|
|
let combo = parse(&["parity", "--allow-ips", "public 10.0.0.0/8 -1.0.0.0/8"]);
|
|
|
|
let ipv6_custom_public = parse(&["parity", "--allow-ips", "public fc00::/7"]);
|
|
|
|
let ipv6_custom_private = parse(&["parity", "--allow-ips", "private -fc00::/7"]);
|
|
|
|
|
|
|
|
assert_eq!(all.ip_filter().unwrap(), IpFilter {
|
|
|
|
predefined: AllowIP::All,
|
|
|
|
custom_allow: vec![],
|
|
|
|
custom_block: vec![],
|
|
|
|
});
|
|
|
|
|
|
|
|
assert_eq!(private.ip_filter().unwrap(), IpFilter {
|
|
|
|
predefined: AllowIP::Private,
|
|
|
|
custom_allow: vec![],
|
|
|
|
custom_block: vec![],
|
|
|
|
});
|
|
|
|
|
|
|
|
assert_eq!(block_custom.ip_filter().unwrap(), IpFilter {
|
|
|
|
predefined: AllowIP::All,
|
|
|
|
custom_allow: vec![],
|
|
|
|
custom_block: vec![IpNetwork::from_str("10.0.0.0/8").unwrap()],
|
|
|
|
});
|
|
|
|
|
|
|
|
assert_eq!(combo.ip_filter().unwrap(), IpFilter {
|
|
|
|
predefined: AllowIP::Public,
|
|
|
|
custom_allow: vec![IpNetwork::from_str("10.0.0.0/8").unwrap()],
|
|
|
|
custom_block: vec![IpNetwork::from_str("1.0.0.0/8").unwrap()],
|
|
|
|
});
|
|
|
|
|
|
|
|
assert_eq!(ipv6_custom_public.ip_filter().unwrap(), IpFilter {
|
|
|
|
predefined: AllowIP::Public,
|
|
|
|
custom_allow: vec![IpNetwork::from_str("fc00::/7").unwrap()],
|
|
|
|
custom_block: vec![],
|
|
|
|
});
|
|
|
|
|
|
|
|
assert_eq!(ipv6_custom_private.ip_filter().unwrap(), IpFilter {
|
|
|
|
predefined: AllowIP::Private,
|
|
|
|
custom_allow: vec![],
|
|
|
|
custom_block: vec![IpNetwork::from_str("fc00::/7").unwrap()],
|
|
|
|
});
|
|
|
|
}
|
2017-08-02 12:38:58 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_use_correct_cache_path_if_base_is_set() {
|
2018-10-31 11:50:38 +01:00
|
|
|
use std::path;
|
|
|
|
|
2017-08-02 12:38:58 +02:00
|
|
|
let std = parse(&["parity"]);
|
|
|
|
let base = parse(&["parity", "--base-path", "/test"]);
|
|
|
|
|
|
|
|
let base_path = ::dir::default_data_path();
|
|
|
|
let local_path = ::dir::default_local_path();
|
2017-12-24 09:34:43 +01:00
|
|
|
assert_eq!(std.directories().cache, dir::helpers::replace_home_and_local(&base_path, &local_path, ::dir::CACHE_PATH));
|
2018-10-31 11:50:38 +01:00
|
|
|
assert_eq!(path::Path::new(&base.directories().cache), path::Path::new("/test/cache"));
|
2017-08-02 12:38:58 +02:00
|
|
|
}
|
2018-04-03 16:51:57 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_respect_only_max_peers_and_default() {
|
|
|
|
let args = vec!["parity", "--max-peers=50"];
|
2018-05-09 08:47:21 +02:00
|
|
|
let conf = Configuration::parse_cli(&args).unwrap();
|
2018-04-03 16:51:57 +02:00
|
|
|
match conf.into_command().unwrap().cmd {
|
|
|
|
Cmd::Run(c) => {
|
|
|
|
assert_eq!(c.net_conf.min_peers, 25);
|
|
|
|
assert_eq!(c.net_conf.max_peers, 50);
|
|
|
|
},
|
|
|
|
_ => panic!("Should be Cmd::Run"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_respect_only_max_peers_less_than_default() {
|
|
|
|
let args = vec!["parity", "--max-peers=5"];
|
2018-05-09 08:47:21 +02:00
|
|
|
let conf = Configuration::parse_cli(&args).unwrap();
|
2018-04-03 16:51:57 +02:00
|
|
|
match conf.into_command().unwrap().cmd {
|
|
|
|
Cmd::Run(c) => {
|
|
|
|
assert_eq!(c.net_conf.min_peers, 5);
|
|
|
|
assert_eq!(c.net_conf.max_peers, 5);
|
|
|
|
},
|
|
|
|
_ => panic!("Should be Cmd::Run"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_respect_only_min_peers_and_default() {
|
|
|
|
let args = vec!["parity", "--min-peers=5"];
|
2018-05-09 08:47:21 +02:00
|
|
|
let conf = Configuration::parse_cli(&args).unwrap();
|
2018-04-03 16:51:57 +02:00
|
|
|
match conf.into_command().unwrap().cmd {
|
|
|
|
Cmd::Run(c) => {
|
|
|
|
assert_eq!(c.net_conf.min_peers, 5);
|
|
|
|
assert_eq!(c.net_conf.max_peers, 50);
|
|
|
|
},
|
|
|
|
_ => panic!("Should be Cmd::Run"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_respect_only_min_peers_and_greater_than_default() {
|
|
|
|
let args = vec!["parity", "--min-peers=500"];
|
2018-05-09 08:47:21 +02:00
|
|
|
let conf = Configuration::parse_cli(&args).unwrap();
|
2018-04-03 16:51:57 +02:00
|
|
|
match conf.into_command().unwrap().cmd {
|
|
|
|
Cmd::Run(c) => {
|
|
|
|
assert_eq!(c.net_conf.min_peers, 500);
|
|
|
|
assert_eq!(c.net_conf.max_peers, 500);
|
|
|
|
},
|
|
|
|
_ => panic!("Should be Cmd::Run"),
|
|
|
|
}
|
|
|
|
}
|
2019-04-20 07:31:37 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_parse_secretstore_cors() {
|
|
|
|
// given
|
|
|
|
|
|
|
|
// when
|
|
|
|
let conf0 = parse(&["parity"]);
|
|
|
|
let conf1 = parse(&["parity", "--secretstore-http-cors", "*"]);
|
|
|
|
let conf2 = parse(&["parity", "--secretstore-http-cors", "http://parity.io,http://something.io"]);
|
|
|
|
|
|
|
|
// then
|
|
|
|
assert_eq!(conf0.secretstore_cors(), Some(vec![]));
|
|
|
|
assert_eq!(conf1.secretstore_cors(), None);
|
|
|
|
assert_eq!(conf2.secretstore_cors(), Some(vec!["http://parity.io".into(),"http://something.io".into()]));
|
|
|
|
}
|
2016-04-30 19:58:28 +02:00
|
|
|
}
|