Fixing minimal transaction queue price (#4204)
* Fixing minimal transaction queue price * Fixing tests
This commit is contained in:
@@ -532,22 +532,32 @@ impl Configuration {
|
||||
}
|
||||
|
||||
fn gas_pricer_config(&self) -> Result<GasPricerConfig, String> {
|
||||
fn wei_per_gas(usd_per_tx: f32, usd_per_eth: f32) -> U256 {
|
||||
let wei_per_usd: f32 = 1.0e18 / usd_per_eth;
|
||||
let gas_per_tx: f32 = 21000.0;
|
||||
let wei_per_gas: f32 = wei_per_usd * usd_per_tx / gas_per_tx;
|
||||
U256::from_dec_str(&format!("{:.0}", wei_per_gas)).unwrap()
|
||||
}
|
||||
|
||||
if let Some(d) = self.args.flag_gasprice.as_ref() {
|
||||
return Ok(GasPricerConfig::Fixed(to_u256(d)?));
|
||||
}
|
||||
|
||||
let usd_per_tx = to_price(&self.args.flag_usd_per_tx)?;
|
||||
if "auto" == self.args.flag_usd_per_eth.as_str() {
|
||||
// Just a very rough estimate to avoid accepting
|
||||
// ZGP transactions before the price is fetched
|
||||
// if user does not want it.
|
||||
let last_known_usd_per_eth = 10.0;
|
||||
return Ok(GasPricerConfig::Calibrated {
|
||||
initial_minimum: wei_per_gas(usd_per_tx, last_known_usd_per_eth),
|
||||
usd_per_tx: usd_per_tx,
|
||||
recalibration_period: to_duration(self.args.flag_price_update_period.as_str())?,
|
||||
});
|
||||
}
|
||||
|
||||
let usd_per_eth = to_price(&self.args.flag_usd_per_eth)?;
|
||||
let wei_per_usd: f32 = 1.0e18 / usd_per_eth;
|
||||
let gas_per_tx: f32 = 21000.0;
|
||||
let wei_per_gas: f32 = wei_per_usd * usd_per_tx / gas_per_tx;
|
||||
let wei_per_gas = wei_per_gas(usd_per_tx, usd_per_eth);
|
||||
|
||||
info!(
|
||||
"Using a fixed conversion rate of Ξ1 = {} ({} wei/gas)",
|
||||
@@ -555,7 +565,7 @@ impl Configuration {
|
||||
Colour::Yellow.bold().paint(format!("{}", wei_per_gas))
|
||||
);
|
||||
|
||||
Ok(GasPricerConfig::Fixed(U256::from_dec_str(&format!("{:.0}", wei_per_gas)).unwrap()))
|
||||
Ok(GasPricerConfig::Fixed(wei_per_gas))
|
||||
}
|
||||
|
||||
fn extra_data(&self) -> Result<Bytes, String> {
|
||||
|
||||
@@ -192,14 +192,25 @@ impl Default for AccountsConfig {
|
||||
pub enum GasPricerConfig {
|
||||
Fixed(U256),
|
||||
Calibrated {
|
||||
initial_minimum: U256,
|
||||
usd_per_tx: f32,
|
||||
recalibration_period: Duration,
|
||||
}
|
||||
}
|
||||
|
||||
impl GasPricerConfig {
|
||||
pub fn initial_min(&self) -> U256 {
|
||||
match *self {
|
||||
GasPricerConfig::Fixed(ref min) => min.clone(),
|
||||
GasPricerConfig::Calibrated { ref initial_minimum, .. } => initial_minimum.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for GasPricerConfig {
|
||||
fn default() -> Self {
|
||||
GasPricerConfig::Calibrated {
|
||||
initial_minimum: 11904761856u64.into(),
|
||||
usd_per_tx: 0.0025f32,
|
||||
recalibration_period: Duration::from_secs(3600),
|
||||
}
|
||||
@@ -210,7 +221,7 @@ impl Into<GasPricer> for GasPricerConfig {
|
||||
fn into(self) -> GasPricer {
|
||||
match self {
|
||||
GasPricerConfig::Fixed(u) => GasPricer::Fixed(u),
|
||||
GasPricerConfig::Calibrated { usd_per_tx, recalibration_period } => {
|
||||
GasPricerConfig::Calibrated { usd_per_tx, recalibration_period, .. } => {
|
||||
GasPricer::new_calibrated(GasPriceCalibratorOptions {
|
||||
usd_per_tx: usd_per_tx,
|
||||
recalibration_period: recalibration_period,
|
||||
|
||||
@@ -236,12 +236,15 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
|
||||
spec.engine.register_account_provider(account_provider.clone());
|
||||
|
||||
// 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()));
|
||||
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);
|
||||
miner.set_extra_data(cmd.miner_extras.extra_data);
|
||||
miner.set_transactions_limit(cmd.miner_extras.transactions_limit);
|
||||
miner.set_minimal_gas_price(initial_min_gas_price);
|
||||
miner.recalibrate_minimal_gas_price();
|
||||
let engine_signer = cmd.miner_extras.engine_signer;
|
||||
|
||||
if engine_signer != Default::default() {
|
||||
|
||||
Reference in New Issue
Block a user