Skip to content

Commit

Permalink
Merge branch 'master' into v2.0-testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
peilun-conflux committed May 13, 2022
2 parents 1cb0a26 + 2c824b8 commit 9c9d86c
Show file tree
Hide file tree
Showing 28 changed files with 359 additions and 286 deletions.
16 changes: 16 additions & 0 deletions changelogs/CHANGELOG-2.0.x.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
# 2.0.3

# 2.0.2

## Improvements

### RPC Improvements
- Improve the performance of `eth_getLogs`.
- Add a new RPC `eth_getAccountPendingTransactions` to get pending transactions by address, also return the first pending transaction's pending reason
- Support WebSockets for eth APIs
- Support block hash param for `eth_call` (EIP1898)
- `cfx_call`, `cfx_estimateGasAndCollateral`, `eth_call`, and `eth_estimate` will respect `from`'s balance if passed, if balance is not enough will return error. If from is not passed then use a random one, which's balance will be very big.

### Transaction Pool Improvements
- Set the minimum gas price to 1 GDrip by default for packing transaction

### Storage Improvement
- Improve the snapshot copy-on-write merging performance on XFS file systems.

## Bug Fixes
- Fix trace validity for transactions reverted in the top checkpoint.
- Fix phantom trace length mismatch issue with failed transactions.
- Fix a possible underflow crash in `eth_estimateGas`.

# 2.0.1

Expand Down
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 @@ -108,6 +108,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
3 changes: 2 additions & 1 deletion core/src/executive/internal_contract/components/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{
vm::{self, ActionParams, Env, Spec},
};
use cfx_state::{state_trait::StateOpsTrait, SubstateTrait};
use cfx_statedb::Result as DbResult;
use cfx_types::{
address_util::AddressUtil, Address, AddressSpaceUtil, H256, U256,
};
Expand Down Expand Up @@ -64,7 +65,7 @@ impl<'a> InternalRefContext<'a> {

pub fn storage_at(
&mut self, params: &ActionParams, key: &[u8],
) -> vm::Result<U256> {
) -> DbResult<U256> {
let receiver = params.address.with_space(params.space);
self.substate
.storage_at(self.state, &receiver, key)
Expand Down
2 changes: 1 addition & 1 deletion core/src/executive/internal_contract/contracts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub(super) mod params_control;
pub(super) mod pos;
mod sponsor;
mod staking;
mod system_storage;
pub(super) mod system_storage;

mod preludes {
pub use keccak_hash::keccak;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// See http://www.gnu.org/licenses/

use cfx_parameters::internal_contract_addresses::PARAMS_CONTROL_CONTRACT_ADDRESS;
use cfx_statedb::params_control_entries::OPTION_INDEX_MAX;
use cfx_types::{Address, U256};
use solidity_abi_derive::ABIVariable;

Expand Down Expand Up @@ -60,3 +59,12 @@ fn test_vote_abi_length() {
use solidity_abi::ABIVariable;
assert_eq!(Vote::STATIC_LENGTH, Some(32 * (1 + OPTION_INDEX_MAX)));
}

pub const POW_BASE_REWARD_INDEX: u8 = 0;
pub const POS_REWARD_INTEREST_RATE_INDEX: u8 = 1;
pub const PARAMETER_INDEX_MAX: usize = 2;

pub const OPTION_UNCHANGE_INDEX: u8 = 0;
pub const OPTION_INCREASE_INDEX: u8 = 1;
pub const OPTION_DECREASE_INDEX: u8 = 2;
pub const OPTION_INDEX_MAX: usize = 3;
4 changes: 2 additions & 2 deletions core/src/executive/internal_contract/contracts/pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl SimpleExecutionTrait for IdentifierToAddress {
context: &mut InternalRefContext, _tracer: &mut dyn VmObserve,
) -> vm::Result<Address>
{
identifier_to_address(inputs, params, context)
Ok(identifier_to_address(inputs, params, context)?)
}
}

Expand All @@ -201,7 +201,7 @@ impl SimpleExecutionTrait for AddressToIdentifier {
context: &mut InternalRefContext, _tracer: &mut dyn VmObserve,
) -> vm::Result<H256>
{
address_to_identifier(inputs, params, context)
Ok(address_to_identifier(inputs, params, context)?)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

use super::preludes::*;
use cfx_parameters::internal_contract_addresses::SYSTEM_STORAGE_ADDRESS;
use cfx_types::U256;

make_solidity_contract! {
pub struct SystemStorage(SYSTEM_STORAGE_ADDRESS, SolFnTable::default, initialize: |params: &CommonParams| params.transition_numbers.cip94, is_active: |spec: &Spec| spec.cip94);
}

pub fn base_slot(contract: Address) -> U256 {
let hash = keccak(H256::from(contract).as_ref());
U256::from_big_endian(hash.as_ref())
}
11 changes: 6 additions & 5 deletions core/src/executive/internal_contract/impls/cross_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
CreateContractAddress, GasLeft, MessageCallResult, ReturnData,
},
executive::{contract_address, executive::gas_required_for},
internal_bail,
observer::{AddressPocket, VmObserve},
state::cleanup_mode,
vm::{
Expand Down Expand Up @@ -284,7 +285,7 @@ pub fn call_to_evmcore(
) -> Result<ExecTrap, vm::Error>
{
if context.depth >= context.spec.max_depth {
return Err(vm::Error::InternalContract("Exceed Depth".into()));
internal_bail!("Exceed Depth");
}

let value = params.value.value();
Expand Down Expand Up @@ -365,7 +366,7 @@ pub fn create_to_evmcore(
) -> Result<ExecTrap, vm::Error>
{
if context.depth >= context.spec.max_depth {
return Err(vm::Error::InternalContract("Exceed Depth".into()));
internal_bail!("Exceed Depth");
}

let call_gas = gas_left / CROSS_SPACE_GAS_RATIO
Expand Down Expand Up @@ -456,9 +457,9 @@ pub fn withdraw_from_evmcore(
let mapped_address = evm_map(sender);
let balance = context.state.balance(&mapped_address)?;
if balance < value {
return Err(vm::Error::InternalContract(
"Not enough balance for withdrawing from mapped address".into(),
));
internal_bail!(
"Not enough balance for withdrawing from mapped address"
);
}
context.state.transfer_balance(
&mapped_address,
Expand Down
Loading

0 comments on commit 9c9d86c

Please sign in to comment.