Compiles.

This commit is contained in:
Gav Wood 2016-11-23 20:35:21 +01:00
parent 90b5d1c62d
commit 03ef95ba50
No known key found for this signature in database
GPG Key ID: C49C1ACA1CC9B252
12 changed files with 87 additions and 34 deletions

View File

@ -270,8 +270,7 @@ impl DatabaseService for Database {
Ok(next_iterator)
}
fn iter_next(&self, handle: IteratorHandle) -> Option<KeyValue>
{
fn iter_next(&self, handle: IteratorHandle) -> Option<KeyValue> {
let mut iterators = self.iterators.write();
let mut iterator = match iterators.get_mut(&handle) {
Some(some_iterator) => some_iterator,

View File

@ -129,7 +129,6 @@ impl SleepState {
/// Call `import_block()` to import a block asynchronously; `flush_queue()` flushes the queue.
pub struct Client {
mode: Mutex<Mode>,
update_policy: UpdatePolicy,
chain: RwLock<Arc<BlockChain>>,
tracedb: RwLock<TraceDB<BlockChain>>,
engine: Arc<Engine>,
@ -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);

View File

@ -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.

View File

@ -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};

View File

@ -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<Client>,
operations: Operations,
pub this: VersionInfo,
pub release_info: Option<ReleaseInfo>,
}
impl Updater {
pub fn new(client: Weak<Client>, operations: Address) -> Self {
pub fn new(client: Weak<Client>, 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))),

View File

@ -153,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, 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<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, 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,

View File

@ -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<String>,
mode_timeout: Option<u64>,
mode_alarm: Option<u64>,
auto_update: Option<String>,
no_download: Option<bool>,
no_consensus: Option<bool>,
chain: Option<String>,
db_path: Option<String>,
keys_path: Option<String>,
@ -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(),

View File

@ -39,8 +39,10 @@ Operating Options:
(default: {flag_auto_update}).
--no-download Normally new releases will be downloaded ready for
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,

View File

@ -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<UpdatePolicy, String> {
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

View File

@ -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;

View File

@ -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<Mode>,
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<RotatingLogger>) -> 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<RotatingLogger>) -> Result<(), String> {
// create client config
let client_config = to_client_config(
&cmd.cache_config,
update_policy,
mode,
tracing,
fat_db,

View File

@ -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,