2020-09-22 14:53:52 +02:00
|
|
|
// Copyright 2015-2020 Parity Technologies (UK) Ltd.
|
|
|
|
// This file is part of OpenEthereum.
|
2018-05-09 08:47:21 +02:00
|
|
|
|
2020-09-22 14:53:52 +02:00
|
|
|
// OpenEthereum is free software: you can redistribute it and/or modify
|
2018-05-09 08:47:21 +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.
|
|
|
|
|
2020-09-22 14:53:52 +02:00
|
|
|
// OpenEthereum is distributed in the hope that it will be useful,
|
2018-05-09 08:47:21 +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
|
2020-09-22 14:53:52 +02:00
|
|
|
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
2018-05-09 08:47:21 +02:00
|
|
|
|
|
|
|
//! Ethcore client application.
|
|
|
|
#![warn(missing_docs)]
|
|
|
|
|
|
|
|
extern crate ansi_term;
|
|
|
|
extern crate docopt;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate clap;
|
|
|
|
extern crate atty;
|
|
|
|
extern crate dir;
|
|
|
|
extern crate futures;
|
|
|
|
extern crate jsonrpc_core;
|
|
|
|
extern crate num_cpus;
|
|
|
|
extern crate number_prefix;
|
|
|
|
extern crate parking_lot;
|
|
|
|
extern crate regex;
|
|
|
|
extern crate rlp;
|
|
|
|
extern crate rpassword;
|
|
|
|
extern crate rustc_hex;
|
|
|
|
extern crate semver;
|
|
|
|
extern crate serde;
|
|
|
|
extern crate serde_json;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_derive;
|
|
|
|
extern crate toml;
|
|
|
|
|
2018-06-20 15:13:07 +02:00
|
|
|
extern crate blooms_db;
|
2018-12-28 10:33:49 +01:00
|
|
|
extern crate cli_signer;
|
2019-01-04 14:05:46 +01:00
|
|
|
extern crate common_types as types;
|
2019-01-17 16:43:08 +01:00
|
|
|
extern crate ethcore;
|
|
|
|
extern crate ethcore_call_contract as call_contract;
|
2019-01-04 14:05:46 +01:00
|
|
|
extern crate ethcore_db;
|
2018-05-09 08:47:21 +02:00
|
|
|
extern crate ethcore_io as io;
|
|
|
|
extern crate ethcore_logger;
|
|
|
|
extern crate ethcore_miner as miner;
|
|
|
|
extern crate ethcore_network as network;
|
|
|
|
extern crate ethcore_service;
|
|
|
|
extern crate ethcore_sync as sync;
|
|
|
|
extern crate ethereum_types;
|
|
|
|
extern crate ethkey;
|
2019-02-07 14:34:24 +01:00
|
|
|
extern crate ethstore;
|
2020-08-14 12:24:16 +02:00
|
|
|
extern crate fetch;
|
2020-09-14 16:08:57 +02:00
|
|
|
extern crate hyper;
|
2019-02-07 14:34:24 +01:00
|
|
|
extern crate journaldb;
|
|
|
|
extern crate keccak_hash as hash;
|
2018-05-09 08:47:21 +02:00
|
|
|
extern crate kvdb;
|
2019-02-07 14:34:24 +01:00
|
|
|
extern crate node_filter;
|
|
|
|
extern crate parity_bytes as bytes;
|
2018-05-09 08:47:21 +02:00
|
|
|
extern crate parity_local_store as local_store;
|
2019-02-07 14:34:24 +01:00
|
|
|
extern crate parity_path as path;
|
2018-05-09 08:47:21 +02:00
|
|
|
extern crate parity_rpc;
|
2019-02-07 14:34:24 +01:00
|
|
|
extern crate parity_runtime;
|
2018-05-09 08:47:21 +02:00
|
|
|
extern crate parity_version;
|
2020-09-14 16:08:57 +02:00
|
|
|
extern crate prometheus;
|
|
|
|
extern crate stats;
|
2018-05-09 08:47:21 +02:00
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate log as rlog;
|
|
|
|
|
2019-02-07 14:34:24 +01:00
|
|
|
#[cfg(feature = "ethcore-accounts")]
|
|
|
|
extern crate ethcore_accounts as accounts;
|
|
|
|
|
2018-06-05 11:28:35 +02:00
|
|
|
#[cfg(feature = "secretstore")]
|
2018-05-09 08:47:21 +02:00
|
|
|
extern crate ethcore_secretstore;
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
#[macro_use]
|
|
|
|
extern crate pretty_assertions;
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
extern crate tempdir;
|
|
|
|
|
2019-02-06 17:53:34 +01:00
|
|
|
#[cfg(test)]
|
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
|
|
|
|
2018-05-09 08:47:21 +02:00
|
|
|
mod account;
|
2019-02-07 14:34:24 +01:00
|
|
|
mod account_utils;
|
2018-05-09 08:47:21 +02:00
|
|
|
mod blockchain;
|
|
|
|
mod cache;
|
|
|
|
mod cli;
|
|
|
|
mod configuration;
|
|
|
|
mod db;
|
|
|
|
mod helpers;
|
|
|
|
mod informant;
|
2020-09-14 16:08:57 +02:00
|
|
|
mod metrics;
|
2018-05-09 08:47:21 +02:00
|
|
|
mod modules;
|
|
|
|
mod params;
|
|
|
|
mod presale;
|
|
|
|
mod rpc;
|
|
|
|
mod rpc_apis;
|
|
|
|
mod run;
|
|
|
|
mod secretstore;
|
|
|
|
mod signer;
|
|
|
|
mod snapshot;
|
|
|
|
mod upgrade;
|
|
|
|
mod user_defaults;
|
|
|
|
|
2019-02-01 19:31:02 +01:00
|
|
|
use std::{fs::File, io::BufReader, sync::Arc};
|
|
|
|
|
2018-05-09 08:47:21 +02:00
|
|
|
use cli::Args;
|
|
|
|
use configuration::{Cmd, Execute};
|
2019-02-01 19:31:02 +01:00
|
|
|
use hash::keccak_buffer;
|
|
|
|
|
2018-06-07 16:48:01 +02:00
|
|
|
#[cfg(feature = "memory_profiling")]
|
2018-07-11 08:02:14 +02:00
|
|
|
use std::alloc::System;
|
2018-05-09 08:47:21 +02:00
|
|
|
|
|
|
|
pub use self::{configuration::Configuration, run::RunningClient};
|
|
|
|
pub use ethcore_logger::{setup_log, Config as LoggerConfig, RotatingLogger};
|
2019-01-02 16:49:01 +01:00
|
|
|
pub use parity_rpc::PubSubSession;
|
2018-05-09 08:47:21 +02:00
|
|
|
|
2018-06-07 16:48:01 +02:00
|
|
|
#[cfg(feature = "memory_profiling")]
|
|
|
|
#[global_allocator]
|
|
|
|
static A: System = System;
|
|
|
|
|
2018-05-09 08:47:21 +02:00
|
|
|
fn print_hash_of(maybe_file: Option<String>) -> Result<String, String> {
|
|
|
|
if let Some(file) = maybe_file {
|
|
|
|
let mut f =
|
|
|
|
BufReader::new(File::open(&file).map_err(|_| "Unable to open file".to_owned())?);
|
|
|
|
let hash = keccak_buffer(&mut f).map_err(|_| "Unable to read from file".to_owned())?;
|
|
|
|
Ok(format!("{:x}", hash))
|
|
|
|
} else {
|
|
|
|
Err("Streaming from standard input not yet supported. Specify a file.".to_owned())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-30 15:42:37 +02:00
|
|
|
#[cfg(feature = "deadlock_detection")]
|
|
|
|
fn run_deadlock_detection_thread() {
|
|
|
|
use ansi_term::Style;
|
|
|
|
use parking_lot::deadlock;
|
2018-06-08 10:04:12 +02:00
|
|
|
use std::{thread, time::Duration};
|
2020-08-05 06:08:03 +02:00
|
|
|
|
2018-05-30 15:42:37 +02:00
|
|
|
info!("Starting deadlock detection thread.");
|
|
|
|
// Create a background thread which checks for deadlocks every 10s
|
|
|
|
thread::spawn(move || loop {
|
|
|
|
thread::sleep(Duration::from_secs(10));
|
|
|
|
let deadlocks = deadlock::check_deadlock();
|
|
|
|
if deadlocks.is_empty() {
|
|
|
|
continue;
|
|
|
|
}
|
2020-08-05 06:08:03 +02:00
|
|
|
|
2018-05-30 15:42:37 +02:00
|
|
|
warn!(
|
|
|
|
"{} {} detected",
|
|
|
|
deadlocks.len(),
|
|
|
|
Style::new().bold().paint("deadlock(s)")
|
|
|
|
);
|
|
|
|
for (i, threads) in deadlocks.iter().enumerate() {
|
|
|
|
warn!("{} #{}", Style::new().bold().paint("Deadlock"), i);
|
|
|
|
for t in threads {
|
|
|
|
warn!("Thread Id {:#?}", t.thread_id());
|
|
|
|
warn!("{:#?}", t.backtrace());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-22 14:53:52 +02:00
|
|
|
/// Action that OpenEthereum performed when running `start`.
|
2018-05-09 08:47:21 +02:00
|
|
|
pub enum ExecutionAction {
|
|
|
|
/// The execution didn't require starting a node, and thus has finished.
|
|
|
|
/// Contains the string to print on stdout, if any.
|
|
|
|
Instant(Option<String>),
|
2020-08-05 06:08:03 +02:00
|
|
|
|
2018-05-09 08:47:21 +02:00
|
|
|
/// The client has started running and must be shut down manually by calling `shutdown`.
|
|
|
|
///
|
|
|
|
/// If you don't call `shutdown()`, execution will continue in the background.
|
|
|
|
Running(RunningClient),
|
|
|
|
}
|
|
|
|
|
2020-08-14 12:24:16 +02:00
|
|
|
fn execute(command: Execute, logger: Arc<RotatingLogger>) -> Result<ExecutionAction, String> {
|
2018-05-30 15:42:37 +02:00
|
|
|
#[cfg(feature = "deadlock_detection")]
|
|
|
|
run_deadlock_detection_thread();
|
2020-08-05 06:08:03 +02:00
|
|
|
|
2018-05-09 08:47:21 +02:00
|
|
|
match command.cmd {
|
|
|
|
Cmd::Run(run_cmd) => {
|
2020-08-14 12:24:16 +02:00
|
|
|
let outcome = run::execute(run_cmd, logger)?;
|
2018-05-09 08:47:21 +02:00
|
|
|
Ok(ExecutionAction::Running(outcome))
|
|
|
|
}
|
|
|
|
Cmd::Version => Ok(ExecutionAction::Instant(Some(Args::print_version()))),
|
|
|
|
Cmd::Hash(maybe_file) => {
|
|
|
|
print_hash_of(maybe_file).map(|s| ExecutionAction::Instant(Some(s)))
|
2020-08-05 06:08:03 +02:00
|
|
|
}
|
2018-05-09 08:47:21 +02:00
|
|
|
Cmd::Account(account_cmd) => {
|
|
|
|
account::execute(account_cmd).map(|s| ExecutionAction::Instant(Some(s)))
|
2020-08-05 06:08:03 +02:00
|
|
|
}
|
2018-05-09 08:47:21 +02:00
|
|
|
Cmd::ImportPresaleWallet(presale_cmd) => {
|
|
|
|
presale::execute(presale_cmd).map(|s| ExecutionAction::Instant(Some(s)))
|
2020-08-05 06:08:03 +02:00
|
|
|
}
|
2018-05-09 08:47:21 +02:00
|
|
|
Cmd::Blockchain(blockchain_cmd) => {
|
|
|
|
blockchain::execute(blockchain_cmd).map(|_| ExecutionAction::Instant(None))
|
2020-08-05 06:08:03 +02:00
|
|
|
}
|
2018-06-06 10:05:52 +02:00
|
|
|
Cmd::SignerToken(ws_conf, logger_config) => {
|
|
|
|
signer::execute(ws_conf, logger_config).map(|s| ExecutionAction::Instant(Some(s)))
|
2020-08-05 06:08:03 +02:00
|
|
|
}
|
2018-12-28 10:33:49 +01:00
|
|
|
Cmd::SignerSign {
|
|
|
|
id,
|
|
|
|
pwfile,
|
|
|
|
port,
|
|
|
|
authfile,
|
|
|
|
} => cli_signer::signer_sign(id, pwfile, port, authfile)
|
|
|
|
.map(|s| ExecutionAction::Instant(Some(s))),
|
|
|
|
Cmd::SignerList { port, authfile } => {
|
|
|
|
cli_signer::signer_list(port, authfile).map(|s| ExecutionAction::Instant(Some(s)))
|
2020-08-05 06:08:03 +02:00
|
|
|
}
|
2018-12-28 10:33:49 +01:00
|
|
|
Cmd::SignerReject { id, port, authfile } => {
|
|
|
|
cli_signer::signer_reject(id, port, authfile).map(|s| ExecutionAction::Instant(Some(s)))
|
2020-08-05 06:08:03 +02:00
|
|
|
}
|
2018-05-09 08:47:21 +02:00
|
|
|
Cmd::Snapshot(snapshot_cmd) => {
|
|
|
|
snapshot::execute(snapshot_cmd).map(|s| ExecutionAction::Instant(Some(s)))
|
2020-08-05 06:08:03 +02:00
|
|
|
}
|
|
|
|
}
|
2018-05-09 08:47:21 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 14:53:52 +02:00
|
|
|
/// Starts the OpenEthereum client.
|
2018-05-09 08:47:21 +02:00
|
|
|
///
|
2020-09-22 14:53:52 +02:00
|
|
|
/// The first parameter is the command line arguments that you would pass when running the openethereum
|
2018-05-09 08:47:21 +02:00
|
|
|
/// binary.
|
|
|
|
///
|
|
|
|
/// On error, returns what to print on stderr.
|
2020-09-22 14:53:52 +02:00
|
|
|
// FIXME: totally independent logging capability, see https://github.com/openethereum/openethereum/issues/10252
|
2020-08-14 12:24:16 +02:00
|
|
|
pub fn start(conf: Configuration, logger: Arc<RotatingLogger>) -> Result<ExecutionAction, String> {
|
|
|
|
execute(conf.into_command()?, logger)
|
2018-05-09 08:47:21 +02:00
|
|
|
}
|