Refactor price_info (#6003)
* refactor PriceInfo to use Fetch and reuse the client * forget Fetch future to keep it running in the background * update Debug message for price_info::Client * wrap underlying errors in price_info client * use debug_struct in price_info client debug implementation * use global fetch service in price_info client * rename gas_pricer parameter in RunCmd * move price_info to its own crate * fix price_info tests * replace rustc_serialize with serde_json in price_info * add documentation for price_info * remove unused rustc-serialize dependency from ethcore * fix price_info formatting * re-export fetch crate in price_info * remove unused cfg attributes in price_info * add tests for price_info
This commit is contained in:
@@ -333,7 +333,7 @@ impl Configuration {
|
||||
let verifier_settings = self.verifier_settings();
|
||||
|
||||
// Special presets are present for the dev chain.
|
||||
let (gas_pricer, miner_options) = match spec {
|
||||
let (gas_pricer_conf, 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)?),
|
||||
};
|
||||
@@ -356,7 +356,7 @@ impl Configuration {
|
||||
net_conf: net_conf,
|
||||
network_id: network_id,
|
||||
acc_conf: self.accounts_config()?,
|
||||
gas_pricer: gas_pricer,
|
||||
gas_pricer_conf: gas_pricer_conf,
|
||||
miner_extras: self.miner_extras()?,
|
||||
stratum: self.stratum_options()?,
|
||||
update_policy: update_policy,
|
||||
@@ -1309,7 +1309,7 @@ mod tests {
|
||||
public_node: false,
|
||||
warp_sync: true,
|
||||
acc_conf: Default::default(),
|
||||
gas_pricer: Default::default(),
|
||||
gas_pricer_conf: Default::default(),
|
||||
miner_extras: Default::default(),
|
||||
update_policy: UpdatePolicy { enable_downloading: true, require_consensus: true, filter: UpdateFilter::Critical, track: ReleaseTrack::Unknown, path: default_hypervisor_path() },
|
||||
mode: Default::default(),
|
||||
@@ -1604,7 +1604,7 @@ mod tests {
|
||||
let conf = parse(&args);
|
||||
match conf.into_command().unwrap().cmd {
|
||||
Cmd::Run(c) => {
|
||||
assert_eq!(c.gas_pricer, GasPricerConfig::Fixed(0.into()));
|
||||
assert_eq!(c.gas_pricer_conf, GasPricerConfig::Fixed(0.into()));
|
||||
assert_eq!(c.miner_options.reseal_min_period, Duration::from_millis(0));
|
||||
},
|
||||
_ => panic!("Should be Cmd::Run"),
|
||||
|
||||
@@ -366,4 +366,3 @@ fn main() {
|
||||
process::exit(main_direct(can_restart));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ use ethcore::spec::Spec;
|
||||
use ethcore::ethereum;
|
||||
use ethcore::client::Mode;
|
||||
use ethcore::miner::{GasPricer, GasPriceCalibratorOptions};
|
||||
use hash_fetch::fetch::Client as FetchClient;
|
||||
use user_defaults::UserDefaults;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@@ -226,15 +227,18 @@ impl Default for GasPricerConfig {
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<GasPricer> for GasPricerConfig {
|
||||
fn into(self) -> GasPricer {
|
||||
match self {
|
||||
impl GasPricerConfig {
|
||||
pub fn to_gas_pricer(&self, fetch: FetchClient) -> GasPricer {
|
||||
match *self {
|
||||
GasPricerConfig::Fixed(u) => GasPricer::Fixed(u),
|
||||
GasPricerConfig::Calibrated { usd_per_tx, recalibration_period, .. } => {
|
||||
GasPricer::new_calibrated(GasPriceCalibratorOptions {
|
||||
usd_per_tx: usd_per_tx,
|
||||
recalibration_period: recalibration_period,
|
||||
})
|
||||
GasPricer::new_calibrated(
|
||||
GasPriceCalibratorOptions {
|
||||
usd_per_tx: usd_per_tx,
|
||||
recalibration_period: recalibration_period,
|
||||
},
|
||||
fetch
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ pub struct RunCmd {
|
||||
pub warp_sync: bool,
|
||||
pub public_node: bool,
|
||||
pub acc_conf: AccountsConfig,
|
||||
pub gas_pricer: GasPricerConfig,
|
||||
pub gas_pricer_conf: GasPricerConfig,
|
||||
pub miner_extras: MinerExtras,
|
||||
pub update_policy: UpdatePolicy,
|
||||
pub mode: Option<Mode>,
|
||||
@@ -480,9 +480,12 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
|
||||
// prepare account provider
|
||||
let account_provider = Arc::new(prepare_account_provider(&cmd.spec, &cmd.dirs, &spec.data_dir, cmd.acc_conf, &passwords)?);
|
||||
|
||||
// fetch service
|
||||
let fetch = FetchClient::new().map_err(|e| format!("Error starting fetch client: {:?}", e))?;
|
||||
|
||||
// create miner
|
||||
let initial_min_gas_price = cmd.gas_pricer.initial_min();
|
||||
let miner = Miner::new(cmd.miner_options, cmd.gas_pricer.into(), &spec, Some(account_provider.clone()));
|
||||
let initial_min_gas_price = cmd.gas_pricer_conf.initial_min();
|
||||
let miner = Miner::new(cmd.miner_options, cmd.gas_pricer_conf.to_gas_pricer(fetch.clone()), &spec, Some(account_provider.clone()));
|
||||
miner.set_author(cmd.miner_extras.author);
|
||||
miner.set_gas_floor_target(cmd.miner_extras.gas_floor_target);
|
||||
miner.set_gas_ceil_target(cmd.miner_extras.gas_ceil_target);
|
||||
@@ -637,9 +640,6 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
|
||||
// spin up event loop
|
||||
let event_loop = EventLoop::spawn();
|
||||
|
||||
// fetch service
|
||||
let fetch = FetchClient::new().map_err(|e| format!("Error starting fetch client: {:?}", e))?;
|
||||
|
||||
// the updater service
|
||||
let updater = Updater::new(
|
||||
Arc::downgrade(&(service.client() as Arc<BlockChainClient>)),
|
||||
|
||||
Reference in New Issue
Block a user