From 03ef95ba5027f899d1aecd29de9b81f06023f997 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 23 Nov 2016 20:35:21 +0100 Subject: [PATCH] Compiles. --- db/src/database.rs | 3 +-- ethcore/src/client/client.rs | 5 +++-- ethcore/src/client/config.rs | 38 +++++++++++++++++++++-------------- ethcore/src/client/mod.rs | 2 +- ethcore/src/client/updater.rs | 7 ++----- parity/blockchain.rs | 4 ++-- parity/cli/mod.rs | 7 +++++++ parity/cli/usage.txt | 4 +++- parity/configuration.rs | 37 +++++++++++++++++++++++++++++++--- parity/helpers.rs | 4 +++- parity/run.rs | 8 +++++++- parity/snapshot.rs | 2 +- 12 files changed, 87 insertions(+), 34 deletions(-) diff --git a/db/src/database.rs b/db/src/database.rs index e1774159b..6504900e6 100644 --- a/db/src/database.rs +++ b/db/src/database.rs @@ -270,8 +270,7 @@ impl DatabaseService for Database { Ok(next_iterator) } - fn iter_next(&self, handle: IteratorHandle) -> Option - { + fn iter_next(&self, handle: IteratorHandle) -> Option { let mut iterators = self.iterators.write(); let mut iterator = match iterators.get_mut(&handle) { Some(some_iterator) => some_iterator, diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 102c4aab6..004f181d9 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -129,7 +129,6 @@ impl SleepState { /// Call `import_block()` to import a block asynchronously; `flush_queue()` flushes the queue. pub struct Client { mode: Mutex, - update_policy: UpdatePolicy, chain: RwLock>, tracedb: RwLock>, engine: Arc, @@ -227,6 +226,8 @@ impl Client { accountdb: Default::default(), }; + + let client = Arc::new(Client { sleep_state: Mutex::new(SleepState::new(awake)), liveness: AtomicBool::new(awake), @@ -262,7 +263,7 @@ impl Client { if let Ok(ops_addr) = registrar.get_address(&(&b"operations"[..]).sha3(), "A") { if !ops_addr.is_zero() { trace!(target: "client", "Found operations at {}", ops_addr); - *client.updater.lock() = Some(Updater::new(Arc::downgrade(&client), ops_addr)); + *client.updater.lock() = Some(Updater::new(Arc::downgrade(&client), ops_addr, client.config.update_policy.clone())); } } *client.registrar.lock() = Some(registrar); diff --git a/ethcore/src/client/config.rs b/ethcore/src/client/config.rs index bf06df462..effa0b1dc 100644 --- a/ethcore/src/client/config.rs +++ b/ethcore/src/client/config.rs @@ -66,33 +66,39 @@ impl FromStr for DatabaseCompactionProfile { } } +/// Filter for releases. #[derive(Debug, Eq, PartialEq, Clone)] pub enum UpdateFilter { + /// All releases following the same track. All, + /// Only those of the same minor version potentially changing tracks. Patch, + /// As with `All`, but only those which are known to be critical. Critical, + /// None. None, } +/// The policy for auto-updating. #[derive(Debug, Eq, PartialEq, Clone)] pub struct UpdatePolicy { - download_only: bool, - track: Track, + /// Download potential updates. + pub enable_downloading: bool, + /// Which of those downloaded should be automatically installed. + pub filter: UpdateFilter, } -/// Operating mode for the client. -#[derive(Debug, Eq, PartialEq, Clone)] -pub enum UpdatePolicy { - /// Always on. - Active, - /// Goes offline after RLP is inactive for some (given) time, but - /// comes back online after a while of inactivity. - Passive(Duration, Duration), - /// Goes offline after RLP is inactive for some (given) time and - /// stays inactive. - Dark(Duration), - /// Always off. - Off, +impl Default for UpdatePolicy { + fn default() -> Self { + UpdatePolicy { + enable_downloading: false, + filter: UpdateFilter::None, + } + } +} + +impl UpdatePolicy { + pub fn new() -> Self { Default::default() } } /// Operating mode for the client. @@ -130,6 +136,8 @@ impl Display for Mode { /// Client configuration. Includes configs for all sub-systems. #[derive(Debug, PartialEq, Default)] pub struct ClientConfig { + /// Updater policy. + pub update_policy: UpdatePolicy, /// Block queue configuration. pub queue: QueueConfig, /// Blockchain configuration. diff --git a/ethcore/src/client/mod.rs b/ethcore/src/client/mod.rs index adeaaf64a..7759d08ef 100644 --- a/ethcore/src/client/mod.rs +++ b/ethcore/src/client/mod.rs @@ -26,7 +26,7 @@ mod client; mod updater; pub use self::client::*; -pub use self::config::{Mode, ClientConfig, UpdatePolicy, Automation, DatabaseCompactionProfile, BlockChainConfig, VMType}; +pub use self::config::{Mode, ClientConfig, UpdatePolicy, UpdateFilter, DatabaseCompactionProfile, BlockChainConfig, VMType}; pub use self::error::Error; pub use types::ids::*; pub use self::test_client::{TestBlockChainClient, EachBlockWith}; diff --git a/ethcore/src/client/updater.rs b/ethcore/src/client/updater.rs index dc45a55ff..f4f40cfad 100644 --- a/ethcore/src/client/updater.rs +++ b/ethcore/src/client/updater.rs @@ -18,8 +18,7 @@ use std::sync::Weak; use util::misc::{VersionInfo, ReleaseTrack, platform}; use util::{Address, H160, H256, FixedHash}; use client::operations::Operations; -use client::client::Client; -use client::BlockId; +use client::{Client, UpdatePolicy, BlockId}; pub struct ReleaseInfo { fork_supported: usize, @@ -34,15 +33,13 @@ pub struct Updater { client: Weak, operations: Operations, - - pub this: VersionInfo, pub release_info: Option, } impl Updater { - pub fn new(client: Weak, operations: Address) -> Self { + pub fn new(client: Weak, operations: Address, _update_policy: UpdatePolicy) -> Self { let mut u = Updater { client: client.clone(), operations: Operations::new(operations, move |a, d| client.upgrade().ok_or("No client!".into()).and_then(|c| c.call_contract(a, d))), diff --git a/parity/blockchain.rs b/parity/blockchain.rs index 7696d1b38..70326de3b 100644 --- a/parity/blockchain.rs +++ b/parity/blockchain.rs @@ -153,7 +153,7 @@ fn execute_import(cmd: ImportBlockchain) -> Result { 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, Mode::Active, 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, Default::default(), 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( @@ -304,7 +304,7 @@ fn execute_export(cmd: ExportBlockchain) -> Result { 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, Mode::Active, 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, Default::default(), 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, diff --git a/parity/cli/mod.rs b/parity/cli/mod.rs index 394892914..08474ea45 100644 --- a/parity/cli/mod.rs +++ b/parity/cli/mod.rs @@ -78,6 +78,8 @@ usage! { 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_auto_update: String = "consensus", or |c: &Config| otry!(c.parity).auto_update.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_db_path: String = "$HOME/.parity", or |c: &Config| otry!(c.parity).db_path.clone(), flag_keys_path: String = "$HOME/.parity/keys", or |c: &Config| otry!(c.parity).keys_path.clone(), @@ -290,6 +292,9 @@ struct Operating { mode: Option, mode_timeout: Option, mode_alarm: Option, + auto_update: Option, + no_download: Option, + no_consensus: Option, chain: Option, db_path: Option, keys_path: Option, @@ -504,6 +509,8 @@ mod tests { flag_mode_timeout: 300u64, flag_mode_alarm: 3600u64, flag_auto_update: "consensus".into(), + flag_no_download: false, + flag_no_consensus: false, flag_chain: "xyz".into(), flag_db_path: "$HOME/.parity".into(), flag_keys_path: "$HOME/.parity/keys".into(), diff --git a/parity/cli/usage.txt b/parity/cli/usage.txt index f905ec74a..1a6fe3b61 100644 --- a/parity/cli/usage.txt +++ b/parity/cli/usage.txt @@ -38,9 +38,11 @@ Operating Options: none - No updates will be auto-installed. (default: {flag_auto_update}). --no-download Normally new releases will be downloaded ready for - updating. This disables it. Not recommended. + updating. This disables it. Not recommended. + (default: {flag_no_download}). --no-consensus Force the binary to run even if there are known issues regarding consensus. Not recommended. + (default: {flag_no_consensus}). --chain CHAIN Specify the blockchain type. CHAIN may be either a JSON chain specification file or olympic, frontier, homestead, mainnet, morden, ropsten, classic, expanse, diff --git a/parity/configuration.rs b/parity/configuration.rs index 0f0c19814..3cb19fe37 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -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, UpdatePolicy}; +use ethcore::client::{VMType, UpdatePolicy, UpdateFilter}; use ethcore::miner::{MinerOptions, Banning}; use rpc::{IpcConfiguration, HttpConfiguration}; @@ -81,6 +81,7 @@ impl Configuration { let pruning_history = self.args.flag_pruning_history; let vm_type = try!(self.vm_type()); 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 update_policy = try!(self.update_policy()); let miner_options = try!(self.miner_options()); let logger_config = self.logger_config(); let http_conf = try!(self.http_config()); @@ -233,6 +234,7 @@ impl Configuration { acc_conf: try!(self.accounts_config()), gas_pricer: try!(self.gas_pricer_config()), miner_extras: try!(self.miner_extras()), + update_policy: update_policy, mode: mode, tracing: tracing, fat_db: fat_db, @@ -251,6 +253,7 @@ impl Configuration { no_periodic_snapshot: self.args.flag_no_periodic_snapshot, check_seal: !self.args.flag_no_seal_check, download_old_blocks: !self.args.flag_no_ancient_blocks, + require_consensus: !self.args.flag_no_consensus, }; Cmd::Run(run_cmd) }; @@ -586,8 +589,17 @@ impl Configuration { } } - fn update_policy(&self) -> UpdatePolicy { - + fn update_policy(&self) -> Result { + Ok(UpdatePolicy { + enable_downloading: !self.args.flag_no_download, + filter: match self.args.flag_auto_update.as_ref() { + "none" => UpdateFilter::None, + "critical" => UpdateFilter::Critical, + "patch" => UpdateFilter::Patch, + "all" => UpdateFilter::All, + _ => return Err("Invalid value for `--auto-update`. See `--help` for more information.".into()), + }, + }) } fn directories(&self) -> Directories { @@ -877,6 +889,7 @@ mod tests { no_periodic_snapshot: false, check_seal: true, download_old_blocks: true, + require_consensus: true, })); } @@ -901,6 +914,24 @@ mod tests { assert_eq!(conf3.miner_options().unwrap(), mining_options); } + #[test] + fn should_parse_updater_options() { + // when + let conf0 = parse(&["parity"]); + let conf1 = parse(&["parity", "--auto-update", "all"]); + let conf2 = parse(&["parity", "--no-download", "--auto-update=patch"]); + let conf3 = parse(&["parity", "--auto-update=xxx"]); + + // then + assert_eq!(conf0.update_policy().unwrap(), UpdatePolicy{enable_downloading: true, filter: UpdateFilter::Critical}); + mining_options.tx_queue_strategy = PrioritizationStrategy::GasFactorAndGasPrice; + assert_eq!(conf1.update_policy().unwrap(), UpdatePolicy{enable_downloading: true, filter: UpdateFilter::All}); + mining_options.tx_queue_strategy = PrioritizationStrategy::GasPriceOnly; + assert_eq!(conf2.update_policy().unwrap(), UpdatePolicy{enable_downloading: false, filter: UpdateFilter::Patch}); + mining_options.tx_queue_strategy = PrioritizationStrategy::GasAndGasPrice; + assert!(conf3.update_policy().is_err()); + } + #[test] fn should_parse_network_settings() { // given diff --git a/parity/helpers.rs b/parity/helpers.rs index fe5303ec8..d748caa6a 100644 --- a/parity/helpers.rs +++ b/parity/helpers.rs @@ -20,7 +20,7 @@ use std::time::Duration; use std::fs::File; use util::{clean_0x, U256, Uint, Address, path, CompactionProfile}; use util::journaldb::Algorithm; -use ethcore::client::{Mode, BlockId, VMType, DatabaseCompactionProfile, ClientConfig, VerifierType}; +use ethcore::client::{UpdatePolicy, Mode, BlockId, VMType, DatabaseCompactionProfile, ClientConfig, VerifierType}; use ethcore::miner::{PendingSet, GasLimit, PrioritizationStrategy}; use cache::CacheConfig; use dir::DatabaseDirectories; @@ -209,6 +209,7 @@ pub fn default_network_config() -> ::ethsync::NetworkConfiguration { #[cfg_attr(feature = "dev", allow(too_many_arguments))] pub fn to_client_config( cache_config: &CacheConfig, + update_policy: UpdatePolicy, mode: Mode, tracing: bool, fat_db: bool, @@ -242,6 +243,7 @@ pub fn to_client_config( // in bytes client_config.jump_table_size = cache_config.jump_tables() as usize * mb; + client_config.update_policy = update_policy; client_config.mode = mode; client_config.tracing.enabled = tracing; client_config.fat_db = fat_db; diff --git a/parity/run.rs b/parity/run.rs index f56ba5b92..daa6aae05 100644 --- a/parity/run.rs +++ b/parity/run.rs @@ -23,7 +23,7 @@ use ethsync::NetworkConfiguration; use util::{Colour, version, RotatingLogger}; use io::{MayPanic, ForwardPanic, PanicHandler}; use ethcore_logger::{Config as LogConfig}; -use ethcore::client::{Mode, DatabaseCompactionProfile, VMType, ChainNotify, BlockChainClient}; +use ethcore::client::{Mode, UpdatePolicy, DatabaseCompactionProfile, VMType, ChainNotify, BlockChainClient}; use ethcore::service::ClientService; use ethcore::account_provider::AccountProvider; use ethcore::miner::{Miner, MinerService, ExternalMiner, MinerOptions}; @@ -75,6 +75,7 @@ pub struct RunCmd { pub acc_conf: AccountsConfig, pub gas_pricer: GasPricerConfig, pub miner_extras: MinerExtras, + pub update_policy: UpdatePolicy, pub mode: Option, pub tracing: Switch, pub fat_db: Switch, @@ -92,6 +93,7 @@ pub struct RunCmd { pub no_periodic_snapshot: bool, pub check_seal: bool, pub download_old_blocks: bool, + pub require_consensus: bool, } pub fn open_ui(dapps_conf: &dapps::Configuration, signer_conf: &signer::Configuration) -> Result<(), String> { @@ -158,6 +160,9 @@ pub fn execute(cmd: RunCmd, logger: Arc) -> Result<(), String> { trace!(target: "mode", "mode is {:?}", mode); let network_enabled = match &mode { &Mode::Dark(_) | &Mode::Off => false, _ => 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(); @@ -219,6 +224,7 @@ pub fn execute(cmd: RunCmd, logger: Arc) -> Result<(), String> { // create client config let client_config = to_client_config( &cmd.cache_config, + update_policy, mode, tracing, fat_db, diff --git a/parity/snapshot.rs b/parity/snapshot.rs index 804047596..d74adc1b4 100644 --- a/parity/snapshot.rs +++ b/parity/snapshot.rs @@ -170,7 +170,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, Mode::Active, tracing, fat_db, self.compaction, self.wal, VMType::default(), "".into(), algorithm, self.pruning_history, true); + let client_config = to_client_config(&self.cache_config, Default::default(), Mode::Active, tracing, fat_db, self.compaction, self.wal, VMType::default(), "".into(), algorithm, self.pruning_history, true); let service = try!(ClientService::start( client_config,