Merge branch 'master' into new-jsonrpc
This commit is contained in:
@@ -190,6 +190,7 @@ fn execute_import(cmd: ImportBlockchain) -> Result<(), String> {
|
||||
// prepare client config
|
||||
let mut client_config = to_client_config(
|
||||
&cmd.cache_config,
|
||||
spec.name.to_lowercase(),
|
||||
Mode::Active,
|
||||
tracing,
|
||||
fat_db,
|
||||
@@ -361,6 +362,7 @@ fn start_client(
|
||||
// prepare client config
|
||||
let client_config = to_client_config(
|
||||
&cache_config,
|
||||
spec.name.to_lowercase(),
|
||||
Mode::Active,
|
||||
tracing,
|
||||
fat_db,
|
||||
|
||||
@@ -90,7 +90,7 @@ usage! {
|
||||
flag_release_track: String = "current", or |c: &Config| otry!(c.parity).release_track.clone(),
|
||||
flag_no_download: bool = false, or |c: &Config| otry!(c.parity).no_download.clone(),
|
||||
flag_no_consensus: bool = false, or |c: &Config| otry!(c.parity).no_consensus.clone(),
|
||||
flag_chain: String = "homestead", or |c: &Config| otry!(c.parity).chain.clone(),
|
||||
flag_chain: String = "foundation", or |c: &Config| otry!(c.parity).chain.clone(),
|
||||
flag_keys_path: String = "$BASE/keys", or |c: &Config| otry!(c.parity).keys_path.clone(),
|
||||
flag_identity: String = "", or |c: &Config| otry!(c.parity).identity.clone(),
|
||||
|
||||
|
||||
@@ -85,14 +85,16 @@ pub struct Execute {
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Configuration {
|
||||
pub args: Args,
|
||||
pub spec_name_override: Option<String>,
|
||||
}
|
||||
|
||||
impl Configuration {
|
||||
pub fn parse<S: AsRef<str>>(command: &[S]) -> Result<Self, ArgsError> {
|
||||
pub fn parse<S: AsRef<str>>(command: &[S], spec_name_override: Option<String>) -> Result<Self, ArgsError> {
|
||||
let args = Args::parse(command)?;
|
||||
|
||||
let config = Configuration {
|
||||
args: args,
|
||||
spec_name_override: spec_name_override,
|
||||
};
|
||||
|
||||
Ok(config)
|
||||
@@ -103,7 +105,11 @@ impl Configuration {
|
||||
let pruning = self.args.flag_pruning.parse()?;
|
||||
let pruning_history = self.args.flag_pruning_history;
|
||||
let vm_type = self.vm_type()?;
|
||||
let mode = match self.args.flag_mode.as_ref() { "last" => None, mode => Some(to_mode(&mode, self.args.flag_mode_timeout, self.args.flag_mode_alarm)?), };
|
||||
let spec = self.chain().parse()?;
|
||||
let mode = match self.args.flag_mode.as_ref() {
|
||||
"last" => None,
|
||||
mode => Some(to_mode(&mode, self.args.flag_mode_timeout, self.args.flag_mode_alarm)?),
|
||||
};
|
||||
let update_policy = self.update_policy()?;
|
||||
let logger_config = self.logger_config();
|
||||
let http_conf = self.http_config()?;
|
||||
@@ -111,7 +117,6 @@ impl Configuration {
|
||||
let net_conf = self.net_config()?;
|
||||
let network_id = self.network_id();
|
||||
let cache_config = self.cache_config();
|
||||
let spec = self.chain().parse()?;
|
||||
let tracing = self.args.flag_tracing.parse()?;
|
||||
let fat_db = self.args.flag_fat_db.parse()?;
|
||||
let compaction = self.args.flag_db_compaction.parse()?;
|
||||
@@ -437,7 +442,10 @@ impl Configuration {
|
||||
}
|
||||
|
||||
fn chain(&self) -> String {
|
||||
if self.args.flag_testnet {
|
||||
if let Some(ref s) = self.spec_name_override {
|
||||
s.clone()
|
||||
}
|
||||
else if self.args.flag_testnet {
|
||||
"testnet".to_owned()
|
||||
} else {
|
||||
self.args.flag_chain.clone()
|
||||
@@ -972,6 +980,7 @@ mod tests {
|
||||
fn parse(args: &[&str]) -> Configuration {
|
||||
Configuration {
|
||||
args: Args::parse_without_config(args).unwrap(),
|
||||
spec_name_override: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1429,7 +1438,7 @@ mod tests {
|
||||
let filename = temp.as_str().to_owned() + "/peers";
|
||||
File::create(filename.clone()).unwrap().write_all(b" \n\t\n").unwrap();
|
||||
let args = vec!["parity", "--reserved-peers", &filename];
|
||||
let conf = Configuration::parse(&args).unwrap();
|
||||
let conf = Configuration::parse(&args, None).unwrap();
|
||||
assert!(conf.init_reserved_nodes().is_ok());
|
||||
}
|
||||
|
||||
|
||||
@@ -215,6 +215,7 @@ pub fn default_network_config() -> ::ethsync::NetworkConfiguration {
|
||||
#[cfg_attr(feature = "dev", allow(too_many_arguments))]
|
||||
pub fn to_client_config(
|
||||
cache_config: &CacheConfig,
|
||||
spec_name: String,
|
||||
mode: Mode,
|
||||
tracing: bool,
|
||||
fat_db: bool,
|
||||
@@ -261,6 +262,7 @@ pub fn to_client_config(
|
||||
client_config.vm_type = vm_type;
|
||||
client_config.name = name;
|
||||
client_config.verifier_type = if check_seal { VerifierType::Canon } else { VerifierType::CanonNoSeal };
|
||||
client_config.spec_name = spec_name;
|
||||
client_config
|
||||
}
|
||||
|
||||
@@ -479,4 +481,3 @@ but the first password is trimmed
|
||||
assert_eq!(to_bootnodes(&Some(two_bootnodes.into())), Ok(vec![one_bootnode.into(), one_bootnode.into()]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ mod stratum;
|
||||
use std::{process, env};
|
||||
use std::collections::HashMap;
|
||||
use std::io::{self as stdio, BufReader, Read, Write};
|
||||
use std::fs::File;
|
||||
use std::fs::{remove_file, metadata, File};
|
||||
use std::path::PathBuf;
|
||||
use util::sha3::sha3;
|
||||
use cli::Args;
|
||||
@@ -143,7 +143,7 @@ fn print_hash_of(maybe_file: Option<String>) -> Result<String, String> {
|
||||
|
||||
enum PostExecutionAction {
|
||||
Print(String),
|
||||
Restart,
|
||||
Restart(Option<String>),
|
||||
Quit,
|
||||
}
|
||||
|
||||
@@ -152,8 +152,8 @@ fn execute(command: Execute, can_restart: bool) -> Result<PostExecutionAction, S
|
||||
|
||||
match command.cmd {
|
||||
Cmd::Run(run_cmd) => {
|
||||
let restart = run::execute(run_cmd, can_restart, logger)?;
|
||||
Ok(if restart { PostExecutionAction::Restart } else { PostExecutionAction::Quit })
|
||||
let (restart, spec_name) = run::execute(run_cmd, can_restart, logger)?;
|
||||
Ok(if restart { PostExecutionAction::Restart(spec_name) } else { PostExecutionAction::Quit })
|
||||
},
|
||||
Cmd::Version => Ok(PostExecutionAction::Print(Args::print_version())),
|
||||
Cmd::Hash(maybe_file) => print_hash_of(maybe_file).map(|s| PostExecutionAction::Print(s)),
|
||||
@@ -170,7 +170,7 @@ fn execute(command: Execute, can_restart: bool) -> Result<PostExecutionAction, S
|
||||
|
||||
fn start(can_restart: bool) -> Result<PostExecutionAction, String> {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let conf = Configuration::parse(&args).unwrap_or_else(|e| e.exit());
|
||||
let conf = Configuration::parse(&args, take_spec_name_override()).unwrap_or_else(|e| e.exit());
|
||||
|
||||
let deprecated = find_deprecated(&conf.args);
|
||||
for d in deprecated {
|
||||
@@ -208,6 +208,22 @@ fn latest_exe_path() -> Option<PathBuf> {
|
||||
.and_then(|mut f| { let mut exe = String::new(); f.read_to_string(&mut exe).ok().map(|_| updates_path(&exe)) })
|
||||
}
|
||||
|
||||
fn set_spec_name_override(spec_name: String) {
|
||||
if let Err(e) = File::create(updates_path("spec_name_overide"))
|
||||
.and_then(|mut f| f.write_all(spec_name.as_bytes()))
|
||||
{
|
||||
warn!("Couldn't override chain spec: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
fn take_spec_name_override() -> Option<String> {
|
||||
let p = updates_path("spec_name_overide");
|
||||
let r = File::open(p.clone()).ok()
|
||||
.and_then(|mut f| { let mut spec_name = String::new(); f.read_to_string(&mut spec_name).ok().map(|_| spec_name) });
|
||||
let _ = remove_file(p);
|
||||
r
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn global_cleanup() {
|
||||
extern "system" { pub fn WSACleanup() -> i32; }
|
||||
@@ -250,7 +266,12 @@ fn main_direct(can_restart: bool) -> i32 {
|
||||
match start(can_restart) {
|
||||
Ok(result) => match result {
|
||||
PostExecutionAction::Print(s) => { println!("{}", s); 0 },
|
||||
PostExecutionAction::Restart => PLEASE_RESTART_EXIT_CODE,
|
||||
PostExecutionAction::Restart(spec_name_override) => {
|
||||
if let Some(spec_name) = spec_name_override {
|
||||
set_spec_name_override(spec_name);
|
||||
}
|
||||
PLEASE_RESTART_EXIT_CODE
|
||||
},
|
||||
PostExecutionAction::Quit => 0,
|
||||
},
|
||||
Err(err) => {
|
||||
@@ -292,8 +313,19 @@ fn main() {
|
||||
let latest_exe = latest_exe_path();
|
||||
let have_update = latest_exe.as_ref().map_or(false, |p| p.exists());
|
||||
let is_non_updated_current = exe.as_ref().map_or(false, |exe| latest_exe.as_ref().map_or(false, |lexe| exe.canonicalize().ok() != lexe.canonicalize().ok()));
|
||||
trace_main!("Starting... (have-update: {}, non-updated-current: {})", have_update, is_non_updated_current);
|
||||
let exit_code = if have_update && is_non_updated_current {
|
||||
let update_is_newer = match (
|
||||
latest_exe.as_ref()
|
||||
.and_then(|p| metadata(p.as_path()).ok())
|
||||
.and_then(|m| m.modified().ok()),
|
||||
exe.as_ref()
|
||||
.and_then(|p| metadata(p.as_path()).ok())
|
||||
.and_then(|m| m.modified().ok())
|
||||
) {
|
||||
(Some(latest_exe_time), Some(this_exe_time)) if latest_exe_time > this_exe_time => true,
|
||||
_ => false,
|
||||
};
|
||||
trace_main!("Starting... (have-update: {}, non-updated-current: {}, update-is-newer: {})", have_update, is_non_updated_current, update_is_newer);
|
||||
let exit_code = if have_update && is_non_updated_current && update_is_newer {
|
||||
trace_main!("Attempting to run latest update ({})...", latest_exe.as_ref().expect("guarded by have_update; latest_exe must exist for have_update; qed").display());
|
||||
run_parity().unwrap_or_else(|| { trace_main!("Falling back to local..."); main_direct(true) })
|
||||
} else {
|
||||
|
||||
@@ -215,6 +215,7 @@ pub fn setup_rpc(stats: Arc<RpcStats>, deps: Arc<Dependencies>, apis: ApiSet) ->
|
||||
&deps.miner,
|
||||
&deps.external_miner,
|
||||
EthClientOptions {
|
||||
pending_nonce_from_queue: deps.geth_compatibility,
|
||||
allow_pending_receipt_query: !deps.geth_compatibility,
|
||||
send_block_number_in_get_work: !deps.geth_compatibility,
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ use util::{Colour, version, RotatingLogger, Mutex, Condvar};
|
||||
use io::{MayPanic, ForwardPanic, PanicHandler};
|
||||
use ethcore_logger::{Config as LogConfig};
|
||||
use ethcore::miner::{StratumOptions, Stratum};
|
||||
use ethcore::client::{Mode, DatabaseCompactionProfile, VMType, BlockChainClient};
|
||||
use ethcore::client::{Client, Mode, DatabaseCompactionProfile, VMType, BlockChainClient};
|
||||
use ethcore::service::ClientService;
|
||||
use ethcore::account_provider::{AccountProvider, AccountProviderSettings};
|
||||
use ethcore::miner::{Miner, MinerService, ExternalMiner, MinerOptions};
|
||||
@@ -152,12 +152,12 @@ impl ::local_store::NodeInfo for FullNodeInfo {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> Result<bool, String> {
|
||||
pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> Result<(bool, Option<String>), String> {
|
||||
if cmd.ui && cmd.dapps_conf.enabled {
|
||||
// Check if Parity is already running
|
||||
let addr = format!("{}:{}", cmd.dapps_conf.interface, cmd.dapps_conf.port);
|
||||
if !TcpListener::bind(&addr as &str).is_ok() {
|
||||
return open_ui(&cmd.dapps_conf, &cmd.signer_conf).map(|_| false);
|
||||
return open_ui(&cmd.dapps_conf, &cmd.signer_conf).map(|_| (false, None));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,6 +286,7 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
|
||||
// create client config
|
||||
let mut client_config = to_client_config(
|
||||
&cmd.cache_config,
|
||||
spec.name.to_lowercase(),
|
||||
mode.clone(),
|
||||
tracing,
|
||||
fat_db,
|
||||
@@ -490,8 +491,10 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
|
||||
user_defaults.save(&user_defaults_path)?;
|
||||
|
||||
// tell client how to save the default mode if it gets changed.
|
||||
client.on_mode_change(move |mode: &Mode| {
|
||||
user_defaults.mode = mode.clone();
|
||||
client.on_user_defaults_change(move |mode: Option<Mode>| {
|
||||
if let Some(mode) = mode {
|
||||
user_defaults.mode = mode;
|
||||
}
|
||||
let _ = user_defaults.save(&user_defaults_path); // discard failures - there's nothing we can do
|
||||
});
|
||||
|
||||
@@ -500,6 +503,7 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
|
||||
true => None,
|
||||
false => {
|
||||
let sync = sync_provider.clone();
|
||||
let client = client.clone();
|
||||
let watcher = Arc::new(snapshot::Watcher::new(
|
||||
service.client(),
|
||||
move || is_major_importing(Some(sync.status().state), client.queue_info()),
|
||||
@@ -523,7 +527,7 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
|
||||
}
|
||||
|
||||
// Handle exit
|
||||
let restart = wait_for_exit(panic_handler, Some(updater), can_restart);
|
||||
let restart = wait_for_exit(panic_handler, Some(updater), Some(client), can_restart);
|
||||
|
||||
// drop this stuff as soon as exit detected.
|
||||
drop((http_server, ipc_server, dapps_server, signer_server, secretstore_key_server, ipfs_server, event_loop));
|
||||
@@ -601,9 +605,10 @@ fn build_create_account_hint(spec: &SpecType, keys: &str) -> String {
|
||||
fn wait_for_exit(
|
||||
panic_handler: Arc<PanicHandler>,
|
||||
updater: Option<Arc<Updater>>,
|
||||
client: Option<Arc<Client>>,
|
||||
can_restart: bool
|
||||
) -> bool {
|
||||
let exit = Arc::new((Mutex::new(false), Condvar::new()));
|
||||
) -> (bool, Option<String>) {
|
||||
let exit = Arc::new((Mutex::new((false, None)), Condvar::new()));
|
||||
|
||||
// Handle possible exits
|
||||
let e = exit.clone();
|
||||
@@ -613,18 +618,24 @@ fn wait_for_exit(
|
||||
let e = exit.clone();
|
||||
panic_handler.on_panic(move |_reason| { e.1.notify_all(); });
|
||||
|
||||
if let Some(updater) = updater {
|
||||
// Handle updater wanting to restart us
|
||||
if can_restart {
|
||||
if can_restart {
|
||||
if let Some(updater) = updater {
|
||||
// Handle updater wanting to restart us
|
||||
let e = exit.clone();
|
||||
updater.set_exit_handler(move || { *e.0.lock() = true; e.1.notify_all(); });
|
||||
} else {
|
||||
updater.set_exit_handler(|| info!("Update installed; ready for restart."));
|
||||
updater.set_exit_handler(move || { *e.0.lock() = (true, None); e.1.notify_all(); });
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
// Wait for signal
|
||||
let mut l = exit.0.lock();
|
||||
let _ = exit.1.wait(&mut l);
|
||||
*l
|
||||
l.clone()
|
||||
}
|
||||
|
||||
@@ -173,6 +173,7 @@ impl SnapshotCommand {
|
||||
// prepare client config
|
||||
let client_config = to_client_config(
|
||||
&self.cache_config,
|
||||
spec.name.to_lowercase(),
|
||||
Mode::Active,
|
||||
tracing,
|
||||
fat_db,
|
||||
|
||||
Reference in New Issue
Block a user