Remove updater
This commit is contained in:
@@ -234,18 +234,6 @@ usage! {
|
||||
{
|
||||
// Global flags and arguments
|
||||
["Operating Options"]
|
||||
FLAG flag_no_download: (bool) = false, or |c: &Config| c.parity.as_ref()?.no_download.clone(),
|
||||
"--no-download",
|
||||
"Normally new releases will be downloaded ready for updating. This disables it. Not recommended.",
|
||||
|
||||
FLAG flag_no_consensus: (bool) = false, or |c: &Config| c.parity.as_ref()?.no_consensus.clone(),
|
||||
"--no-consensus",
|
||||
"Force the binary to run even if there are known issues regarding consensus. Not recommended.",
|
||||
|
||||
FLAG flag_force_direct: (bool) = false, or |_| None,
|
||||
"--force-direct",
|
||||
"Run the originally installed version of Parity, ignoring any updates that have since been installed.",
|
||||
|
||||
ARG arg_mode: (String) = "last", or |c: &Config| c.parity.as_ref()?.mode.clone(),
|
||||
"--mode=[MODE]",
|
||||
"Set the operating mode. MODE can be one of: last - Uses the last-used mode, active if none; active - Parity continuously syncs the chain; passive - Parity syncs initially, then sleeps and wakes regularly to resync; dark - Parity syncs only when the JSON-RPC is active; offline - Parity doesn't sync.",
|
||||
@@ -258,22 +246,6 @@ usage! {
|
||||
"--mode-alarm=[SECS]",
|
||||
"Specify the number of seconds before auto sleep reawake timeout occurs when mode is passive",
|
||||
|
||||
ARG arg_auto_update: (String) = "critical", or |c: &Config| c.parity.as_ref()?.auto_update.clone(),
|
||||
"--auto-update=[SET]",
|
||||
"Set a releases set to automatically update and install. SET can be one of: all - All updates in the our release track; critical - Only consensus/security updates; none - No updates will be auto-installed.",
|
||||
|
||||
ARG arg_auto_update_delay: (u16) = 100u16, or |c: &Config| c.parity.as_ref()?.auto_update_delay.clone(),
|
||||
"--auto-update-delay=[NUM]",
|
||||
"Specify the maximum number of blocks used for randomly delaying updates.",
|
||||
|
||||
ARG arg_auto_update_check_frequency: (u16) = 20u16, or |c: &Config| c.parity.as_ref()?.auto_update_check_frequency.clone(),
|
||||
"--auto-update-check-frequency=[NUM]",
|
||||
"Specify the number of blocks between each auto-update check.",
|
||||
|
||||
ARG arg_release_track: (String) = "current", or |c: &Config| c.parity.as_ref()?.release_track.clone(),
|
||||
"--release-track=[TRACK]",
|
||||
"Set which release track we should use for updates. TRACK can be one of: stable - Stable releases; beta - Beta releases; nightly - Nightly releases (unstable); testing - Testing releases (do not use); current - Whatever track this executable was released on.",
|
||||
|
||||
ARG arg_chain: (String) = "foundation", or |c: &Config| c.parity.as_ref()?.chain.clone(),
|
||||
"--chain=[CHAIN]",
|
||||
"Specify the blockchain type. CHAIN may be either a JSON chain specification file or ethereum, classic, poacore, xdai, volta, ewc, musicoin, ellaism, mix, callisto, morden, mordor, ropsten, kovan, rinkeby, goerli, kotti, poasokol, testnet, or dev.",
|
||||
@@ -896,12 +868,6 @@ struct Operating {
|
||||
mode: Option<String>,
|
||||
mode_timeout: Option<u64>,
|
||||
mode_alarm: Option<u64>,
|
||||
auto_update: Option<String>,
|
||||
auto_update_delay: Option<u16>,
|
||||
auto_update_check_frequency: Option<u16>,
|
||||
release_track: Option<String>,
|
||||
no_download: Option<bool>,
|
||||
no_consensus: Option<bool>,
|
||||
chain: Option<String>,
|
||||
base_path: Option<String>,
|
||||
db_path: Option<String>,
|
||||
@@ -1344,19 +1310,12 @@ mod tests {
|
||||
arg_mode: "last".into(),
|
||||
arg_mode_timeout: 300u64,
|
||||
arg_mode_alarm: 3600u64,
|
||||
arg_auto_update: "none".into(),
|
||||
arg_auto_update_delay: 200u16,
|
||||
arg_auto_update_check_frequency: 50u16,
|
||||
arg_release_track: "current".into(),
|
||||
flag_no_download: false,
|
||||
flag_no_consensus: false,
|
||||
arg_chain: "xyz".into(),
|
||||
arg_base_path: Some("$HOME/.parity".into()),
|
||||
arg_db_path: Some("$HOME/.parity/chains".into()),
|
||||
arg_keys_path: "$HOME/.parity/keys".into(),
|
||||
arg_identity: "".into(),
|
||||
flag_no_persistent_txqueue: false,
|
||||
flag_force_direct: false,
|
||||
|
||||
// -- Convenience Options
|
||||
arg_config: "$BASE/config.toml".into(),
|
||||
@@ -1574,12 +1533,6 @@ mod tests {
|
||||
mode: Some("dark".into()),
|
||||
mode_timeout: Some(15u64),
|
||||
mode_alarm: Some(10u64),
|
||||
auto_update: None,
|
||||
auto_update_delay: None,
|
||||
auto_update_check_frequency: None,
|
||||
release_track: None,
|
||||
no_download: None,
|
||||
no_consensus: None,
|
||||
chain: Some("./chain.json".into()),
|
||||
base_path: None,
|
||||
db_path: None,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
[parity]
|
||||
no_consensus = true
|
||||
chain = "dev"
|
||||
|
||||
[mining]
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
[parity]
|
||||
no_consensus = true
|
||||
|
||||
[rpc]
|
||||
interface = "all"
|
||||
apis = ["all"]
|
||||
|
||||
@@ -2,12 +2,6 @@
|
||||
mode = "last"
|
||||
mode_timeout = 300
|
||||
mode_alarm = 3600
|
||||
auto_update = "none"
|
||||
auto_update_delay = 200
|
||||
auto_update_check_frequency = 50
|
||||
release_track = "current"
|
||||
no_download = false
|
||||
no_consensus = false
|
||||
no_persistent_txqueue = false
|
||||
|
||||
chain = "homestead"
|
||||
|
||||
@@ -47,7 +47,7 @@ use blockchain::{
|
||||
};
|
||||
use cache::CacheConfig;
|
||||
use dir::{
|
||||
self, default_data_path, default_hypervisor_path, default_local_path,
|
||||
self, default_data_path, default_local_path,
|
||||
helpers::{replace_home, replace_home_and_local},
|
||||
Directories,
|
||||
};
|
||||
@@ -70,7 +70,6 @@ use secretstore::{
|
||||
};
|
||||
use snapshot::{self, SnapshotCommand};
|
||||
use types::data_format::DataFormat;
|
||||
use updater::{ReleaseTrack, UpdateFilter, UpdatePolicy};
|
||||
|
||||
const DEFAULT_MAX_PEERS: u16 = 50;
|
||||
const DEFAULT_MIN_PEERS: u16 = 25;
|
||||
@@ -146,7 +145,6 @@ impl Configuration {
|
||||
self.args.arg_mode_alarm,
|
||||
)?),
|
||||
};
|
||||
let update_policy = self.update_policy()?;
|
||||
let logger_config = self.logger_config();
|
||||
let ws_conf = self.ws_config()?;
|
||||
let snapshot_conf = self.snapshot_config()?;
|
||||
@@ -411,7 +409,6 @@ impl Configuration {
|
||||
gas_pricer_conf: self.gas_pricer_config()?,
|
||||
miner_extras: self.miner_extras()?,
|
||||
stratum: self.stratum_options()?,
|
||||
update_policy: update_policy,
|
||||
allow_missing_blocks: self.args.flag_jsonrpc_allow_missing_blocks,
|
||||
mode: mode,
|
||||
tracing: tracing,
|
||||
@@ -1036,41 +1033,6 @@ impl Configuration {
|
||||
})
|
||||
}
|
||||
|
||||
fn update_policy(&self) -> Result<UpdatePolicy, String> {
|
||||
Ok(UpdatePolicy {
|
||||
enable_downloading: !self.args.flag_no_download,
|
||||
require_consensus: !self.args.flag_no_consensus,
|
||||
filter: match self.args.arg_auto_update.as_ref() {
|
||||
"none" => UpdateFilter::None,
|
||||
"critical" => UpdateFilter::Critical,
|
||||
"all" => UpdateFilter::All,
|
||||
_ => {
|
||||
return Err(
|
||||
"Invalid value for `--auto-update`. See `--help` for more information."
|
||||
.into(),
|
||||
)
|
||||
}
|
||||
},
|
||||
track: match self.args.arg_release_track.as_ref() {
|
||||
"stable" => ReleaseTrack::Stable,
|
||||
"beta" => ReleaseTrack::Beta,
|
||||
"nightly" => ReleaseTrack::Nightly,
|
||||
"testing" => ReleaseTrack::Testing,
|
||||
"current" => ReleaseTrack::Unknown,
|
||||
_ => {
|
||||
return Err(
|
||||
"Invalid value for `--releases-track`. See `--help` for more information."
|
||||
.into(),
|
||||
)
|
||||
}
|
||||
},
|
||||
path: default_hypervisor_path(),
|
||||
max_size: 128 * 1024 * 1024,
|
||||
max_delay: self.args.arg_auto_update_delay as u64,
|
||||
frequency: self.args.arg_auto_update_check_frequency as u64,
|
||||
})
|
||||
}
|
||||
|
||||
fn directories(&self) -> Directories {
|
||||
let local_path = default_local_path();
|
||||
let base_path = self
|
||||
@@ -1318,7 +1280,7 @@ mod tests {
|
||||
use account::{AccountCmd, ImportAccounts, ListAccounts, NewAccount};
|
||||
use blockchain::{BlockchainCmd, ExportBlockchain, ExportState, ImportBlockchain};
|
||||
use cli::Args;
|
||||
use dir::{default_hypervisor_path, Directories};
|
||||
use dir::Directories;
|
||||
use ethcore::{client::VMType, miner::MinerOptions};
|
||||
use helpers::default_network_config;
|
||||
use miner::pool::PrioritizationStrategy;
|
||||
@@ -1330,7 +1292,6 @@ mod tests {
|
||||
use run::RunCmd;
|
||||
use tempdir::TempDir;
|
||||
use types::{data_format::DataFormat, ids::BlockId};
|
||||
use updater::{ReleaseTrack, UpdateFilter, UpdatePolicy};
|
||||
|
||||
use network::{AllowIP, IpFilter};
|
||||
|
||||
@@ -1611,16 +1572,6 @@ mod tests {
|
||||
acc_conf: Default::default(),
|
||||
gas_pricer_conf: Default::default(),
|
||||
miner_extras: Default::default(),
|
||||
update_policy: UpdatePolicy {
|
||||
enable_downloading: true,
|
||||
require_consensus: true,
|
||||
filter: UpdateFilter::Critical,
|
||||
track: ReleaseTrack::Unknown,
|
||||
path: default_hypervisor_path(),
|
||||
max_size: 128 * 1024 * 1024,
|
||||
max_delay: 100,
|
||||
frequency: 20,
|
||||
},
|
||||
mode: Default::default(),
|
||||
tracing: Default::default(),
|
||||
compaction: Default::default(),
|
||||
@@ -1677,71 +1628,6 @@ mod tests {
|
||||
assert!(conf.miner_options().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_parse_updater_options() {
|
||||
// when
|
||||
let conf0 = parse(&["parity", "--release-track=testing"]);
|
||||
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",
|
||||
]);
|
||||
let conf3 = parse(&["parity", "--auto-update=xxx"]);
|
||||
|
||||
// then
|
||||
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,
|
||||
max_delay: 100,
|
||||
frequency: 20,
|
||||
}
|
||||
);
|
||||
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,
|
||||
max_delay: 300,
|
||||
frequency: 20,
|
||||
}
|
||||
);
|
||||
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,
|
||||
max_delay: 300,
|
||||
frequency: 100,
|
||||
}
|
||||
);
|
||||
assert!(conf3.update_policy().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_parse_network_settings() {
|
||||
// given
|
||||
@@ -1922,7 +1808,6 @@ mod tests {
|
||||
let conf = Configuration::parse_cli(&args).unwrap();
|
||||
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()),
|
||||
@@ -1945,7 +1830,6 @@ mod tests {
|
||||
assert_eq!(c.net_settings.chain, "dev");
|
||||
assert_eq!(c.gas_pricer_conf, GasPricerConfig::Fixed(0.into()));
|
||||
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()),
|
||||
|
||||
@@ -55,18 +55,17 @@ extern crate ethcore_sync as sync;
|
||||
extern crate ethereum_types;
|
||||
extern crate ethkey;
|
||||
extern crate ethstore;
|
||||
extern crate fetch;
|
||||
extern crate journaldb;
|
||||
extern crate keccak_hash as hash;
|
||||
extern crate kvdb;
|
||||
extern crate node_filter;
|
||||
extern crate parity_bytes as bytes;
|
||||
extern crate parity_hash_fetch as hash_fetch;
|
||||
extern crate parity_ipfs_api;
|
||||
extern crate parity_local_store as local_store;
|
||||
extern crate parity_path as path;
|
||||
extern crate parity_rpc;
|
||||
extern crate parity_runtime;
|
||||
extern crate parity_updater as updater;
|
||||
extern crate parity_version;
|
||||
extern crate registrar;
|
||||
|
||||
@@ -182,22 +181,13 @@ pub enum ExecutionAction {
|
||||
Running(RunningClient),
|
||||
}
|
||||
|
||||
fn execute<Cr, Rr>(
|
||||
command: Execute,
|
||||
logger: Arc<RotatingLogger>,
|
||||
on_client_rq: Cr,
|
||||
on_updater_rq: Rr,
|
||||
) -> Result<ExecutionAction, String>
|
||||
where
|
||||
Cr: Fn(String) + 'static + Send,
|
||||
Rr: Fn() + 'static + Send,
|
||||
{
|
||||
fn execute(command: Execute, logger: Arc<RotatingLogger>) -> Result<ExecutionAction, String> {
|
||||
#[cfg(feature = "deadlock_detection")]
|
||||
run_deadlock_detection_thread();
|
||||
|
||||
match command.cmd {
|
||||
Cmd::Run(run_cmd) => {
|
||||
let outcome = run::execute(run_cmd, logger, on_client_rq, on_updater_rq)?;
|
||||
let outcome = run::execute(run_cmd, logger)?;
|
||||
Ok(ExecutionAction::Running(outcome))
|
||||
}
|
||||
Cmd::Version => Ok(ExecutionAction::Instant(Some(Args::print_version()))),
|
||||
@@ -237,25 +227,11 @@ where
|
||||
|
||||
/// Starts the parity client.
|
||||
///
|
||||
/// `on_client_rq` is the action to perform when the client receives an RPC request to be restarted
|
||||
/// with a different chain.
|
||||
///
|
||||
/// `on_updater_rq` is the action to perform when the updater has a new binary to execute.
|
||||
///
|
||||
/// The first parameter is the command line arguments that you would pass when running the parity
|
||||
/// binary.
|
||||
///
|
||||
/// On error, returns what to print on stderr.
|
||||
// FIXME: totally independent logging capability, see https://github.com/paritytech/parity-ethereum/issues/10252
|
||||
pub fn start<Cr, Rr>(
|
||||
conf: Configuration,
|
||||
logger: Arc<RotatingLogger>,
|
||||
on_client_rq: Cr,
|
||||
on_updater_rq: Rr,
|
||||
) -> Result<ExecutionAction, String>
|
||||
where
|
||||
Cr: Fn(String) + 'static + Send,
|
||||
Rr: Fn() + 'static + Send,
|
||||
{
|
||||
execute(conf.into_command()?, logger, on_client_rq, on_updater_rq)
|
||||
pub fn start(conf: Configuration, logger: Arc<RotatingLogger>) -> Result<ExecutionAction, String> {
|
||||
execute(conf.into_command()?, logger)
|
||||
}
|
||||
|
||||
352
parity/main.rs
352
parity/main.rs
@@ -34,11 +34,7 @@ extern crate ethcore_logger;
|
||||
extern crate winapi;
|
||||
|
||||
use std::{
|
||||
env,
|
||||
ffi::OsString,
|
||||
fs::{create_dir_all, metadata, remove_file, File},
|
||||
io::{Read, Write},
|
||||
path::PathBuf,
|
||||
io::Write,
|
||||
process,
|
||||
sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
@@ -48,148 +44,12 @@ use std::{
|
||||
|
||||
use ansi_term::Colour;
|
||||
use ctrlc::CtrlC;
|
||||
use dir::default_hypervisor_path;
|
||||
use ethcore_logger::setup_log;
|
||||
use fdlimit::raise_fd_limit;
|
||||
use parity_daemonize::AsHandle;
|
||||
use parity_ethereum::{start, ExecutionAction};
|
||||
use parking_lot::{Condvar, Mutex};
|
||||
|
||||
const PLEASE_RESTART_EXIT_CODE: i32 = 69;
|
||||
const PARITY_EXECUTABLE_NAME: &str = "parity";
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Error {
|
||||
BinaryNotFound,
|
||||
ExitCode(i32),
|
||||
Restart,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
fn update_path(name: &str) -> PathBuf {
|
||||
let mut dest = default_hypervisor_path();
|
||||
dest.push(name);
|
||||
dest
|
||||
}
|
||||
|
||||
fn latest_exe_path() -> Result<PathBuf, Error> {
|
||||
File::open(update_path("latest"))
|
||||
.and_then(|mut f| {
|
||||
let mut exe_path = String::new();
|
||||
trace!(target: "updater", "latest binary path: {:?}", f);
|
||||
f.read_to_string(&mut exe_path)
|
||||
.map(|_| update_path(&exe_path))
|
||||
})
|
||||
.or(Err(Error::BinaryNotFound))
|
||||
}
|
||||
|
||||
fn latest_binary_is_newer(
|
||||
current_binary: &Option<PathBuf>,
|
||||
latest_binary: &Option<PathBuf>,
|
||||
) -> bool {
|
||||
match (
|
||||
current_binary
|
||||
.as_ref()
|
||||
.and_then(|p| metadata(p.as_path()).ok())
|
||||
.and_then(|m| m.modified().ok()),
|
||||
latest_binary
|
||||
.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,
|
||||
}
|
||||
}
|
||||
|
||||
fn set_spec_name_override(spec_name: &str) {
|
||||
if let Err(e) = create_dir_all(default_hypervisor_path()).and_then(|_| {
|
||||
File::create(update_path("spec_name_override"))
|
||||
.and_then(|mut f| f.write_all(spec_name.as_bytes()))
|
||||
}) {
|
||||
warn!(
|
||||
"Couldn't override chain spec: {} at {:?}",
|
||||
e,
|
||||
update_path("spec_name_override")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn take_spec_name_override() -> Option<String> {
|
||||
let p = update_path("spec_name_override");
|
||||
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() {
|
||||
// We need to cleanup all sockets before spawning another Parity process. This makes sure everything is cleaned up.
|
||||
// The loop is required because of internal reference counter for winsock dll. We don't know how many crates we use do
|
||||
// initialize it. There's at least 2 now.
|
||||
for _ in 0..10 {
|
||||
unsafe {
|
||||
::winapi::um::winsock2::WSACleanup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn global_init() {}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn global_init() {
|
||||
// When restarting in the same process this reinits windows sockets.
|
||||
unsafe {
|
||||
const WS_VERSION: u16 = 0x202;
|
||||
let mut wsdata: ::winapi::um::winsock2::WSADATA = ::std::mem::zeroed();
|
||||
::winapi::um::winsock2::WSAStartup(WS_VERSION, &mut wsdata);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn global_cleanup() {}
|
||||
|
||||
// Starts parity binary installed via `parity-updater` and returns the code it exits with.
|
||||
fn run_parity() -> Result<(), Error> {
|
||||
global_init();
|
||||
|
||||
let prefix = vec![
|
||||
OsString::from("--can-restart"),
|
||||
OsString::from("--force-direct"),
|
||||
];
|
||||
|
||||
let res: Result<(), Error> = latest_exe_path().and_then(|exe| {
|
||||
process::Command::new(exe)
|
||||
.args(
|
||||
&(env::args_os()
|
||||
.skip(1)
|
||||
.chain(prefix.into_iter())
|
||||
.collect::<Vec<_>>()),
|
||||
)
|
||||
.status()
|
||||
.ok()
|
||||
.map_or(Err(Error::Unknown), |es| {
|
||||
match es.code() {
|
||||
// Process success
|
||||
Some(0) => Ok(()),
|
||||
// Please restart
|
||||
Some(PLEASE_RESTART_EXIT_CODE) => Err(Error::Restart),
|
||||
// Process error code `c`
|
||||
Some(c) => Err(Error::ExitCode(c)),
|
||||
// Unknown error, couldn't determine error code
|
||||
_ => Err(Error::Unknown),
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
global_cleanup();
|
||||
res
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
/// Status used to exit or restart the program.
|
||||
struct ExitStatus {
|
||||
@@ -197,18 +57,10 @@ struct ExitStatus {
|
||||
panicking: bool,
|
||||
/// Whether the program should exit.
|
||||
should_exit: bool,
|
||||
/// Whether the program should restart.
|
||||
should_restart: bool,
|
||||
/// If a restart happens, whether a new chain spec should be used.
|
||||
spec_name_override: Option<String>,
|
||||
}
|
||||
|
||||
// Run `locally installed version` of parity (i.e, not installed via `parity-updater`)
|
||||
// Returns the exit error code.
|
||||
fn main_direct(force_can_restart: bool) -> i32 {
|
||||
global_init();
|
||||
|
||||
let mut conf = {
|
||||
fn main() -> Result<(), i32> {
|
||||
let conf = {
|
||||
let args = std::env::args().collect::<Vec<_>>();
|
||||
parity_ethereum::Configuration::parse_cli(&args).unwrap_or_else(|e| e.exit())
|
||||
};
|
||||
@@ -218,10 +70,6 @@ fn main_direct(force_can_restart: bool) -> i32 {
|
||||
process::exit(2)
|
||||
});
|
||||
|
||||
if let Some(spec_override) = take_spec_name_override() {
|
||||
conf.args.arg_chain = spec_override;
|
||||
}
|
||||
|
||||
// FIXME: `pid_file` shouldn't need to cloned here
|
||||
// see: `https://github.com/paritytech/parity-daemonize/pull/13` for more info
|
||||
let handle = if let Some(pid) = conf.args.arg_daemon_pid_file.clone() {
|
||||
@@ -235,15 +83,13 @@ fn main_direct(force_can_restart: bool) -> i32 {
|
||||
Ok(h) => Some(h),
|
||||
Err(e) => {
|
||||
error!("{}", Colour::Red.paint(format!("{}", e)));
|
||||
return 1;
|
||||
return Err(1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let can_restart = force_can_restart || conf.args.flag_can_restart;
|
||||
|
||||
// increase max number of open files
|
||||
raise_fd_limit();
|
||||
|
||||
@@ -251,8 +97,6 @@ fn main_direct(force_can_restart: bool) -> i32 {
|
||||
Mutex::new(ExitStatus {
|
||||
panicking: false,
|
||||
should_exit: false,
|
||||
should_restart: false,
|
||||
spec_name_override: None,
|
||||
}),
|
||||
Condvar::new(),
|
||||
));
|
||||
@@ -261,53 +105,16 @@ fn main_direct(force_can_restart: bool) -> i32 {
|
||||
// again.
|
||||
let exiting = Arc::new(AtomicBool::new(false));
|
||||
|
||||
let exec = if can_restart {
|
||||
start(
|
||||
conf,
|
||||
logger,
|
||||
{
|
||||
let e = exit.clone();
|
||||
let exiting = exiting.clone();
|
||||
move |new_chain: String| {
|
||||
if !exiting.swap(true, Ordering::SeqCst) {
|
||||
*e.0.lock() = ExitStatus {
|
||||
panicking: false,
|
||||
should_exit: true,
|
||||
should_restart: true,
|
||||
spec_name_override: Some(new_chain),
|
||||
};
|
||||
e.1.notify_all();
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
let e = exit.clone();
|
||||
let exiting = exiting.clone();
|
||||
move || {
|
||||
if !exiting.swap(true, Ordering::SeqCst) {
|
||||
*e.0.lock() = ExitStatus {
|
||||
panicking: false,
|
||||
should_exit: true,
|
||||
should_restart: true,
|
||||
spec_name_override: None,
|
||||
};
|
||||
e.1.notify_all();
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
} else {
|
||||
trace!(target: "mode", "Not hypervised: not setting exit handlers.");
|
||||
start(conf, logger, move |_| {}, move || {})
|
||||
};
|
||||
trace!(target: "mode", "Not hypervised: not setting exit handlers.");
|
||||
let exec = start(conf, logger);
|
||||
|
||||
let res = match exec {
|
||||
match exec {
|
||||
Ok(result) => match result {
|
||||
ExecutionAction::Instant(Some(s)) => {
|
||||
println!("{}", s);
|
||||
0
|
||||
ExecutionAction::Instant(output) => {
|
||||
if let Some(s) = output {
|
||||
println!("{}", s);
|
||||
}
|
||||
}
|
||||
ExecutionAction::Instant(None) => 0,
|
||||
ExecutionAction::Running(client) => {
|
||||
panic_hook::set_with({
|
||||
let e = exit.clone();
|
||||
@@ -319,8 +126,6 @@ fn main_direct(force_can_restart: bool) -> i32 {
|
||||
*e.0.lock() = ExitStatus {
|
||||
panicking: true,
|
||||
should_exit: true,
|
||||
should_restart: false,
|
||||
spec_name_override: None,
|
||||
};
|
||||
e.1.notify_all();
|
||||
}
|
||||
@@ -335,8 +140,6 @@ fn main_direct(force_can_restart: bool) -> i32 {
|
||||
*e.0.lock() = ExitStatus {
|
||||
panicking: false,
|
||||
should_exit: true,
|
||||
should_restart: false,
|
||||
spec_name_override: None,
|
||||
};
|
||||
e.1.notify_all();
|
||||
}
|
||||
@@ -357,17 +160,8 @@ fn main_direct(force_can_restart: bool) -> i32 {
|
||||
|
||||
client.shutdown();
|
||||
|
||||
if lock.should_restart {
|
||||
if let Some(ref spec_name) = lock.spec_name_override {
|
||||
set_spec_name_override(&spec_name.clone());
|
||||
}
|
||||
PLEASE_RESTART_EXIT_CODE
|
||||
} else {
|
||||
if lock.panicking {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
if lock.panicking {
|
||||
return Err(1);
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -378,125 +172,9 @@ fn main_direct(force_can_restart: bool) -> i32 {
|
||||
handle.detach_with_msg(format!("{}", Colour::Red.paint(&err)))
|
||||
}
|
||||
eprintln!("{}", err);
|
||||
1
|
||||
return Err(1);
|
||||
}
|
||||
};
|
||||
|
||||
global_cleanup();
|
||||
res
|
||||
}
|
||||
|
||||
fn println_trace_main(s: String) {
|
||||
if env::var("RUST_LOG")
|
||||
.ok()
|
||||
.and_then(|s| s.find("main=trace"))
|
||||
.is_some()
|
||||
{
|
||||
println!("{}", s);
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! trace_main {
|
||||
($arg:expr) => (println_trace_main($arg.into()));
|
||||
($($arg:tt)*) => (println_trace_main(format!("{}", format_args!($($arg)*))));
|
||||
}
|
||||
|
||||
fn main() {
|
||||
panic_hook::set_abort();
|
||||
|
||||
// the user has specified to run its originally installed binary (not via `parity-updater`)
|
||||
let force_direct = std::env::args().any(|arg| arg == "--force-direct");
|
||||
|
||||
// absolute path to the current `binary`
|
||||
let exe_path = std::env::current_exe().ok();
|
||||
|
||||
// the binary is named `target/xx/yy`
|
||||
let development = exe_path
|
||||
.as_ref()
|
||||
.and_then(|p| {
|
||||
p.parent()
|
||||
.and_then(|p| p.parent())
|
||||
.and_then(|p| p.file_name())
|
||||
.map(|n| n == "target")
|
||||
})
|
||||
.unwrap_or(false);
|
||||
|
||||
// the binary is named `parity`
|
||||
let same_name = exe_path.as_ref().map_or(false, |p| {
|
||||
p.file_stem().map_or(false, |n| n == PARITY_EXECUTABLE_NAME)
|
||||
});
|
||||
|
||||
trace_main!(
|
||||
"Starting up {} (force-direct: {}, development: {}, same-name: {})",
|
||||
std::env::current_exe()
|
||||
.ok()
|
||||
.map_or_else(|| "<unknown>".into(), |x| format!("{}", x.display())),
|
||||
force_direct,
|
||||
development,
|
||||
same_name
|
||||
);
|
||||
|
||||
if !force_direct && !development && same_name {
|
||||
// Try to run the latest installed version of `parity`,
|
||||
// Upon failure it falls back to the locally installed version of `parity`
|
||||
// Everything run inside a loop, so we'll be able to restart from the child into a new version seamlessly.
|
||||
loop {
|
||||
// `Path` to the latest downloaded binary
|
||||
let latest_exe = latest_exe_path().ok();
|
||||
|
||||
// `Latest´ binary exist
|
||||
let have_update = latest_exe.as_ref().map_or(false, |p| p.exists());
|
||||
|
||||
// Canonicalized path to the current binary is not the same as to latest binary
|
||||
let canonicalized_path_not_same = exe_path.as_ref().map_or(false, |exe| {
|
||||
latest_exe.as_ref().map_or(false, |lexe| {
|
||||
exe.canonicalize().ok() != lexe.canonicalize().ok()
|
||||
})
|
||||
});
|
||||
|
||||
// Downloaded `binary` is newer
|
||||
let update_is_newer = latest_binary_is_newer(&latest_exe, &exe_path);
|
||||
trace_main!(
|
||||
"Starting... (have-update: {}, non-updated-current: {}, update-is-newer: {})",
|
||||
have_update,
|
||||
canonicalized_path_not_same,
|
||||
update_is_newer
|
||||
);
|
||||
|
||||
let exit_code = if have_update && canonicalized_path_not_same && 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()
|
||||
);
|
||||
match run_parity() {
|
||||
Ok(_) => 0,
|
||||
// Restart parity
|
||||
Err(Error::Restart) => PLEASE_RESTART_EXIT_CODE,
|
||||
// Fall back to local version
|
||||
Err(e) => {
|
||||
error!(target: "updater", "Updated binary could not be executed error: {:?}. Falling back to local version", e);
|
||||
main_direct(true)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
trace_main!("No latest update. Attempting to direct...");
|
||||
main_direct(true)
|
||||
};
|
||||
trace_main!("Latest binary exited with exit code: {}", exit_code);
|
||||
if exit_code != PLEASE_RESTART_EXIT_CODE {
|
||||
trace_main!("Quitting...");
|
||||
process::exit(exit_code);
|
||||
}
|
||||
trace!(target: "updater", "Re-running updater loop");
|
||||
}
|
||||
} else {
|
||||
trace_main!("Running direct");
|
||||
// Otherwise, we're presumably running the version we want. Just run and fall-through.
|
||||
process::exit(main_direct(false));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ use ethcore::{
|
||||
spec::{Spec, SpecParams},
|
||||
};
|
||||
use ethereum_types::{Address, U256};
|
||||
use hash_fetch::fetch::Client as FetchClient;
|
||||
use fetch::Client as FetchClient;
|
||||
use journaldb::Algorithm;
|
||||
use miner::{
|
||||
gas_price_calibrator::{GasPriceCalibrator, GasPriceCalibratorOptions},
|
||||
|
||||
@@ -22,7 +22,7 @@ use account_utils::{self, AccountProvider};
|
||||
use ethcore::{client::Client, miner::Miner, snapshot::SnapshotService};
|
||||
use ethcore_logger::RotatingLogger;
|
||||
use ethcore_service::PrivateTxService;
|
||||
use hash_fetch::fetch::Client as FetchClient;
|
||||
use fetch::Client as FetchClient;
|
||||
use jsonrpc_core::{self as core, MetaIoHandler};
|
||||
use miner::external::ExternalMiner;
|
||||
use parity_rpc::{
|
||||
@@ -33,7 +33,6 @@ use parity_rpc::{
|
||||
use parity_runtime::Executor;
|
||||
use parking_lot::Mutex;
|
||||
use sync::{ManageNetwork, SyncProvider};
|
||||
use updater::Updater;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Eq, Hash)]
|
||||
pub enum Api {
|
||||
@@ -198,7 +197,6 @@ pub struct FullDependencies {
|
||||
pub logger: Arc<RotatingLogger>,
|
||||
pub settings: Arc<NetworkSettings>,
|
||||
pub net_service: Arc<dyn ManageNetwork>,
|
||||
pub updater: Arc<Updater>,
|
||||
pub experimental_rpcs: bool,
|
||||
pub ws_address: Option<Host>,
|
||||
pub fetch: FetchClient,
|
||||
@@ -326,7 +324,6 @@ impl FullDependencies {
|
||||
self.client.clone(),
|
||||
self.miner.clone(),
|
||||
self.sync.clone(),
|
||||
self.updater.clone(),
|
||||
self.net_service.clone(),
|
||||
self.logger.clone(),
|
||||
self.settings.clone(),
|
||||
@@ -373,7 +370,6 @@ impl FullDependencies {
|
||||
ParitySetClient::new(
|
||||
&self.client,
|
||||
&self.miner,
|
||||
&self.updater,
|
||||
&self.net_service,
|
||||
self.fetch.clone(),
|
||||
)
|
||||
|
||||
@@ -23,15 +23,11 @@ use std::{
|
||||
|
||||
use account_utils;
|
||||
use ansi_term::Colour;
|
||||
use bytes::Bytes;
|
||||
use cache::CacheConfig;
|
||||
use call_contract::CallContract;
|
||||
use db;
|
||||
use dir::{DatabaseDirectories, Directories};
|
||||
use ethcore::{
|
||||
client::{
|
||||
BlockChainClient, BlockId, BlockInfo, Client, DatabaseCompactionProfile, Mode, VMType,
|
||||
},
|
||||
client::{BlockChainClient, BlockInfo, Client, DatabaseCompactionProfile, Mode, VMType},
|
||||
miner::{self, stratum, Miner, MinerOptions, MinerService},
|
||||
snapshot::{self, SnapshotConfiguration},
|
||||
verification::queue::VerifierSettings,
|
||||
@@ -39,9 +35,6 @@ use ethcore::{
|
||||
use ethcore_logger::{Config as LogConfig, RotatingLogger};
|
||||
use ethcore_private_tx::{EncryptorConfig, ProviderConfig, SecretStoreEncryptor};
|
||||
use ethcore_service::ClientService;
|
||||
use ethereum_types::Address;
|
||||
use futures::IntoFuture;
|
||||
use hash_fetch::{self, fetch};
|
||||
use helpers::{execute_upgrades, passwords_from_files, to_client_config};
|
||||
use informant::{FullNodeInformantData, Informant};
|
||||
use ipfs;
|
||||
@@ -60,13 +53,11 @@ use parity_rpc::{
|
||||
};
|
||||
use parity_runtime::Runtime;
|
||||
use parity_version::version;
|
||||
use registrar::{Asynchronous, RegistrarClient};
|
||||
use rpc;
|
||||
use rpc_apis;
|
||||
use secretstore;
|
||||
use signer;
|
||||
use sync::{self, PrivateTxHandler, SyncConfig};
|
||||
use updater::{UpdatePolicy, Updater};
|
||||
use user_defaults::UserDefaults;
|
||||
|
||||
// how often to take periodic snapshots.
|
||||
@@ -102,7 +93,6 @@ pub struct RunCmd {
|
||||
pub acc_conf: AccountsConfig,
|
||||
pub gas_pricer_conf: GasPricerConfig,
|
||||
pub miner_extras: MinerExtras,
|
||||
pub update_policy: UpdatePolicy,
|
||||
pub mode: Option<Mode>,
|
||||
pub tracing: Switch,
|
||||
pub fat_db: Switch,
|
||||
@@ -154,22 +144,8 @@ impl ::local_store::NodeInfo for FullNodeInfo {
|
||||
|
||||
/// Executes the given run command.
|
||||
///
|
||||
/// `on_client_rq` is the action to perform when the client receives an RPC request to be restarted
|
||||
/// with a different chain.
|
||||
///
|
||||
/// `on_updater_rq` is the action to perform when the updater has a new binary to execute.
|
||||
///
|
||||
/// On error, returns what to print on stderr.
|
||||
pub fn execute<Cr, Rr>(
|
||||
cmd: RunCmd,
|
||||
logger: Arc<RotatingLogger>,
|
||||
on_client_rq: Cr,
|
||||
on_updater_rq: Rr,
|
||||
) -> Result<RunningClient, String>
|
||||
where
|
||||
Cr: Fn(String) + 'static + Send,
|
||||
Rr: Fn() + 'static + Send,
|
||||
{
|
||||
pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<RunningClient, String> {
|
||||
// load spec
|
||||
let spec = cmd.spec.spec(&cmd.dirs.cache)?;
|
||||
|
||||
@@ -206,9 +182,6 @@ where
|
||||
_ => true,
|
||||
};
|
||||
|
||||
// get the update policy
|
||||
let update_policy = cmd.update_policy;
|
||||
|
||||
// prepare client and snapshot paths.
|
||||
let client_path = db_dirs.client_path(algorithm);
|
||||
let snapshot_path = db_dirs.snapshot_path();
|
||||
@@ -523,41 +496,6 @@ where
|
||||
chain_notify.start();
|
||||
}
|
||||
|
||||
let contract_client = {
|
||||
struct FullRegistrar {
|
||||
client: Arc<Client>,
|
||||
}
|
||||
impl RegistrarClient for FullRegistrar {
|
||||
type Call = Asynchronous;
|
||||
fn registrar_address(&self) -> Result<Address, String> {
|
||||
self.client
|
||||
.registrar_address()
|
||||
.ok_or_else(|| "Registrar not defined.".into())
|
||||
}
|
||||
fn call_contract(&self, address: Address, data: Bytes) -> Self::Call {
|
||||
Box::new(
|
||||
self.client
|
||||
.call_contract(BlockId::Latest, address, data)
|
||||
.into_future(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Arc::new(FullRegistrar {
|
||||
client: client.clone(),
|
||||
})
|
||||
};
|
||||
|
||||
// the updater service
|
||||
let updater_fetch = fetch.clone();
|
||||
let updater = Updater::new(
|
||||
&Arc::downgrade(&(service.client() as Arc<dyn BlockChainClient>)),
|
||||
&Arc::downgrade(&sync_provider),
|
||||
update_policy,
|
||||
hash_fetch::Client::with_fetch(contract_client.clone(), updater_fetch, runtime.executor()),
|
||||
);
|
||||
service.add_notify(updater.clone());
|
||||
|
||||
// set up dependencies for rpc servers
|
||||
let rpc_stats = Arc::new(informant::RpcStats::default());
|
||||
let secret_store = account_provider.clone();
|
||||
@@ -575,7 +513,6 @@ where
|
||||
logger: logger.clone(),
|
||||
settings: Arc::new(cmd.net_settings.clone()),
|
||||
net_service: manage_network.clone(),
|
||||
updater: updater.clone(),
|
||||
experimental_rpcs: cmd.experimental_rpcs,
|
||||
ws_address: cmd.ws_conf.address(),
|
||||
fetch: fetch.clone(),
|
||||
@@ -672,9 +609,6 @@ where
|
||||
}
|
||||
};
|
||||
|
||||
client.set_exit_handler(on_client_rq);
|
||||
updater.set_exit_handler(on_updater_rq);
|
||||
|
||||
Ok(RunningClient {
|
||||
inner: RunningClientInner::Full {
|
||||
rpc: rpc_direct,
|
||||
@@ -683,7 +617,6 @@ where
|
||||
client_service: Arc::new(service),
|
||||
keep_alive: Box::new((
|
||||
watcher,
|
||||
updater,
|
||||
ws_server,
|
||||
http_server,
|
||||
ipc_server,
|
||||
|
||||
Reference in New Issue
Block a user