From cf366bdb298bed6371b14af958efe8f4c0bea2e0 Mon Sep 17 00:00:00 2001 From: Hawstein Date: Fri, 1 Sep 2017 22:57:57 +0800 Subject: [PATCH 1/7] util should not reexport ansi_term --- Cargo.lock | 2 ++ ethcore/Cargo.toml | 1 + ethcore/src/blockchain/blockchain.rs | 1 + ethcore/src/lib.rs | 1 + ethcore/src/miner/miner.rs | 1 + ethcore/src/service.rs | 1 + parity/configuration.rs | 2 +- parity/informant.rs | 4 ++-- parity/run.rs | 3 ++- rpc/Cargo.toml | 1 + rpc/src/lib.rs | 1 + rpc/src/v1/types/confirmations.rs | 2 +- rpc/src/v1/types/transaction_request.rs | 2 +- util/src/lib.rs | 1 - 14 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 15d841103..d5a63f9df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -492,6 +492,7 @@ dependencies = [ name = "ethcore" version = "1.8.0" dependencies = [ + "ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "bloomable 0.1.0", "bloomchain 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2013,6 +2014,7 @@ dependencies = [ name = "parity-rpc" version = "1.8.0" dependencies = [ + "ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "cid 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "clippy 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "ethash 1.8.0", diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index 6ee332c99..4741c37ee 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -11,6 +11,7 @@ build = "build.rs" "ethcore-ipc-codegen" = { path = "../ipc/codegen" } [dependencies] +ansi_term = "0.9" bit-set = "0.4" bloomchain = "0.1" bn = { git = "https://github.com/paritytech/bn" } diff --git a/ethcore/src/blockchain/blockchain.rs b/ethcore/src/blockchain/blockchain.rs index 022c93b8f..ac51a789e 100644 --- a/ethcore/src/blockchain/blockchain.rs +++ b/ethcore/src/blockchain/blockchain.rs @@ -41,6 +41,7 @@ use db::{self, Writable, Readable, CacheUpdatePolicy}; use cache_manager::CacheManager; use encoded; use engines::epoch::{Transition as EpochTransition, PendingTransition as PendingEpochTransition}; +use ansi_term::Colour; const LOG_BLOOMS_LEVELS: usize = 3; const LOG_BLOOMS_ELEMENTS_PER_INDEX: usize = 16; diff --git a/ethcore/src/lib.rs b/ethcore/src/lib.rs index daab42acf..6732e63c6 100644 --- a/ethcore/src/lib.rs +++ b/ethcore/src/lib.rs @@ -103,6 +103,7 @@ extern crate rand; extern crate rlp; extern crate hash; extern crate heapsize; +extern crate ansi_term; #[macro_use] extern crate rlp_derive; diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index 2fa4a76e2..1fa4508bf 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -40,6 +40,7 @@ use miner::service_transaction_checker::ServiceTransactionChecker; use price_info::{Client as PriceInfoClient, PriceInfo}; use price_info::fetch::Client as FetchClient; use header::{Header, BlockNumber}; +use ansi_term::Colour; /// Different possible definitions for pending transaction set. #[derive(Debug, PartialEq)] diff --git a/ethcore/src/service.rs b/ethcore/src/service.rs index 5e65a4de8..1be5c9a19 100644 --- a/ethcore/src/service.rs +++ b/ethcore/src/service.rs @@ -28,6 +28,7 @@ use miner::Miner; use snapshot::ManifestData; use snapshot::service::{Service as SnapshotService, ServiceParams as SnapServiceParams}; use std::sync::atomic::AtomicBool; +use ansi_term::Colour; #[cfg(feature="ipc")] use nanoipc; diff --git a/parity/configuration.rs b/parity/configuration.rs index 11360c41b..c27872905 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -25,7 +25,7 @@ use cli::{Args, ArgsError}; use hash::keccak; use util::{H256, U256, Bytes, version_data, Address}; use util::journaldb::Algorithm; -use util::Colour; +use ansi_term::Colour; use ethsync::{NetworkConfiguration, is_valid_node_url}; use ethcore::ethstore::ethkey::{Secret, Public}; use ethcore::client::{VMType}; diff --git a/parity/informant.rs b/parity/informant.rs index 1935ec9b6..4e2987892 100644 --- a/parity/informant.rs +++ b/parity/informant.rs @@ -16,7 +16,7 @@ extern crate ansi_term; use self::ansi_term::Colour::{White, Yellow, Green, Cyan, Blue}; -use self::ansi_term::Style; +use self::ansi_term::{Colour, Style}; use std::sync::{Arc}; use std::sync::atomic::{AtomicUsize, AtomicBool, Ordering as AtomicOrdering}; @@ -35,7 +35,7 @@ use light::client::LightChainClient; use number_prefix::{binary_prefix, Standalone, Prefixed}; use parity_rpc::{is_major_importing}; use parity_rpc::informant::RpcStats; -use util::{RwLock, Mutex, H256, Colour, Bytes}; +use util::{RwLock, Mutex, H256, Bytes}; /// Format byte counts to standard denominations. pub fn format_bytes(b: usize) -> String { diff --git a/parity/run.rs b/parity/run.rs index a81d61ba0..093a019f3 100644 --- a/parity/run.rs +++ b/parity/run.rs @@ -37,7 +37,8 @@ use node_health; use parity_reactor::EventLoop; use parity_rpc::{NetworkSettings, informant, is_major_importing}; use updater::{UpdatePolicy, Updater}; -use util::{Colour, version, Mutex, Condvar}; +use util::{version, Mutex, Condvar}; +use ansi_term::Colour; use node_filter::NodeFilter; use params::{ diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index 382878683..a0bbe95ca 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -8,6 +8,7 @@ authors = ["Parity Technologies "] [lib] [dependencies] +ansi_term = "0.9" cid = "0.2" futures = "0.1" futures-cpupool = "0.1" diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 7db99ba2c..22f623bf6 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -20,6 +20,7 @@ #![cfg_attr(feature="dev", feature(plugin))] #![cfg_attr(feature="dev", plugin(clippy))] +extern crate ansi_term; extern crate cid; extern crate crypto as rust_crypto; extern crate futures; diff --git a/rpc/src/v1/types/confirmations.rs b/rpc/src/v1/types/confirmations.rs index bbc8b350e..39bf8d0a1 100644 --- a/rpc/src/v1/types/confirmations.rs +++ b/rpc/src/v1/types/confirmations.rs @@ -18,7 +18,7 @@ use std::fmt; use serde::{Serialize, Serializer}; -use util::Colour; +use ansi_term::Colour; use util::bytes::ToPretty; use v1::types::{U256, TransactionRequest, RichRawTransaction, H160, H256, H520, Bytes, TransactionCondition, Origin}; diff --git a/rpc/src/v1/types/transaction_request.rs b/rpc/src/v1/types/transaction_request.rs index cb74e071b..7f1c16287 100644 --- a/rpc/src/v1/types/transaction_request.rs +++ b/rpc/src/v1/types/transaction_request.rs @@ -18,7 +18,7 @@ use v1::types::{Bytes, H160, U256, TransactionCondition}; use v1::helpers; -use util::Colour; +use ansi_term::Colour; use std::fmt; diff --git a/util/src/lib.rs b/util/src/lib.rs index 0f16609c7..790a1c3f9 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -149,7 +149,6 @@ pub use vector::*; pub use bigint::prelude::*; pub use bigint::hash; -pub use ansi_term::{Colour, Style}; pub use parking_lot::{Condvar, Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard}; /// 160-bit integer representing account address From 6b8c9cac23215312932ee40ef5560543a0c053b5 Mon Sep 17 00:00:00 2001 From: GitLab Build Bot Date: Fri, 1 Sep 2017 16:33:31 +0000 Subject: [PATCH 2/7] [ci skip] js-precompiled 20170901-161931 --- Cargo.lock | 2 +- js/package-lock.json | 2 +- js/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d5a63f9df..bf0a72ac1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2119,7 +2119,7 @@ dependencies = [ [[package]] name = "parity-ui-precompiled" version = "1.4.0" -source = "git+https://github.com/paritytech/js-precompiled.git#d809723e58bcb36c0f8d2eca5ca94abbb3690544" +source = "git+https://github.com/paritytech/js-precompiled.git#f34bdb63272fd59edf2062dda44113831964d800" dependencies = [ "parity-dapps-glue 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/js/package-lock.json b/js/package-lock.json index 7b272b35f..0bc45f0c5 100644 --- a/js/package-lock.json +++ b/js/package-lock.json @@ -1,6 +1,6 @@ { "name": "parity.js", - "version": "1.8.17", + "version": "1.8.18", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/js/package.json b/js/package.json index 1bb76b21c..52415f95a 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "parity.js", - "version": "1.8.17", + "version": "1.8.18", "main": "release/index.js", "jsnext:main": "src/index.js", "author": "Parity Team ", From 0b5285c282ed48f0a2b387259a0870b1fa5940f1 Mon Sep 17 00:00:00 2001 From: Hawstein Date: Sat, 2 Sep 2017 16:54:39 +0800 Subject: [PATCH 3/7] move timer.rs to ethcore (#6437) --- ethcore/src/client/client.rs | 3 ++- ethcore/src/lib.rs | 1 + ethcore/src/miner/miner.rs | 1 + {util => ethcore}/src/timer.rs | 0 util/src/lib.rs | 2 -- 5 files changed, 4 insertions(+), 3 deletions(-) rename {util => ethcore}/src/timer.rs (100%) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 9d5465593..69674901f 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -24,7 +24,8 @@ use itertools::Itertools; // util use hash::keccak; -use util::{Bytes, PerfTimer, Mutex, RwLock, MutexGuard}; +use timer::PerfTimer; +use util::{Bytes, Mutex, RwLock, MutexGuard}; use util::{journaldb, DBValue, TrieFactory, Trie}; use util::{U256, H256, Address, H2048}; use util::trie::TrieSpec; diff --git a/ethcore/src/lib.rs b/ethcore/src/lib.rs index 6732e63c6..57abf12dd 100644 --- a/ethcore/src/lib.rs +++ b/ethcore/src/lib.rs @@ -151,6 +151,7 @@ pub mod service; pub mod snapshot; pub mod spec; pub mod state; +pub mod timer; pub mod trace; pub mod transaction; pub mod verification; diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index 1fa4508bf..fb1753760 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -19,6 +19,7 @@ use std::collections::{BTreeMap, HashSet}; use std::sync::Arc; use util::*; +use timer::PerfTimer; use using_queue::{UsingQueue, GetAction}; use account_provider::{AccountProvider, SignError as AccountError}; use state::State; diff --git a/util/src/timer.rs b/ethcore/src/timer.rs similarity index 100% rename from util/src/timer.rs rename to ethcore/src/timer.rs diff --git a/util/src/lib.rs b/util/src/lib.rs index 790a1c3f9..405fec797 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -131,7 +131,6 @@ pub mod nibblevec; pub mod semantic_version; pub mod snappy; pub mod cache; -mod timer; pub use misc::*; pub use hashdb::*; @@ -142,7 +141,6 @@ pub use triehash::*; pub use trie::{Trie, TrieMut, TrieDB, TrieDBMut, TrieFactory, TrieError, SecTrieDB, SecTrieDBMut}; pub use semantic_version::*; pub use kvdb::*; -pub use timer::*; pub use error::*; pub use bytes::*; pub use vector::*; From 2faa28ce9b9e65d4b09db9ab3e38747cdfc3d24a Mon Sep 17 00:00:00 2001 From: Hawstein Date: Sat, 2 Sep 2017 19:14:21 +0800 Subject: [PATCH 4/7] separate semantic_version from util (#6438) --- Cargo.lock | 5 +++++ ethcore/Cargo.toml | 1 + ethcore/src/engines/authority_round/mod.rs | 1 + ethcore/src/engines/basic_authority.rs | 1 + ethcore/src/engines/mod.rs | 1 + ethcore/src/engines/tendermint/mod.rs | 1 + ethcore/src/ethereum/ethash.rs | 1 + ethcore/src/lib.rs | 1 + util/semantic_version/Cargo.toml | 6 ++++++ .../semantic_version.rs => semantic_version/src/lib.rs} | 4 ++-- util/src/lib.rs | 2 -- 11 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 util/semantic_version/Cargo.toml rename util/{src/semantic_version.rs => semantic_version/src/lib.rs} (95%) diff --git a/Cargo.lock b/Cargo.lock index bf0a72ac1..207145a29 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -536,6 +536,7 @@ dependencies = [ "rlp_derive 0.1.0", "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "semantic_version 0.1.0", "semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "stats 0.1.0", "table 0.1.0", @@ -2634,6 +2635,10 @@ dependencies = [ "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "semantic_version" +version = "0.1.0" + [[package]] name = "semver" version = "0.1.20" diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index 4741c37ee..59e0b14d1 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -62,6 +62,7 @@ bloomable = { path = "../util/bloomable" } vm = { path = "vm" } wasm = { path = "wasm" } hash = { path = "../util/hash" } +semantic_version = { path = "../util/semantic_version" } [dev-dependencies] native-contracts = { path = "native_contracts", features = ["test_contracts"] } diff --git a/ethcore/src/engines/authority_round/mod.rs b/ethcore/src/engines/authority_round/mod.rs index 776aca320..c9c483773 100644 --- a/ethcore/src/engines/authority_round/mod.rs +++ b/ethcore/src/engines/authority_round/mod.rs @@ -42,6 +42,7 @@ use ethkey::{verify_address, Signature}; use io::{IoContext, IoHandler, TimerToken, IoService}; use itertools::{self, Itertools}; use rlp::{UntrustedRlp, encode}; +use semantic_version::SemanticVersion; use util::*; mod finality; diff --git a/ethcore/src/engines/basic_authority.rs b/ethcore/src/engines/basic_authority.rs index c22e66dfd..ccd69b386 100644 --- a/ethcore/src/engines/basic_authority.rs +++ b/ethcore/src/engines/basic_authority.rs @@ -31,6 +31,7 @@ use evm::Schedule; use ethjson; use header::{Header, BlockNumber}; use client::Client; +use semantic_version::SemanticVersion; use super::signer::EngineSigner; use super::validator_set::{ValidatorSet, SimpleList, new_validator_set}; diff --git a/ethcore/src/engines/mod.rs b/ethcore/src/engines/mod.rs index cb13c984a..d3cbdccaa 100644 --- a/ethcore/src/engines/mod.rs +++ b/ethcore/src/engines/mod.rs @@ -54,6 +54,7 @@ use spec::CommonParams; use transaction::{UnverifiedTransaction, SignedTransaction}; use ethkey::Signature; +use semantic_version::SemanticVersion; use util::*; /// Default EIP-210 contrat code. diff --git a/ethcore/src/engines/tendermint/mod.rs b/ethcore/src/engines/tendermint/mod.rs index f6981c210..f4b1422d8 100644 --- a/ethcore/src/engines/tendermint/mod.rs +++ b/ethcore/src/engines/tendermint/mod.rs @@ -48,6 +48,7 @@ use super::transition::TransitionHandler; use super::vote_collector::VoteCollector; use self::message::*; use self::params::TendermintParams; +use semantic_version::SemanticVersion; #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] pub enum Step { diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index abb77aefc..c6383039d 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -35,6 +35,7 @@ use evm::Schedule; use ethjson; use rlp::{self, UntrustedRlp}; use vm::LastHashes; +use semantic_version::SemanticVersion; /// Parity tries to round block.gas_limit to multiple of this constant pub const PARITY_GAS_LIMIT_DETERMINANT: U256 = U256([37, 0, 0, 0]); diff --git a/ethcore/src/lib.rs b/ethcore/src/lib.rs index 57abf12dd..df7c25d3f 100644 --- a/ethcore/src/lib.rs +++ b/ethcore/src/lib.rs @@ -104,6 +104,7 @@ extern crate rlp; extern crate hash; extern crate heapsize; extern crate ansi_term; +extern crate semantic_version; #[macro_use] extern crate rlp_derive; diff --git a/util/semantic_version/Cargo.toml b/util/semantic_version/Cargo.toml new file mode 100644 index 000000000..5cd888d0a --- /dev/null +++ b/util/semantic_version/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "semantic_version" +version = "0.1.0" +authors = ["Parity Technologies "] + +[dependencies] diff --git a/util/src/semantic_version.rs b/util/semantic_version/src/lib.rs similarity index 95% rename from util/src/semantic_version.rs rename to util/semantic_version/src/lib.rs index fe4b8727f..0a8eeb499 100644 --- a/util/src/semantic_version.rs +++ b/util/semantic_version/src/lib.rs @@ -20,8 +20,8 @@ /// /// # Example /// ``` -/// extern crate ethcore_util as util; -/// use util::semantic_version::*; +/// extern crate semantic_version; +/// use semantic_version::*; /// /// fn main() { /// assert_eq!(SemanticVersion::new(1, 2, 3).as_u32(), 0x010203); diff --git a/util/src/lib.rs b/util/src/lib.rs index 405fec797..305b17220 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -128,7 +128,6 @@ pub mod triehash; pub mod trie; pub mod nibbleslice; pub mod nibblevec; -pub mod semantic_version; pub mod snappy; pub mod cache; @@ -139,7 +138,6 @@ pub use overlaydb::*; pub use journaldb::JournalDB; pub use triehash::*; pub use trie::{Trie, TrieMut, TrieDB, TrieDBMut, TrieFactory, TrieError, SecTrieDB, SecTrieDBMut}; -pub use semantic_version::*; pub use kvdb::*; pub use error::*; pub use bytes::*; From 1d95fe481f6cb77f8491d5a12af6bb17ecc9faf0 Mon Sep 17 00:00:00 2001 From: Hawstein Date: Sun, 3 Sep 2017 02:08:34 +0800 Subject: [PATCH 5/7] fix modexp bug: return 0 if base=0 (#6424) --- ethcore/src/builtin.rs | 92 +++++++++++++++++++++++++++++------------- 1 file changed, 63 insertions(+), 29 deletions(-) diff --git a/ethcore/src/builtin.rs b/ethcore/src/builtin.rs index b6d7064eb..a752064cd 100644 --- a/ethcore/src/builtin.rs +++ b/ethcore/src/builtin.rs @@ -267,6 +267,34 @@ impl Impl for Ripemd160 { } } +// calculate modexp: exponentiation by squaring. the `num` crate has pow, but not modular. +fn modexp(mut base: BigUint, mut exp: BigUint, modulus: BigUint) -> BigUint { + use num::Integer; + + match (base.is_zero(), exp.is_zero()) { + (_, true) => return BigUint::one(), // n^0 % m + (true, false) => return BigUint::zero(), // 0^n % m, n>0 + (false, false) if modulus <= BigUint::one() => return BigUint::zero(), // a^b % 1 = 0. + _ => {} + } + + let mut result = BigUint::one(); + base = base % &modulus; + + // fast path for base divisible by modulus. + if base.is_zero() { return BigUint::zero() } + while !exp.is_zero() { + if exp.is_odd() { + result = (result * &base) % &modulus; + } + + exp = exp >> 1; + base = (base.clone() * base) % &modulus; + } + + result +} + impl Impl for ModexpImpl { fn execute(&self, input: &[u8], output: &mut BytesRef) -> Result<(), Error> { let mut reader = input.chain(io::repeat(0)); @@ -295,34 +323,6 @@ impl Impl for ModexpImpl { let exp = read_num(exp_len); let modulus = read_num(mod_len); - // calculate modexp: exponentiation by squaring. the `num` crate has pow, but not modular. - fn modexp(mut base: BigUint, mut exp: BigUint, modulus: BigUint) -> BigUint { - use num::Integer; - - match (base.is_zero(), exp.is_zero()) { - (_, true) => return BigUint::one(), // n^0 % m - (true, false) => return BigUint::zero(), // 0^n % m, n>0 - (false, false) if modulus <= BigUint::one() => return BigUint::zero(), // a^b % 1 = 0. - _ => {} - } - - let mut result = BigUint::one(); - base = base % &modulus; - - // fast path for base divisible by modulus. - if base.is_zero() { return result } - while !exp.is_zero() { - if exp.is_odd() { - result = (result * &base) % &modulus; - } - - exp = exp >> 1; - base = (base.clone() * base) % &modulus; - } - - result - } - // write output to given memory, left padded and same length as the modulus. let bytes = modexp(base, exp, modulus).to_bytes_be(); @@ -504,10 +504,44 @@ impl Impl for Bn128PairingImpl { #[cfg(test)] mod tests { - use super::{Builtin, Linear, ethereum_builtin, Pricer, Modexp}; + use super::{Builtin, Linear, ethereum_builtin, Pricer, Modexp, modexp as me}; use ethjson; use util::{U256, BytesRef}; use rustc_hex::FromHex; + use num::{BigUint, Zero, One}; + + #[test] + fn modexp_func() { + // n^0 % m == 1 + let mut base = BigUint::parse_bytes(b"12345", 10).unwrap(); + let mut exp = BigUint::zero(); + let mut modulus = BigUint::parse_bytes(b"789", 10).unwrap(); + assert_eq!(me(base, exp, modulus), BigUint::one()); + + // 0^n % m == 0 + base = BigUint::zero(); + exp = BigUint::parse_bytes(b"12345", 10).unwrap(); + modulus = BigUint::parse_bytes(b"789", 10).unwrap(); + assert_eq!(me(base, exp, modulus), BigUint::zero()); + + // n^m % 1 == 0 + base = BigUint::parse_bytes(b"12345", 10).unwrap(); + exp = BigUint::parse_bytes(b"789", 10).unwrap(); + modulus = BigUint::one(); + assert_eq!(me(base, exp, modulus), BigUint::zero()); + + // if n % d == 0, then n^m % d == 0 + base = BigUint::parse_bytes(b"12345", 10).unwrap(); + exp = BigUint::parse_bytes(b"789", 10).unwrap(); + modulus = BigUint::parse_bytes(b"15", 10).unwrap(); + assert_eq!(me(base, exp, modulus), BigUint::zero()); + + // others + base = BigUint::parse_bytes(b"12345", 10).unwrap(); + exp = BigUint::parse_bytes(b"789", 10).unwrap(); + modulus = BigUint::parse_bytes(b"97", 10).unwrap(); + assert_eq!(me(base, exp, modulus), BigUint::parse_bytes(b"55", 10).unwrap()); + } #[test] fn identity() { From 7b8af30590ebe7ae78e06c7bd6d70fb79d85cc43 Mon Sep 17 00:00:00 2001 From: Hawstein Date: Sun, 3 Sep 2017 02:09:13 +0800 Subject: [PATCH 6/7] remove re-export of parking_lot in util (#6435) --- Cargo.lock | 11 +++++++++++ Cargo.toml | 1 + dapps/Cargo.toml | 1 + dapps/src/apps/fetcher/mod.rs | 2 +- dapps/src/handlers/fetch.rs | 2 +- dapps/src/lib.rs | 3 ++- dapps/src/tests/helpers/fetch.rs | 2 +- dapps/src/tests/helpers/registrar.rs | 3 ++- ethcore/Cargo.toml | 1 + ethcore/evm/Cargo.toml | 1 + ethcore/evm/src/interpreter/shared_cache.rs | 3 ++- ethcore/evm/src/lib.rs | 1 + ethcore/light/Cargo.toml | 1 + ethcore/light/src/client/header_chain.rs | 6 +++--- ethcore/light/src/client/mod.rs | 3 ++- ethcore/light/src/client/service.rs | 6 +++--- ethcore/light/src/lib.rs | 1 + ethcore/light/src/net/load_timer.rs | 2 +- ethcore/light/src/net/mod.rs | 5 +++-- ethcore/light/src/net/tests/mod.rs | 2 +- ethcore/light/src/on_demand/mod.rs | 2 +- ethcore/light/src/on_demand/request.rs | 6 ++++-- ethcore/light/src/on_demand/tests.rs | 3 ++- ethcore/light/src/provider.rs | 3 ++- ethcore/node_filter/Cargo.toml | 1 + ethcore/node_filter/src/lib.rs | 4 +++- ethcore/src/account_provider/mod.rs | 2 +- ethcore/src/blockchain/blockchain.rs | 1 + ethcore/src/client/ancient_import.rs | 2 +- ethcore/src/client/client.rs | 3 ++- ethcore/src/client/test_client.rs | 1 + ethcore/src/db.rs | 3 ++- ethcore/src/engines/authority_round/mod.rs | 1 + ethcore/src/engines/basic_authority.rs | 1 + ethcore/src/engines/tendermint/mod.rs | 1 + ethcore/src/engines/validator_set/contract.rs | 1 + ethcore/src/engines/validator_set/multi.rs | 3 ++- ethcore/src/engines/validator_set/safe_contract.rs | 1 + ethcore/src/engines/vote_collector.rs | 1 + ethcore/src/lib.rs | 1 + ethcore/src/miner/external.rs | 3 ++- ethcore/src/miner/miner.rs | 1 + ethcore/src/miner/service_transaction_checker.rs | 3 ++- ethcore/src/miner/stratum.rs | 2 +- ethcore/src/miner/work_notify.rs | 1 + ethcore/src/snapshot/mod.rs | 2 +- ethcore/src/snapshot/service.rs | 3 ++- ethcore/src/snapshot/tests/proof_of_work.rs | 3 ++- ethcore/src/snapshot/tests/state.rs | 2 +- ethcore/src/snapshot/watcher.rs | 2 +- ethcore/src/spec/spec.rs | 1 + ethcore/src/state/backend.rs | 3 ++- ethcore/src/state_db.rs | 3 ++- ethcore/src/trace/db.rs | 3 ++- ethcore/src/verification/queue/mod.rs | 1 + hash-fetch/Cargo.toml | 1 + hash-fetch/src/client.rs | 2 +- hash-fetch/src/lib.rs | 1 + hash-fetch/src/urlhint.rs | 3 ++- parity/blockchain.rs | 3 ++- parity/informant.rs | 3 ++- parity/light_helpers/queue_cull.rs | 2 +- parity/main.rs | 1 + parity/rpc_apis.rs | 2 +- parity/run.rs | 7 ++++--- rpc/Cargo.toml | 1 + rpc/src/lib.rs | 1 + rpc/src/v1/helpers/dispatch.rs | 3 ++- rpc/src/v1/helpers/light_fetch.rs | 3 ++- rpc/src/v1/helpers/signer.rs | 2 +- rpc/src/v1/helpers/signing_queue.rs | 6 ++++-- rpc/src/v1/helpers/subscription_manager.rs | 2 +- rpc/src/v1/impls/eth.rs | 2 +- rpc/src/v1/impls/eth_filter.rs | 3 ++- rpc/src/v1/impls/eth_pubsub.rs | 3 ++- rpc/src/v1/impls/light/eth.rs | 3 ++- rpc/src/v1/impls/pubsub.rs | 2 +- rpc/src/v1/impls/signer.rs | 2 +- rpc/src/v1/impls/signing.rs | 3 ++- rpc/src/v1/informant.rs | 2 +- rpc/src/v1/tests/helpers/miner_service.rs | 3 ++- rpc/src/v1/tests/helpers/snapshot_service.rs | 3 ++- rpc/src/v1/tests/helpers/sync_provider.rs | 3 ++- rpc/src/v1/tests/mocked/eth.rs | 3 ++- rpc_client/Cargo.toml | 1 + rpc_client/src/client.rs | 2 +- rpc_client/src/lib.rs | 1 + stratum/Cargo.toml | 1 + stratum/src/lib.rs | 4 +++- sync/src/chain.rs | 4 +++- sync/src/light_sync/mod.rs | 3 ++- sync/src/light_sync/tests/test_net.rs | 2 +- sync/src/tests/helpers.rs | 1 + sync/src/tests/snapshot.rs | 1 + updater/Cargo.toml | 1 + updater/src/lib.rs | 1 + updater/src/updater.rs | 3 ++- util/network/src/tests.rs | 3 ++- util/src/lib.rs | 2 -- 99 files changed, 161 insertions(+), 75 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 207145a29..b126d3d35 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -530,6 +530,7 @@ dependencies = [ "native-contracts 0.1.0", "num 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "price-info 1.7.0", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.2.0", @@ -662,6 +663,7 @@ dependencies = [ "heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.2.0", "rlp_derive 0.1.0", @@ -771,6 +773,7 @@ dependencies = [ "jsonrpc-tcp-server 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-core 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -937,6 +940,7 @@ dependencies = [ "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wasm 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.2.0", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "vm 0.1.0", @@ -1650,6 +1654,7 @@ dependencies = [ "futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "native-contracts 0.1.0", + "parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1890,6 +1895,7 @@ dependencies = [ "parity-rpc-client 1.4.0", "parity-updater 1.8.0", "parity-whisper 0.1.0", + "parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "path 0.1.0", "pretty_assertions 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1932,6 +1938,7 @@ dependencies = [ "parity-hash-fetch 1.8.0", "parity-reactor 0.1.0", "parity-ui 1.8.0", + "parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1971,6 +1978,7 @@ dependencies = [ "mime_guess 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "native-contracts 0.1.0", "parity-reactor 0.1.0", + "parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2049,6 +2057,7 @@ dependencies = [ "order-stat 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "parity-reactor 0.1.0", "parity-updater 1.8.0", + "parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.2.0", @@ -2077,6 +2086,7 @@ dependencies = [ "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-rpc 1.8.0", + "parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2140,6 +2150,7 @@ dependencies = [ "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "parity-hash-fetch 1.8.0", "parity-reactor 0.1.0", + "parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "path 0.1.0", "target_info 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/Cargo.toml b/Cargo.toml index 9f6dd9ccb..8eb4acd28 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ number_prefix = "0.2" rpassword = "0.2.1" semver = "0.6" ansi_term = "0.9" +parking_lot = "0.4" regex = "0.2" isatty = "0.1" toml = "0.4" diff --git a/dapps/Cargo.toml b/dapps/Cargo.toml index 76b026c9a..35ec2d983 100644 --- a/dapps/Cargo.toml +++ b/dapps/Cargo.toml @@ -13,6 +13,7 @@ futures = "0.1" linked-hash-map = "0.3" log = "0.3" parity-dapps-glue = "1.7" +parking_lot = "0.4" mime = "0.2" mime_guess = "1.6.1" rand = "0.3" diff --git a/dapps/src/apps/fetcher/mod.rs b/dapps/src/apps/fetcher/mod.rs index 5b91da1a3..fe529d772 100644 --- a/dapps/src/apps/fetcher/mod.rs +++ b/dapps/src/apps/fetcher/mod.rs @@ -32,7 +32,7 @@ use hyper; use hyper::status::StatusCode; use {Embeddable, SyncStatus, random_filename}; -use util::Mutex; +use parking_lot::Mutex; use page::LocalPageEndpoint; use handlers::{ContentHandler, ContentFetcherHandler}; use endpoint::{Endpoint, EndpointPath, Handler}; diff --git a/dapps/src/handlers/fetch.rs b/dapps/src/handlers/fetch.rs index 7740247d9..afe1f5083 100644 --- a/dapps/src/handlers/fetch.rs +++ b/dapps/src/handlers/fetch.rs @@ -23,7 +23,7 @@ use std::time::{Instant, Duration}; use fetch::{self, Fetch}; use futures::Future; use parity_reactor::Remote; -use util::Mutex; +use parking_lot::Mutex; use hyper::{server, Decoder, Encoder, Next, Method, Control}; use hyper::net::HttpStream; diff --git a/dapps/src/lib.rs b/dapps/src/lib.rs index f5670c959..688f1c8ac 100644 --- a/dapps/src/lib.rs +++ b/dapps/src/lib.rs @@ -24,6 +24,7 @@ extern crate futures; extern crate itertools; extern crate linked_hash_map; extern crate mime_guess; +extern crate parking_lot; extern crate rand; extern crate rustc_hex; extern crate serde; @@ -73,7 +74,7 @@ use std::collections::HashMap; use std::mem; use std::path::PathBuf; use std::sync::Arc; -use util::RwLock; +use parking_lot::RwLock; use jsonrpc_http_server::{self as http, hyper, Origin}; diff --git a/dapps/src/tests/helpers/fetch.rs b/dapps/src/tests/helpers/fetch.rs index e6e875c51..853d6857e 100644 --- a/dapps/src/tests/helpers/fetch.rs +++ b/dapps/src/tests/helpers/fetch.rs @@ -16,7 +16,7 @@ use std::{io, thread, time}; use std::sync::{atomic, mpsc, Arc}; -use util::Mutex; +use parking_lot::Mutex; use futures::{self, Future}; use fetch::{self, Fetch}; diff --git a/dapps/src/tests/helpers/registrar.rs b/dapps/src/tests/helpers/registrar.rs index d7890675b..03fe3d5e4 100644 --- a/dapps/src/tests/helpers/registrar.rs +++ b/dapps/src/tests/helpers/registrar.rs @@ -20,7 +20,8 @@ use std::collections::HashMap; use rustc_hex::FromHex; use hash_fetch::urlhint::ContractClient; -use util::{Bytes, Address, Mutex, H256, ToPretty}; +use parking_lot::Mutex; +use util::{Bytes, Address, H256, ToPretty}; const REGISTRAR: &'static str = "8e4e9b13d4b45cb0befc93c3061b1408f67316b2"; const URLHINT: &'static str = "deadbeefcafe0000000000000000000000000000"; diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index 59e0b14d1..5b37d96ca 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -46,6 +46,7 @@ lru-cache = "0.1.0" native-contracts = { path = "native_contracts" } num = "0.1" num_cpus = "1.2" +parking_lot = "0.4" price-info = { path = "../price-info" } rand = "0.3" rlp = { path = "../util/rlp" } diff --git a/ethcore/evm/Cargo.toml b/ethcore/evm/Cargo.toml index 7d323d622..e6b72e68a 100644 --- a/ethcore/evm/Cargo.toml +++ b/ethcore/evm/Cargo.toml @@ -16,6 +16,7 @@ log = "0.3" rlp = { path = "../../util/rlp" } vm = { path = "../vm" } parity-wasm = "0.12" +parking_lot = "0.4" ethcore-logger = { path = "../../logger" } wasm-utils = { git = "https://github.com/paritytech/wasm-utils" } hash = { path = "../../util/hash" } diff --git a/ethcore/evm/src/interpreter/shared_cache.rs b/ethcore/evm/src/interpreter/shared_cache.rs index 4f70044dd..ed39d30c8 100644 --- a/ethcore/evm/src/interpreter/shared_cache.rs +++ b/ethcore/evm/src/interpreter/shared_cache.rs @@ -17,7 +17,8 @@ use std::sync::Arc; use hash::KECCAK_EMPTY; use heapsize::HeapSizeOf; -use util::{H256, Mutex}; +use parking_lot::Mutex; +use util::H256; use util::cache::MemoryLruCache; use bit_set::BitSet; use super::super::instructions; diff --git a/ethcore/evm/src/lib.rs b/ethcore/evm/src/lib.rs index d5b08c8d8..4b418fd74 100644 --- a/ethcore/evm/src/lib.rs +++ b/ethcore/evm/src/lib.rs @@ -23,6 +23,7 @@ extern crate ethcore_util as util; extern crate ethjson; extern crate rlp; extern crate parity_wasm; +extern crate parking_lot; extern crate wasm_utils; extern crate ethcore_logger; extern crate heapsize; diff --git a/ethcore/light/Cargo.toml b/ethcore/light/Cargo.toml index 4e7b3523d..46ae3afe0 100644 --- a/ethcore/light/Cargo.toml +++ b/ethcore/light/Cargo.toml @@ -31,6 +31,7 @@ itertools = "0.5" bincode = "0.8.0" serde = "1.0" serde_derive = "1.0" +parking_lot = "0.4" stats = { path = "../../util/stats" } hash = { path = "../../util/hash" } diff --git a/ethcore/light/src/client/header_chain.rs b/ethcore/light/src/client/header_chain.rs index a16cb0c85..85f8123c4 100644 --- a/ethcore/light/src/client/header_chain.rs +++ b/ethcore/light/src/client/header_chain.rs @@ -37,11 +37,11 @@ use ethcore::ids::BlockId; use rlp::{Encodable, Decodable, DecoderError, RlpStream, Rlp, UntrustedRlp}; use heapsize::HeapSizeOf; -use util::{H256, U256, RwLock}; +use util::{H256, U256}; use util::kvdb::{DBTransaction, KeyValueDB}; use cache::Cache; -use util::Mutex; +use parking_lot::{Mutex, RwLock}; use smallvec::SmallVec; @@ -555,7 +555,7 @@ mod tests { use cache::Cache; use time::Duration; - use util::Mutex; + use parking_lot::Mutex; fn make_db() -> Arc<::util::KeyValueDB> { Arc::new(::util::kvdb::in_memory(0)) diff --git a/ethcore/light/src/client/mod.rs b/ethcore/light/src/client/mod.rs index ee270c977..387abc8ad 100644 --- a/ethcore/light/src/client/mod.rs +++ b/ethcore/light/src/client/mod.rs @@ -30,8 +30,9 @@ use ethcore::spec::Spec; use ethcore::service::ClientIoMessage; use ethcore::encoded; use io::IoChannel; +use parking_lot::{Mutex, RwLock}; -use util::{H256, U256, Mutex, RwLock}; +use util::{H256, U256}; use util::kvdb::{KeyValueDB, CompactionProfile}; use self::header_chain::{AncestryIter, HeaderChain}; diff --git a/ethcore/light/src/client/service.rs b/ethcore/light/src/client/service.rs index 83949a2f1..99dccc999 100644 --- a/ethcore/light/src/client/service.rs +++ b/ethcore/light/src/client/service.rs @@ -28,7 +28,7 @@ use io::{IoContext, IoError, IoHandler, IoService}; use util::kvdb::{Database, DatabaseConfig}; use cache::Cache; -use util::Mutex; +use parking_lot::Mutex; use super::{Client, Config as ClientConfig}; @@ -117,11 +117,11 @@ mod tests { use super::Service; use devtools::RandomTempPath; use ethcore::spec::Spec; - + use std::sync::Arc; use cache::Cache; use time::Duration; - use util::Mutex; + use parking_lot::Mutex; #[test] fn it_works() { diff --git a/ethcore/light/src/lib.rs b/ethcore/light/src/lib.rs index 37de03205..5d9a5ae32 100644 --- a/ethcore/light/src/lib.rs +++ b/ethcore/light/src/lib.rs @@ -77,6 +77,7 @@ extern crate futures; extern crate itertools; extern crate rand; extern crate rlp; +extern crate parking_lot; #[macro_use] extern crate rlp_derive; extern crate serde; diff --git a/ethcore/light/src/net/load_timer.rs b/ethcore/light/src/net/load_timer.rs index a169b86d9..7b78fc693 100644 --- a/ethcore/light/src/net/load_timer.rs +++ b/ethcore/light/src/net/load_timer.rs @@ -32,7 +32,7 @@ use request::{CompleteRequest, Kind}; use bincode; use time; -use util::{RwLock, Mutex}; +use parking_lot::{RwLock, Mutex}; /// Number of time periods samples should be kept for. pub const MOVING_SAMPLE_SIZE: usize = 256; diff --git a/ethcore/light/src/net/mod.rs b/ethcore/light/src/net/mod.rs index 046dc68bd..9f47c56ff 100644 --- a/ethcore/light/src/net/mod.rs +++ b/ethcore/light/src/net/mod.rs @@ -24,7 +24,8 @@ use io::TimerToken; use network::{HostInfo, NetworkProtocolHandler, NetworkContext, PeerId}; use rlp::{RlpStream, UntrustedRlp}; use util::hash::H256; -use util::{DBValue, Mutex, RwLock, U256}; +use util::{DBValue, U256}; +use parking_lot::{Mutex, RwLock}; use time::{Duration, SteadyTime}; use std::collections::{HashMap, HashSet}; @@ -287,7 +288,7 @@ pub type PeerMap = HashMap>; mod id_guard { use network::PeerId; - use util::RwLockReadGuard; + use parking_lot::RwLockReadGuard; use super::{PeerMap, ReqId}; diff --git a/ethcore/light/src/net/tests/mod.rs b/ethcore/light/src/net/tests/mod.rs index ef86c08f5..15a5eb21a 100644 --- a/ethcore/light/src/net/tests/mod.rs +++ b/ethcore/light/src/net/tests/mod.rs @@ -606,7 +606,7 @@ fn id_guard() { pending_requests.insert(req_id_1, req.clone(), 0.into(), ::time::SteadyTime::now()); pending_requests.insert(req_id_2, req, 1.into(), ::time::SteadyTime::now()); - proto.peers.write().insert(peer_id, ::util::Mutex::new(Peer { + proto.peers.write().insert(peer_id, ::parking_lot::Mutex::new(Peer { local_credits: flow_params.create_credits(), status: status(provider.client.chain_info()), capabilities: capabilities.clone(), diff --git a/ethcore/light/src/on_demand/mod.rs b/ethcore/light/src/on_demand/mod.rs index 42469725b..d67b7dc4e 100644 --- a/ethcore/light/src/on_demand/mod.rs +++ b/ethcore/light/src/on_demand/mod.rs @@ -27,7 +27,7 @@ use ethcore::executed::{Executed, ExecutionError}; use futures::{Async, Poll, Future}; use futures::sync::oneshot::{self, Sender, Receiver, Canceled}; use network::PeerId; -use util::{RwLock, Mutex}; +use parking_lot::{RwLock, Mutex}; use net::{ self, Handler, PeerStatus, Status, Capabilities, diff --git a/ethcore/light/src/on_demand/request.rs b/ethcore/light/src/on_demand/request.rs index 8ee41437b..3a38ec974 100644 --- a/ethcore/light/src/on_demand/request.rs +++ b/ethcore/light/src/on_demand/request.rs @@ -30,7 +30,8 @@ use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY, KECCAK_EMPTY_LIST_RLP, keccak}; use request::{self as net_request, IncompleteRequest, CompleteRequest, Output, OutputKind, Field}; use rlp::{RlpStream, UntrustedRlp}; -use util::{Address, Bytes, DBValue, HashDB, Mutex, H256, U256}; +use parking_lot::Mutex; +use util::{Address, Bytes, DBValue, HashDB, H256, U256}; use util::memorydb::MemoryDB; use util::trie::{Trie, TrieDB, TrieError}; @@ -850,7 +851,8 @@ impl TransactionProof { #[cfg(test)] mod tests { use super::*; - use util::{MemoryDB, Address, Mutex, H256}; + use parking_lot::Mutex; + use util::{MemoryDB, Address, H256}; use util::trie::{Trie, TrieMut, SecTrieDB, SecTrieDBMut}; use util::trie::recorder::Recorder; use hash::keccak; diff --git a/ethcore/light/src/on_demand/tests.rs b/ethcore/light/src/on_demand/tests.rs index 10c4ceae5..52d2bc5ea 100644 --- a/ethcore/light/src/on_demand/tests.rs +++ b/ethcore/light/src/on_demand/tests.rs @@ -22,7 +22,8 @@ use ethcore::header::{Header, Seal}; use futures::Future; use network::{PeerId, NodeId}; use net::*; -use util::{H256, Mutex}; +use parking_lot::Mutex; +use util::H256; use time::Duration; use ::request::{self as basic_request, Response}; diff --git a/ethcore/light/src/provider.rs b/ethcore/light/src/provider.rs index 3632783ca..8fc4c93e8 100644 --- a/ethcore/light/src/provider.rs +++ b/ethcore/light/src/provider.rs @@ -24,7 +24,8 @@ use ethcore::client::{BlockChainClient, ProvingBlockChainClient}; use ethcore::transaction::PendingTransaction; use ethcore::ids::BlockId; use ethcore::encoded; -use util::{RwLock, H256}; +use parking_lot::RwLock; +use util::H256; use cht::{self, BlockInfo}; use client::{LightChainClient, AsLightClient}; diff --git a/ethcore/node_filter/Cargo.toml b/ethcore/node_filter/Cargo.toml index e885ef1d1..3abf86205 100644 --- a/ethcore/node_filter/Cargo.toml +++ b/ethcore/node_filter/Cargo.toml @@ -14,3 +14,4 @@ ethcore-network = { path = "../../util/network" } native-contracts = { path = "../native_contracts" } futures = "0.1" log = "0.3" +parking_lot = "0.4" diff --git a/ethcore/node_filter/src/lib.rs b/ethcore/node_filter/src/lib.rs index d3dcbaa3b..b5ed94bb9 100644 --- a/ethcore/node_filter/src/lib.rs +++ b/ethcore/node_filter/src/lib.rs @@ -21,6 +21,7 @@ extern crate ethcore_util as util; extern crate ethcore_network as network; extern crate native_contracts; extern crate futures; +extern crate parking_lot; #[cfg(test)] extern crate ethcore_io as io; #[macro_use] extern crate log; @@ -29,7 +30,8 @@ use std::collections::HashMap; use native_contracts::PeerSet as Contract; use network::{NodeId, ConnectionFilter, ConnectionDirection}; use ethcore::client::{BlockChainClient, BlockId, ChainNotify}; -use util::{Mutex, Address, H256, Bytes}; +use util::{Address, H256, Bytes}; +use parking_lot::Mutex; use futures::Future; const MAX_CACHE_SIZE: usize = 4096; diff --git a/ethcore/src/account_provider/mod.rs b/ethcore/src/account_provider/mod.rs index 752cec964..6f8eab7b7 100755 --- a/ethcore/src/account_provider/mod.rs +++ b/ethcore/src/account_provider/mod.rs @@ -23,7 +23,7 @@ use self::stores::{AddressBook, DappsSettingsStore, NewDappsPolicy}; use std::fmt; use std::collections::{HashMap, HashSet}; use std::time::{Instant, Duration}; -use util::{RwLock}; +use parking_lot::RwLock; use ethstore::{ SimpleSecretStore, SecretStore, Error as SSError, EthStore, EthMultiStore, random_string, SecretVaultRef, StoreAccountRef, OpaqueSecret, diff --git a/ethcore/src/blockchain/blockchain.rs b/ethcore/src/blockchain/blockchain.rs index ac51a789e..c4b39d180 100644 --- a/ethcore/src/blockchain/blockchain.rs +++ b/ethcore/src/blockchain/blockchain.rs @@ -22,6 +22,7 @@ use std::mem; use itertools::Itertools; use bloomchain as bc; use heapsize::HeapSizeOf; +use parking_lot::{Mutex, RwLock}; use util::*; use rlp::*; use header::*; diff --git a/ethcore/src/client/ancient_import.rs b/ethcore/src/client/ancient_import.rs index d4d8696d2..aaf24cdc1 100644 --- a/ethcore/src/client/ancient_import.rs +++ b/ethcore/src/client/ancient_import.rs @@ -23,7 +23,7 @@ use engines::{Engine, EpochVerifier}; use header::Header; use rand::Rng; -use util::RwLock; +use parking_lot::RwLock; // do "heavy" verification on ~1/50 blocks, randomly sampled. const HEAVY_VERIFY_RATE: f32 = 0.02; diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 69674901f..3ad909ae1 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -25,7 +25,7 @@ use itertools::Itertools; // util use hash::keccak; use timer::PerfTimer; -use util::{Bytes, Mutex, RwLock, MutexGuard}; +use util::Bytes; use util::{journaldb, DBValue, TrieFactory, Trie}; use util::{U256, H256, Address, H2048}; use util::trie::TrieSpec; @@ -56,6 +56,7 @@ use io::*; use log_entry::LocalizedLogEntry; use miner::{Miner, MinerService, TransactionImportResult}; use native_contracts::Registry; +use parking_lot::{Mutex, RwLock, MutexGuard}; use rand::OsRng; use receipt::{Receipt, LocalizedReceipt}; use rlp::UntrustedRlp; diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index 256d7953d..94e40e975 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -23,6 +23,7 @@ use std::mem; use itertools::Itertools; use rustc_hex::FromHex; use hash::keccak; +use parking_lot::RwLock; use util::*; use rlp::*; use ethkey::{Generator, Random}; diff --git a/ethcore/src/db.rs b/ethcore/src/db.rs index bccb8e943..e60b77b2e 100644 --- a/ethcore/src/db.rs +++ b/ethcore/src/db.rs @@ -19,7 +19,8 @@ use std::ops::Deref; use std::hash::Hash; use std::collections::HashMap; -use util::{DBTransaction, KeyValueDB, RwLock}; +use parking_lot::RwLock; +use util::{DBTransaction, KeyValueDB}; use rlp; diff --git a/ethcore/src/engines/authority_round/mod.rs b/ethcore/src/engines/authority_round/mod.rs index c9c483773..8868a0657 100644 --- a/ethcore/src/engines/authority_round/mod.rs +++ b/ethcore/src/engines/authority_round/mod.rs @@ -43,6 +43,7 @@ use io::{IoContext, IoHandler, TimerToken, IoService}; use itertools::{self, Itertools}; use rlp::{UntrustedRlp, encode}; use semantic_version::SemanticVersion; +use parking_lot::{Mutex, RwLock}; use util::*; mod finality; diff --git a/ethcore/src/engines/basic_authority.rs b/ethcore/src/engines/basic_authority.rs index ccd69b386..7847f0432 100644 --- a/ethcore/src/engines/basic_authority.rs +++ b/ethcore/src/engines/basic_authority.rs @@ -19,6 +19,7 @@ use std::sync::{Weak, Arc}; use std::collections::BTreeMap; use std::cmp; +use parking_lot::RwLock; use util::*; use ethkey::{recover, public_to_address, Signature}; use account_provider::AccountProvider; diff --git a/ethcore/src/engines/tendermint/mod.rs b/ethcore/src/engines/tendermint/mod.rs index f4b1422d8..71f5565e9 100644 --- a/ethcore/src/engines/tendermint/mod.rs +++ b/ethcore/src/engines/tendermint/mod.rs @@ -30,6 +30,7 @@ use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering}; use std::collections::{HashSet, BTreeMap, HashMap}; use hash::keccak; use std::cmp; +use parking_lot::RwLock; use util::*; use client::{Client, EngineClient}; use error::{Error, BlockError}; diff --git a/ethcore/src/engines/validator_set/contract.rs b/ethcore/src/engines/validator_set/contract.rs index ff16eb1d2..28414be0f 100644 --- a/ethcore/src/engines/validator_set/contract.rs +++ b/ethcore/src/engines/validator_set/contract.rs @@ -18,6 +18,7 @@ /// It can also report validators for misbehaviour with two levels: `reportMalicious` and `reportBenign`. use std::sync::Weak; +use parking_lot::RwLock; use util::*; use futures::Future; diff --git a/ethcore/src/engines/validator_set/multi.rs b/ethcore/src/engines/validator_set/multi.rs index 477a453b2..53617094a 100644 --- a/ethcore/src/engines/validator_set/multi.rs +++ b/ethcore/src/engines/validator_set/multi.rs @@ -19,7 +19,8 @@ use std::collections::BTreeMap; use std::sync::Weak; use engines::{Call, Engine}; -use util::{Bytes, H256, Address, RwLock}; +use parking_lot::RwLock; +use util::{Bytes, H256, Address}; use ids::BlockId; use header::{BlockNumber, Header}; use client::{Client, BlockChainClient}; diff --git a/ethcore/src/engines/validator_set/safe_contract.rs b/ethcore/src/engines/validator_set/safe_contract.rs index 6480a298e..dc186818a 100644 --- a/ethcore/src/engines/validator_set/safe_contract.rs +++ b/ethcore/src/engines/validator_set/safe_contract.rs @@ -21,6 +21,7 @@ use futures::Future; use native_contracts::ValidatorSet as Provider; use hash::keccak; +use parking_lot::RwLock; use util::*; use util::cache::MemoryLruCache; use rlp::{UntrustedRlp, RlpStream}; diff --git a/ethcore/src/engines/vote_collector.rs b/ethcore/src/engines/vote_collector.rs index 387715a03..8dd9f7c36 100644 --- a/ethcore/src/engines/vote_collector.rs +++ b/ethcore/src/engines/vote_collector.rs @@ -19,6 +19,7 @@ use std::fmt::Debug; use std::collections::{BTreeMap, HashSet, HashMap}; use std::hash::Hash; +use parking_lot:: RwLock; use util::*; use rlp::{Encodable, RlpStream}; diff --git a/ethcore/src/lib.rs b/ethcore/src/lib.rs index df7c25d3f..7d175ad7a 100644 --- a/ethcore/src/lib.rs +++ b/ethcore/src/lib.rs @@ -98,6 +98,7 @@ extern crate lru_cache; extern crate native_contracts; extern crate num_cpus; extern crate num; +extern crate parking_lot; extern crate price_info; extern crate rand; extern crate rlp; diff --git a/ethcore/src/miner/external.rs b/ethcore/src/miner/external.rs index 65f8ee8cc..c38bb16d4 100644 --- a/ethcore/src/miner/external.rs +++ b/ethcore/src/miner/external.rs @@ -17,7 +17,8 @@ use std::collections::HashMap; use std::sync::Arc; use std::time::{Instant, Duration}; -use util::{Mutex, U256, H256}; +use util::{U256, H256}; +use parking_lot::Mutex; /// External miner interface. pub trait ExternalMinerService: Send + Sync { diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index fb1753760..6f5e5f23c 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -18,6 +18,7 @@ use std::time::{Instant, Duration}; use std::collections::{BTreeMap, HashSet}; use std::sync::Arc; +use parking_lot::{Mutex, RwLock}; use util::*; use timer::PerfTimer; use using_queue::{UsingQueue, GetAction}; diff --git a/ethcore/src/miner/service_transaction_checker.rs b/ethcore/src/miner/service_transaction_checker.rs index d21643772..a78f2a2c7 100644 --- a/ethcore/src/miner/service_transaction_checker.rs +++ b/ethcore/src/miner/service_transaction_checker.rs @@ -20,7 +20,8 @@ use types::ids::BlockId; use futures::{future, Future}; use native_contracts::ServiceTransactionChecker as Contract; -use util::{U256, Mutex}; +use parking_lot::Mutex; +use util::U256; const SERVICE_TRANSACTION_CONTRACT_REGISTRY_NAME: &'static str = "service_transaction_checker"; diff --git a/ethcore/src/miner/stratum.rs b/ethcore/src/miner/stratum.rs index 0031bb715..1586dc69f 100644 --- a/ethcore/src/miner/stratum.rs +++ b/ethcore/src/miner/stratum.rs @@ -28,7 +28,7 @@ use std::fmt; use util::{H256, U256, H64, clean_0x}; use ethereum::ethash::Ethash; use ethash::SeedHashCompute; -use util::Mutex; +use parking_lot::Mutex; use miner::{self, Miner, MinerService}; use client::Client; use block::IsBlock; diff --git a/ethcore/src/miner/work_notify.rs b/ethcore/src/miner/work_notify.rs index ff330d30c..160aa1f46 100644 --- a/ethcore/src/miner/work_notify.rs +++ b/ethcore/src/miner/work_notify.rs @@ -24,6 +24,7 @@ use hyper::{Next}; use hyper::net::HttpStream; use ethash::SeedHashCompute; use hyper::Url; +use parking_lot::Mutex; use util::*; use ethereum::ethash::Ethash; diff --git a/ethcore/src/snapshot/mod.rs b/ethcore/src/snapshot/mod.rs index 974b074cf..fa6ab8f06 100644 --- a/ethcore/src/snapshot/mod.rs +++ b/ethcore/src/snapshot/mod.rs @@ -31,7 +31,7 @@ use header::Header; use ids::BlockId; use util::{Bytes, HashDB, DBValue, snappy, U256}; -use util::Mutex; +use parking_lot::Mutex; use util::hash::{H256}; use util::journaldb::{self, Algorithm, JournalDB}; use util::kvdb::KeyValueDB; diff --git a/ethcore/src/snapshot/service.rs b/ethcore/src/snapshot/service.rs index 47bbb5997..24ce91d39 100644 --- a/ethcore/src/snapshot/service.rs +++ b/ethcore/src/snapshot/service.rs @@ -35,7 +35,8 @@ use service::ClientIoMessage; use io::IoChannel; -use util::{Bytes, H256, Mutex, RwLock, RwLockReadGuard, UtilError}; +use parking_lot::{Mutex, RwLock, RwLockReadGuard}; +use util::{Bytes, H256, UtilError}; use util::journaldb::Algorithm; use util::kvdb::{Database, DatabaseConfig}; use util::snappy; diff --git a/ethcore/src/snapshot/tests/proof_of_work.rs b/ethcore/src/snapshot/tests/proof_of_work.rs index 907fcead8..428023a5c 100644 --- a/ethcore/src/snapshot/tests/proof_of_work.rs +++ b/ethcore/src/snapshot/tests/proof_of_work.rs @@ -24,7 +24,8 @@ use blockchain::BlockChain; use snapshot::{chunk_secondary, Error as SnapshotError, Progress, SnapshotComponents}; use snapshot::io::{PackedReader, PackedWriter, SnapshotReader, SnapshotWriter}; -use util::{Mutex, snappy}; +use parking_lot::Mutex; +use util::snappy; use util::kvdb::{self, KeyValueDB, DBTransaction}; use std::sync::Arc; diff --git a/ethcore/src/snapshot/tests/state.rs b/ethcore/src/snapshot/tests/state.rs index 9a98af5ff..4e2e70a6f 100644 --- a/ethcore/src/snapshot/tests/state.rs +++ b/ethcore/src/snapshot/tests/state.rs @@ -29,7 +29,7 @@ use util::hash::H256; use util::journaldb::{self, Algorithm}; use util::kvdb::{Database, DatabaseConfig}; use util::memorydb::MemoryDB; -use util::Mutex; +use parking_lot::Mutex; use devtools::RandomTempPath; use std::sync::Arc; diff --git a/ethcore/src/snapshot/watcher.rs b/ethcore/src/snapshot/watcher.rs index cff9be18c..89f8b62df 100644 --- a/ethcore/src/snapshot/watcher.rs +++ b/ethcore/src/snapshot/watcher.rs @@ -16,7 +16,7 @@ //! Watcher for snapshot-related chain events. -use util::Mutex; +use parking_lot::Mutex; use client::{BlockChainClient, Client, ChainNotify}; use ids::BlockId; use service::ClientIoMessage; diff --git a/ethcore/src/spec/spec.rs b/ethcore/src/spec/spec.rs index e93703871..98f04da6f 100644 --- a/ethcore/src/spec/spec.rs +++ b/ethcore/src/spec/spec.rs @@ -40,6 +40,7 @@ use state_db::StateDB; use state::{Backend, State, Substate}; use state::backend::Basic as BasicBackend; use trace::{NoopTracer, NoopVMTracer}; +use parking_lot::RwLock; use util::*; /// Parameters common to ethereum-like blockchains. diff --git a/ethcore/src/state/backend.rs b/ethcore/src/state/backend.rs index ea172b5af..ffe63f423 100644 --- a/ethcore/src/state/backend.rs +++ b/ethcore/src/state/backend.rs @@ -25,7 +25,8 @@ use std::collections::{HashSet, HashMap}; use std::sync::Arc; use state::Account; -use util::{Address, MemoryDB, Mutex, H256}; +use parking_lot::Mutex; +use util::{Address, MemoryDB, H256}; use util::hashdb::{AsHashDB, HashDB, DBValue}; /// State backend. See module docs for more details. diff --git a/ethcore/src/state_db.rs b/ethcore/src/state_db.rs index ce96dc4fc..dbba01125 100644 --- a/ethcore/src/state_db.rs +++ b/ethcore/src/state_db.rs @@ -25,7 +25,8 @@ use util::hashdb::HashDB; use state::{self, Account}; use header::BlockNumber; use hash::keccak; -use util::{Address, DBTransaction, UtilError, Mutex}; +use parking_lot::Mutex; +use util::{Address, DBTransaction, UtilError}; use bloom_journal::{Bloom, BloomJournal}; use db::COL_ACCOUNT_BLOOM; use byteorder::{LittleEndian, ByteOrder}; diff --git a/ethcore/src/trace/db.rs b/ethcore/src/trace/db.rs index 0fe057a64..d7055a547 100644 --- a/ethcore/src/trace/db.rs +++ b/ethcore/src/trace/db.rs @@ -21,7 +21,8 @@ use std::sync::Arc; use bloomchain::{Number, Config as BloomConfig}; use bloomchain::group::{BloomGroupDatabase, BloomGroupChain, GroupPosition, BloomGroup}; use heapsize::HeapSizeOf; -use util::{H256, H264, KeyValueDB, DBTransaction, RwLock}; +use parking_lot::RwLock; +use util::{H256, H264, KeyValueDB, DBTransaction}; use header::BlockNumber; use trace::{LocalizedTrace, Config, Filter, Database as TraceDatabase, ImportRequest, DatabaseExtras}; use db::{self, Key, Writable, Readable, CacheUpdatePolicy}; diff --git a/ethcore/src/verification/queue/mod.rs b/ethcore/src/verification/queue/mod.rs index 8fc4a5919..ab019a216 100644 --- a/ethcore/src/verification/queue/mod.rs +++ b/ethcore/src/verification/queue/mod.rs @@ -23,6 +23,7 @@ use std::sync::{Condvar as SCondvar, Mutex as SMutex, Arc}; use std::cmp; use std::collections::{VecDeque, HashSet, HashMap}; use heapsize::HeapSizeOf; +use parking_lot::{Condvar, Mutex, RwLock}; use util::*; use io::*; use error::*; diff --git a/hash-fetch/Cargo.toml b/hash-fetch/Cargo.toml index e87ffea1a..884729a69 100644 --- a/hash-fetch/Cargo.toml +++ b/hash-fetch/Cargo.toml @@ -14,6 +14,7 @@ mime = "0.2" mime_guess = "1.6.1" rand = "0.3" rustc-hex = "1.0" +parking_lot = "0.4" fetch = { path = "../util/fetch" } ethcore-util = { path = "../util" } parity-reactor = { path = "../util/reactor" } diff --git a/hash-fetch/src/client.rs b/hash-fetch/src/client.rs index d63df794a..6ebfdcb5c 100644 --- a/hash-fetch/src/client.rs +++ b/hash-fetch/src/client.rs @@ -191,7 +191,7 @@ fn random_temp_path() -> PathBuf { mod tests { use rustc_hex::FromHex; use std::sync::{Arc, mpsc}; - use util::Mutex; + use parking_lot::Mutex; use futures::future; use fetch::{self, Fetch}; use parity_reactor::Remote; diff --git a/hash-fetch/src/lib.rs b/hash-fetch/src/lib.rs index 987770252..c09af0c89 100644 --- a/hash-fetch/src/lib.rs +++ b/hash-fetch/src/lib.rs @@ -29,6 +29,7 @@ extern crate futures; extern crate mime_guess; extern crate native_contracts; extern crate parity_reactor; +extern crate parking_lot; extern crate rand; extern crate rustc_hex; extern crate hash; diff --git a/hash-fetch/src/urlhint.rs b/hash-fetch/src/urlhint.rs index 3fa32eb15..945d20d72 100644 --- a/hash-fetch/src/urlhint.rs +++ b/hash-fetch/src/urlhint.rs @@ -216,7 +216,8 @@ pub mod tests { use super::*; use super::guess_mime_type; - use util::{Bytes, Address, Mutex, ToPretty}; + use parking_lot::Mutex; + use util::{Bytes, Address, ToPretty}; pub struct FakeRegistrar { pub calls: Arc>>, diff --git a/parity/blockchain.rs b/parity/blockchain.rs index a94b387d4..266be7dfd 100644 --- a/parity/blockchain.rs +++ b/parity/blockchain.rs @@ -155,6 +155,7 @@ pub fn execute(cmd: BlockchainCmd) -> Result<(), String> { fn execute_import_light(cmd: ImportBlockchain) -> Result<(), String> { use light::client::{Service as LightClientService, Config as LightClientConfig}; use light::cache::Cache as LightDataCache; + use parking_lot::Mutex; let timer = Instant::now(); @@ -188,7 +189,7 @@ fn execute_import_light(cmd: ImportBlockchain) -> Result<(), String> { // create dirs used by parity cmd.dirs.create_dirs(false, false, false)?; - let cache = Arc::new(::util::Mutex::new( + let cache = Arc::new(Mutex::new( LightDataCache::new(Default::default(), ::time::Duration::seconds(0)) )); diff --git a/parity/informant.rs b/parity/informant.rs index 4e2987892..166e36a62 100644 --- a/parity/informant.rs +++ b/parity/informant.rs @@ -35,7 +35,8 @@ use light::client::LightChainClient; use number_prefix::{binary_prefix, Standalone, Prefixed}; use parity_rpc::{is_major_importing}; use parity_rpc::informant::RpcStats; -use util::{RwLock, Mutex, H256, Bytes}; +use parking_lot::{RwLock, Mutex}; +use util::{H256, Bytes}; /// Format byte counts to standard denominations. pub fn format_bytes(b: usize) -> String { diff --git a/parity/light_helpers/queue_cull.rs b/parity/light_helpers/queue_cull.rs index 982e69e48..eaf0ca9c5 100644 --- a/parity/light_helpers/queue_cull.rs +++ b/parity/light_helpers/queue_cull.rs @@ -31,7 +31,7 @@ use futures::{future, Future}; use parity_reactor::Remote; -use util::RwLock; +use parking_lot::RwLock; // Attepmt to cull once every 10 minutes. const TOKEN: TimerToken = 1; diff --git a/parity/main.rs b/parity/main.rs index 00c219963..485101b66 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -34,6 +34,7 @@ extern crate isatty; extern crate jsonrpc_core; extern crate num_cpus; extern crate number_prefix; +extern crate parking_lot; extern crate regex; extern crate rlp; extern crate rpassword; diff --git a/parity/rpc_apis.rs b/parity/rpc_apis.rs index 7948d9b20..d3171f381 100644 --- a/parity/rpc_apis.rs +++ b/parity/rpc_apis.rs @@ -38,7 +38,7 @@ use parity_rpc::dispatch::{FullDispatcher, LightDispatcher}; use parity_rpc::informant::{ActivityNotifier, ClientNotifier}; use parity_rpc::{Metadata, NetworkSettings}; use updater::Updater; -use util::{Mutex, RwLock}; +use parking_lot::{Mutex, RwLock}; #[derive(Debug, PartialEq, Clone, Eq, Hash)] pub enum Api { diff --git a/parity/run.rs b/parity/run.rs index 093a019f3..c9c1283ca 100644 --- a/parity/run.rs +++ b/parity/run.rs @@ -37,8 +37,9 @@ use node_health; use parity_reactor::EventLoop; use parity_rpc::{NetworkSettings, informant, is_major_importing}; use updater::{UpdatePolicy, Updater}; -use util::{version, Mutex, Condvar}; use ansi_term::Colour; +use util::version; +use parking_lot::{Condvar, Mutex}; use node_filter::NodeFilter; use params::{ @@ -171,7 +172,7 @@ impl ::local_store::NodeInfo for FullNodeInfo { fn execute_light(cmd: RunCmd, can_restart: bool, logger: Arc) -> Result<(bool, Option), String> { use light::client as light_client; use ethsync::{LightSyncParams, LightSync, ManageNetwork}; - use util::RwLock; + use parking_lot::{Mutex, RwLock}; // load spec let spec = cmd.spec.spec(&cmd.dirs.cache)?; @@ -206,7 +207,7 @@ fn execute_light(cmd: RunCmd, can_restart: bool, logger: Arc) -> // TODO: configurable cache size. let cache = LightDataCache::new(Default::default(), ::time::Duration::minutes(GAS_CORPUS_EXPIRATION_MINUTES)); - let cache = Arc::new(::util::Mutex::new(cache)); + let cache = Arc::new(Mutex::new(cache)); // start client and create transaction queue. let mut config = light_client::Config { diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index a0bbe95ca..daa6cf3ce 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -15,6 +15,7 @@ futures-cpupool = "0.1" log = "0.3" multihash ="0.6" order-stat = "0.1" +parking_lot = "0.4" rand = "0.3" rust-crypto = "0.2" rustc-hex = "1.0" diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 22f623bf6..b6e9c28fe 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -28,6 +28,7 @@ extern crate futures_cpupool; extern crate itertools; extern crate multihash; extern crate order_stat; +extern crate parking_lot; extern crate rand; extern crate rustc_hex; extern crate semver; diff --git a/rpc/src/v1/helpers/dispatch.rs b/rpc/src/v1/helpers/dispatch.rs index 41fc201cf..96e2c8b4e 100644 --- a/rpc/src/v1/helpers/dispatch.rs +++ b/rpc/src/v1/helpers/dispatch.rs @@ -27,7 +27,8 @@ use light::on_demand::{request, OnDemand}; use light::TransactionQueue as LightTransactionQueue; use rlp; use hash::keccak; -use util::{Address, H520, H256, U256, Bytes, Mutex, RwLock}; +use util::{Address, H520, H256, U256, Bytes}; +use parking_lot::{Mutex, RwLock}; use stats::Corpus; use ethkey::Signature; diff --git a/rpc/src/v1/helpers/light_fetch.rs b/rpc/src/v1/helpers/light_fetch.rs index 972315272..b46de402f 100644 --- a/rpc/src/v1/helpers/light_fetch.rs +++ b/rpc/src/v1/helpers/light_fetch.rs @@ -37,7 +37,8 @@ use light::on_demand::{request, OnDemand, HeaderRef, Request as OnDemandRequest, use light::request::Field; use ethsync::LightSync; -use util::{Address, Mutex, U256}; +use util::{Address, U256}; +use parking_lot::Mutex; use v1::helpers::{CallRequest as CallRequestHelper, errors, dispatch}; use v1::types::{BlockNumber, CallRequest, Log}; diff --git a/rpc/src/v1/helpers/signer.rs b/rpc/src/v1/helpers/signer.rs index 81d21eb82..6d9606f87 100644 --- a/rpc/src/v1/helpers/signer.rs +++ b/rpc/src/v1/helpers/signer.rs @@ -17,7 +17,7 @@ use std::sync::Arc; use std::ops::Deref; use http::Origin; -use util::Mutex; +use parking_lot::Mutex; use transient_hashmap::TransientHashMap; use ethstore::random_string; diff --git a/rpc/src/v1/helpers/signing_queue.rs b/rpc/src/v1/helpers/signing_queue.rs index e9e6313f4..6dba2f7a2 100644 --- a/rpc/src/v1/helpers/signing_queue.rs +++ b/rpc/src/v1/helpers/signing_queue.rs @@ -19,7 +19,8 @@ use std::cell::RefCell; use std::sync::Arc; use std::collections::BTreeMap; use jsonrpc_core; -use util::{Mutex, RwLock, U256, Address}; +use parking_lot::{Mutex, RwLock}; +use util::{U256, Address}; use ethcore::account_provider::DappId; use v1::helpers::{ConfirmationRequest, ConfirmationPayload}; use v1::types::{ConfirmationResponse, H160 as RpcH160, Origin, DappId as RpcDappId}; @@ -297,7 +298,8 @@ mod test { use std::time::Duration; use std::thread; use std::sync::{mpsc, Arc}; - use util::{Address, U256, Mutex}; + use parking_lot::Mutex; + use util::{Address, U256}; use v1::helpers::{SigningQueue, ConfirmationsQueue, QueueEvent, FilledTransactionRequest, ConfirmationPayload}; use v1::types::ConfirmationResponse; diff --git a/rpc/src/v1/helpers/subscription_manager.rs b/rpc/src/v1/helpers/subscription_manager.rs index c5e4216f4..f529d4810 100644 --- a/rpc/src/v1/helpers/subscription_manager.rs +++ b/rpc/src/v1/helpers/subscription_manager.rs @@ -18,7 +18,7 @@ use std::sync::Arc; use std::sync::atomic::{self, AtomicBool}; -use util::Mutex; +use parking_lot::Mutex; use jsonrpc_core::futures::future::{self, Either}; use jsonrpc_core::futures::sync::mpsc; diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index f31d32426..30afe4771 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -24,7 +24,7 @@ use futures::{self, future, BoxFuture, Future}; use rlp::{self, UntrustedRlp}; use time::get_time; use util::{H160, H256, Address, U256, H64}; -use util::Mutex; +use parking_lot::Mutex; use ethash::SeedHashCompute; use ethcore::account_provider::{AccountProvider, DappId}; diff --git a/rpc/src/v1/impls/eth_filter.rs b/rpc/src/v1/impls/eth_filter.rs index 8f448feb5..ee8e27778 100644 --- a/rpc/src/v1/impls/eth_filter.rs +++ b/rpc/src/v1/impls/eth_filter.rs @@ -23,7 +23,8 @@ use jsonrpc_core::*; use ethcore::miner::MinerService; use ethcore::filter::Filter as EthcoreFilter; use ethcore::client::{BlockChainClient, BlockId}; -use util::{H256, Mutex}; +use util::H256; +use parking_lot::Mutex; use futures::{future, Future, BoxFuture}; diff --git a/rpc/src/v1/impls/eth_pubsub.rs b/rpc/src/v1/impls/eth_pubsub.rs index f918a44ea..4eff9cdaa 100644 --- a/rpc/src/v1/impls/eth_pubsub.rs +++ b/rpc/src/v1/impls/eth_pubsub.rs @@ -39,7 +39,8 @@ use light::cache::Cache; use light::on_demand::OnDemand; use light::client::{LightChainClient, LightChainNotify}; use parity_reactor::Remote; -use util::{RwLock, Mutex, H256, Bytes}; +use util::{H256, Bytes}; +use parking_lot::{RwLock, Mutex}; type Client = Sink; diff --git a/rpc/src/v1/impls/light/eth.rs b/rpc/src/v1/impls/light/eth.rs index 7e40bf71a..c9a0b9999 100644 --- a/rpc/src/v1/impls/light/eth.rs +++ b/rpc/src/v1/impls/light/eth.rs @@ -39,7 +39,8 @@ use ethcore::transaction::{Action, SignedTransaction, Transaction as EthTransact use ethsync::LightSync; use rlp::UntrustedRlp; use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP}; -use util::{RwLock, Mutex, U256}; +use util::U256; +use parking_lot::{RwLock, Mutex}; use futures::{future, Future, BoxFuture, IntoFuture}; use futures::sync::oneshot; diff --git a/rpc/src/v1/impls/pubsub.rs b/rpc/src/v1/impls/pubsub.rs index 616905f4a..44b9fcbeb 100644 --- a/rpc/src/v1/impls/pubsub.rs +++ b/rpc/src/v1/impls/pubsub.rs @@ -18,7 +18,7 @@ use std::sync::Arc; use std::time::Duration; -use util::RwLock; +use parking_lot::RwLock; use futures::{self, BoxFuture, Future, Stream, Sink}; use jsonrpc_core::{self as core, Error, MetaIoHandler}; diff --git a/rpc/src/v1/impls/signer.rs b/rpc/src/v1/impls/signer.rs index 79f4f0e38..a01b66364 100644 --- a/rpc/src/v1/impls/signer.rs +++ b/rpc/src/v1/impls/signer.rs @@ -24,7 +24,7 @@ use ethkey; use futures::{future, BoxFuture, Future, IntoFuture}; use parity_reactor::Remote; use rlp::UntrustedRlp; -use util::Mutex; +use parking_lot::Mutex; use jsonrpc_core::{futures, Error}; use jsonrpc_pubsub::SubscriptionId; diff --git a/rpc/src/v1/impls/signing.rs b/rpc/src/v1/impls/signing.rs index 23ce3c78a..a7ef5cc10 100644 --- a/rpc/src/v1/impls/signing.rs +++ b/rpc/src/v1/impls/signing.rs @@ -18,7 +18,8 @@ use std::sync::Arc; use transient_hashmap::TransientHashMap; -use util::{U256, Mutex}; +use parking_lot::Mutex; +use util::U256; use ethcore::account_provider::AccountProvider; diff --git a/rpc/src/v1/informant.rs b/rpc/src/v1/informant.rs index 160f0ea9f..0cbe7d449 100644 --- a/rpc/src/v1/informant.rs +++ b/rpc/src/v1/informant.rs @@ -24,7 +24,7 @@ use futures::Future; use futures_cpupool as pool; use jsonrpc_core as rpc; use order_stat; -use util::RwLock; +use parking_lot::RwLock; pub use self::pool::CpuPool; diff --git a/rpc/src/v1/tests/helpers/miner_service.rs b/rpc/src/v1/tests/helpers/miner_service.rs index 7139d636b..5670824dc 100644 --- a/rpc/src/v1/tests/helpers/miner_service.rs +++ b/rpc/src/v1/tests/helpers/miner_service.rs @@ -18,7 +18,8 @@ use std::collections::{BTreeMap, HashMap}; use std::collections::hash_map::Entry; -use util::{Address, H256, Bytes, U256, RwLock, Mutex}; +use util::{Address, H256, Bytes, U256}; +use parking_lot::{RwLock, Mutex}; use ethcore::error::Error; use ethcore::client::MiningBlockChainClient; use ethcore::block::ClosedBlock; diff --git a/rpc/src/v1/tests/helpers/snapshot_service.rs b/rpc/src/v1/tests/helpers/snapshot_service.rs index cfb80619a..6d2b71aea 100644 --- a/rpc/src/v1/tests/helpers/snapshot_service.rs +++ b/rpc/src/v1/tests/helpers/snapshot_service.rs @@ -16,7 +16,8 @@ use ethcore::snapshot::{ManifestData, RestorationStatus, SnapshotService}; -use util::{Bytes, Mutex}; +use parking_lot::Mutex; +use util::Bytes; use util::hash::H256; /// Mocked snapshot service (used for sync info extensions). diff --git a/rpc/src/v1/tests/helpers/sync_provider.rs b/rpc/src/v1/tests/helpers/sync_provider.rs index 83c7db015..4498fa85e 100644 --- a/rpc/src/v1/tests/helpers/sync_provider.rs +++ b/rpc/src/v1/tests/helpers/sync_provider.rs @@ -17,7 +17,8 @@ //! Test implementation of SyncProvider. use std::collections::BTreeMap; -use util::{H256, RwLock}; +use parking_lot::RwLock; +use util::H256; use ethsync::{SyncProvider, EthProtocolInfo, SyncStatus, SyncState, PeerInfo, TransactionStats}; /// TestSyncProvider config. diff --git a/rpc/src/v1/tests/mocked/eth.rs b/rpc/src/v1/tests/mocked/eth.rs index d1835948f..3338cd1bd 100644 --- a/rpc/src/v1/tests/mocked/eth.rs +++ b/rpc/src/v1/tests/mocked/eth.rs @@ -22,7 +22,8 @@ use rustc_hex::{FromHex, ToHex}; use time::get_time; use rlp; -use util::{U256, Address, H256, Mutex}; +use util::{U256, Address, H256}; +use parking_lot::Mutex; use ethkey::Secret; use ethcore::account_provider::AccountProvider; use ethcore::client::{TestBlockChainClient, EachBlockWith, Executed, TransactionId}; diff --git a/rpc_client/Cargo.toml b/rpc_client/Cargo.toml index 1e39d8b1e..1f1840848 100644 --- a/rpc_client/Cargo.toml +++ b/rpc_client/Cargo.toml @@ -15,6 +15,7 @@ serde_json = "1.0" tempdir = "0.3.5" url = "1.2.0" matches = "0.1" +parking_lot = "0.4" jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.7" } jsonrpc-ws-server = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.7" } parity-rpc = { path = "../rpc" } diff --git a/rpc_client/src/client.rs b/rpc_client/src/client.rs index 9c6c4ebe8..27b72ab78 100644 --- a/rpc_client/src/client.rs +++ b/rpc_client/src/client.rs @@ -10,7 +10,7 @@ use std::time; use std::path::PathBuf; use hash::keccak; -use util::Mutex; +use parking_lot::Mutex; use url::Url; use std::fs::File; diff --git a/rpc_client/src/lib.rs b/rpc_client/src/lib.rs index 805754b22..7459ca9a4 100644 --- a/rpc_client/src/lib.rs +++ b/rpc_client/src/lib.rs @@ -6,6 +6,7 @@ extern crate futures; extern crate jsonrpc_core; extern crate jsonrpc_ws_server as ws; extern crate parity_rpc as rpc; +extern crate parking_lot; extern crate rand; extern crate serde; extern crate serde_json; diff --git a/stratum/Cargo.toml b/stratum/Cargo.toml index 9bf75779f..ffd933a59 100644 --- a/stratum/Cargo.toml +++ b/stratum/Cargo.toml @@ -23,5 +23,6 @@ semver = "0.6" ethcore-ipc-nano = { path = "../ipc/nano" } futures = "0.1" tokio-core = "0.1" +parking_lot = "0.4" ethcore-logger = { path = "../logger" } hash = { path = "../util/hash" } diff --git a/stratum/src/lib.rs b/stratum/src/lib.rs index 0cffd67b6..2649436dd 100644 --- a/stratum/src/lib.rs +++ b/stratum/src/lib.rs @@ -26,6 +26,7 @@ extern crate semver; extern crate futures; extern crate ethcore_logger; extern crate hash; +extern crate parking_lot; #[cfg(test)] extern crate tokio_core; extern crate ethcore_devtools as devtools; @@ -56,7 +57,8 @@ use std::sync::Arc; use std::net::SocketAddr; use std::collections::{HashSet, HashMap}; use hash::keccak; -use util::{H256, RwLock, RwLockReadGuard}; +use parking_lot::{RwLock, RwLockReadGuard}; +use util::H256; type RpcResult = BoxFuture; diff --git a/sync/src/chain.rs b/sync/src/chain.rs index 432a0d0f5..822ae143d 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -93,6 +93,7 @@ use std::collections::{HashSet, HashMap}; use std::cmp; use hash::keccak; use heapsize::HeapSizeOf; +use parking_lot::RwLock; use util::*; use rlp::*; use network::*; @@ -2230,7 +2231,8 @@ mod tests { use network::PeerId; use tests::helpers::*; use tests::snapshot::TestSnapshotService; - use util::{U256, Address, RwLock}; + use parking_lot::RwLock; + use util::{U256, Address}; use util::hash::H256; use util::bytes::Bytes; use rlp::{Rlp, RlpStream, UntrustedRlp}; diff --git a/sync/src/light_sync/mod.rs b/sync/src/light_sync/mod.rs index f05e4d7d0..12b6ca2a8 100644 --- a/sync/src/light_sync/mod.rs +++ b/sync/src/light_sync/mod.rs @@ -45,7 +45,8 @@ use light::net::{ }; use light::request::{self, CompleteHeadersRequest as HeadersRequest}; use network::PeerId; -use util::{U256, H256, Mutex, RwLock}; +use util::{U256, H256}; +use parking_lot::{Mutex, RwLock}; use rand::{Rng, OsRng}; use self::sync_round::{AbortReason, SyncRound, ResponseContext}; diff --git a/sync/src/light_sync/tests/test_net.rs b/sync/src/light_sync/tests/test_net.rs index f6d5eddf0..65ddf92da 100644 --- a/sync/src/light_sync/tests/test_net.rs +++ b/sync/src/light_sync/tests/test_net.rs @@ -29,7 +29,7 @@ use light::client::Client as LightClient; use light::net::{LightProtocol, IoContext, Capabilities, Params as LightParams}; use light::provider::LightProvider; use network::{NodeId, PeerId}; -use util::RwLock; +use parking_lot::RwLock; use time::Duration; use light::cache::Cache; diff --git a/sync/src/tests/helpers.rs b/sync/src/tests/helpers.rs index 3ac68b0fb..f41d630e6 100644 --- a/sync/src/tests/helpers.rs +++ b/sync/src/tests/helpers.rs @@ -16,6 +16,7 @@ use std::collections::{VecDeque, HashSet, HashMap}; use std::sync::Arc; +use parking_lot::RwLock; use util::*; use network::*; use tests::snapshot::*; diff --git a/sync/src/tests/snapshot.rs b/sync/src/tests/snapshot.rs index d49bcf440..ba68f6143 100644 --- a/sync/src/tests/snapshot.rs +++ b/sync/src/tests/snapshot.rs @@ -17,6 +17,7 @@ use std::collections::HashMap; use std::sync::Arc; use hash::keccak; +use parking_lot::Mutex; use util::*; use ethcore::snapshot::{SnapshotService, ManifestData, RestorationStatus}; use ethcore::header::BlockNumber; diff --git a/updater/Cargo.toml b/updater/Cargo.toml index bb6557f6d..90dcbfeab 100644 --- a/updater/Cargo.toml +++ b/updater/Cargo.toml @@ -17,6 +17,7 @@ ethcore = { path = "../ethcore" } ethsync = { path = "../sync" } ethcore-util = { path = "../util" } futures = "0.1" +parking_lot = "0.4" parity-hash-fetch = { path = "../hash-fetch" } ipc-common-types = { path = "../ipc-common-types" } ethcore-ipc = { path = "../ipc/rpc" } diff --git a/updater/src/lib.rs b/updater/src/lib.rs index b27f2039e..64b67b2dc 100644 --- a/updater/src/lib.rs +++ b/updater/src/lib.rs @@ -19,6 +19,7 @@ #[macro_use] extern crate log; extern crate ethcore_util as util; extern crate ipc_common_types; +extern crate parking_lot; extern crate parity_hash_fetch as hash_fetch; extern crate ethcore; extern crate ethabi; diff --git a/updater/src/updater.rs b/updater/src/updater.rs index 817688688..5d2bb1177 100644 --- a/updater/src/updater.rs +++ b/updater/src/updater.rs @@ -31,7 +31,8 @@ use path::restrict_permissions_owner; use service::{Service}; use target_info::Target; use types::all::{ReleaseInfo, OperationsInfo, CapState}; -use util::{Address, H160, H256, Mutex, Bytes}; +use parking_lot::Mutex; +use util::{Address, H160, H256, Bytes}; use util::misc; /// Filter for releases. diff --git a/util/network/src/tests.rs b/util/network/src/tests.rs index d743318ab..f6c8ed1e8 100644 --- a/util/network/src/tests.rs +++ b/util/network/src/tests.rs @@ -19,7 +19,8 @@ use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering}; use std::sync::Arc; use std::thread; use std::time::*; -use util::{Bytes, Mutex}; +use parking_lot::Mutex; +use util::Bytes; use io::TimerToken; use ethkey::{Random, Generator}; diff --git a/util/src/lib.rs b/util/src/lib.rs index 305b17220..61fc616da 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -145,7 +145,5 @@ pub use vector::*; pub use bigint::prelude::*; pub use bigint::hash; -pub use parking_lot::{Condvar, Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard}; - /// 160-bit integer representing account address pub type Address = H160; From b731ccea1843560ff436f563c2b6906d2d12cdb2 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Sun, 3 Sep 2017 09:11:14 +0200 Subject: [PATCH 7/7] triehash is separated from util (#6428) --- Cargo.lock | 13 ++ ethcore/Cargo.toml | 1 + ethcore/light/Cargo.toml | 1 + ethcore/light/src/cht.rs | 2 +- ethcore/light/src/lib.rs | 1 + ethcore/light/src/on_demand/request.rs | 6 +- ethcore/src/block.rs | 3 +- .../engines/validator_set/safe_contract.rs | 2 +- ethcore/src/lib.rs | 1 + ethcore/src/pod_account.rs | 1 + ethcore/src/pod_state.rs | 1 + ethcore/src/snapshot/block.rs | 4 +- ethcore/src/snapshot/consensus/work.rs | 2 +- ethcore/src/verification/verification.rs | 2 + sync/Cargo.toml | 1 + sync/src/blocks.rs | 1 + sync/src/lib.rs | 1 + util/Cargo.toml | 1 + util/benches/trie.rs | 3 +- util/src/lib.rs | 4 - util/src/trie/triedbmut.rs | 3 +- util/src/vector.rs | 68 --------- util/triehash/Cargo.toml | 9 ++ util/{src/triehash.rs => triehash/src/lib.rs} | 132 ++++++++++-------- 24 files changed, 124 insertions(+), 139 deletions(-) delete mode 100644 util/src/vector.rs create mode 100644 util/triehash/Cargo.toml rename util/{src/triehash.rs => triehash/src/lib.rs} (79%) diff --git a/Cargo.lock b/Cargo.lock index b126d3d35..d53c197cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -543,6 +543,7 @@ dependencies = [ "table 0.1.0", "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", "transient-hashmap 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "triehash 0.1.0", "using_queue 0.1.0", "vm 0.1.0", "wasm 0.1.0", @@ -672,6 +673,7 @@ dependencies = [ "smallvec 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "stats 0.1.0", "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", + "triehash 0.1.0", "vm 0.1.0", ] @@ -807,6 +809,7 @@ dependencies = [ "target_info 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "triehash 0.1.0", "vergen 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -922,6 +925,7 @@ dependencies = [ "semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", + "triehash 0.1.0", ] [[package]] @@ -3106,6 +3110,15 @@ dependencies = [ "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "triehash" +version = "0.1.0" +dependencies = [ + "ethcore-bigint 0.1.3", + "hash 0.1.0", + "rlp 0.2.0", +] + [[package]] name = "typeable" version = "0.1.2" diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index 5b37d96ca..71326e163 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -63,6 +63,7 @@ bloomable = { path = "../util/bloomable" } vm = { path = "vm" } wasm = { path = "wasm" } hash = { path = "../util/hash" } +triehash = { path = "../util/triehash" } semantic_version = { path = "../util/semantic_version" } [dev-dependencies] diff --git a/ethcore/light/Cargo.toml b/ethcore/light/Cargo.toml index 46ae3afe0..4232413fb 100644 --- a/ethcore/light/Cargo.toml +++ b/ethcore/light/Cargo.toml @@ -34,6 +34,7 @@ serde_derive = "1.0" parking_lot = "0.4" stats = { path = "../../util/stats" } hash = { path = "../../util/hash" } +triehash = { path = "../../util/triehash" } [features] default = [] diff --git a/ethcore/light/src/cht.rs b/ethcore/light/src/cht.rs index 7f2ccc3a8..78b45cafc 100644 --- a/ethcore/light/src/cht.rs +++ b/ethcore/light/src/cht.rs @@ -130,7 +130,7 @@ pub fn compute_root(cht_num: u64, iterable: I) -> Option } if v.len() == SIZE as usize { - Some(::util::triehash::trie_root(v)) + Some(::triehash::trie_root(v)) } else { None } diff --git a/ethcore/light/src/lib.rs b/ethcore/light/src/lib.rs index 5d9a5ae32..b7842e055 100644 --- a/ethcore/light/src/lib.rs +++ b/ethcore/light/src/lib.rs @@ -86,6 +86,7 @@ extern crate stats; extern crate time; extern crate vm; extern crate hash; +extern crate triehash; #[cfg(feature = "ipc")] extern crate ethcore_ipc as ipc; diff --git a/ethcore/light/src/on_demand/request.rs b/ethcore/light/src/on_demand/request.rs index 3a38ec974..2dae37555 100644 --- a/ethcore/light/src/on_demand/request.rs +++ b/ethcore/light/src/on_demand/request.rs @@ -709,7 +709,7 @@ impl Body { pub fn check_response(&self, cache: &Mutex<::cache::Cache>, body: &encoded::Body) -> Result { // check the integrity of the the body against the header let header = self.0.as_ref()?; - let tx_root = ::util::triehash::ordered_trie_root(body.rlp().at(0).iter().map(|r| r.as_raw().to_vec())); + let tx_root = ::triehash::ordered_trie_root(body.rlp().at(0).iter().map(|r| r.as_raw().to_vec())); if tx_root != header.transactions_root() { return Err(Error::WrongTrieRoot(header.transactions_root(), tx_root)); } @@ -739,7 +739,7 @@ impl BlockReceipts { /// Check a response with receipts against the stored header. pub fn check_response(&self, cache: &Mutex<::cache::Cache>, receipts: &[Receipt]) -> Result, Error> { let receipts_root = self.0.as_ref()?.receipts_root(); - let found_root = ::util::triehash::ordered_trie_root(receipts.iter().map(|r| ::rlp::encode(r).into_vec())); + let found_root = ::triehash::ordered_trie_root(receipts.iter().map(|r| ::rlp::encode(r).into_vec())); match receipts_root == found_root { true => { @@ -936,7 +936,7 @@ mod tests { }).collect::>(); let mut header = Header::new(); - let receipts_root = ::util::triehash::ordered_trie_root( + let receipts_root = ::triehash::ordered_trie_root( receipts.iter().map(|x| ::rlp::encode(x).into_vec()) ); diff --git a/ethcore/src/block.rs b/ethcore/src/block.rs index 5181dff1f..a48dfbcb7 100644 --- a/ethcore/src/block.rs +++ b/ethcore/src/block.rs @@ -20,9 +20,10 @@ use std::cmp; use std::sync::Arc; use std::collections::HashSet; use hash::{keccak, KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP}; +use triehash::ordered_trie_root; use rlp::{UntrustedRlp, RlpStream, Encodable, Decodable, DecoderError}; -use util::{Bytes, Address, U256, H256, ordered_trie_root}; +use util::{Bytes, Address, U256, H256}; use util::error::{Mismatch, OutOfBounds}; use basic_types::{LogBloom, Seal}; diff --git a/ethcore/src/engines/validator_set/safe_contract.rs b/ethcore/src/engines/validator_set/safe_contract.rs index dc186818a..82fb448d9 100644 --- a/ethcore/src/engines/validator_set/safe_contract.rs +++ b/ethcore/src/engines/validator_set/safe_contract.rs @@ -353,7 +353,7 @@ impl ValidatorSet for ValidatorSafeContract { // ensure receipts match header. // TODO: optimize? these were just decoded. - let found_root = ::util::triehash::ordered_trie_root( + let found_root = ::triehash::ordered_trie_root( receipts.iter().map(::rlp::encode).map(|x| x.to_vec()) ); if found_root != *old_header.receipts_root() { diff --git a/ethcore/src/lib.rs b/ethcore/src/lib.rs index 7d175ad7a..02211ed77 100644 --- a/ethcore/src/lib.rs +++ b/ethcore/src/lib.rs @@ -104,6 +104,7 @@ extern crate rand; extern crate rlp; extern crate hash; extern crate heapsize; +extern crate triehash; extern crate ansi_term; extern crate semantic_version; diff --git a/ethcore/src/pod_account.rs b/ethcore/src/pod_account.rs index b8606008c..f8c658deb 100644 --- a/ethcore/src/pod_account.rs +++ b/ethcore/src/pod_account.rs @@ -18,6 +18,7 @@ use std::fmt; use std::collections::BTreeMap; use itertools::Itertools; use hash::{keccak}; +use triehash::sec_trie_root; use util::*; use state::Account; use ethjson; diff --git a/ethcore/src/pod_state.rs b/ethcore/src/pod_state.rs index 5a0265dc1..e35e602b2 100644 --- a/ethcore/src/pod_state.rs +++ b/ethcore/src/pod_state.rs @@ -19,6 +19,7 @@ use std::fmt; use std::collections::BTreeMap; use itertools::Itertools; +use triehash::sec_trie_root; use util::*; use pod_account::{self, PodAccount}; use types::state_diff::StateDiff; diff --git a/ethcore/src/snapshot/block.rs b/ethcore/src/snapshot/block.rs index fa4b3c19f..2ef54b53b 100644 --- a/ethcore/src/snapshot/block.rs +++ b/ethcore/src/snapshot/block.rs @@ -23,7 +23,7 @@ use hash::keccak; use views::BlockView; use rlp::{DecoderError, RlpStream, UntrustedRlp}; use util::{Bytes, H256}; -use util::triehash::ordered_trie_root; +use triehash::ordered_trie_root; const HEADER_FIELDS: usize = 8; const BLOCK_FIELDS: usize = 2; @@ -190,7 +190,7 @@ mod tests { b.transactions.push(t2.into()); let receipts_root = b.header.receipts_root().clone(); - b.header.set_transactions_root(::util::triehash::ordered_trie_root( + b.header.set_transactions_root(::triehash::ordered_trie_root( b.transactions.iter().map(::rlp::encode).map(|out| out.into_vec()) )); diff --git a/ethcore/src/snapshot/consensus/work.rs b/ethcore/src/snapshot/consensus/work.rs index 2bf154fc4..7e0b896c4 100644 --- a/ethcore/src/snapshot/consensus/work.rs +++ b/ethcore/src/snapshot/consensus/work.rs @@ -222,7 +222,7 @@ impl Rebuilder for PowRebuilder { use views::BlockView; use snapshot::verify_old_block; use util::U256; - use util::triehash::ordered_trie_root; + use triehash::ordered_trie_root; let rlp = UntrustedRlp::new(chunk); let item_count = rlp.item_count()?; diff --git a/ethcore/src/verification/verification.rs b/ethcore/src/verification/verification.rs index f9290309c..eb055fd4a 100644 --- a/ethcore/src/verification/verification.rs +++ b/ethcore/src/verification/verification.rs @@ -23,6 +23,7 @@ use std::collections::HashSet; use hash::keccak; +use triehash::ordered_trie_root; use heapsize::HeapSizeOf; use util::*; use engines::Engine; @@ -269,6 +270,7 @@ fn verify_block_integrity(block: &[u8], transactions_root: &H256, uncles_hash: & mod tests { use std::collections::{BTreeMap, HashMap}; use hash::keccak; + use triehash::ordered_trie_root; use util::*; use ethkey::{Random, Generator}; use header::*; diff --git a/sync/Cargo.toml b/sync/Cargo.toml index 5fb3628df..0e1bd3d5b 100644 --- a/sync/Cargo.toml +++ b/sync/Cargo.toml @@ -19,6 +19,7 @@ ethcore-light = { path = "../ethcore/light"} ethcore = { path = "../ethcore" } rlp = { path = "../util/rlp" } hash = { path = "../util/hash" } +triehash = { path = "../util/triehash" } clippy = { version = "0.0.103", optional = true} log = "0.3" env_logger = "0.4" diff --git a/sync/src/blocks.rs b/sync/src/blocks.rs index 77cb206c8..a07d9dfd0 100644 --- a/sync/src/blocks.rs +++ b/sync/src/blocks.rs @@ -19,6 +19,7 @@ use std::collections::hash_map::Entry; use smallvec::SmallVec; use hash::{keccak, KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP}; use heapsize::HeapSizeOf; +use triehash::ordered_trie_root; use util::*; use rlp::*; use network::NetworkError; diff --git a/sync/src/lib.rs b/sync/src/lib.rs index 237d6c437..b5f97c6bc 100644 --- a/sync/src/lib.rs +++ b/sync/src/lib.rs @@ -39,6 +39,7 @@ extern crate smallvec; extern crate rlp; extern crate ipnetwork; extern crate hash; +extern crate triehash; extern crate ethcore_light as light; diff --git a/util/Cargo.toml b/util/Cargo.toml index d04450053..e4e95bad7 100644 --- a/util/Cargo.toml +++ b/util/Cargo.toml @@ -33,6 +33,7 @@ ethcore-bloom-journal = { path = "bloom" } regex = "0.2" lru-cache = "0.1.0" ethcore-logger = { path = "../logger" } +triehash = { path = "triehash" } [features] default = [] diff --git a/util/benches/trie.rs b/util/benches/trie.rs index 2ae10cf39..20b0858aa 100644 --- a/util/benches/trie.rs +++ b/util/benches/trie.rs @@ -17,6 +17,7 @@ #![feature(test)] extern crate test; +extern crate triehash; extern crate ethcore_util; #[macro_use] extern crate log; @@ -27,7 +28,7 @@ use ethcore_util::hash::*; use ethcore_util::bytes::*; use ethcore_util::trie::*; use ethcore_util::memorydb::*; -use ethcore_util::triehash::*; +use triehash::*; use hash::keccak; fn random_word(alphabet: &[u8], min_count: usize, diff_count: usize, seed: &mut H256) -> Vec { diff --git a/util/src/lib.rs b/util/src/lib.rs index 61fc616da..710a96127 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -117,14 +117,12 @@ pub mod common; pub mod error; pub mod bytes; pub mod misc; -pub mod vector; pub mod hashdb; pub mod memorydb; pub mod migration; pub mod overlaydb; pub mod journaldb; pub mod kvdb; -pub mod triehash; pub mod trie; pub mod nibbleslice; pub mod nibblevec; @@ -136,12 +134,10 @@ pub use hashdb::*; pub use memorydb::MemoryDB; pub use overlaydb::*; pub use journaldb::JournalDB; -pub use triehash::*; pub use trie::{Trie, TrieMut, TrieDB, TrieDBMut, TrieFactory, TrieError, SecTrieDB, SecTrieDBMut}; pub use kvdb::*; pub use error::*; pub use bytes::*; -pub use vector::*; pub use bigint::prelude::*; pub use bigint::hash; diff --git a/util/src/trie/triedbmut.rs b/util/src/trie/triedbmut.rs index fa23ca756..14d7f4f81 100644 --- a/util/src/trie/triedbmut.rs +++ b/util/src/trie/triedbmut.rs @@ -937,7 +937,8 @@ impl<'a> Drop for TrieDBMut<'a> { #[cfg(test)] mod tests { - use triehash::trie_root; + extern crate triehash; + use self::triehash::trie_root; use hashdb::*; use memorydb::*; use super::*; diff --git a/util/src/vector.rs b/util/src/vector.rs deleted file mode 100644 index 951d396c7..000000000 --- a/util/src/vector.rs +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2015-2017 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . - -//! Vector extensions. - -/// Returns len of prefix shared with elem -/// -/// ```rust -/// extern crate ethcore_util as util; -/// use util::vector::SharedPrefix; -/// -/// fn main () { -/// let a = vec![1,2,3,3,5]; -/// let b = vec![1,2,3]; -/// assert_eq!(a.shared_prefix_len(&b), 3); -/// } -/// ``` -pub trait SharedPrefix { - /// Get common prefix length - fn shared_prefix_len(&self, elem: &[T]) -> usize; -} - -impl SharedPrefix for [T] where T: Eq { - fn shared_prefix_len(&self, elem: &[T]) -> usize { - use std::cmp; - let len = cmp::min(self.len(), elem.len()); - (0..len).take_while(|&i| self[i] == elem[i]).count() - } -} - -#[cfg(test)] -mod test { - use vector::SharedPrefix; - - #[test] - fn test_shared_prefix() { - let a = vec![1,2,3,4,5,6]; - let b = vec![4,2,3,4,5,6]; - assert_eq!(a.shared_prefix_len(&b), 0); - } - - #[test] - fn test_shared_prefix2() { - let a = vec![1,2,3,3,5]; - let b = vec![1,2,3]; - assert_eq!(a.shared_prefix_len(&b), 3); - } - - #[test] - fn test_shared_prefix3() { - let a = vec![1,2,3,4,5,6]; - let b = vec![1,2,3,4,5,6]; - assert_eq!(a.shared_prefix_len(&b), 6); - } -} diff --git a/util/triehash/Cargo.toml b/util/triehash/Cargo.toml new file mode 100644 index 000000000..cc18a6ea8 --- /dev/null +++ b/util/triehash/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "triehash" +version = "0.1.0" +authors = ["Parity Technologies "] + +[dependencies] +rlp = { path = "../rlp" } +ethcore-bigint = { path = "../bigint" } +hash = { path = "../hash" } diff --git a/util/src/triehash.rs b/util/triehash/src/lib.rs similarity index 79% rename from util/src/triehash.rs rename to util/triehash/src/lib.rs index fa790f3f4..d166aa5d0 100644 --- a/util/src/triehash.rs +++ b/util/triehash/src/lib.rs @@ -18,26 +18,31 @@ //! //! This module should be used to generate trie root hash. +extern crate ethcore_bigint; +extern crate hash; +extern crate rlp; + use std::collections::BTreeMap; use std::cmp; -use hash::*; -use keccak::keccak; -use rlp; +use ethcore_bigint::hash::H256; +use hash::keccak; use rlp::RlpStream; -use vector::SharedPrefix; + +fn shared_prefix_len(first: &[T], second: &[T]) -> usize { + let len = cmp::min(first.len(), second.len()); + (0..len).take_while(|&i| first[i] == second[i]).count() +} /// Generates a trie root hash for a vector of values /// /// ```rust -/// extern crate ethcore_util as util; -/// use std::str::FromStr; -/// use util::triehash::*; -/// use util::hash::*; +/// extern crate triehash; +/// use triehash::ordered_trie_root; /// /// fn main() { /// let v = vec![From::from("doe"), From::from("reindeer")]; /// let root = "e766d5d51b89dc39d981b41bda63248d7abce4f0225eefd023792a540bcffee3"; -/// assert_eq!(ordered_trie_root(v), H256::from_str(root).unwrap()); +/// assert_eq!(ordered_trie_root(v), root.parse().unwrap()); /// } /// ``` pub fn ordered_trie_root(input: I) -> H256 @@ -61,10 +66,8 @@ pub fn ordered_trie_root(input: I) -> H256 /// Generates a trie root hash for a vector of key-values /// /// ```rust -/// extern crate ethcore_util as util; -/// use std::str::FromStr; -/// use util::triehash::*; -/// use util::hash::*; +/// extern crate triehash; +/// use triehash::trie_root; /// /// fn main() { /// let v = vec![ @@ -74,7 +77,7 @@ pub fn ordered_trie_root(input: I) -> H256 /// ]; /// /// let root = "8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3"; -/// assert_eq!(trie_root(v), H256::from_str(root).unwrap()); +/// assert_eq!(trie_root(v), root.parse().unwrap()); /// } /// ``` pub fn trie_root(input: I) -> H256 @@ -95,10 +98,8 @@ pub fn trie_root(input: I) -> H256 /// Generates a key-hashed (secure) trie root hash for a vector of key-values. /// /// ```rust -/// extern crate ethcore_util as util; -/// use std::str::FromStr; -/// use util::triehash::*; -/// use util::hash::*; +/// extern crate triehash; +/// use triehash::sec_trie_root; /// /// fn main() { /// let v = vec![ @@ -108,7 +109,7 @@ pub fn trie_root(input: I) -> H256 /// ]; /// /// let root = "d4cd937e4a4368d7931a9cf51686b7e10abb3dce38a39000fd7902a092b64585"; -/// assert_eq!(sec_trie_root(v), H256::from_str(root).unwrap()); +/// assert_eq!(sec_trie_root(v), root.parse().unwrap()); /// } /// ``` pub fn sec_trie_root(input: Vec<(Vec, Vec)>) -> H256 { @@ -216,7 +217,7 @@ fn hash256rlp(input: &[(Vec, Vec)], pre_len: usize, stream: &mut RlpStre .skip(1) // get minimum number of shared nibbles between first and each successive .fold(key.len(), | acc, &(ref k, _) | { - cmp::min(key.shared_prefix_len(k), acc) + cmp::min(shared_prefix_len(key, k), acc) }); // if shared prefix is higher than current prefix append its @@ -288,50 +289,49 @@ fn test_nibbles() { assert_eq!(as_nibbles(&v), e); } -#[test] -fn test_hex_prefix_encode() { - let v = vec![0, 0, 1, 2, 3, 4, 5]; - let e = vec![0x10, 0x01, 0x23, 0x45]; - let h = hex_prefix_encode(&v, false); - assert_eq!(h, e); - - let v = vec![0, 1, 2, 3, 4, 5]; - let e = vec![0x00, 0x01, 0x23, 0x45]; - let h = hex_prefix_encode(&v, false); - assert_eq!(h, e); - - let v = vec![0, 1, 2, 3, 4, 5]; - let e = vec![0x20, 0x01, 0x23, 0x45]; - let h = hex_prefix_encode(&v, true); - assert_eq!(h, e); - - let v = vec![1, 2, 3, 4, 5]; - let e = vec![0x31, 0x23, 0x45]; - let h = hex_prefix_encode(&v, true); - assert_eq!(h, e); - - let v = vec![1, 2, 3, 4]; - let e = vec![0x00, 0x12, 0x34]; - let h = hex_prefix_encode(&v, false); - assert_eq!(h, e); - - let v = vec![4, 1]; - let e = vec![0x20, 0x41]; - let h = hex_prefix_encode(&v, true); - assert_eq!(h, e); -} #[cfg(test)] mod tests { - use std::str::FromStr; - use hash::H256; - use super::trie_root; + use super::{trie_root, shared_prefix_len, hex_prefix_encode}; + + #[test] + fn test_hex_prefix_encode() { + let v = vec![0, 0, 1, 2, 3, 4, 5]; + let e = vec![0x10, 0x01, 0x23, 0x45]; + let h = hex_prefix_encode(&v, false); + assert_eq!(h, e); + + let v = vec![0, 1, 2, 3, 4, 5]; + let e = vec![0x00, 0x01, 0x23, 0x45]; + let h = hex_prefix_encode(&v, false); + assert_eq!(h, e); + + let v = vec![0, 1, 2, 3, 4, 5]; + let e = vec![0x20, 0x01, 0x23, 0x45]; + let h = hex_prefix_encode(&v, true); + assert_eq!(h, e); + + let v = vec![1, 2, 3, 4, 5]; + let e = vec![0x31, 0x23, 0x45]; + let h = hex_prefix_encode(&v, true); + assert_eq!(h, e); + + let v = vec![1, 2, 3, 4]; + let e = vec![0x00, 0x12, 0x34]; + let h = hex_prefix_encode(&v, false); + assert_eq!(h, e); + + let v = vec![4, 1]; + let e = vec![0x20, 0x41]; + let h = hex_prefix_encode(&v, true); + assert_eq!(h, e); + } #[test] fn simple_test() { assert_eq!(trie_root(vec![ (b"A".to_vec(), b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".to_vec()) - ]), H256::from_str("d23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab").unwrap()); + ]), "d23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab".parse().unwrap()); } #[test] @@ -348,4 +348,24 @@ mod tests { ])); } + #[test] + fn test_shared_prefix() { + let a = vec![1,2,3,4,5,6]; + let b = vec![4,2,3,4,5,6]; + assert_eq!(shared_prefix_len(&a, &b), 0); + } + + #[test] + fn test_shared_prefix2() { + let a = vec![1,2,3,3,5]; + let b = vec![1,2,3]; + assert_eq!(shared_prefix_len(&a, &b), 3); + } + + #[test] + fn test_shared_prefix3() { + let a = vec![1,2,3,4,5,6]; + let b = vec![1,2,3,4,5,6]; + assert_eq!(shared_prefix_len(&a, &b), 6); + } }