Merge branch 'master' into lightserv

This commit is contained in:
Robert Habermeier
2016-12-09 01:29:46 +01:00
132 changed files with 2594 additions and 767 deletions

View File

@@ -28,6 +28,7 @@ use ethcore::service::ClientService;
use ethcore::client::{Mode, DatabaseCompactionProfile, VMType, BlockImportError, BlockChainClient, BlockID};
use ethcore::error::ImportError;
use ethcore::miner::Miner;
use ethcore::verification::queue::VerifierSettings;
use cache::CacheConfig;
use informant::{Informant, MillisecondDuration};
use params::{SpecType, Pruning, Switch, tracing_switch_to_bool, fatdb_switch_to_bool};
@@ -84,6 +85,7 @@ pub struct ImportBlockchain {
pub vm_type: VMType,
pub check_seal: bool,
pub with_color: bool,
pub verifier_settings: VerifierSettings,
}
#[derive(Debug, PartialEq)]
@@ -175,7 +177,21 @@ 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 mut 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
);
client_config.queue.verifier_settings = cmd.verifier_settings;
// build client
let service = try!(ClientService::start(

View File

@@ -62,6 +62,7 @@ pass = "test_pass"
[mining]
author = "0xdeadbeefcafe0000000000000000000000000001"
engine_signer = "0xdeadbeefcafe0000000000000000000000000001"
force_sealing = true
reseal_on_txs = "all"
reseal_min_period = 4000
@@ -95,6 +96,8 @@ cache_size = 128 # Overrides above caches with total size
fast_and_loose = false
db_compaction = "ssd"
fat_db = "auto"
scale_verifiers = true
num_verifiers = 6
[snapshots]
disable_periodic = false

View File

@@ -40,6 +40,7 @@ pass = "password"
[mining]
author = "0xdeadbeefcafe0000000000000000000000000001"
engine_signer = "0xdeadbeefcafe0000000000000000000000000001"
force_sealing = true
reseal_on_txs = "all"
reseal_min_period = 4000
@@ -57,6 +58,7 @@ cache_size_queue = 100
cache_size_state = 25
db_compaction = "ssd"
fat_db = "off"
scale_verifiers = false
[snapshots]
disable_periodic = true

View File

@@ -180,6 +180,8 @@ usage! {
// -- Sealing/Mining Options
flag_author: Option<String> = None,
or |c: &Config| otry!(c.mining).author.clone().map(Some),
flag_engine_signer: Option<String> = None,
or |c: &Config| otry!(c.mining).engine_signer.clone().map(Some),
flag_force_sealing: bool = false,
or |c: &Config| otry!(c.mining).force_sealing.clone(),
flag_reseal_on_txs: String = "own",
@@ -244,6 +246,10 @@ usage! {
or |c: &Config| otry!(c.footprint).db_compaction.clone(),
flag_fat_db: String = "auto",
or |c: &Config| otry!(c.footprint).fat_db.clone(),
flag_scale_verifiers: bool = false,
or |c: &Config| otry!(c.footprint).scale_verifiers.clone(),
flag_num_verifiers: Option<usize> = None,
or |c: &Config| otry!(c.footprint).num_verifiers.clone().map(Some),
// -- Import/Export Options
flag_from: String = "1", or |_| None,
@@ -370,6 +376,7 @@ struct Dapps {
#[derive(Default, Debug, PartialEq, RustcDecodable)]
struct Mining {
author: Option<String>,
engine_signer: Option<String>,
force_sealing: Option<bool>,
reseal_on_txs: Option<String>,
reseal_min_period: Option<u64>,
@@ -405,6 +412,8 @@ struct Footprint {
cache_size_state: Option<u32>,
db_compaction: Option<String>,
fat_db: Option<String>,
scale_verifiers: Option<bool>,
num_verifiers: Option<usize>,
}
#[derive(Default, Debug, PartialEq, RustcDecodable)]
@@ -573,6 +582,7 @@ mod tests {
// -- Sealing/Mining Options
flag_author: Some("0xdeadbeefcafe0000000000000000000000000001".into()),
flag_engine_signer: Some("0xdeadbeefcafe0000000000000000000000000001".into()),
flag_force_sealing: true,
flag_reseal_on_txs: "all".into(),
flag_reseal_min_period: 4000u64,
@@ -606,6 +616,8 @@ mod tests {
flag_fast_and_loose: false,
flag_db_compaction: "ssd".into(),
flag_fat_db: "auto".into(),
flag_scale_verifiers: true,
flag_num_verifiers: Some(6),
// -- Import/Export Options
flag_from: "1".into(),
@@ -743,6 +755,7 @@ mod tests {
}),
mining: Some(Mining {
author: Some("0xdeadbeefcafe0000000000000000000000000001".into()),
engine_signer: Some("0xdeadbeefcafe0000000000000000000000000001".into()),
force_sealing: Some(true),
reseal_on_txs: Some("all".into()),
reseal_min_period: Some(4000),
@@ -776,6 +789,8 @@ mod tests {
cache_size_state: Some(25),
db_compaction: Some("ssd".into()),
fat_db: Some("off".into()),
scale_verifiers: Some(false),
num_verifiers: None,
}),
snapshots: Some(Snapshots {
disable_periodic: Some(true),

View File

@@ -150,6 +150,10 @@ Sealing/Mining Options:
for sending block rewards from sealed blocks.
NOTE: MINING WILL NOT WORK WITHOUT THIS OPTION.
(default: {flag_author:?})
--engine-signer ADDRESS Specify the address which should be used to
sign consensus messages and issue blocks.
Relevant only to non-PoW chains.
(default: {flag_engine_signer:?})
--force-sealing Force the node to author new blocks as if it were
always sealing/mining.
(default: {flag_force_sealing})
@@ -251,7 +255,7 @@ Footprint Options:
the state cache (default: {flag_cache_size_state}).
--cache-size MB Set total amount of discretionary memory to use for
the entire system, overrides other cache and queue
options.a (default: {flag_cache_size:?})
options. (default: {flag_cache_size:?})
--fast-and-loose Disables DB WAL, which gives a significant speed up
but means an unclean exit is unrecoverable. (default: {flag_fast_and_loose})
--db-compaction TYPE Database compaction type. TYPE may be one of:
@@ -262,6 +266,11 @@ Footprint Options:
of all accounts and storage keys. Doubles the size
of the state database. BOOL may be one of on, off
or auto. (default: {flag_fat_db})
--scale-verifiers Automatically scale amount of verifier threads based on
workload. Not guaranteed to be faster.
(default: {flag_scale_verifiers})
--num-verifiers INT Amount of verifier threads to use or to begin with, if verifier
auto-scaling is enabled. (default: {flag_num_verifiers:?})
Import/Export Options:
--from BLOCK Export from block BLOCK, which may be an index or

View File

@@ -25,6 +25,7 @@ use util::log::Colour;
use ethsync::{NetworkConfiguration, is_valid_node_url, AllowIP};
use ethcore::client::VMType;
use ethcore::miner::{MinerOptions, Banning};
use ethcore::verification::queue::VerifierSettings;
use rpc::{IpcConfiguration, HttpConfiguration};
use ethcore_rpc::NetworkSettings;
@@ -158,6 +159,7 @@ impl Configuration {
vm_type: vm_type,
check_seal: !self.args.flag_no_seal_check,
with_color: logger_config.color,
verifier_settings: self.verifier_settings(),
};
Cmd::Blockchain(BlockchainCmd::Import(import_cmd))
} else if self.args.cmd_export {
@@ -241,6 +243,8 @@ impl Configuration {
None
};
let verifier_settings = self.verifier_settings();
let run_cmd = RunCmd {
cache_config: cache_config,
dirs: dirs,
@@ -276,6 +280,7 @@ impl Configuration {
check_seal: !self.args.flag_no_seal_check,
download_old_blocks: !self.args.flag_no_ancient_blocks,
serve_light: self.args.flag_serve_light,
verifier_settings: verifier_settings,
};
Cmd::Run(run_cmd)
};
@@ -301,6 +306,7 @@ impl Configuration {
gas_floor_target: try!(to_u256(&self.args.flag_gas_floor_target)),
gas_ceil_target: try!(to_u256(&self.args.flag_gas_cap)),
transactions_limit: self.args.flag_tx_queue_size,
engine_signer: try!(self.engine_signer()),
};
Ok(extras)
@@ -310,6 +316,10 @@ impl Configuration {
to_address(self.args.flag_etherbase.clone().or(self.args.flag_author.clone()))
}
fn engine_signer(&self) -> Result<Address, String> {
to_address(self.args.flag_engine_signer.clone())
}
fn format(&self) -> Result<Option<DataFormat>, String> {
match self.args.flag_format {
Some(ref f) => Ok(Some(try!(f.parse()))),
@@ -703,6 +713,16 @@ impl Configuration {
!ui_disabled
}
fn verifier_settings(&self) -> VerifierSettings {
let mut settings = VerifierSettings::default();
settings.scale_verifiers = self.args.flag_scale_verifiers;
if let Some(num_verifiers) = self.args.flag_num_verifiers {
settings.num_verifiers = num_verifiers;
}
settings
}
}
#[cfg(test)]
@@ -799,6 +819,7 @@ mod tests {
vm_type: VMType::Interpreter,
check_seal: true,
with_color: !cfg!(windows),
verifier_settings: Default::default(),
})));
}
@@ -923,6 +944,7 @@ mod tests {
check_seal: true,
download_old_blocks: true,
serve_light: false,
verifier_settings: Default::default(),
}));
}

View File

@@ -300,14 +300,14 @@ pub fn password_prompt() -> Result<String, String> {
/// Read a password from password file.
pub fn password_from_file(path: String) -> Result<String, String> {
let passwords = try!(passwords_from_files(vec![path]));
let passwords = try!(passwords_from_files(&[path]));
// use only first password from the file
passwords.get(0).map(String::to_owned)
.ok_or_else(|| "Password file seems to be empty.".to_owned())
}
/// Reads passwords from files. Treats each line as a separate password.
pub fn passwords_from_files(files: Vec<String>) -> Result<Vec<String>, String> {
pub fn passwords_from_files(files: &[String]) -> Result<Vec<String>, String> {
let passwords = files.iter().map(|filename| {
let file = try!(File::open(filename).map_err(|_| format!("{} Unable to read password file. Ensure it exists and permissions are correct.", filename)));
let reader = BufReader::new(&file);

View File

@@ -204,6 +204,7 @@ pub struct MinerExtras {
pub gas_floor_target: U256,
pub gas_ceil_target: U256,
pub transactions_limit: usize,
pub engine_signer: Address,
}
impl Default for MinerExtras {
@@ -214,6 +215,7 @@ impl Default for MinerExtras {
gas_floor_target: U256::from(4_700_000),
gas_ceil_target: U256::from(6_283_184),
transactions_limit: 1024,
engine_signer: Default::default(),
}
}
}

View File

@@ -28,6 +28,7 @@ use ethcore::service::ClientService;
use ethcore::account_provider::AccountProvider;
use ethcore::miner::{Miner, MinerService, ExternalMiner, MinerOptions};
use ethcore::snapshot;
use ethcore::verification::queue::VerifierSettings;
use ethsync::SyncConfig;
use informant::Informant;
@@ -93,6 +94,7 @@ pub struct RunCmd {
pub check_seal: bool,
pub download_old_blocks: bool,
pub serve_light: bool,
pub verifier_settings: VerifierSettings,
}
pub fn open_ui(dapps_conf: &dapps::Configuration, signer_conf: &signer::Configuration) -> Result<(), String> {
@@ -212,8 +214,13 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<(), String> {
sync_config.download_old_blocks = cmd.download_old_blocks;
sync_config.serve_light = cmd.serve_light;
let passwords = try!(passwords_from_files(&cmd.acc_conf.password_files));
// prepare account provider
let account_provider = Arc::new(try!(prepare_account_provider(&cmd.dirs, cmd.acc_conf)));
let account_provider = Arc::new(try!(prepare_account_provider(&cmd.dirs, cmd.acc_conf, &passwords)));
// let the Engine access the accounts
spec.engine.register_account_provider(account_provider.clone());
// create miner
let miner = Miner::new(cmd.miner_options, cmd.gas_pricer.into(), &spec, Some(account_provider.clone()));
@@ -222,9 +229,15 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<(), String> {
miner.set_gas_ceil_target(cmd.miner_extras.gas_ceil_target);
miner.set_extra_data(cmd.miner_extras.extra_data);
miner.set_transactions_limit(cmd.miner_extras.transactions_limit);
let engine_signer = cmd.miner_extras.engine_signer;
if engine_signer != Default::default() {
if !passwords.into_iter().any(|p| miner.set_engine_signer(engine_signer, p).is_ok()) {
return Err(format!("No password found for the consensus signer {}. Make sure valid password is present in files passed using `--password`.", engine_signer));
}
}
// create client config
let client_config = to_client_config(
let mut client_config = to_client_config(
&cmd.cache_config,
mode.clone(),
tracing,
@@ -238,6 +251,8 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<(), String> {
cmd.check_seal,
);
client_config.queue.verifier_settings = cmd.verifier_settings;
// set up bootnodes
let mut net_conf = cmd.net_conf;
if !cmd.custom_bootnodes {
@@ -434,19 +449,17 @@ fn daemonize(_pid_file: String) -> Result<(), String> {
Err("daemon is no supported on windows".into())
}
fn prepare_account_provider(dirs: &Directories, cfg: AccountsConfig) -> Result<AccountProvider, String> {
fn prepare_account_provider(dirs: &Directories, cfg: AccountsConfig, passwords: &[String]) -> Result<AccountProvider, String> {
use ethcore::ethstore::EthStore;
use ethcore::ethstore::dir::DiskDirectory;
let passwords = try!(passwords_from_files(cfg.password_files));
let dir = Box::new(try!(DiskDirectory::create(dirs.keys.clone()).map_err(|e| format!("Could not open keys directory: {}", e))));
let account_service = AccountProvider::new(Box::new(
try!(EthStore::open_with_iterations(dir, cfg.iterations).map_err(|e| format!("Could not open keys directory: {}", e)))
));
for a in cfg.unlocked_accounts {
if passwords.iter().find(|p| account_service.unlock_account_permanently(a, (*p).clone()).is_ok()).is_none() {
if !passwords.iter().any(|p| account_service.unlock_account_permanently(a, (*p).clone()).is_ok()) {
return Err(format!("No password found to unlock account {}. Make sure valid password is present in files passed using `--password`.", a));
}
}