2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2016-07-25 16:09:47 +02:00
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// 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
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-12-11 02:02:40 +01:00
|
|
|
use std::sync::Arc;
|
2016-11-03 12:00:39 +01:00
|
|
|
use std::net::{TcpListener};
|
2016-07-25 16:09:47 +02:00
|
|
|
use ctrlc::CtrlC;
|
|
|
|
use fdlimit::raise_fd_limit;
|
2017-04-13 16:32:07 +02:00
|
|
|
use parity_rpc::{NetworkSettings, informant, is_major_importing};
|
2016-08-05 10:32:04 +02:00
|
|
|
use ethsync::NetworkConfiguration;
|
2017-03-22 06:23:40 +01:00
|
|
|
use util::{Colour, version, Mutex, Condvar};
|
2016-08-05 10:32:04 +02:00
|
|
|
use io::{MayPanic, ForwardPanic, PanicHandler};
|
2017-03-22 06:23:40 +01:00
|
|
|
use ethcore_logger::{Config as LogConfig, RotatingLogger};
|
2017-01-25 11:03:36 +01:00
|
|
|
use ethcore::miner::{StratumOptions, Stratum};
|
2017-03-13 12:10:53 +01:00
|
|
|
use ethcore::client::{Client, Mode, DatabaseCompactionProfile, VMType, BlockChainClient};
|
2016-07-25 16:09:47 +02:00
|
|
|
use ethcore::service::ClientService;
|
2017-02-10 01:07:06 +01:00
|
|
|
use ethcore::account_provider::{AccountProvider, AccountProviderSettings};
|
2016-07-25 16:09:47 +02:00
|
|
|
use ethcore::miner::{Miner, MinerService, ExternalMiner, MinerOptions};
|
2016-09-02 18:48:07 +02:00
|
|
|
use ethcore::snapshot;
|
2016-12-02 18:21:54 +01:00
|
|
|
use ethcore::verification::queue::VerifierSettings;
|
2017-03-22 22:00:52 +01:00
|
|
|
use light::Cache as LightDataCache;
|
2016-10-11 18:42:20 +02:00
|
|
|
use ethsync::SyncConfig;
|
2016-07-25 16:09:47 +02:00
|
|
|
use informant::Informant;
|
2016-12-11 02:02:40 +01:00
|
|
|
use updater::{UpdatePolicy, Updater};
|
2016-12-23 13:39:06 +01:00
|
|
|
use parity_reactor::EventLoop;
|
2016-12-27 16:38:55 +01:00
|
|
|
use hash_fetch::fetch::{Fetch, Client as FetchClient};
|
2016-07-25 16:09:47 +02:00
|
|
|
|
2016-10-03 11:13:10 +02:00
|
|
|
use params::{
|
|
|
|
SpecType, Pruning, AccountsConfig, GasPricerConfig, MinerExtras, Switch,
|
2016-11-05 10:38:00 +01:00
|
|
|
tracing_switch_to_bool, fatdb_switch_to_bool, mode_switch_to_bool
|
2016-10-03 11:13:10 +02:00
|
|
|
};
|
2016-07-25 16:09:47 +02:00
|
|
|
use helpers::{to_client_config, execute_upgrades, passwords_from_files};
|
2016-12-12 16:51:07 +01:00
|
|
|
use upgrade::upgrade_key_location;
|
2016-07-25 16:09:47 +02:00
|
|
|
use dir::Directories;
|
|
|
|
use cache::CacheConfig;
|
2016-09-26 19:21:25 +02:00
|
|
|
use user_defaults::UserDefaults;
|
2016-07-25 16:09:47 +02:00
|
|
|
use dapps;
|
2017-02-14 19:30:37 +01:00
|
|
|
use ipfs;
|
2016-07-25 16:09:47 +02:00
|
|
|
use signer;
|
2017-02-20 16:13:21 +01:00
|
|
|
use secretstore;
|
2016-07-25 16:09:47 +02:00
|
|
|
use modules;
|
|
|
|
use rpc_apis;
|
|
|
|
use rpc;
|
|
|
|
use url;
|
|
|
|
|
2016-09-02 20:24:59 +02:00
|
|
|
// how often to take periodic snapshots.
|
2016-09-02 18:48:07 +02:00
|
|
|
const SNAPSHOT_PERIOD: u64 = 10000;
|
2016-09-02 20:24:59 +02:00
|
|
|
|
|
|
|
// how many blocks to wait before starting a periodic snapshot.
|
2016-10-30 15:39:36 +01:00
|
|
|
const SNAPSHOT_HISTORY: u64 = 100;
|
2016-09-02 18:48:07 +02:00
|
|
|
|
2017-03-22 22:00:52 +01:00
|
|
|
// Number of minutes before a given gas price corpus should expire.
|
|
|
|
// Light client only.
|
|
|
|
const GAS_CORPUS_EXPIRATION_MINUTES: i64 = 60 * 6;
|
|
|
|
|
2017-01-04 14:48:32 +01:00
|
|
|
// Pops along with error messages when a password is missing or invalid.
|
|
|
|
const VERIFY_PASSWORD_HINT: &'static str = "Make sure valid password is present in files passed using `--password` or in the configuration file.";
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub struct RunCmd {
|
|
|
|
pub cache_config: CacheConfig,
|
|
|
|
pub dirs: Directories,
|
|
|
|
pub spec: SpecType,
|
|
|
|
pub pruning: Pruning,
|
2016-10-14 14:44:56 +02:00
|
|
|
pub pruning_history: u64,
|
2017-01-20 13:25:53 +01:00
|
|
|
pub pruning_memory: usize,
|
2016-07-25 16:09:47 +02:00
|
|
|
/// Some if execution should be daemonized. Contains pid_file path.
|
|
|
|
pub daemon: Option<String>,
|
|
|
|
pub logger_config: LogConfig,
|
|
|
|
pub miner_options: MinerOptions,
|
2017-04-13 16:32:07 +02:00
|
|
|
pub ws_conf: rpc::WsConfiguration,
|
2017-04-03 10:27:37 +02:00
|
|
|
pub http_conf: rpc::HttpConfiguration,
|
|
|
|
pub ipc_conf: rpc::IpcConfiguration,
|
2016-07-25 16:09:47 +02:00
|
|
|
pub net_conf: NetworkConfiguration,
|
2016-12-05 15:54:31 +01:00
|
|
|
pub network_id: Option<u64>,
|
2016-10-18 18:16:00 +02:00
|
|
|
pub warp_sync: bool,
|
2017-03-29 17:07:58 +02:00
|
|
|
pub public_node: bool,
|
2016-07-25 16:09:47 +02:00
|
|
|
pub acc_conf: AccountsConfig,
|
|
|
|
pub gas_pricer: GasPricerConfig,
|
|
|
|
pub miner_extras: MinerExtras,
|
2016-11-23 20:35:21 +01:00
|
|
|
pub update_policy: UpdatePolicy,
|
2016-11-05 10:38:00 +01:00
|
|
|
pub mode: Option<Mode>,
|
2016-07-25 16:09:47 +02:00
|
|
|
pub tracing: Switch,
|
2016-10-03 11:13:10 +02:00
|
|
|
pub fat_db: Switch,
|
2016-07-25 16:09:47 +02:00
|
|
|
pub compaction: DatabaseCompactionProfile,
|
2016-07-29 15:36:00 +02:00
|
|
|
pub wal: bool,
|
2016-07-25 16:09:47 +02:00
|
|
|
pub vm_type: VMType,
|
|
|
|
pub geth_compatibility: bool,
|
2016-11-09 19:41:47 +01:00
|
|
|
pub ui_address: Option<(String, u16)>,
|
2016-07-25 16:09:47 +02:00
|
|
|
pub net_settings: NetworkSettings,
|
|
|
|
pub dapps_conf: dapps::Configuration,
|
2017-02-16 14:41:33 +01:00
|
|
|
pub ipfs_conf: ipfs::Configuration,
|
2016-07-25 16:09:47 +02:00
|
|
|
pub signer_conf: signer::Configuration,
|
2017-02-20 16:13:21 +01:00
|
|
|
pub secretstore_conf: secretstore::Configuration,
|
2017-01-06 16:05:58 +01:00
|
|
|
pub dapp: Option<String>,
|
2016-07-25 16:09:47 +02:00
|
|
|
pub ui: bool,
|
|
|
|
pub name: String,
|
|
|
|
pub custom_bootnodes: bool,
|
2017-01-25 11:03:36 +01:00
|
|
|
pub stratum: Option<StratumOptions>,
|
2016-09-02 20:24:59 +02:00
|
|
|
pub no_periodic_snapshot: bool,
|
2016-10-24 15:09:13 +02:00
|
|
|
pub check_seal: bool,
|
2016-11-22 18:03:35 +01:00
|
|
|
pub download_old_blocks: bool,
|
2016-12-02 18:21:54 +01:00
|
|
|
pub verifier_settings: VerifierSettings,
|
2017-03-22 16:45:50 +01:00
|
|
|
pub serve_light: bool,
|
|
|
|
pub light: bool,
|
2017-05-04 12:13:50 +02:00
|
|
|
pub no_persistent_txqueue: bool,
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
|
|
|
|
2017-04-03 10:27:37 +02:00
|
|
|
pub fn open_ui(signer_conf: &signer::Configuration) -> Result<(), String> {
|
2016-11-14 11:56:01 +01:00
|
|
|
if !signer_conf.enabled {
|
|
|
|
return Err("Cannot use UI command with UI turned off.".into())
|
|
|
|
}
|
|
|
|
|
2016-12-27 12:53:56 +01:00
|
|
|
let token = signer::generate_token_and_url(signer_conf)?;
|
2016-11-16 09:37:48 +01:00
|
|
|
// Open a browser
|
|
|
|
url::open(&token.url);
|
|
|
|
// Print a message
|
|
|
|
println!("{}", token.message);
|
2016-11-14 11:56:01 +01:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2017-04-03 10:27:37 +02:00
|
|
|
pub fn open_dapp(dapps_conf: &dapps::Configuration, rpc_conf: &rpc::HttpConfiguration, dapp: &str) -> Result<(), String> {
|
2017-01-06 16:05:58 +01:00
|
|
|
if !dapps_conf.enabled {
|
|
|
|
return Err("Cannot use DAPP command with Dapps turned off.".into())
|
|
|
|
}
|
|
|
|
|
2017-04-03 10:27:37 +02:00
|
|
|
let url = format!("http://{}:{}/{}/", rpc_conf.interface, rpc_conf.port, dapp);
|
2017-01-06 16:05:58 +01:00
|
|
|
url::open(&url);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2017-02-20 17:21:55 +01:00
|
|
|
// node info fetcher for the local store.
|
|
|
|
struct FullNodeInfo {
|
2017-05-04 12:13:50 +02:00
|
|
|
miner: Option<Arc<Miner>>, // TODO: only TXQ needed, just use that after decoupling.
|
2017-02-20 17:21:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ::local_store::NodeInfo for FullNodeInfo {
|
|
|
|
fn pending_transactions(&self) -> Vec<::ethcore::transaction::PendingTransaction> {
|
2017-05-04 12:13:50 +02:00
|
|
|
let miner = match self.miner.as_ref() {
|
|
|
|
Some(m) => m,
|
|
|
|
None => return Vec::new(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let local_txs = miner.local_transactions();
|
|
|
|
miner.pending_transactions()
|
2017-02-20 17:21:55 +01:00
|
|
|
.into_iter()
|
2017-05-04 12:13:50 +02:00
|
|
|
.chain(miner.future_transactions())
|
2017-02-20 17:21:55 +01:00
|
|
|
.filter(|tx| local_txs.contains_key(&tx.hash()))
|
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
}
|
2017-01-06 16:05:58 +01:00
|
|
|
|
2017-03-22 18:32:04 +01:00
|
|
|
// helper for light execution.
|
2017-03-22 22:00:52 +01:00
|
|
|
fn execute_light(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> Result<(bool, Option<String>), String> {
|
2017-03-22 18:32:04 +01:00
|
|
|
use light::client as light_client;
|
|
|
|
use ethsync::{LightSyncParams, LightSync, ManageNetwork};
|
|
|
|
use util::RwLock;
|
|
|
|
|
|
|
|
let panic_handler = PanicHandler::new_in_arc();
|
|
|
|
|
|
|
|
// load spec
|
|
|
|
let spec = cmd.spec.spec()?;
|
|
|
|
|
|
|
|
// load genesis hash
|
|
|
|
let genesis_hash = spec.genesis_header().hash();
|
|
|
|
|
|
|
|
// database paths
|
|
|
|
let db_dirs = cmd.dirs.database(genesis_hash, cmd.spec.legacy_fork_name(), spec.data_dir.clone());
|
|
|
|
|
|
|
|
// user defaults path
|
|
|
|
let user_defaults_path = db_dirs.user_defaults_path();
|
|
|
|
|
|
|
|
// load user defaults
|
|
|
|
let user_defaults = UserDefaults::load(&user_defaults_path)?;
|
|
|
|
|
|
|
|
// select pruning algorithm
|
|
|
|
let algorithm = cmd.pruning.to_algorithm(&user_defaults);
|
|
|
|
|
|
|
|
let compaction = cmd.compaction.compaction_profile(db_dirs.db_root_path().as_path());
|
|
|
|
|
|
|
|
// execute upgrades
|
|
|
|
execute_upgrades(&cmd.dirs.base, &db_dirs, algorithm, compaction.clone())?;
|
|
|
|
|
|
|
|
// create dirs used by parity
|
|
|
|
cmd.dirs.create_dirs(cmd.dapps_conf.enabled, cmd.signer_conf.enabled, cmd.secretstore_conf.enabled)?;
|
|
|
|
|
|
|
|
info!("Starting {}", Colour::White.bold().paint(version()));
|
|
|
|
info!("Running in experimental {} mode.", Colour::Blue.bold().paint("Light Client"));
|
|
|
|
|
2017-04-07 17:38:03 +02:00
|
|
|
// TODO: configurable cache size.
|
|
|
|
let cache = LightDataCache::new(Default::default(), ::time::Duration::minutes(GAS_CORPUS_EXPIRATION_MINUTES));
|
|
|
|
let cache = Arc::new(::util::Mutex::new(cache));
|
|
|
|
|
2017-03-22 18:32:04 +01:00
|
|
|
// start client and create transaction queue.
|
|
|
|
let mut config = light_client::Config {
|
|
|
|
queue: Default::default(),
|
|
|
|
chain_column: ::ethcore::db::COL_LIGHT_CHAIN,
|
|
|
|
db_cache_size: Some(cmd.cache_config.blockchain() as usize * 1024 * 1024),
|
|
|
|
db_compaction: compaction,
|
|
|
|
db_wal: cmd.wal,
|
|
|
|
};
|
|
|
|
|
|
|
|
config.queue.max_mem_use = cmd.cache_config.queue() as usize * 1024 * 1024;
|
|
|
|
config.queue.verifier_settings = cmd.verifier_settings;
|
|
|
|
|
2017-04-07 17:38:03 +02:00
|
|
|
let service = light_client::Service::start(config, &spec, &db_dirs.client_path(algorithm), cache.clone())
|
2017-03-22 18:32:04 +01:00
|
|
|
.map_err(|e| format!("Error starting light client: {}", e))?;
|
|
|
|
let txq = Arc::new(RwLock::new(::light::transaction_queue::TransactionQueue::default()));
|
2017-03-22 22:00:52 +01:00
|
|
|
let provider = ::light::provider::LightProvider::new(service.client().clone(), txq.clone());
|
2017-03-22 18:32:04 +01:00
|
|
|
|
|
|
|
// start network.
|
|
|
|
// set up bootnodes
|
|
|
|
let mut net_conf = cmd.net_conf;
|
|
|
|
if !cmd.custom_bootnodes {
|
|
|
|
net_conf.boot_nodes = spec.nodes.clone();
|
|
|
|
}
|
|
|
|
|
2017-03-22 22:00:52 +01:00
|
|
|
// start on_demand service.
|
2017-04-12 12:07:54 +02:00
|
|
|
let account_start_nonce = service.client().engine().account_start_nonce();
|
|
|
|
let on_demand = Arc::new(::light::on_demand::OnDemand::new(cache.clone(), account_start_nonce));
|
2017-03-22 22:00:52 +01:00
|
|
|
|
2017-03-22 18:32:04 +01:00
|
|
|
// set network path.
|
|
|
|
net_conf.net_config_path = Some(db_dirs.network_path().to_string_lossy().into_owned());
|
|
|
|
let sync_params = LightSyncParams {
|
|
|
|
network_config: net_conf.into_basic().map_err(|e| format!("Failed to produce network config: {}", e))?,
|
|
|
|
client: Arc::new(provider),
|
|
|
|
network_id: cmd.network_id.unwrap_or(spec.network_id()),
|
|
|
|
subprotocol_name: ::ethsync::LIGHT_PROTOCOL,
|
2017-03-22 22:00:52 +01:00
|
|
|
handlers: vec![on_demand.clone()],
|
2017-03-22 18:32:04 +01:00
|
|
|
};
|
|
|
|
let light_sync = LightSync::new(sync_params).map_err(|e| format!("Error starting network: {}", e))?;
|
2017-03-22 22:00:52 +01:00
|
|
|
let light_sync = Arc::new(light_sync);
|
2017-03-22 18:32:04 +01:00
|
|
|
|
2017-03-22 22:00:52 +01:00
|
|
|
// spin up event loop
|
|
|
|
let event_loop = EventLoop::spawn();
|
|
|
|
|
2017-03-23 22:20:00 +01:00
|
|
|
// queue cull service.
|
|
|
|
let queue_cull = Arc::new(::light_helpers::QueueCull {
|
|
|
|
client: service.client().clone(),
|
|
|
|
sync: light_sync.clone(),
|
|
|
|
on_demand: on_demand.clone(),
|
|
|
|
txq: txq.clone(),
|
|
|
|
remote: event_loop.remote(),
|
|
|
|
});
|
|
|
|
|
|
|
|
service.register_handler(queue_cull).map_err(|e| format!("Error attaching service: {:?}", e))?;
|
|
|
|
|
|
|
|
// start the network.
|
|
|
|
light_sync.start_network();
|
|
|
|
|
2017-03-22 22:00:52 +01:00
|
|
|
// fetch service
|
|
|
|
let fetch = FetchClient::new().map_err(|e| format!("Error starting fetch client: {:?}", e))?;
|
2017-03-22 18:32:04 +01:00
|
|
|
let passwords = passwords_from_files(&cmd.acc_conf.password_files)?;
|
|
|
|
|
|
|
|
// prepare account provider
|
2017-03-22 22:00:52 +01:00
|
|
|
let account_provider = Arc::new(prepare_account_provider(&cmd.spec, &cmd.dirs, &spec.data_dir, cmd.acc_conf, &passwords)?);
|
|
|
|
let rpc_stats = Arc::new(informant::RpcStats::default());
|
|
|
|
let signer_path = cmd.signer_conf.signer_path.clone();
|
|
|
|
|
2017-03-23 22:20:00 +01:00
|
|
|
// start RPCs
|
2017-03-22 22:00:52 +01:00
|
|
|
let deps_for_rpc_apis = Arc::new(rpc_apis::LightDependencies {
|
|
|
|
signer_service: Arc::new(rpc_apis::SignerService::new(move || {
|
|
|
|
signer::generate_new_token(signer_path.clone()).map_err(|e| format!("{:?}", e))
|
|
|
|
}, cmd.ui_address)),
|
|
|
|
client: service.client().clone(),
|
|
|
|
sync: light_sync.clone(),
|
|
|
|
net: light_sync.clone(),
|
|
|
|
secret_store: account_provider,
|
|
|
|
logger: logger,
|
|
|
|
settings: Arc::new(cmd.net_settings),
|
|
|
|
on_demand: on_demand,
|
|
|
|
cache: cache,
|
|
|
|
transaction_queue: txq,
|
|
|
|
dapps_interface: match cmd.dapps_conf.enabled {
|
2017-04-03 12:44:52 +02:00
|
|
|
true => Some(cmd.http_conf.interface.clone()),
|
2017-03-22 22:00:52 +01:00
|
|
|
false => None,
|
|
|
|
},
|
|
|
|
dapps_port: match cmd.dapps_conf.enabled {
|
2017-04-03 12:44:52 +02:00
|
|
|
true => Some(cmd.http_conf.port),
|
2017-03-22 22:00:52 +01:00
|
|
|
false => None,
|
|
|
|
},
|
|
|
|
fetch: fetch,
|
|
|
|
geth_compatibility: cmd.geth_compatibility,
|
|
|
|
});
|
|
|
|
|
|
|
|
let dependencies = rpc::Dependencies {
|
|
|
|
apis: deps_for_rpc_apis.clone(),
|
|
|
|
remote: event_loop.raw_remote(),
|
|
|
|
stats: rpc_stats.clone(),
|
|
|
|
};
|
|
|
|
|
|
|
|
// start rpc servers
|
2017-04-13 16:32:07 +02:00
|
|
|
let _ws_server = rpc::new_ws(cmd.ws_conf, &dependencies)?;
|
|
|
|
let _http_server = rpc::new_http(cmd.http_conf.clone(), &dependencies, None)?;
|
2017-03-22 22:00:52 +01:00
|
|
|
let _ipc_server = rpc::new_ipc(cmd.ipc_conf, &dependencies)?;
|
|
|
|
|
|
|
|
// the signer server
|
|
|
|
let signer_deps = signer::Dependencies {
|
|
|
|
apis: deps_for_rpc_apis.clone(),
|
|
|
|
remote: event_loop.raw_remote(),
|
|
|
|
rpc_stats: rpc_stats.clone(),
|
|
|
|
};
|
|
|
|
let signing_queue = deps_for_rpc_apis.signer_service.queue();
|
|
|
|
let _signer_server = signer::start(cmd.signer_conf.clone(), signing_queue, signer_deps)?;
|
|
|
|
|
|
|
|
// TODO: Dapps
|
2017-03-22 18:32:04 +01:00
|
|
|
|
2017-03-23 22:20:00 +01:00
|
|
|
// minimal informant thread. Just prints block number every 5 seconds.
|
|
|
|
// TODO: integrate with informant.rs
|
|
|
|
let informant_client = service.client().clone();
|
|
|
|
::std::thread::spawn(move || loop {
|
|
|
|
info!("#{}", informant_client.best_block_header().number());
|
|
|
|
::std::thread::sleep(::std::time::Duration::from_secs(5));
|
|
|
|
});
|
|
|
|
|
2017-03-22 18:32:04 +01:00
|
|
|
// wait for ctrl-c.
|
|
|
|
Ok(wait_for_exit(panic_handler, None, None, can_restart))
|
|
|
|
}
|
|
|
|
|
2017-03-13 12:10:53 +01:00
|
|
|
pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> Result<(bool, Option<String>), String> {
|
2016-11-03 12:00:39 +01:00
|
|
|
if cmd.ui && cmd.dapps_conf.enabled {
|
|
|
|
// Check if Parity is already running
|
2017-04-03 10:27:37 +02:00
|
|
|
let addr = format!("{}:{}", cmd.signer_conf.interface, cmd.signer_conf.port);
|
2016-11-03 12:00:39 +01:00
|
|
|
if !TcpListener::bind(&addr as &str).is_ok() {
|
2017-04-03 10:27:37 +02:00
|
|
|
return open_ui(&cmd.signer_conf).map(|_| (false, None));
|
2016-11-03 12:00:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-26 19:21:25 +02:00
|
|
|
// increase max number of open files
|
|
|
|
raise_fd_limit();
|
2016-07-25 16:09:47 +02:00
|
|
|
|
2017-03-22 18:32:04 +01:00
|
|
|
// run as light client.
|
|
|
|
if cmd.light {
|
|
|
|
return execute_light(cmd, can_restart, logger);
|
|
|
|
}
|
|
|
|
|
|
|
|
// set up panic handler
|
|
|
|
let panic_handler = PanicHandler::new_in_arc();
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
// load spec
|
2016-12-27 12:53:56 +01:00
|
|
|
let spec = cmd.spec.spec()?;
|
2016-07-25 16:09:47 +02:00
|
|
|
|
|
|
|
// load genesis hash
|
|
|
|
let genesis_hash = spec.genesis_header().hash();
|
|
|
|
|
2016-09-26 19:21:25 +02:00
|
|
|
// database paths
|
2016-12-12 16:51:07 +01:00
|
|
|
let db_dirs = cmd.dirs.database(genesis_hash, cmd.spec.legacy_fork_name(), spec.data_dir.clone());
|
2016-09-26 19:21:25 +02:00
|
|
|
|
|
|
|
// user defaults path
|
|
|
|
let user_defaults_path = db_dirs.user_defaults_path();
|
|
|
|
|
|
|
|
// load user defaults
|
2016-12-27 12:53:56 +01:00
|
|
|
let mut user_defaults = UserDefaults::load(&user_defaults_path)?;
|
2016-09-26 19:21:25 +02:00
|
|
|
|
2016-10-03 11:13:10 +02:00
|
|
|
// select pruning algorithm
|
|
|
|
let algorithm = cmd.pruning.to_algorithm(&user_defaults);
|
|
|
|
|
2016-09-26 19:21:25 +02:00
|
|
|
// check if tracing is on
|
2016-12-27 12:53:56 +01:00
|
|
|
let tracing = tracing_switch_to_bool(cmd.tracing, &user_defaults)?;
|
2016-09-26 19:21:25 +02:00
|
|
|
|
2016-10-03 11:13:10 +02:00
|
|
|
// check if fatdb is on
|
2016-12-27 12:53:56 +01:00
|
|
|
let fat_db = fatdb_switch_to_bool(cmd.fat_db, &user_defaults, algorithm)?;
|
2016-07-25 16:09:47 +02:00
|
|
|
|
2016-11-05 10:38:00 +01:00
|
|
|
// get the mode
|
2016-12-27 12:53:56 +01:00
|
|
|
let mode = mode_switch_to_bool(cmd.mode, &user_defaults)?;
|
2016-11-05 10:38:00 +01:00
|
|
|
trace!(target: "mode", "mode is {:?}", mode);
|
2016-11-28 13:20:49 +01:00
|
|
|
let network_enabled = match mode { Mode::Dark(_) | Mode::Off => false, _ => true, };
|
2016-11-05 10:38:00 +01:00
|
|
|
|
2016-11-23 20:35:21 +01:00
|
|
|
// get the update policy
|
|
|
|
let update_policy = cmd.update_policy;
|
|
|
|
|
2016-09-07 15:27:28 +02:00
|
|
|
// prepare client and snapshot paths.
|
2016-09-26 19:21:25 +02:00
|
|
|
let client_path = db_dirs.client_path(algorithm);
|
|
|
|
let snapshot_path = db_dirs.snapshot_path();
|
2016-07-25 16:09:47 +02:00
|
|
|
|
|
|
|
// execute upgrades
|
2016-12-27 12:53:56 +01:00
|
|
|
execute_upgrades(&cmd.dirs.base, &db_dirs, algorithm, cmd.compaction.compaction_profile(db_dirs.db_root_path().as_path()))?;
|
2016-07-25 16:09:47 +02:00
|
|
|
|
2016-12-13 23:38:29 +01:00
|
|
|
// create dirs used by parity
|
2017-02-20 16:13:21 +01:00
|
|
|
cmd.dirs.create_dirs(cmd.dapps_conf.enabled, cmd.signer_conf.enabled, cmd.secretstore_conf.enabled)?;
|
2016-07-25 16:09:47 +02:00
|
|
|
|
|
|
|
// run in daemon mode
|
|
|
|
if let Some(pid_file) = cmd.daemon {
|
2016-12-27 12:53:56 +01:00
|
|
|
daemonize(pid_file)?;
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// display info about used pruning algorithm
|
|
|
|
info!("Starting {}", Colour::White.bold().paint(version()));
|
2016-12-14 15:15:19 +01:00
|
|
|
info!("State DB configuration: {}{}{}",
|
2016-10-03 11:13:10 +02:00
|
|
|
Colour::White.bold().paint(algorithm.as_str()),
|
|
|
|
match fat_db {
|
|
|
|
true => Colour::White.bold().paint(" +Fat").to_string(),
|
|
|
|
false => "".to_owned(),
|
|
|
|
},
|
|
|
|
match tracing {
|
|
|
|
true => Colour::White.bold().paint(" +Trace").to_string(),
|
|
|
|
false => "".to_owned(),
|
|
|
|
}
|
|
|
|
);
|
2016-11-05 10:38:00 +01:00
|
|
|
info!("Operating mode: {}", Colour::White.bold().paint(format!("{}", mode)));
|
2016-07-25 16:09:47 +02:00
|
|
|
|
2017-05-09 17:46:46 +02:00
|
|
|
// display warning about using experimental journaldb algorithm
|
2016-07-25 16:09:47 +02:00
|
|
|
if !algorithm.is_stable() {
|
|
|
|
warn!("Your chosen strategy is {}! You can re-run with --pruning to change.", Colour::Red.bold().paint("unstable"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// create sync config
|
|
|
|
let mut sync_config = SyncConfig::default();
|
|
|
|
sync_config.network_id = match cmd.network_id {
|
|
|
|
Some(id) => id,
|
|
|
|
None => spec.network_id(),
|
|
|
|
};
|
2016-09-28 14:21:59 +02:00
|
|
|
if spec.subprotocol_name().len() != 3 {
|
|
|
|
warn!("Your chain specification's subprotocol length is not 3. Ignoring.");
|
|
|
|
} else {
|
|
|
|
sync_config.subprotocol_name.clone_from_slice(spec.subprotocol_name().as_bytes());
|
|
|
|
}
|
2016-08-03 19:01:48 +02:00
|
|
|
sync_config.fork_block = spec.fork_block();
|
2016-10-18 18:16:00 +02:00
|
|
|
sync_config.warp_sync = cmd.warp_sync;
|
2016-11-22 18:03:35 +01:00
|
|
|
sync_config.download_old_blocks = cmd.download_old_blocks;
|
2017-03-22 16:45:50 +01:00
|
|
|
sync_config.serve_light = cmd.serve_light;
|
2016-07-25 16:09:47 +02:00
|
|
|
|
2016-12-27 12:53:56 +01:00
|
|
|
let passwords = passwords_from_files(&cmd.acc_conf.password_files)?;
|
2016-12-05 20:23:03 +01:00
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
// prepare account provider
|
2017-01-04 16:51:27 +01:00
|
|
|
let account_provider = Arc::new(prepare_account_provider(&cmd.spec, &cmd.dirs, &spec.data_dir, cmd.acc_conf, &passwords)?);
|
2016-07-25 16:09:47 +02:00
|
|
|
|
|
|
|
// create miner
|
2017-01-18 19:44:24 +01:00
|
|
|
let initial_min_gas_price = cmd.gas_pricer.initial_min();
|
2016-08-05 23:33:55 +02:00
|
|
|
let miner = Miner::new(cmd.miner_options, cmd.gas_pricer.into(), &spec, Some(account_provider.clone()));
|
2016-07-25 16:09:47 +02:00
|
|
|
miner.set_author(cmd.miner_extras.author);
|
|
|
|
miner.set_gas_floor_target(cmd.miner_extras.gas_floor_target);
|
|
|
|
miner.set_gas_ceil_target(cmd.miner_extras.gas_ceil_target);
|
|
|
|
miner.set_extra_data(cmd.miner_extras.extra_data);
|
|
|
|
miner.set_transactions_limit(cmd.miner_extras.transactions_limit);
|
2017-01-18 19:44:24 +01:00
|
|
|
miner.set_minimal_gas_price(initial_min_gas_price);
|
|
|
|
miner.recalibrate_minimal_gas_price();
|
2016-12-05 22:31:38 +01:00
|
|
|
let engine_signer = cmd.miner_extras.engine_signer;
|
2017-01-04 12:50:50 +01:00
|
|
|
|
2016-12-07 10:34:06 +01:00
|
|
|
if engine_signer != Default::default() {
|
2017-01-04 12:50:50 +01:00
|
|
|
// Check if engine signer exists
|
|
|
|
if !account_provider.has_account(engine_signer).unwrap_or(false) {
|
2017-01-04 16:51:27 +01:00
|
|
|
return Err(format!("Consensus signer account not found for the current chain. {}", build_create_account_hint(&cmd.spec, &cmd.dirs.keys)));
|
2017-01-04 12:50:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if any passwords have been read from the password file(s)
|
|
|
|
if passwords.is_empty() {
|
2017-01-04 14:48:32 +01:00
|
|
|
return Err(format!("No password found for the consensus signer {}. {}", engine_signer, VERIFY_PASSWORD_HINT));
|
2017-01-04 12:50:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Attempt to sign in the engine signer.
|
2016-12-07 10:34:06 +01:00
|
|
|
if !passwords.into_iter().any(|p| miner.set_engine_signer(engine_signer, p).is_ok()) {
|
2017-01-04 14:48:32 +01:00
|
|
|
return Err(format!("No valid password for the consensus signer {}. {}", engine_signer, VERIFY_PASSWORD_HINT));
|
2016-12-07 10:34:06 +01:00
|
|
|
}
|
2016-12-05 20:23:03 +01:00
|
|
|
}
|
2016-07-25 16:09:47 +02:00
|
|
|
|
|
|
|
// create client config
|
2016-12-02 18:21:54 +01:00
|
|
|
let mut client_config = to_client_config(
|
2016-07-25 16:09:47 +02:00
|
|
|
&cmd.cache_config,
|
2017-03-13 12:10:53 +01:00
|
|
|
spec.name.to_lowercase(),
|
2016-11-27 11:11:56 +01:00
|
|
|
mode.clone(),
|
2016-09-26 19:21:25 +02:00
|
|
|
tracing,
|
2016-10-03 11:13:10 +02:00
|
|
|
fat_db,
|
2016-07-25 16:09:47 +02:00
|
|
|
cmd.compaction,
|
2016-07-29 15:36:00 +02:00
|
|
|
cmd.wal,
|
2016-07-25 16:09:47 +02:00
|
|
|
cmd.vm_type,
|
|
|
|
cmd.name,
|
2016-09-26 19:21:25 +02:00
|
|
|
algorithm,
|
2016-10-14 14:44:56 +02:00
|
|
|
cmd.pruning_history,
|
2017-01-20 13:25:53 +01:00
|
|
|
cmd.pruning_memory,
|
2016-10-24 15:09:13 +02:00
|
|
|
cmd.check_seal,
|
2016-07-25 16:09:47 +02:00
|
|
|
);
|
|
|
|
|
2016-12-02 18:21:54 +01:00
|
|
|
client_config.queue.verifier_settings = cmd.verifier_settings;
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
// set up bootnodes
|
|
|
|
let mut net_conf = cmd.net_conf;
|
|
|
|
if !cmd.custom_bootnodes {
|
|
|
|
net_conf.boot_nodes = spec.nodes.clone();
|
|
|
|
}
|
|
|
|
|
2016-10-11 18:42:20 +02:00
|
|
|
// set network path.
|
|
|
|
net_conf.net_config_path = Some(db_dirs.network_path().to_string_lossy().into_owned());
|
|
|
|
|
2016-08-10 21:07:01 +02:00
|
|
|
// create supervisor
|
2016-09-07 15:27:28 +02:00
|
|
|
let mut hypervisor = modules::hypervisor(&cmd.dirs.ipc_path());
|
2016-08-10 21:07:01 +02:00
|
|
|
|
2016-08-05 17:00:46 +02:00
|
|
|
// create client service.
|
2016-12-27 12:53:56 +01:00
|
|
|
let service = ClientService::start(
|
2016-07-25 16:09:47 +02:00
|
|
|
client_config,
|
2016-08-05 23:33:55 +02:00
|
|
|
&spec,
|
2016-09-07 15:27:28 +02:00
|
|
|
&client_path,
|
|
|
|
&snapshot_path,
|
|
|
|
&cmd.dirs.ipc_path(),
|
2016-07-25 16:09:47 +02:00
|
|
|
miner.clone(),
|
2016-12-27 12:53:56 +01:00
|
|
|
).map_err(|e| format!("Client service error: {:?}", e))?;
|
2016-07-25 16:09:47 +02:00
|
|
|
|
2016-11-15 19:07:23 +01:00
|
|
|
// drop the spec to free up genesis state.
|
|
|
|
drop(spec);
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
// forward panics from service
|
|
|
|
panic_handler.forward_from(&service);
|
|
|
|
|
|
|
|
// take handle to client
|
|
|
|
let client = service.client();
|
2016-09-06 15:31:13 +02:00
|
|
|
let snapshot_service = service.snapshot_service();
|
2016-07-25 16:09:47 +02:00
|
|
|
|
2017-02-20 17:21:55 +01:00
|
|
|
// initialize the local node information store.
|
|
|
|
let store = {
|
|
|
|
let db = service.db();
|
|
|
|
let node_info = FullNodeInfo {
|
2017-05-04 12:13:50 +02:00
|
|
|
miner: match cmd.no_persistent_txqueue {
|
|
|
|
true => None,
|
|
|
|
false => Some(miner.clone()),
|
|
|
|
}
|
2017-02-20 17:21:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
let store = ::local_store::create(db, ::ethcore::db::COL_NODE_INFO, node_info);
|
|
|
|
|
2017-05-04 12:13:50 +02:00
|
|
|
if cmd.no_persistent_txqueue {
|
|
|
|
info!("Running without a persistent transaction queue.");
|
|
|
|
|
|
|
|
if let Err(e) = store.clear() {
|
|
|
|
warn!("Error clearing persistent transaction queue: {}", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-20 17:21:55 +01:00
|
|
|
// re-queue pending transactions.
|
|
|
|
match store.pending_transactions() {
|
|
|
|
Ok(pending) => {
|
|
|
|
for pending_tx in pending {
|
|
|
|
if let Err(e) = miner.import_own_transaction(&*client, pending_tx) {
|
|
|
|
warn!("Error importing saved transaction: {}", e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(e) => warn!("Error loading cached pending transactions from disk: {}", e),
|
|
|
|
}
|
|
|
|
|
|
|
|
Arc::new(store)
|
|
|
|
};
|
|
|
|
|
|
|
|
// register it as an IO service to update periodically.
|
|
|
|
service.register_io_handler(store).map_err(|_| "Unable to register local store handler".to_owned())?;
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
// create external miner
|
|
|
|
let external_miner = Arc::new(ExternalMiner::default());
|
|
|
|
|
2017-01-25 11:03:36 +01:00
|
|
|
// start stratum
|
|
|
|
if let Some(ref stratum_config) = cmd.stratum {
|
|
|
|
Stratum::register(stratum_config, miner.clone(), Arc::downgrade(&client))
|
|
|
|
.map_err(|e| format!("Stratum start error: {:?}", e))?;
|
|
|
|
}
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
// create sync object
|
2016-12-27 12:53:56 +01:00
|
|
|
let (sync_provider, manage_network, chain_notify) = modules::sync(
|
2016-12-15 23:50:16 +01:00
|
|
|
&mut hypervisor,
|
|
|
|
sync_config,
|
|
|
|
net_conf.into(),
|
|
|
|
client.clone(),
|
|
|
|
snapshot_service.clone(),
|
|
|
|
client.clone(),
|
2016-12-08 23:21:47 +01:00
|
|
|
&cmd.logger_config,
|
2016-12-27 12:53:56 +01:00
|
|
|
).map_err(|e| format!("Sync error: {}", e))?;
|
2016-07-25 16:09:47 +02:00
|
|
|
|
|
|
|
service.add_notify(chain_notify.clone());
|
|
|
|
|
|
|
|
// start network
|
2016-11-05 10:38:00 +01:00
|
|
|
if network_enabled {
|
2016-07-25 16:09:47 +02:00
|
|
|
chain_notify.start();
|
|
|
|
}
|
|
|
|
|
2016-12-22 18:26:39 +01:00
|
|
|
// spin up event loop
|
|
|
|
let event_loop = EventLoop::spawn();
|
|
|
|
|
|
|
|
// fetch service
|
2016-12-27 12:53:56 +01:00
|
|
|
let fetch = FetchClient::new().map_err(|e| format!("Error starting fetch client: {:?}", e))?;
|
2016-12-22 18:26:39 +01:00
|
|
|
|
2016-12-10 23:58:39 +01:00
|
|
|
// the updater service
|
2016-12-22 18:26:39 +01:00
|
|
|
let updater = Updater::new(
|
|
|
|
Arc::downgrade(&(service.client() as Arc<BlockChainClient>)),
|
|
|
|
Arc::downgrade(&sync_provider),
|
|
|
|
update_policy,
|
|
|
|
fetch.clone(),
|
|
|
|
event_loop.remote(),
|
|
|
|
);
|
2016-12-11 02:02:40 +01:00
|
|
|
service.add_notify(updater.clone());
|
2016-12-10 23:58:39 +01:00
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
// set up dependencies for rpc servers
|
2017-02-04 22:18:19 +01:00
|
|
|
let rpc_stats = Arc::new(informant::RpcStats::default());
|
2016-09-21 12:44:49 +02:00
|
|
|
let signer_path = cmd.signer_conf.signer_path.clone();
|
2017-03-29 17:07:58 +02:00
|
|
|
let secret_store = match cmd.public_node {
|
|
|
|
true => None,
|
|
|
|
false => Some(account_provider.clone())
|
|
|
|
};
|
2017-04-03 08:51:23 +02:00
|
|
|
|
2017-03-22 20:14:40 +01:00
|
|
|
let deps_for_rpc_apis = Arc::new(rpc_apis::FullDependencies {
|
2016-10-03 15:01:10 +02:00
|
|
|
signer_service: Arc::new(rpc_apis::SignerService::new(move || {
|
|
|
|
signer::generate_new_token(signer_path.clone()).map_err(|e| format!("{:?}", e))
|
2016-11-09 19:41:47 +01:00
|
|
|
}, cmd.ui_address)),
|
2016-10-31 17:32:53 +01:00
|
|
|
snapshot: snapshot_service.clone(),
|
2016-07-25 16:09:47 +02:00
|
|
|
client: client.clone(),
|
|
|
|
sync: sync_provider.clone(),
|
|
|
|
net: manage_network.clone(),
|
2017-03-29 17:07:58 +02:00
|
|
|
secret_store: secret_store,
|
2016-07-25 16:09:47 +02:00
|
|
|
miner: miner.clone(),
|
|
|
|
external_miner: external_miner.clone(),
|
|
|
|
logger: logger.clone(),
|
|
|
|
settings: Arc::new(cmd.net_settings.clone()),
|
2016-08-03 15:31:00 +02:00
|
|
|
net_service: manage_network.clone(),
|
2016-12-11 19:14:42 +01:00
|
|
|
updater: updater.clone(),
|
2016-08-03 15:31:00 +02:00
|
|
|
geth_compatibility: cmd.geth_compatibility,
|
2016-11-09 19:41:47 +01:00
|
|
|
dapps_interface: match cmd.dapps_conf.enabled {
|
2017-04-03 10:27:37 +02:00
|
|
|
true => Some(cmd.http_conf.interface.clone()),
|
2016-11-09 19:41:47 +01:00
|
|
|
false => None,
|
|
|
|
},
|
2016-10-24 12:21:15 +02:00
|
|
|
dapps_port: match cmd.dapps_conf.enabled {
|
2017-04-03 10:27:37 +02:00
|
|
|
true => Some(cmd.http_conf.port),
|
2016-10-24 12:21:15 +02:00
|
|
|
false => None,
|
|
|
|
},
|
2016-12-22 18:26:39 +01:00
|
|
|
fetch: fetch.clone(),
|
2017-05-06 13:24:18 +02:00
|
|
|
remote: event_loop.remote(),
|
2016-07-25 16:09:47 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
let dependencies = rpc::Dependencies {
|
|
|
|
apis: deps_for_rpc_apis.clone(),
|
2017-01-11 20:02:27 +01:00
|
|
|
remote: event_loop.raw_remote(),
|
2017-02-04 22:18:19 +01:00
|
|
|
stats: rpc_stats.clone(),
|
2016-07-25 16:09:47 +02:00
|
|
|
};
|
|
|
|
|
2016-12-10 23:58:39 +01:00
|
|
|
// the dapps server
|
2017-03-22 22:00:52 +01:00
|
|
|
let dapps_deps = {
|
|
|
|
let (sync, client) = (sync_provider.clone(), client.clone());
|
|
|
|
let contract_client = Arc::new(::dapps::FullRegistrar { client: client.clone() });
|
|
|
|
|
|
|
|
dapps::Dependencies {
|
|
|
|
sync_status: Arc::new(move || is_major_importing(Some(sync.status().state), client.queue_info())),
|
|
|
|
contract_client: contract_client,
|
|
|
|
remote: event_loop.raw_remote(),
|
|
|
|
fetch: fetch.clone(),
|
|
|
|
signer: deps_for_rpc_apis.signer_service.clone(),
|
|
|
|
}
|
2016-07-25 16:09:47 +02:00
|
|
|
};
|
2017-04-03 10:27:37 +02:00
|
|
|
let dapps_middleware = dapps::new(cmd.dapps_conf.clone(), dapps_deps)?;
|
|
|
|
|
|
|
|
// start rpc servers
|
2017-04-13 16:32:07 +02:00
|
|
|
let ws_server = rpc::new_ws(cmd.ws_conf, &dependencies)?;
|
2017-04-03 10:27:37 +02:00
|
|
|
let http_server = rpc::new_http(cmd.http_conf.clone(), &dependencies, dapps_middleware)?;
|
|
|
|
let ipc_server = rpc::new_ipc(cmd.ipc_conf, &dependencies)?;
|
2016-07-25 16:09:47 +02:00
|
|
|
|
2016-12-10 23:58:39 +01:00
|
|
|
// the signer server
|
2016-07-25 16:09:47 +02:00
|
|
|
let signer_deps = signer::Dependencies {
|
|
|
|
apis: deps_for_rpc_apis.clone(),
|
2017-01-11 20:02:27 +01:00
|
|
|
remote: event_loop.raw_remote(),
|
2017-02-04 22:18:19 +01:00
|
|
|
rpc_stats: rpc_stats.clone(),
|
2016-07-25 16:09:47 +02:00
|
|
|
};
|
2017-03-22 20:14:40 +01:00
|
|
|
let signing_queue = deps_for_rpc_apis.signer_service.queue();
|
|
|
|
let signer_server = signer::start(cmd.signer_conf.clone(), signing_queue, signer_deps)?;
|
2016-07-25 16:09:47 +02:00
|
|
|
|
2017-02-20 16:13:21 +01:00
|
|
|
// secret store key server
|
2017-04-03 17:46:51 +02:00
|
|
|
let secretstore_deps = secretstore::Dependencies {
|
|
|
|
client: client.clone(),
|
|
|
|
};
|
2017-04-08 11:26:16 +02:00
|
|
|
let secretstore_key_server = secretstore::start(cmd.secretstore_conf.clone(), secretstore_deps)?;
|
2017-02-20 16:13:21 +01:00
|
|
|
|
2017-02-14 19:30:37 +01:00
|
|
|
// the ipfs server
|
2017-02-24 10:32:42 +01:00
|
|
|
let ipfs_server = ipfs::start_server(cmd.ipfs_conf.clone(), client.clone())?;
|
2017-02-14 19:30:37 +01:00
|
|
|
|
2016-12-10 23:58:39 +01:00
|
|
|
// the informant
|
2016-10-18 18:16:00 +02:00
|
|
|
let informant = Arc::new(Informant::new(
|
|
|
|
service.client(),
|
|
|
|
Some(sync_provider.clone()),
|
|
|
|
Some(manage_network.clone()),
|
|
|
|
Some(snapshot_service.clone()),
|
2017-02-04 22:18:19 +01:00
|
|
|
Some(rpc_stats.clone()),
|
|
|
|
cmd.logger_config.color,
|
2016-10-18 18:16:00 +02:00
|
|
|
));
|
2016-12-10 23:58:39 +01:00
|
|
|
service.add_notify(informant.clone());
|
|
|
|
service.register_io_handler(informant.clone()).map_err(|_| "Unable to register informant handler".to_owned())?;
|
2016-07-25 16:09:47 +02:00
|
|
|
|
2016-11-05 10:38:00 +01:00
|
|
|
// save user defaults
|
|
|
|
user_defaults.pruning = algorithm;
|
|
|
|
user_defaults.tracing = tracing;
|
2016-11-27 11:11:56 +01:00
|
|
|
user_defaults.fat_db = fat_db;
|
|
|
|
user_defaults.mode = mode;
|
2016-12-27 12:53:56 +01:00
|
|
|
user_defaults.save(&user_defaults_path)?;
|
2016-11-05 10:38:00 +01:00
|
|
|
|
2016-12-10 23:58:39 +01:00
|
|
|
// tell client how to save the default mode if it gets changed.
|
2017-03-13 12:10:53 +01:00
|
|
|
client.on_user_defaults_change(move |mode: Option<Mode>| {
|
|
|
|
if let Some(mode) = mode {
|
|
|
|
user_defaults.mode = mode;
|
|
|
|
}
|
2016-11-05 10:38:00 +01:00
|
|
|
let _ = user_defaults.save(&user_defaults_path); // discard failures - there's nothing we can do
|
2016-12-10 23:58:39 +01:00
|
|
|
});
|
2016-11-05 10:38:00 +01:00
|
|
|
|
2016-09-05 14:25:56 +02:00
|
|
|
// the watcher must be kept alive.
|
|
|
|
let _watcher = match cmd.no_periodic_snapshot {
|
|
|
|
true => None,
|
|
|
|
false => {
|
2016-09-07 15:27:14 +02:00
|
|
|
let sync = sync_provider.clone();
|
2017-03-13 12:10:53 +01:00
|
|
|
let client = client.clone();
|
2016-09-05 14:25:56 +02:00
|
|
|
let watcher = Arc::new(snapshot::Watcher::new(
|
|
|
|
service.client(),
|
2016-10-20 23:36:18 +02:00
|
|
|
move || is_major_importing(Some(sync.status().state), client.queue_info()),
|
2016-09-05 14:25:56 +02:00
|
|
|
service.io().channel(),
|
|
|
|
SNAPSHOT_PERIOD,
|
|
|
|
SNAPSHOT_HISTORY,
|
|
|
|
));
|
|
|
|
|
|
|
|
service.add_notify(watcher.clone());
|
|
|
|
Some(watcher)
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
// start ui
|
|
|
|
if cmd.ui {
|
2017-04-03 10:27:37 +02:00
|
|
|
open_ui(&cmd.signer_conf)?;
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
|
|
|
|
2017-01-06 16:05:58 +01:00
|
|
|
if let Some(dapp) = cmd.dapp {
|
2017-04-03 10:27:37 +02:00
|
|
|
open_dapp(&cmd.dapps_conf, &cmd.http_conf, &dapp)?;
|
2017-01-06 16:05:58 +01:00
|
|
|
}
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
// Handle exit
|
2017-03-13 12:10:53 +01:00
|
|
|
let restart = wait_for_exit(panic_handler, Some(updater), Some(client), can_restart);
|
2016-12-10 23:58:39 +01:00
|
|
|
|
2016-12-17 00:44:18 +01:00
|
|
|
// drop this stuff as soon as exit detected.
|
2017-04-13 16:32:07 +02:00
|
|
|
drop((ws_server, http_server, ipc_server, signer_server, secretstore_key_server, ipfs_server, event_loop));
|
2016-12-10 23:58:39 +01:00
|
|
|
|
|
|
|
info!("Finishing work, please wait...");
|
2016-07-25 16:09:47 +02:00
|
|
|
|
2016-09-03 10:31:29 +02:00
|
|
|
// to make sure timer does not spawn requests while shutdown is in progress
|
2016-12-11 02:02:40 +01:00
|
|
|
informant.shutdown();
|
2016-09-03 10:31:29 +02:00
|
|
|
// just Arc is dropping here, to allow other reference release in its default time
|
2016-12-11 02:02:40 +01:00
|
|
|
drop(informant);
|
2016-09-03 10:31:29 +02:00
|
|
|
|
2016-08-30 14:05:02 +02:00
|
|
|
// hypervisor should be shutdown first while everything still works and can be
|
|
|
|
// terminated gracefully
|
|
|
|
drop(hypervisor);
|
|
|
|
|
2016-12-11 13:10:33 +01:00
|
|
|
Ok(restart)
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
fn daemonize(pid_file: String) -> Result<(), String> {
|
|
|
|
extern crate daemonize;
|
|
|
|
|
|
|
|
daemonize::Daemonize::new()
|
2016-12-10 23:58:39 +01:00
|
|
|
.pid_file(pid_file)
|
|
|
|
.chown_pid_file(true)
|
|
|
|
.start()
|
|
|
|
.map(|_| ())
|
|
|
|
.map_err(|e| format!("Couldn't daemonize; {}", e))
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
fn daemonize(_pid_file: String) -> Result<(), String> {
|
|
|
|
Err("daemon is no supported on windows".into())
|
|
|
|
}
|
|
|
|
|
2017-01-04 16:51:27 +01:00
|
|
|
fn prepare_account_provider(spec: &SpecType, dirs: &Directories, data_dir: &str, cfg: AccountsConfig, passwords: &[String]) -> Result<AccountProvider, String> {
|
2016-10-04 10:44:47 +02:00
|
|
|
use ethcore::ethstore::EthStore;
|
2017-01-30 11:44:09 +01:00
|
|
|
use ethcore::ethstore::dir::RootDiskDirectory;
|
2016-07-25 16:09:47 +02:00
|
|
|
|
2016-12-12 16:51:07 +01:00
|
|
|
let path = dirs.keys_path(data_dir);
|
|
|
|
upgrade_key_location(&dirs.legacy_keys_path(cfg.testnet), &path);
|
2017-01-30 11:44:09 +01:00
|
|
|
let dir = Box::new(RootDiskDirectory::create(&path).map_err(|e| format!("Could not open keys directory: {}", e))?);
|
2017-02-10 01:07:06 +01:00
|
|
|
let account_settings = AccountProviderSettings {
|
|
|
|
enable_hardware_wallets: cfg.enable_hardware_wallets,
|
|
|
|
hardware_wallet_classic_key: spec == &SpecType::Classic,
|
|
|
|
};
|
|
|
|
let account_provider = AccountProvider::new(
|
|
|
|
Box::new(EthStore::open_with_iterations(dir, cfg.iterations).map_err(|e| format!("Could not open keys directory: {}", e))?),
|
|
|
|
account_settings);
|
2016-07-25 16:09:47 +02:00
|
|
|
|
|
|
|
for a in cfg.unlocked_accounts {
|
2017-01-04 14:05:32 +01:00
|
|
|
// Check if the account exists
|
|
|
|
if !account_provider.has_account(a).unwrap_or(false) {
|
2017-01-04 16:51:27 +01:00
|
|
|
return Err(format!("Account {} not found for the current chain. {}", a, build_create_account_hint(spec, &dirs.keys)));
|
2017-01-04 14:05:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if any passwords have been read from the password file(s)
|
|
|
|
if passwords.is_empty() {
|
2017-01-04 14:48:32 +01:00
|
|
|
return Err(format!("No password found to unlock account {}. {}", a, VERIFY_PASSWORD_HINT));
|
2017-01-04 14:05:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if !passwords.iter().any(|p| account_provider.unlock_account_permanently(a, (*p).clone()).is_ok()) {
|
2017-01-04 14:48:32 +01:00
|
|
|
return Err(format!("No valid password to unlock account {}. {}", a, VERIFY_PASSWORD_HINT));
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-04 14:05:32 +01:00
|
|
|
Ok(account_provider)
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|
|
|
|
|
2017-01-04 16:51:27 +01:00
|
|
|
// Construct an error `String` with an adaptive hint on how to create an account.
|
|
|
|
fn build_create_account_hint(spec: &SpecType, keys: &str) -> String {
|
|
|
|
format!("You can create an account via RPC, UI or `parity account new --chain {} --keys-path {}`.", spec, keys)
|
|
|
|
}
|
|
|
|
|
2016-07-25 16:09:47 +02:00
|
|
|
fn wait_for_exit(
|
|
|
|
panic_handler: Arc<PanicHandler>,
|
2016-12-16 21:45:51 +01:00
|
|
|
updater: Option<Arc<Updater>>,
|
2017-03-13 12:10:53 +01:00
|
|
|
client: Option<Arc<Client>>,
|
2016-12-11 04:05:02 +01:00
|
|
|
can_restart: bool
|
2017-03-13 12:10:53 +01:00
|
|
|
) -> (bool, Option<String>) {
|
|
|
|
let exit = Arc::new((Mutex::new((false, None)), Condvar::new()));
|
2016-07-25 16:09:47 +02:00
|
|
|
|
|
|
|
// Handle possible exits
|
|
|
|
let e = exit.clone();
|
2016-12-10 23:58:39 +01:00
|
|
|
CtrlC::set_handler(move || { e.1.notify_all(); });
|
2016-07-25 16:09:47 +02:00
|
|
|
|
|
|
|
// Handle panics
|
|
|
|
let e = exit.clone();
|
2016-12-10 23:58:39 +01:00
|
|
|
panic_handler.on_panic(move |_reason| { e.1.notify_all(); });
|
|
|
|
|
2017-03-13 12:10:53 +01:00
|
|
|
if can_restart {
|
|
|
|
if let Some(updater) = updater {
|
|
|
|
// Handle updater wanting to restart us
|
2016-12-16 21:45:51 +01:00
|
|
|
let e = exit.clone();
|
2017-03-13 12:10:53 +01:00
|
|
|
updater.set_exit_handler(move || { *e.0.lock() = (true, None); e.1.notify_all(); });
|
2016-12-16 21:45:51 +01:00
|
|
|
}
|
2017-03-13 12:10:53 +01:00
|
|
|
|
|
|
|
if let Some(client) = client {
|
|
|
|
// Handle updater wanting to restart us
|
|
|
|
let e = exit.clone();
|
|
|
|
client.set_exit_handler(move |restart, new_chain: Option<String>| { *e.0.lock() = (restart, new_chain); e.1.notify_all(); });
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
trace!(target: "mode", "Not hypervised: not setting exit handlers.");
|
2016-12-11 04:05:02 +01:00
|
|
|
}
|
2016-07-25 16:09:47 +02:00
|
|
|
|
|
|
|
// Wait for signal
|
2016-12-11 02:02:40 +01:00
|
|
|
let mut l = exit.0.lock();
|
|
|
|
let _ = exit.1.wait(&mut l);
|
2017-03-13 12:10:53 +01:00
|
|
|
l.clone()
|
2016-07-25 16:09:47 +02:00
|
|
|
}
|