Silent running operating modes (#1477)
* Command=line options. * Keep alive for the eth protocol. * Wire up final pieces. * No network when dark. * Passive and dark mode work. * Ensure all RPCs keep alive. * Fix tests. * Fix minor bug. * Minor whitespace. * Split out some of the sleep-state. * Fix help text.
This commit is contained in:
@@ -32,7 +32,19 @@ Usage:
|
||||
parity [options]
|
||||
parity ui [options]
|
||||
|
||||
Protocol Options:
|
||||
Operating Options:
|
||||
--mode MODE Set the operating mode. MODE can be one of:
|
||||
active - Parity continuously syncs the chain.
|
||||
passive - Parity syncs initially, then sleeps and
|
||||
wakes regularly to resync.
|
||||
dark - Parity syncs only when an external interface
|
||||
is active. [default: active].
|
||||
--mode-timeout SECS Specify the number of seconds before inactivity
|
||||
timeout occurs when mode is dark or passive
|
||||
[default: 300].
|
||||
--mode-alarm SECS Specify the number of seconds before auto sleep
|
||||
reawake timeout occurs when mode is passive
|
||||
[default: 3600].
|
||||
--chain CHAIN Specify the blockchain type. CHAIN may be either a
|
||||
JSON chain specification file or olympic, frontier,
|
||||
homestead, mainnet, morden, or testnet
|
||||
@@ -269,6 +281,9 @@ pub struct Args {
|
||||
pub arg_pid_file: String,
|
||||
pub arg_file: Option<String>,
|
||||
pub arg_path: Vec<String>,
|
||||
pub flag_mode: String,
|
||||
pub flag_mode_timeout: u64,
|
||||
pub flag_mode_alarm: u64,
|
||||
pub flag_chain: String,
|
||||
pub flag_db_path: String,
|
||||
pub flag_identity: String,
|
||||
|
||||
@@ -28,7 +28,7 @@ use util::*;
|
||||
use util::log::Colour::*;
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
use util::network_settings::NetworkSettings;
|
||||
use ethcore::client::{append_path, get_db_path, ClientConfig, DatabaseCompactionProfile, Switch, VMType};
|
||||
use ethcore::client::{append_path, get_db_path, Mode, ClientConfig, DatabaseCompactionProfile, Switch, VMType};
|
||||
use ethcore::miner::{MinerOptions, PendingSet};
|
||||
use ethcore::ethereum;
|
||||
use ethcore::spec::Spec;
|
||||
@@ -61,6 +61,15 @@ impl Configuration {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mode(&self) -> Mode {
|
||||
match &(self.args.flag_mode[..]) {
|
||||
"active" => Mode::Active,
|
||||
"passive" => Mode::Passive(Duration::from_secs(self.args.flag_mode_timeout), Duration::from_secs(self.args.flag_mode_alarm)),
|
||||
"dark" => Mode::Dark(Duration::from_secs(self.args.flag_mode_timeout)),
|
||||
_ => die!("{}: Invalid address for --mode. Must be one of active, passive or dark.", self.args.flag_mode),
|
||||
}
|
||||
}
|
||||
|
||||
fn net_port(&self) -> u16 {
|
||||
self.args.flag_port
|
||||
}
|
||||
@@ -302,6 +311,8 @@ impl Configuration {
|
||||
pub fn client_config(&self, spec: &Spec) -> ClientConfig {
|
||||
let mut client_config = ClientConfig::default();
|
||||
|
||||
client_config.mode = self.mode();
|
||||
|
||||
match self.args.flag_cache {
|
||||
Some(mb) => {
|
||||
client_config.blockchain.max_cache_size = mb * 1024 * 1024;
|
||||
|
||||
@@ -82,7 +82,7 @@ use rustc_serialize::hex::FromHex;
|
||||
use ctrlc::CtrlC;
|
||||
use util::{H256, ToPretty, NetworkConfiguration, PayloadInfo, Bytes, UtilError, paint, Colour, version};
|
||||
use util::panics::{MayPanic, ForwardPanic, PanicHandler};
|
||||
use ethcore::client::{BlockID, BlockChainClient, ClientConfig, get_db_path, BlockImportError};
|
||||
use ethcore::client::{Mode, BlockID, BlockChainClient, ClientConfig, get_db_path, BlockImportError};
|
||||
use ethcore::error::{ImportError};
|
||||
use ethcore::service::ClientService;
|
||||
use ethcore::spec::Spec;
|
||||
@@ -213,7 +213,12 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig)
|
||||
|
||||
// Build client
|
||||
let mut service = ClientService::start(
|
||||
client_config, spec, net_settings, Path::new(&conf.path()), miner.clone(), !conf.args.flag_no_network
|
||||
client_config,
|
||||
spec,
|
||||
net_settings,
|
||||
Path::new(&conf.path()),
|
||||
miner.clone(),
|
||||
match conf.mode() { Mode::Dark(..) => false, _ => !conf.args.flag_no_network }
|
||||
).unwrap_or_else(|e| die_with_error("Client", e));
|
||||
|
||||
panic_handler.forward_from(&service);
|
||||
@@ -282,7 +287,7 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig)
|
||||
});
|
||||
|
||||
// Register IO handler
|
||||
let io_handler = Arc::new(ClientIoHandler {
|
||||
let io_handler = Arc::new(ClientIoHandler {
|
||||
client: service.client(),
|
||||
info: Informant::new(conf.have_color()),
|
||||
sync: sync.clone(),
|
||||
|
||||
@@ -166,7 +166,7 @@ pub fn setup_rpc<T: Extendable>(server: T, deps: Arc<Dependencies>, apis: ApiSet
|
||||
server.add_delegate(EthcoreClient::new(&deps.client, &deps.miner, deps.logger.clone(), deps.settings.clone(), queue).to_delegate())
|
||||
},
|
||||
Api::EthcoreSet => {
|
||||
server.add_delegate(EthcoreSetClient::new(&deps.miner, &deps.net_service).to_delegate())
|
||||
server.add_delegate(EthcoreSetClient::new(&deps.client, &deps.miner, &deps.net_service).to_delegate())
|
||||
},
|
||||
Api::Traces => {
|
||||
server.add_delegate(TracesClient::new(&deps.client, &deps.miner).to_delegate())
|
||||
|
||||
Reference in New Issue
Block a user