Skip to content

Commit

Permalink
Merge branch 'master' into v2.0-stable
Browse files Browse the repository at this point in the history
  • Loading branch information
peilun-conflux committed Jul 1, 2022
2 parents bd62bea + 189f8a0 commit 302c382
Show file tree
Hide file tree
Showing 34 changed files with 690 additions and 120 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ target
**/*.rs.bk
**/__pycache__
.idea/
.vscode/
.git/
.gitmodules
.phabricator*
Expand Down
13 changes: 9 additions & 4 deletions client/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,10 +888,7 @@ impl Configuration {
conf.additional_maintained_trace_epoch_count = Some(0);
}
}
if conf
.additional_maintained_transaction_index_epoch_count
.is_some()
{
if conf.additional_maintained_transaction_index_epoch_count != Some(0) {
conf.persist_tx_index = true;
}
conf
Expand Down Expand Up @@ -1152,6 +1149,14 @@ impl Configuration {
.raw_conf
.dao_vote_transition_number
.unwrap_or(non_genesis_default_transition_time);
params.transition_numbers.cip97 = self
.raw_conf
.dao_vote_transition_number
.unwrap_or(default_transition_time);
params.transition_numbers.cip98 = self
.raw_conf
.dao_vote_transition_number
.unwrap_or(default_transition_time);
if self.is_test_or_dev_mode() {
params.transition_numbers.cip43b =
self.raw_conf.cip43_init_end_number.unwrap_or(u64::MAX);
Expand Down
18 changes: 8 additions & 10 deletions client/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ use crate::{
rpc_apis::{Api, ApiSet},
},
};
use jsonrpc_core::futures::{future::poll_fn, Async, Future};
use futures01::lazy;
use jsonrpc_core::futures::Future;
use lazy_static::lazy_static;
pub use metadata::Metadata;
use metrics::{register_timer_with_group, ScopeTimer, Timer};
Expand Down Expand Up @@ -596,14 +597,11 @@ impl RpcInterceptor for MetricsInterceptor {
.lock()
.get(name)
.map(|timer| timer.clone());
let f = move || {
Ok(Async::Ready(
maybe_timer
.as_ref()
.map(|timer| ScopeTimer::time_scope(timer.clone())),
))
};
let setup = poll_fn(f);
Box::new(setup.and_then(|_timer| method_call))
let setup = lazy(move || {
Ok(maybe_timer
.as_ref()
.map(|timer| ScopeTimer::time_scope(timer.clone())))
});
Box::new(setup.then(|_timer: Result<_, ()>| method_call))
}
}
13 changes: 6 additions & 7 deletions client/src/rpc/interceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Conflux is free software and distributed under GNU General Public License.
// See http://www.gnu.org/licenses/

use futures01::{future::poll_fn, Async, Future};
use futures01::{lazy, Future};
use jsonrpc_core::{
BoxFuture, Metadata, Params, RemoteProcedure, Result as RpcResult,
RpcMethod,
Expand Down Expand Up @@ -110,14 +110,13 @@ where
fn call(&self, params: Params, meta: M) -> BoxFuture<Value> {
let name = self.name.clone();
let interceptor = self.interceptor.clone();
let before_future = poll_fn(move || {
interceptor.before(&name).map(|_| Async::Ready(()))
});
let before_future = lazy(move || interceptor.before(&name));

let method = self.method.clone();
let method_call = self
.interceptor
.around(&self.name, method.call(params, meta));
let method_call = self.interceptor.around(
&self.name,
lazy(move || method.call(params, meta)).boxed(),
);
let method_future = before_future.and_then(move |_| method_call);

Box::new(method_future)
Expand Down
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ criterion = "0.3"
cfx-storage = { path = "storage", features = ["testonly_code"] }
proptest = "1.0.0"
proptest-derive = "0.3.0"
consensus-types = { path = "./src/pos/consensus/consensus-types", features = ["fuzzing"] }
#tokio = { version = "0.2.11", features = ["time"] }

[dependencies.parity-util-mem]
Expand Down
10 changes: 10 additions & 0 deletions core/src/executive/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ impl<
}

fn blockhash(&mut self, number: &U256) -> H256 {
if self.local_part.space == Space::Ethereum
&& self.local_part.spec.cip98
{
return if U256::from(self.env().epoch_height) == number + 1 {
self.env().last_hash.clone()
} else {
H256::default()
};
}

// In Conflux, we only maintain the block hash of the previous block.
// For other block numbers, it always returns zero.
if U256::from(self.env().number) == number + 1 {
Expand Down
5 changes: 4 additions & 1 deletion core/src/executive/executive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,15 @@ impl EstimateRequest {
pub struct TransactCheckSettings {
pub charge_collateral: ChargeCollateral,
pub charge_gas: bool,
pub real_execution: bool,
}

impl TransactCheckSettings {
fn all_checks() -> Self {
Self {
charge_collateral: ChargeCollateral::Normal,
charge_gas: true,
real_execution: true,
}
}

Expand All @@ -263,6 +265,7 @@ impl TransactCheckSettings {
Self {
charge_collateral,
charge_gas: request.charge_gas(),
real_execution: false,
}
}
}
Expand Down Expand Up @@ -1517,7 +1520,7 @@ impl<
// We don't want to bump nonce for non-existent account when we
// can't charge gas fee. In this case, the sender account will
// not be created if it does not exist.
if !self.state.exists(&sender)? {
if !self.state.exists(&sender)? && check_settings.real_execution {
return Ok(ExecutionOutcome::NotExecutedToReconsiderPacking(
ToRepackError::SenderDoesNotExist,
));
Expand Down
70 changes: 64 additions & 6 deletions core/src/executive/internal_contract/contracts/params_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,46 @@ use cfx_parameters::internal_contract_addresses::PARAMS_CONTROL_CONTRACT_ADDRESS
use cfx_types::{Address, U256};
use solidity_abi_derive::ABIVariable;

use crate::evm::GasPriceTier;

use super::{super::impls::params_control::*, preludes::*};

make_solidity_contract! {
pub struct ParamsControl(PARAMS_CONTROL_CONTRACT_ADDRESS, generate_fn_table, initialize: |params: &CommonParams| params.transition_numbers.cip94, is_active: |spec: &Spec| spec.cip94);
}
fn generate_fn_table() -> SolFnTable {
make_function_table!(CastVote, ReadVote)
make_function_table!(CastVote, ReadVote, CurrentRound, TotalVotes)
}
group_impl_is_active!(
|spec: &Spec| spec.cip94,
CastVote,
ReadVote,
CurrentRound,
TotalVotes
);

make_solidity_event! {
pub struct VoteEvent("Vote(uint64,address,uint16,uint256[3])", indexed: (u64,Address,u16), non_indexed: [U256;3]);
}
make_solidity_event! {
pub struct RevokeEvent("Revoke(uint64,address,uint16,uint256[3])", indexed: (u64,Address,u16), non_indexed: [U256;3]);
}
group_impl_is_active!(|spec: &Spec| spec.cip94, CastVote, ReadVote);

make_solidity_function! {
struct CastVote((u64, Vec<Vote>), "castVote(uint64,(uint16,uint256[3])[])");
}
// FIXME(lpl): What's the gas cost?
impl_function_type!(CastVote, "non_payable_write", gas: |spec: &Spec| spec.sstore_reset_gas);
impl_function_type!(CastVote, "non_payable_write");

impl UpfrontPaymentTrait for CastVote {
fn upfront_gas_payment(
&self, (_, votes): &(u64, Vec<Vote>), _params: &ActionParams,
context: &InternalRefContext,
) -> DbResult<U256>
{
let spec = context.spec;
Ok(cast_vote_gas(votes.len(), spec).into())
}
}

impl SimpleExecutionTrait for CastVote {
fn execute_inner(
Expand All @@ -35,8 +60,8 @@ impl SimpleExecutionTrait for CastVote {
make_solidity_function! {
struct ReadVote(Address, "readVote(address)", Vec<Vote>);
}
// FIXME(lpl): What's the gas cost?
impl_function_type!(ReadVote, "query_with_default_gas");

impl_function_type!(ReadVote, "query", gas: |spec: &Spec| PARAMETER_INDEX_MAX * OPTION_INDEX_MAX * (spec.sload_gas + 2 * spec.sha3_gas));

impl SimpleExecutionTrait for ReadVote {
fn execute_inner(
Expand All @@ -48,6 +73,39 @@ impl SimpleExecutionTrait for ReadVote {
}
}

make_solidity_function! {
struct CurrentRound((), "currentRound()", u64);
}
impl_function_type!(CurrentRound, "query", gas: |spec:&Spec| spec.tier_step_gas[(GasPriceTier::Low).idx()]);
impl SimpleExecutionTrait for CurrentRound {
fn execute_inner(
&self, _input: (), _params: &ActionParams,
context: &mut InternalRefContext, _tracer: &mut dyn VmObserve,
) -> vm::Result<u64>
{
Ok(
(context.env.number - context.spec.cip94_activation_block_number)
/ context.spec.params_dao_vote_period
+ 1,
)
}
}

make_solidity_function! {
struct TotalVotes(u64, "totalVotes(uint64)", Vec<Vote>);
}
impl_function_type!(TotalVotes, "query", gas: |spec: &Spec| PARAMETER_INDEX_MAX * OPTION_INDEX_MAX * spec.sload_gas);

impl SimpleExecutionTrait for TotalVotes {
fn execute_inner(
&self, input: u64, _params: &ActionParams,
context: &mut InternalRefContext, _tracer: &mut dyn VmObserve,
) -> vm::Result<Vec<Vote>>
{
total_votes(input, context)
}
}

#[derive(ABIVariable, Clone, Eq, PartialEq, Default)]
pub struct Vote {
pub index: u16,
Expand Down
21 changes: 19 additions & 2 deletions core/src/executive/internal_contract/contracts/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ impl SimpleExecutionTrait for Deposit {
context: &mut InternalRefContext, tracer: &mut dyn VmObserve,
) -> vm::Result<()>
{
deposit(input, params, context.env, context.state, tracer)
deposit(
input,
params,
context.env,
context.spec,
context.state,
tracer,
)
}
}

Expand All @@ -69,6 +76,9 @@ impl UpfrontPaymentTrait for Withdraw {
context: &InternalRefContext,
) -> DbResult<U256>
{
if context.spec.cip97 {
return Ok(U256::from(2 * context.spec.sload_gas));
}
let length = context.state.deposit_list_length(&params.sender)?;
Ok(U256::from(2 * context.spec.sstore_reset_gas) * U256::from(length))
}
Expand All @@ -80,7 +90,14 @@ impl SimpleExecutionTrait for Withdraw {
context: &mut InternalRefContext, tracer: &mut dyn VmObserve,
) -> vm::Result<()>
{
withdraw(input, params, context.env, context.state, tracer)
withdraw(
input,
params,
context.env,
context.spec,
context.state,
tracer,
)
}
}

Expand Down
Loading

0 comments on commit 302c382

Please sign in to comment.