Replace dev chain special case with preset

Add --min-gas-price (does the same as legacy --gasprice) and tweak
gas_pricer_config() and test cases.  Dev preset will still be
overridden by CLI arguments, including --gasprice.
This commit is contained in:
Joseph Mark 2017-07-13 19:25:41 +07:00
parent 451ef7f09b
commit e0b15116a5
No known key found for this signature in database
GPG Key ID: 9BA8D1EE2E53C283
6 changed files with 27 additions and 16 deletions

View File

@ -101,6 +101,7 @@ reseal_min_period = 4000
reseal_max_period = 60000 reseal_max_period = 60000
work_queue_size = 20 work_queue_size = 20
relay_set = "cheap" relay_set = "cheap"
min_gas_price = ""
usd_per_tx = "0.0025" usd_per_tx = "0.0025"
usd_per_eth = "auto" usd_per_eth = "auto"
price_update_period = "hourly" price_update_period = "hourly"

View File

@ -269,6 +269,8 @@ usage! {
or |c: &Config| otry!(c.mining).tx_time_limit.clone().map(Some), or |c: &Config| otry!(c.mining).tx_time_limit.clone().map(Some),
flag_relay_set: String = "cheap", flag_relay_set: String = "cheap",
or |c: &Config| otry!(c.mining).relay_set.clone(), or |c: &Config| otry!(c.mining).relay_set.clone(),
flag_min_gas_price: Option<String> = None,
or |c: &Config| otry!(c.mining).min_gas_price.clone().map(Some),
flag_usd_per_tx: String = "0.0025", flag_usd_per_tx: String = "0.0025",
or |c: &Config| otry!(c.mining).usd_per_tx.clone(), or |c: &Config| otry!(c.mining).usd_per_tx.clone(),
flag_usd_per_eth: String = "auto", flag_usd_per_eth: String = "auto",
@ -542,6 +544,7 @@ struct Mining {
tx_gas_limit: Option<String>, tx_gas_limit: Option<String>,
tx_time_limit: Option<u64>, tx_time_limit: Option<u64>,
relay_set: Option<String>, relay_set: Option<String>,
min_gas_price: Option<String>,
usd_per_tx: Option<String>, usd_per_tx: Option<String>,
usd_per_eth: Option<String>, usd_per_eth: Option<String>,
price_update_period: Option<String>, price_update_period: Option<String>,
@ -808,6 +811,7 @@ mod tests {
flag_tx_gas_limit: Some("6283184".into()), flag_tx_gas_limit: Some("6283184".into()),
flag_tx_time_limit: Some(100u64), flag_tx_time_limit: Some(100u64),
flag_relay_set: "cheap".into(), flag_relay_set: "cheap".into(),
flag_min_gas_price: Some("".into()),
flag_usd_per_tx: "0.0025".into(), flag_usd_per_tx: "0.0025".into(),
flag_usd_per_eth: "auto".into(), flag_usd_per_eth: "auto".into(),
flag_price_update_period: "hourly".into(), flag_price_update_period: "hourly".into(),
@ -1035,6 +1039,7 @@ mod tests {
reseal_max_period: Some(60000), reseal_max_period: Some(60000),
work_queue_size: None, work_queue_size: None,
relay_set: None, relay_set: None,
min_gas_price: None,
usd_per_tx: None, usd_per_tx: None,
usd_per_eth: None, usd_per_eth: None,
price_update_period: Some("hourly".into()), price_update_period: Some("hourly".into()),

View File

@ -0,0 +1,6 @@
[parity]
chain = "dev"
[mining]
reseal_min_period = 0
min_gas_price = "0"

View File

@ -16,8 +16,7 @@
pub fn preset_config_string(arg: &str) -> Result<&'static str, &str> { pub fn preset_config_string(arg: &str) -> Result<&'static str, &str> {
match arg.to_lowercase().as_ref() { match arg.to_lowercase().as_ref() {
"poa" => Ok(include_str!("./config.poa.toml")), "dev" => Ok(include_str!("./config.dev.toml")),
"pow" => Ok(include_str!("./config.pow.toml")),
_ => Err(arg.clone()) _ => Err(arg.clone())
} }
} }

View File

@ -295,6 +295,10 @@ Sealing/Mining Options:
means we relay nothing if not mining); means we relay nothing if not mining);
lenient - Same as strict when mining, and cheap lenient - Same as strict when mining, and cheap
when not (default: {flag_relay_set}). when not (default: {flag_relay_set}).
--min-gas-price STRING Minimum amount of Wei per GAS to be paid for a
transaction to be accepted for mining. Overrides
--basic-tx-usd.
(default: {flag_min_gas_price:?})
--usd-per-tx USD Amount of USD to be paid for a basic transaction --usd-per-tx USD Amount of USD to be paid for a basic transaction
(default: {flag_usd_per_tx}). The minimum gas price is set (default: {flag_usd_per_tx}). The minimum gas price is set
accordingly. accordingly.

View File

@ -36,7 +36,7 @@ use parity_rpc::NetworkSettings;
use cache::CacheConfig; use cache::CacheConfig;
use helpers::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_price, replace_home, replace_home_and_local, use helpers::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_price, replace_home, replace_home_and_local,
geth_ipc_path, parity_ipc_path, to_bootnodes, to_addresses, to_address, to_gas_limit, to_queue_strategy}; geth_ipc_path, parity_ipc_path, to_bootnodes, to_addresses, to_address, to_gas_limit, to_queue_strategy};
use params::{SpecType, ResealPolicy, AccountsConfig, GasPricerConfig, MinerExtras, Pruning, Switch}; use params::{ResealPolicy, AccountsConfig, GasPricerConfig, MinerExtras, Pruning, Switch};
use ethcore_logger::Config as LogConfig; use ethcore_logger::Config as LogConfig;
use dir::{self, Directories, default_hypervisor_path, default_local_path, default_data_path}; use dir::{self, Directories, default_hypervisor_path, default_local_path, default_data_path};
use dapps::Configuration as DappsConfiguration; use dapps::Configuration as DappsConfiguration;
@ -332,12 +332,6 @@ impl Configuration {
let verifier_settings = self.verifier_settings(); let verifier_settings = self.verifier_settings();
// Special presets are present for the dev chain.
let (gas_pricer, miner_options) = match spec {
SpecType::Dev => (GasPricerConfig::Fixed(0.into()), self.miner_options(0)?),
_ => (self.gas_pricer_config()?, self.miner_options(self.args.flag_reseal_min_period)?),
};
let run_cmd = RunCmd { let run_cmd = RunCmd {
cache_config: cache_config, cache_config: cache_config,
dirs: dirs, dirs: dirs,
@ -347,14 +341,14 @@ impl Configuration {
pruning_memory: self.args.flag_pruning_memory, pruning_memory: self.args.flag_pruning_memory,
daemon: daemon, daemon: daemon,
logger_config: logger_config.clone(), logger_config: logger_config.clone(),
miner_options: miner_options, miner_options: self.miner_options(self.args.flag_reseal_min_period)?,
ws_conf: ws_conf, ws_conf: ws_conf,
http_conf: http_conf, http_conf: http_conf,
ipc_conf: ipc_conf, ipc_conf: ipc_conf,
net_conf: net_conf, net_conf: net_conf,
network_id: network_id, network_id: network_id,
acc_conf: self.accounts_config()?, acc_conf: self.accounts_config()?,
gas_pricer: gas_pricer, gas_pricer: self.gas_pricer_config()?,
miner_extras: self.miner_extras()?, miner_extras: self.miner_extras()?,
stratum: self.stratum_options()?, stratum: self.stratum_options()?,
update_policy: update_policy, update_policy: update_policy,
@ -625,8 +619,10 @@ impl Configuration {
U256::from_dec_str(&format!("{:.0}", wei_per_gas)).unwrap() U256::from_dec_str(&format!("{:.0}", wei_per_gas)).unwrap()
} }
if let Some(d) = self.args.flag_gasprice.as_ref() { if let Some(dec) = self.args.flag_gasprice.as_ref() {
return Ok(GasPricerConfig::Fixed(to_u256(d)?)); return Ok(GasPricerConfig::Fixed(to_u256(dec)?));
} else if let Some(dec) = self.args.flag_min_gas_price.as_ref() {
return Ok(GasPricerConfig::Fixed(to_u256(dec)?));
} }
let usd_per_tx = to_price(&self.args.flag_usd_per_tx)?; let usd_per_tx = to_price(&self.args.flag_usd_per_tx)?;
@ -1586,9 +1582,9 @@ mod tests {
} }
#[test] #[test]
fn test_dev_chain() { fn test_dev_preset() {
let args = vec!["parity", "--chain", "dev"]; let args = vec!["parity", "preset", "dev"];
let conf = parse(&args); let conf = Configuration::parse(&args, None).unwrap();
match conf.into_command().unwrap().cmd { match conf.into_command().unwrap().cmd {
Cmd::Run(c) => { Cmd::Run(c) => {
assert_eq!(c.gas_pricer, GasPricerConfig::Fixed(0.into())); assert_eq!(c.gas_pricer, GasPricerConfig::Fixed(0.into()));