Skip to content

Commit

Permalink
Merge pull request #2511 from Conflux-Chain/defaultGasPrice
Browse files Browse the repository at this point in the history
Update RPC default gas_price to 1 Gdrip
  • Loading branch information
Pana authored May 12, 2022
2 parents 48652cb + 72f866f commit 2c824b8
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 11 deletions.
6 changes: 4 additions & 2 deletions client/src/rpc/impls/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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())
}

Expand Down
5 changes: 3 additions & 2 deletions client/src/rpc/impls/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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<U256> {
Expand Down
4 changes: 2 additions & 2 deletions client/src/rpc/impls/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion client/src/rpc/types/call_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions core/parameters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions core/src/consensus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion tests/rpc/test_gas_price.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 2c824b8

Please sign in to comment.