Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Mode improvements for UI #3109

Merged
merged 17 commits into from
Nov 5, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl Client {
let panic_handler = PanicHandler::new_in_arc();
panic_handler.forward_from(&block_queue);

let awake = match config.mode { Mode::Dark(..) => false, _ => true };
let awake = match config.mode { Mode::Dark(..) | Mode::Off => false, _ => true };

let factories = Factories {
vm: EvmFactory::new(config.vm_type.clone(), config.jump_table_size),
Expand Down
4 changes: 2 additions & 2 deletions js/src/jsonrpc/interfaces/ethcore.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export default {
},

mode: {
desc: 'Get the mode. Results one of: "active", "passive", "dark", "off".',
desc: 'Get the mode. Results one of: "active", "passive", "dark", "offline".',
params: [],
returns: {
type: String,
Expand Down Expand Up @@ -330,7 +330,7 @@ export default {
params: [
{
type: String,
desc: 'The mode to set, one of "active", "passive", "dark", "off"'
desc: 'The mode to set, one of "active", "passive", "dark", "offline"'
}
],
returns: {
Expand Down
6 changes: 2 additions & 4 deletions parity/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ pub struct ImportBlockchain {
pub pruning_history: u64,
pub compaction: DatabaseCompactionProfile,
pub wal: bool,
pub mode: Mode,
pub tracing: Switch,
pub fat_db: Switch,
pub vm_type: VMType,
Expand All @@ -97,7 +96,6 @@ pub struct ExportBlockchain {
pub pruning_history: u64,
pub compaction: DatabaseCompactionProfile,
pub wal: bool,
pub mode: Mode,
pub fat_db: Switch,
pub tracing: Switch,
pub from_block: BlockID,
Expand Down Expand Up @@ -155,7 +153,7 @@ fn execute_import(cmd: ImportBlockchain) -> Result<String, String> {
try!(execute_upgrades(&db_dirs, algorithm, cmd.compaction.compaction_profile(db_dirs.fork_path().as_path())));

// prepare client config
let client_config = to_client_config(&cmd.cache_config, cmd.mode, tracing, fat_db, cmd.compaction, cmd.wal, cmd.vm_type, "".into(), algorithm, cmd.pruning_history, cmd.check_seal);
let client_config = to_client_config(&cmd.cache_config, Mode::Active, tracing, fat_db, cmd.compaction, cmd.wal, cmd.vm_type, "".into(), algorithm, cmd.pruning_history, cmd.check_seal);

// build client
let service = try!(ClientService::start(
Expand Down Expand Up @@ -303,7 +301,7 @@ fn execute_export(cmd: ExportBlockchain) -> Result<String, String> {
try!(execute_upgrades(&db_dirs, algorithm, cmd.compaction.compaction_profile(db_dirs.fork_path().as_path())));

// prepare client config
let client_config = to_client_config(&cmd.cache_config, cmd.mode, tracing, fat_db, cmd.compaction, cmd.wal, VMType::default(), "".into(), algorithm, cmd.pruning_history, cmd.check_seal);
let client_config = to_client_config(&cmd.cache_config, Mode::Active, tracing, fat_db, cmd.compaction, cmd.wal, VMType::default(), "".into(), algorithm, cmd.pruning_history, cmd.check_seal);

let service = try!(ClientService::start(
client_config,
Expand Down
7 changes: 2 additions & 5 deletions parity/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ usage! {
}
{
// -- Operating Options
flag_mode: String = "active", or |c: &Config| otry!(c.parity).mode.clone(),
flag_mode: String = "auto", or |c: &Config| otry!(c.parity).mode.clone(),
flag_mode_timeout: u64 = 300u64, or |c: &Config| otry!(c.parity).mode_timeout.clone(),
flag_mode_alarm: u64 = 3600u64, or |c: &Config| otry!(c.parity).mode_alarm.clone(),
flag_chain: String = "homestead", or |c: &Config| otry!(c.parity).chain.clone(),
Expand Down Expand Up @@ -104,8 +104,6 @@ usage! {
flag_signer_no_validation: bool = false, or |_| None,

// -- Networking Options
flag_no_network: bool = false,
or |c: &Config| otry!(c.network).disable.clone(),
flag_warp: bool = false,
or |c: &Config| otry!(c.network).warp.clone(),
flag_port: u16 = 30303u16,
Expand Down Expand Up @@ -500,7 +498,7 @@ mod tests {
arg_path: vec![],

// -- Operating Options
flag_mode: "active".into(),
flag_mode: "auto".into(),
flag_mode_timeout: 300u64,
flag_mode_alarm: 3600u64,
flag_chain: "xyz".into(),
Expand All @@ -521,7 +519,6 @@ mod tests {
flag_signer_no_validation: false,

// -- Networking Options
flag_no_network: false,
flag_warp: true,
flag_port: 30303u16,
flag_min_peers: 25u16,
Expand Down
6 changes: 3 additions & 3 deletions parity/cli/usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ Usage:

Operating Options:
--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 an external interface
is active. (default: {flag_mode}).
dark - Parity syncs only when the RPC is active.
offline - Parity doesn't sync. (default: {flag_mode}).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto not mentioned here, but is set as the default

--mode-timeout SECS Specify the number of seconds before inactivity
timeout occurs when mode is dark or passive
(default: {flag_mode_timeout}).
Expand Down Expand Up @@ -66,7 +67,6 @@ Account Options:
development. (default: {flag_signer_no_validation})

Networking Options:
--no-network Disable p2p networking. (default: {flag_no_network})
--warp Enable syncing from the snapshot over the network. (default: {flag_warp})
--port PORT Override the port on which the node should listen
(default: {flag_port}).
Expand Down
18 changes: 2 additions & 16 deletions parity/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use cli::{Args, ArgsError};
use util::{Hashable, U256, Uint, Bytes, version_data, Secret, Address};
use util::log::Colour;
use ethsync::{NetworkConfiguration, is_valid_node_url, AllowIP};
use ethcore::client::{VMType, Mode};
use ethcore::client::VMType;
use ethcore::miner::{MinerOptions, Banning};

use rpc::{IpcConfiguration, HttpConfiguration};
Expand Down Expand Up @@ -80,7 +80,7 @@ impl Configuration {
let pruning = try!(self.args.flag_pruning.parse());
let pruning_history = self.args.flag_pruning_history;
let vm_type = try!(self.vm_type());
let mode = try!(to_mode(&self.args.flag_mode, self.args.flag_mode_timeout, self.args.flag_mode_alarm));
let mode = match self.args.flag_mode.as_ref() { "last" => None, mode => Some(try!(to_mode(&mode, self.args.flag_mode_timeout, self.args.flag_mode_alarm))), };
let miner_options = try!(self.miner_options());
let logger_config = self.logger_config();
let http_conf = try!(self.http_config());
Expand All @@ -93,7 +93,6 @@ impl Configuration {
let fat_db = try!(self.args.flag_fat_db.parse());
let compaction = try!(self.args.flag_db_compaction.parse());
let wal = !self.args.flag_fast_and_loose;
let enable_network = self.enable_network(&mode);
let warp_sync = self.args.flag_warp;
let geth_compatibility = self.args.flag_geth;
let signer_port = self.signer_port();
Expand Down Expand Up @@ -156,7 +155,6 @@ impl Configuration {
pruning_history: pruning_history,
compaction: compaction,
wal: wal,
mode: mode,
tracing: tracing,
fat_db: fat_db,
vm_type: vm_type,
Expand All @@ -175,7 +173,6 @@ impl Configuration {
pruning_history: pruning_history,
compaction: compaction,
wal: wal,
mode: mode,
tracing: tracing,
fat_db: fat_db,
from_block: try!(to_block_id(&self.args.flag_from)),
Expand All @@ -190,7 +187,6 @@ impl Configuration {
spec: spec,
pruning: pruning,
pruning_history: pruning_history,
mode: mode,
tracing: tracing,
fat_db: fat_db,
compaction: compaction,
Expand All @@ -207,7 +203,6 @@ impl Configuration {
spec: spec,
pruning: pruning,
pruning_history: pruning_history,
mode: mode,
tracing: tracing,
fat_db: fat_db,
compaction: compaction,
Expand Down Expand Up @@ -246,7 +241,6 @@ impl Configuration {
compaction: compaction,
wal: wal,
vm_type: vm_type,
enable_network: enable_network,
warp_sync: warp_sync,
geth_compatibility: geth_compatibility,
signer_port: signer_port,
Expand All @@ -268,13 +262,6 @@ impl Configuration {
})
}

fn enable_network(&self, mode: &Mode) -> bool {
match *mode {
Mode::Dark(_) => false,
_ => !self.args.flag_no_network,
}
}

fn vm_type(&self) -> Result<VMType, String> {
if self.args.flag_jitvm {
VMType::jit().ok_or("Parity is built without the JIT EVM.".into())
Expand Down Expand Up @@ -858,7 +845,6 @@ mod tests {
compaction: Default::default(),
wal: true,
vm_type: Default::default(),
enable_network: true,
geth_compatibility: false,
signer_port: Some(8180),
net_settings: Default::default(),
Expand Down
1 change: 1 addition & 0 deletions parity/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub fn to_mode(s: &str, timeout: u64, alarm: u64) -> Result<Mode, String> {
"active" => Ok(Mode::Active),
"passive" => Ok(Mode::Passive(Duration::from_secs(timeout), Duration::from_secs(alarm))),
"dark" => Ok(Mode::Dark(Duration::from_secs(timeout))),
"off" => Ok(Mode::Off),
_ => Err(format!("{}: Invalid address for --mode. Must be one of active, passive or dark.", s)),
}
}
Expand Down
5 changes: 5 additions & 0 deletions parity/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use util::{Address, U256, version_data};
use util::journaldb::Algorithm;
use ethcore::spec::Spec;
use ethcore::ethereum;
use ethcore::client::Mode;
use ethcore::miner::{GasPricer, GasPriceCalibratorOptions};
use user_defaults::UserDefaults;

Expand Down Expand Up @@ -264,6 +265,10 @@ pub fn fatdb_switch_to_bool(switch: Switch, user_defaults: &UserDefaults, algori
result
}

pub fn mode_switch_to_bool(switch: Option<Mode>, user_defaults: &UserDefaults) -> Result<Mode, String> {
Ok(switch.unwrap_or(user_defaults.mode.clone()))
}

#[cfg(test)]
mod tests {
use util::journaldb::Algorithm;
Expand Down
14 changes: 9 additions & 5 deletions parity/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use dapps::WebappServer;
use io_handler::ClientIoHandler;
use params::{
SpecType, Pruning, AccountsConfig, GasPricerConfig, MinerExtras, Switch,
tracing_switch_to_bool, fatdb_switch_to_bool,
tracing_switch_to_bool, fatdb_switch_to_bool, mode_switch_to_bool
};
use helpers::{to_client_config, execute_upgrades, passwords_from_files};
use dir::Directories;
Expand Down Expand Up @@ -75,13 +75,12 @@ pub struct RunCmd {
pub acc_conf: AccountsConfig,
pub gas_pricer: GasPricerConfig,
pub miner_extras: MinerExtras,
pub mode: Mode,
pub mode: Option<Mode>,
pub tracing: Switch,
pub fat_db: Switch,
pub compaction: DatabaseCompactionProfile,
pub wal: bool,
pub vm_type: VMType,
pub enable_network: bool,
pub geth_compatibility: bool,
pub signer_port: Option<u16>,
pub net_settings: NetworkSettings,
Expand Down Expand Up @@ -137,6 +136,11 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<(), String> {
// check if fatdb is on
let fat_db = try!(fatdb_switch_to_bool(cmd.fat_db, &user_defaults, algorithm));

// get the mode
let mode = try!(mode_switch_to_bool(cmd.mode, &user_defaults));
let network_enabled = match &mode { &Mode::Dark(_) | &Mode::Off => false, _ => true, };


// prepare client and snapshot paths.
let client_path = db_dirs.client_path(algorithm);
let snapshot_path = db_dirs.snapshot_path();
Expand Down Expand Up @@ -196,7 +200,7 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<(), String> {
// create client config
let client_config = to_client_config(
&cmd.cache_config,
cmd.mode,
mode,
tracing,
fat_db,
cmd.compaction,
Expand Down Expand Up @@ -248,7 +252,7 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<(), String> {
service.add_notify(chain_notify.clone());

// start network
if cmd.enable_network {
if network_enabled {
chain_notify.start();
}

Expand Down
3 changes: 1 addition & 2 deletions parity/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ pub struct SnapshotCommand {
pub spec: SpecType,
pub pruning: Pruning,
pub pruning_history: u64,
pub mode: Mode,
pub tracing: Switch,
pub fat_db: Switch,
pub compaction: DatabaseCompactionProfile,
Expand Down Expand Up @@ -158,7 +157,7 @@ impl SnapshotCommand {
try!(execute_upgrades(&db_dirs, algorithm, self.compaction.compaction_profile(db_dirs.fork_path().as_path())));

// prepare client config
let client_config = to_client_config(&self.cache_config, self.mode, tracing, fat_db, self.compaction, self.wal, VMType::default(), "".into(), algorithm, self.pruning_history, true);
let client_config = to_client_config(&self.cache_config, Mode::Active, tracing, fat_db, self.compaction, self.wal, VMType::default(), "".into(), algorithm, self.pruning_history, true);

let service = try!(ClientService::start(
client_config,
Expand Down
36 changes: 36 additions & 0 deletions parity/user_defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@ use std::fs::File;
use std::io::Write;
use std::path::Path;
use std::collections::BTreeMap;
use std::time::Duration;
use serde::{Serialize, Serializer, Error, Deserialize, Deserializer};
use serde::de::{Visitor, MapVisitor};
use serde::de::impls::BTreeMapVisitor;
use serde_json::Value;
use serde_json::de::from_reader;
use serde_json::ser::to_string;
use util::journaldb::Algorithm;
use ethcore::client::Mode;

pub struct UserDefaults {
pub is_first_launch: bool,
pub pruning: Algorithm,
pub tracing: bool,
pub fat_db: bool,
pub mode: Mode,
}

impl Serialize for UserDefaults {
Expand All @@ -40,6 +43,21 @@ impl Serialize for UserDefaults {
map.insert("pruning".into(), Value::String(self.pruning.as_str().into()));
map.insert("tracing".into(), Value::Bool(self.tracing));
map.insert("fat_db".into(), Value::Bool(self.fat_db));
let mode_str = match self.mode {
Mode::Off => "offline",
Mode::Dark(timeout) => {
map.insert("mode.timeout".into(), Value::U64(timeout.as_secs()));
"dark"
},
Mode::Passive(timeout, alarm) => {
map.insert("mode.timeout".into(), Value::U64(timeout.as_secs()));
map.insert("mode.alarm".into(), Value::U64(alarm.as_secs()));
"passive"
},
Mode::Active => "active",
};
map.insert("mode".into(), Value::String(mode_str.into()));

map.serialize(serializer)
}
}
Expand Down Expand Up @@ -67,11 +85,28 @@ impl Visitor for UserDefaultsVisitor {
let fat_db: Value = map.remove("fat_db".into()).unwrap_or_else(|| Value::Bool(false));
let fat_db = try!(fat_db.as_bool().ok_or_else(|| Error::custom("invalid fat_db value")));

let mode: Value = map.remove("mode".into()).unwrap_or_else(|| Value::String("active".to_owned()));
let mode = match try!(mode.as_str().ok_or_else(|| Error::custom("invalid mode value"))) {
"off" => Mode::Off,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"offline" probably?

"dark" => {
let timeout = try!(map.remove("mode.timeout".into()).and_then(|v| v.as_u64()).ok_or_else(|| Error::custom("invalid/missing mode.timeout value")));
Mode::Dark(Duration::from_secs(timeout))
},
"passive" => {
let timeout = try!(map.remove("mode.timeout".into()).and_then(|v| v.as_u64()).ok_or_else(|| Error::custom("invalid/missing mode.timeout value")));
let alarm = try!(map.remove("mode.alarm".into()).and_then(|v| v.as_u64()).ok_or_else(|| Error::custom("invalid/missing mode.alarm value")));
Mode::Passive(Duration::from_secs(timeout), Duration::from_secs(alarm))
},
"active" => Mode::Active,
_ => { return Err(Error::custom("invalid mode value")); },
};

let user_defaults = UserDefaults {
is_first_launch: false,
pruning: pruning,
tracing: tracing,
fat_db: fat_db,
mode: mode,
};

Ok(user_defaults)
Expand All @@ -85,6 +120,7 @@ impl Default for UserDefaults {
pruning: Algorithm::default(),
tracing: false,
fat_db: false,
mode: Mode::Active,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/v1/impls/ethcore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl<C, M, S: ?Sized, F> Ethcore for EthcoreClient<C, M, S, F> where

fn mode(&self) -> Result<String, Error> {
Ok(match take_weak!(self.client).mode() {
Mode::Off => "off",
Mode::Off => "offline",
Mode::Dark(..) => "dark",
Mode::Passive(..) => "passive",
Mode::Active => "active",
Expand Down
Loading