From 72f866f68beec9ba52336ff740fba410896aaff0 Mon Sep 17 00:00:00 2001 From: PanaW Date: Thu, 12 May 2022 11:46:06 +0800 Subject: [PATCH] update default gas_price to 1 Gdrip --- client/src/rpc/impls/common.rs | 6 ++++-- client/src/rpc/impls/eth.rs | 5 +++-- client/src/rpc/impls/light.rs | 4 ++-- client/src/rpc/types/call_request.rs | 3 ++- core/parameters/src/lib.rs | 1 + core/src/consensus/mod.rs | 7 ++++--- tests/rpc/test_gas_price.py | 2 +- 7 files changed, 17 insertions(+), 11 deletions(-) diff --git a/client/src/rpc/impls/common.rs b/client/src/rpc/impls/common.rs index bee5e553bf..bc041308e2 100644 --- a/client/src/rpc/impls/common.rs +++ b/client/src/rpc/impls/common.rs @@ -33,7 +33,9 @@ use parking_lot::{Condvar, Mutex}; use crate::rpc::types::pos::{Block as RpcPosBlock, Decision}; use cfx_addr::Network; -use cfx_parameters::staking::DRIPS_PER_STORAGE_COLLATERAL_UNIT; +use cfx_parameters::{ + rpc::GAS_PRICE_DEFAULT_VALUE, staking::DRIPS_PER_STORAGE_COLLATERAL_UNIT, +}; use cfx_types::{ Address, AddressSpaceUtil, Space, H160, H256, H520, U128, U256, U512, U64, }; @@ -206,7 +208,7 @@ impl RpcImpl { info!("RPC Request: cfx_gasPrice()"); Ok(consensus_graph .gas_price(Space::Native) - .unwrap_or(cfxcore::consensus_parameters::ONE_GDRIP_IN_DRIP.into()) + .unwrap_or(GAS_PRICE_DEFAULT_VALUE.into()) .into()) } diff --git a/client/src/rpc/impls/eth.rs b/client/src/rpc/impls/eth.rs index 0ea042fa4c..abef9d7f86 100644 --- a/client/src/rpc/impls/eth.rs +++ b/client/src/rpc/impls/eth.rs @@ -18,6 +18,7 @@ use crate::rpc::{ Bytes, Index, MAX_GAS_CALL_REQUEST, }, }; +use cfx_parameters::rpc::GAS_PRICE_DEFAULT_VALUE; use cfx_statedb::StateDbExt; use cfx_types::{ Address, AddressSpaceUtil, BigEndianHash, Space, H160, H256, U256, U64, @@ -84,7 +85,7 @@ pub fn sign_call( nonce: request.nonce.unwrap_or_default(), action: request.to.map_or(Action::Create, |addr| Action::Call(addr)), gas, - gas_price: request.gas_price.unwrap_or(1.into()), + gas_price: request.gas_price.unwrap_or(GAS_PRICE_DEFAULT_VALUE.into()), value: request.value.unwrap_or_default(), chain_id: Some(chain_id), data: request.data.unwrap_or_default().into_vec(), @@ -367,7 +368,7 @@ impl Eth for EthHandler { Ok(self .consensus_graph() .gas_price(Space::Ethereum) - .unwrap_or(5000000000u64.into())) + .unwrap_or(GAS_PRICE_DEFAULT_VALUE.into())) } fn max_priority_fee_per_gas(&self) -> jsonrpc_core::Result { diff --git a/client/src/rpc/impls/light.rs b/client/src/rpc/impls/light.rs index 6f0de1a7a9..99e98d2878 100644 --- a/client/src/rpc/impls/light.rs +++ b/client/src/rpc/impls/light.rs @@ -8,7 +8,6 @@ use cfx_types::{ }; use cfxcore::{ block_data_manager::BlockDataManager, - consensus_parameters::ONE_GDRIP_IN_DRIP, light_protocol::{ self, query_service::TxInfo, Error as LightError, ErrorKind, }, @@ -54,6 +53,7 @@ use crate::{ }, }; use cfx_addr::Network; +use cfx_parameters::rpc::GAS_PRICE_DEFAULT_VALUE; use cfxcore::{ light_protocol::QueryService, rpc_errors::ErrorKind::LightProtocol, }; @@ -929,7 +929,7 @@ impl RpcImpl { .await .map_err(|e| e.to_string()) .map_err(RpcError::invalid_params)? - .unwrap_or(ONE_GDRIP_IN_DRIP.into())) + .unwrap_or(GAS_PRICE_DEFAULT_VALUE.into())) }; Box::new(fut.boxed().compat()) diff --git a/client/src/rpc/types/call_request.rs b/client/src/rpc/types/call_request.rs index 8ce68194fe..9d2c02a7e2 100644 --- a/client/src/rpc/types/call_request.rs +++ b/client/src/rpc/types/call_request.rs @@ -11,6 +11,7 @@ use crate::rpc::{ RpcResult, }; use cfx_addr::Network; +use cfx_parameters::rpc::GAS_PRICE_DEFAULT_VALUE; use cfx_types::{Address, AddressSpaceUtil, U256, U64}; use cfxcore::rpc_errors::invalid_params_check; use cfxcore_accounts::AccountProvider; @@ -156,7 +157,7 @@ pub fn sign_call( Action::Call(rpc_addr.hex_address) }), gas, - gas_price: request.gas_price.unwrap_or(1.into()), + gas_price: request.gas_price.unwrap_or(GAS_PRICE_DEFAULT_VALUE.into()), value: request.value.unwrap_or_default(), storage_limit: request .storage_limit diff --git a/core/parameters/src/lib.rs b/core/parameters/src/lib.rs index 5e58a4c319..bbac40e468 100644 --- a/core/parameters/src/lib.rs +++ b/core/parameters/src/lib.rs @@ -109,6 +109,7 @@ pub mod rpc { pub const EVM_GAS_PRICE_TRANSACTION_SAMPLE_SIZE: usize = 1000; pub const TRANSACTION_COUNT_PER_BLOCK_WATER_LINE_LOW: usize = 100; pub const TRANSACTION_COUNT_PER_BLOCK_WATER_LINE_MEDIUM: usize = 600; + pub const GAS_PRICE_DEFAULT_VALUE: usize = 1_000_000_000; } pub mod sync { diff --git a/core/src/consensus/mod.rs b/core/src/consensus/mod.rs index e9a0c52dde..e85cf031c4 100644 --- a/core/src/consensus/mod.rs +++ b/core/src/consensus/mod.rs @@ -52,7 +52,8 @@ use cfx_parameters::{ consensus_internal::REWARD_EPOCH_COUNT, rpc::{ EVM_GAS_PRICE_BLOCK_SAMPLE_SIZE, EVM_GAS_PRICE_TRANSACTION_SAMPLE_SIZE, - GAS_PRICE_BLOCK_SAMPLE_SIZE, GAS_PRICE_TRANSACTION_SAMPLE_SIZE, + GAS_PRICE_BLOCK_SAMPLE_SIZE, GAS_PRICE_DEFAULT_VALUE, + GAS_PRICE_TRANSACTION_SAMPLE_SIZE, }, }; use cfx_state::state_trait::StateOpsTrait; @@ -584,13 +585,13 @@ impl ConsensusGraph { prices.sort(); if prices.is_empty() || total_tx_gas_limit == 0 { - Some(U256::from(1)) + Some(U256::from(GAS_PRICE_DEFAULT_VALUE)) } else { let average_gas_limit_multiple = total_block_gas_limit / total_tx_gas_limit; if average_gas_limit_multiple > 5 { // used less than 20% - Some(U256::from(1)) + Some(U256::from(GAS_PRICE_DEFAULT_VALUE)) } else if average_gas_limit_multiple >= 2 { // used less than 50% Some(prices[prices.len() / 8]) diff --git a/tests/rpc/test_gas_price.py b/tests/rpc/test_gas_price.py index 0a33abae2b..d672f13006 100644 --- a/tests/rpc/test_gas_price.py +++ b/tests/rpc/test_gas_price.py @@ -41,5 +41,5 @@ def test_median_prices(self): self.wait_for_receipt(tx, 1, 10, False) # median of prices - assert_equal(self.gas_price(), 1) + assert_equal(self.gas_price(), 1000000000)