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 Jun 28, 2022
2 parents 955e710 + daa144b commit d89f5df
Show file tree
Hide file tree
Showing 18 changed files with 312 additions and 39 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
4 changes: 4 additions & 0 deletions client/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,10 @@ impl Configuration {
.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
2 changes: 2 additions & 0 deletions core/src/spec/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ pub struct TransitionsBlockNumber {
pub cip94: BlockNumber,
/// CIP-97: Remove Staking List
pub cip97: BlockNumber,
/// CIP-98: Fix BLOCKHASH in espace
pub cip98: BlockNumber,
}

#[derive(Default, Debug, Clone)]
Expand Down
1 change: 0 additions & 1 deletion core/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ impl<StateDbStorage: StorageStateTrait> StateOpsTrait
/// Maintain `total_issued_tokens`. This is only used in the extremely
/// unlikely case that there are a lot of partial invalid blocks.
fn subtract_total_issued(&mut self, v: U256) {
assert!(self.world_statistics_checkpoints.get_mut().is_empty());
self.world_statistics.total_issued_tokens -= v;
}

Expand Down
6 changes: 5 additions & 1 deletion core/src/sync/synchronization_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,11 @@ impl SynchronizationState {
}
};

if peer_best_epoches.len() < self.min_phase_change_normal_peer_count {
// `peer_best_epoches.is_empty()` is only possible if
// `self.min_phase_change_normal_peer_count == 0`
if peer_best_epoches.len() < self.min_phase_change_normal_peer_count
|| peer_best_epoches.is_empty()
{
return if fresh_start {
debug!("median_epoch_from_normal_peers: fresh start");
Some(0)
Expand Down
4 changes: 4 additions & 0 deletions core/src/vm/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ pub struct Spec {
pub cip94_activation_block_number: u64,
/// CIP-97: Remove staking list
pub cip97: bool,
/// CIP-98: Fix espace bug
pub cip98: bool,
pub params_dao_vote_period: u64,
}

Expand Down Expand Up @@ -295,6 +297,7 @@ impl Spec {
cip94_activation_block_number: u64::MAX,
params_dao_vote_period: DAO_PARAMETER_VOTE_PERIOD,
cip97: false,
cip98: false,
}
}

Expand All @@ -314,6 +317,7 @@ impl Spec {
spec.cip94 = number >= params.transition_numbers.cip94;
spec.cip94_activation_block_number = params.transition_numbers.cip94;
spec.cip97 = number >= params.transition_numbers.cip97;
spec.cip98 = number >= params.transition_numbers.cip98;
spec.params_dao_vote_period = params.params_dao_vote_period;
spec
}
Expand Down
Loading

0 comments on commit d89f5df

Please sign in to comment.