Merge branch 'master' into fo-6418-dont-export-bigint
# Conflicts: # dapps/src/tests/helpers/registrar.rs # ethcore/evm/src/interpreter/shared_cache.rs # ethcore/light/src/client/header_chain.rs # ethcore/light/src/client/mod.rs # ethcore/light/src/net/mod.rs # ethcore/light/src/on_demand/request.rs # ethcore/light/src/on_demand/tests.rs # ethcore/light/src/provider.rs # ethcore/node_filter/src/lib.rs # ethcore/src/block.rs # ethcore/src/blockchain/blockchain.rs # ethcore/src/client/test_client.rs # ethcore/src/engines/authority_round/mod.rs # ethcore/src/engines/basic_authority.rs # ethcore/src/engines/mod.rs # ethcore/src/engines/tendermint/mod.rs # ethcore/src/engines/validator_set/contract.rs # ethcore/src/engines/validator_set/multi.rs # ethcore/src/engines/validator_set/safe_contract.rs # ethcore/src/engines/vote_collector.rs # ethcore/src/miner/external.rs # ethcore/src/miner/miner.rs # ethcore/src/miner/service_transaction_checker.rs # ethcore/src/miner/work_notify.rs # ethcore/src/pod_account.rs # ethcore/src/pod_state.rs # ethcore/src/snapshot/block.rs # ethcore/src/snapshot/consensus/work.rs # ethcore/src/snapshot/mod.rs # ethcore/src/snapshot/service.rs # ethcore/src/spec/spec.rs # ethcore/src/state/backend.rs # ethcore/src/trace/db.rs # ethcore/src/verification/queue/mod.rs # ethcore/src/verification/verification.rs # parity/informant.rs # rpc/src/v1/helpers/dispatch.rs # rpc/src/v1/helpers/light_fetch.rs # rpc/src/v1/helpers/signing_queue.rs # rpc/src/v1/impls/eth.rs # rpc/src/v1/impls/eth_filter.rs # rpc/src/v1/impls/eth_pubsub.rs # rpc/src/v1/impls/light/eth.rs # rpc/src/v1/impls/signing.rs # rpc/src/v1/tests/helpers/miner_service.rs # rpc/src/v1/tests/helpers/snapshot_service.rs # rpc/src/v1/tests/helpers/sync_provider.rs # rpc/src/v1/tests/mocked/eth.rs # stratum/src/lib.rs # sync/src/blocks.rs # sync/src/chain.rs # sync/src/light_sync/mod.rs # sync/src/tests/helpers.rs # sync/src/tests/snapshot.rs # updater/src/updater.rs # util/src/lib.rs # util/triehash/src/lib.rs
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -20,11 +20,12 @@ 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 bigint::prelude::U256;
|
||||
use bigint::hash::H256;
|
||||
use util::{Bytes, Address, ordered_trie_root};
|
||||
use util::{Bytes, Address};
|
||||
use util::error::{Mismatch, OutOfBounds};
|
||||
|
||||
use basic_types::{LogBloom, Seal};
|
||||
|
||||
@@ -24,6 +24,7 @@ use bloomchain as bc;
|
||||
use heapsize::HeapSizeOf;
|
||||
use bigint::prelude::U256;
|
||||
use bigint::hash::{H256, H2048};
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use util::*;
|
||||
use rlp::*;
|
||||
use header::*;
|
||||
@@ -43,6 +44,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;
|
||||
|
||||
@@ -269,6 +269,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));
|
||||
@@ -297,34 +325,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();
|
||||
|
||||
@@ -506,11 +506,45 @@ 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 bigint::prelude::U256;
|
||||
use util::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() {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -24,7 +24,8 @@ use itertools::Itertools;
|
||||
|
||||
// util
|
||||
use hash::keccak;
|
||||
use util::{Bytes, PerfTimer, Mutex, RwLock, MutexGuard};
|
||||
use timer::PerfTimer;
|
||||
use util::Bytes;
|
||||
use util::{journaldb, DBValue, TrieFactory, Trie};
|
||||
use util::Address;
|
||||
use util::trie::TrieSpec;
|
||||
@@ -57,6 +58,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;
|
||||
|
||||
@@ -25,6 +25,7 @@ use rustc_hex::FromHex;
|
||||
use hash::keccak;
|
||||
use bigint::prelude::U256;
|
||||
use bigint::hash::{H256, H2048};
|
||||
use parking_lot::RwLock;
|
||||
use util::*;
|
||||
use rlp::*;
|
||||
use ethkey::{Generator, Random};
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -44,6 +44,8 @@ use itertools::{self, Itertools};
|
||||
use rlp::{UntrustedRlp, encode};
|
||||
use bigint::prelude::{U256, U128};
|
||||
use bigint::hash::{H256, H520};
|
||||
use semantic_version::SemanticVersion;
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use util::*;
|
||||
|
||||
mod finality;
|
||||
|
||||
@@ -21,6 +21,7 @@ use std::collections::BTreeMap;
|
||||
use std::cmp;
|
||||
use bigint::prelude::U256;
|
||||
use bigint::hash::{H256, H520};
|
||||
use parking_lot::RwLock;
|
||||
use util::*;
|
||||
use ethkey::{recover, public_to_address, Signature};
|
||||
use account_provider::AccountProvider;
|
||||
@@ -33,6 +34,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};
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ use transaction::{UnverifiedTransaction, SignedTransaction};
|
||||
use ethkey::Signature;
|
||||
use bigint::prelude::U256;
|
||||
use bigint::hash::H256;
|
||||
use semantic_version::SemanticVersion;
|
||||
use util::*;
|
||||
|
||||
/// Default EIP-210 contrat code.
|
||||
|
||||
@@ -32,6 +32,7 @@ use hash::keccak;
|
||||
use std::cmp;
|
||||
use bigint::prelude::{U128, U256};
|
||||
use bigint::hash::{H256, H520};
|
||||
use parking_lot::RwLock;
|
||||
use util::*;
|
||||
use client::{Client, EngineClient};
|
||||
use error::{Error, BlockError};
|
||||
@@ -50,6 +51,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 {
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
use std::sync::Weak;
|
||||
use bigint::hash::H256;
|
||||
use parking_lot::RwLock;
|
||||
use util::*;
|
||||
|
||||
use futures::Future;
|
||||
|
||||
@@ -20,7 +20,8 @@ use std::collections::BTreeMap;
|
||||
use std::sync::Weak;
|
||||
use engines::{Call, Engine};
|
||||
use bigint::hash::H256;
|
||||
use util::{Bytes, Address, RwLock};
|
||||
use parking_lot::RwLock;
|
||||
use util::{Bytes, Address};
|
||||
use ids::BlockId;
|
||||
use header::{BlockNumber, Header};
|
||||
use client::{Client, BlockChainClient};
|
||||
|
||||
@@ -23,6 +23,7 @@ use hash::keccak;
|
||||
|
||||
use bigint::prelude::U256;
|
||||
use bigint::hash::{H160, H256};
|
||||
use parking_lot::RwLock;
|
||||
use util::*;
|
||||
use util::cache::MemoryLruCache;
|
||||
use rlp::{UntrustedRlp, RlpStream};
|
||||
@@ -354,7 +355,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() {
|
||||
|
||||
@@ -20,6 +20,7 @@ use std::fmt::Debug;
|
||||
use std::collections::{BTreeMap, HashSet, HashMap};
|
||||
use std::hash::Hash;
|
||||
use bigint::hash::{H256, H520};
|
||||
use parking_lot:: RwLock;
|
||||
use util::*;
|
||||
use rlp::{Encodable, RlpStream};
|
||||
|
||||
|
||||
@@ -37,6 +37,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]);
|
||||
|
||||
@@ -99,11 +99,15 @@ 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;
|
||||
extern crate hash;
|
||||
extern crate heapsize;
|
||||
extern crate triehash;
|
||||
extern crate ansi_term;
|
||||
extern crate semantic_version;
|
||||
|
||||
#[macro_use]
|
||||
extern crate rlp_derive;
|
||||
@@ -151,6 +155,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;
|
||||
|
||||
@@ -19,7 +19,7 @@ use std::sync::Arc;
|
||||
use std::time::{Instant, Duration};
|
||||
use bigint::prelude::U256;
|
||||
use bigint::hash::H256;
|
||||
use util::Mutex;
|
||||
use parking_lot::Mutex;
|
||||
|
||||
/// External miner interface.
|
||||
pub trait ExternalMinerService: Send + Sync {
|
||||
|
||||
@@ -20,7 +20,9 @@ use std::sync::Arc;
|
||||
|
||||
use bigint::prelude::U256;
|
||||
use bigint::hash::H256;
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use util::*;
|
||||
use timer::PerfTimer;
|
||||
use using_queue::{UsingQueue, GetAction};
|
||||
use account_provider::{AccountProvider, SignError as AccountError};
|
||||
use state::State;
|
||||
@@ -42,6 +44,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)]
|
||||
|
||||
@@ -21,7 +21,7 @@ use types::ids::BlockId;
|
||||
use futures::{future, Future};
|
||||
use native_contracts::ServiceTransactionChecker as Contract;
|
||||
use bigint::prelude::U256;
|
||||
use util::Mutex;
|
||||
use parking_lot::Mutex;
|
||||
|
||||
const SERVICE_TRANSACTION_CONTRACT_REGISTRY_NAME: &'static str = "service_transaction_checker";
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ use bigint::prelude::U256;
|
||||
use bigint::hash::{H64, H256, 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;
|
||||
|
||||
@@ -26,6 +26,7 @@ use ethash::SeedHashCompute;
|
||||
use hyper::Url;
|
||||
use bigint::prelude::U256;
|
||||
use bigint::hash::H256;
|
||||
use parking_lot::Mutex;
|
||||
use util::*;
|
||||
use ethereum::ethash::Ethash;
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ use itertools::Itertools;
|
||||
use hash::{keccak};
|
||||
use bigint::prelude::U256;
|
||||
use bigint::hash::H256;
|
||||
use triehash::sec_trie_root;
|
||||
use util::*;
|
||||
use state::Account;
|
||||
use ethjson;
|
||||
|
||||
@@ -20,6 +20,7 @@ use std::fmt;
|
||||
use std::collections::BTreeMap;
|
||||
use itertools::Itertools;
|
||||
use bigint::hash::H256;
|
||||
use triehash::sec_trie_root;
|
||||
use util::*;
|
||||
use pod_account::{self, PodAccount};
|
||||
use types::state_diff::StateDiff;
|
||||
|
||||
@@ -29,6 +29,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;
|
||||
|
||||
@@ -24,7 +24,7 @@ use views::BlockView;
|
||||
use rlp::{DecoderError, RlpStream, UntrustedRlp};
|
||||
use bigint::hash::H256;
|
||||
use util::Bytes;
|
||||
use util::triehash::ordered_trie_root;
|
||||
use triehash::ordered_trie_root;
|
||||
|
||||
const HEADER_FIELDS: usize = 8;
|
||||
const BLOCK_FIELDS: usize = 2;
|
||||
@@ -193,7 +193,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())
|
||||
));
|
||||
|
||||
|
||||
@@ -223,7 +223,7 @@ impl Rebuilder for PowRebuilder {
|
||||
use views::BlockView;
|
||||
use snapshot::verify_old_block;
|
||||
use bigint::prelude::U256;
|
||||
use util::triehash::ordered_trie_root;
|
||||
use triehash::ordered_trie_root;
|
||||
|
||||
let rlp = UntrustedRlp::new(chunk);
|
||||
let item_count = rlp.item_count()?;
|
||||
|
||||
@@ -33,7 +33,7 @@ use ids::BlockId;
|
||||
use bigint::prelude::U256;
|
||||
use bigint::hash::H256;
|
||||
use util::{Bytes, HashDB, DBValue, snappy};
|
||||
use util::Mutex;
|
||||
use parking_lot::Mutex;
|
||||
use util::journaldb::{self, Algorithm, JournalDB};
|
||||
use util::kvdb::KeyValueDB;
|
||||
use util::trie::{TrieDB, TrieDBMut, Trie, TrieMut};
|
||||
|
||||
@@ -36,7 +36,8 @@ use service::ClientIoMessage;
|
||||
use io::IoChannel;
|
||||
|
||||
use bigint::hash::H256;
|
||||
use util::{Bytes, Mutex, RwLock, RwLockReadGuard, UtilError};
|
||||
use parking_lot::{Mutex, RwLock, RwLockReadGuard};
|
||||
use util::{Bytes, UtilError};
|
||||
use util::journaldb::Algorithm;
|
||||
use util::kvdb::{Database, DatabaseConfig};
|
||||
use util::snappy;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -29,7 +29,7 @@ use bigint::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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -42,6 +42,7 @@ use state::backend::Basic as BasicBackend;
|
||||
use trace::{NoopTracer, NoopVMTracer};
|
||||
use bigint::prelude::U256;
|
||||
use bigint::hash::{H256, H2048};
|
||||
use parking_lot::RwLock;
|
||||
use util::*;
|
||||
|
||||
/// Parameters common to ethereum-like blockchains.
|
||||
|
||||
@@ -26,7 +26,8 @@ use std::sync::Arc;
|
||||
|
||||
use state::Account;
|
||||
use bigint::hash::H256;
|
||||
use util::{Address, MemoryDB, Mutex};
|
||||
use parking_lot::Mutex;
|
||||
use util::{Address, MemoryDB};
|
||||
use util::hashdb::{AsHashDB, HashDB, DBValue};
|
||||
|
||||
/// State backend. See module docs for more details.
|
||||
|
||||
@@ -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};
|
||||
|
||||
51
ethcore/src/timer.rs
Normal file
51
ethcore/src/timer.rs
Normal file
@@ -0,0 +1,51 @@
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Performance timer with logging
|
||||
use time::precise_time_ns;
|
||||
|
||||
/// Performance timer with logging. Starts measuring time in the constructor, prints
|
||||
/// elapsed time in the destructor or when `stop` is called.
|
||||
pub struct PerfTimer {
|
||||
name: &'static str,
|
||||
start: u64,
|
||||
stopped: bool,
|
||||
}
|
||||
|
||||
impl PerfTimer {
|
||||
/// Create an instance with given name.
|
||||
pub fn new(name: &'static str) -> PerfTimer {
|
||||
PerfTimer {
|
||||
name: name,
|
||||
start: precise_time_ns(),
|
||||
stopped: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Stop the timer and print elapsed time on trace level with `perf` target.
|
||||
pub fn stop(&mut self) {
|
||||
if !self.stopped {
|
||||
trace!(target: "perf", "{}: {:.2}ms", self.name, (precise_time_ns() - self.start) as f32 / 1000_000.0);
|
||||
self.stopped = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for PerfTimer {
|
||||
fn drop(&mut self) {
|
||||
self.stop()
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,8 @@ use bloomchain::{Number, Config as BloomConfig};
|
||||
use bloomchain::group::{BloomGroupDatabase, BloomGroupChain, GroupPosition, BloomGroup};
|
||||
use heapsize::HeapSizeOf;
|
||||
use bigint::hash::{H256, H264};
|
||||
use util::{KeyValueDB, DBTransaction, RwLock};
|
||||
use util::{KeyValueDB, DBTransaction};
|
||||
use parking_lot::RwLock;
|
||||
use header::BlockNumber;
|
||||
use trace::{LocalizedTrace, Config, Filter, Database as TraceDatabase, ImportRequest, DatabaseExtras};
|
||||
use db::{self, Key, Writable, Readable, CacheUpdatePolicy};
|
||||
|
||||
@@ -25,6 +25,7 @@ use std::collections::{VecDeque, HashSet, HashMap};
|
||||
use heapsize::HeapSizeOf;
|
||||
use bigint::prelude::U256;
|
||||
use bigint::hash::H256;
|
||||
use parking_lot::{Condvar, Mutex, RwLock};
|
||||
use util::*;
|
||||
use io::*;
|
||||
use error::*;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
use std::collections::HashSet;
|
||||
use hash::keccak;
|
||||
use triehash::ordered_trie_root;
|
||||
use heapsize::HeapSizeOf;
|
||||
use bigint::hash::H256;
|
||||
use util::*;
|
||||
@@ -272,6 +273,7 @@ mod tests {
|
||||
use hash::keccak;
|
||||
use bigint::prelude::U256;
|
||||
use bigint::hash::{H256, H2048};
|
||||
use triehash::ordered_trie_root;
|
||||
use util::*;
|
||||
use ethkey::{Random, Generator};
|
||||
use header::*;
|
||||
|
||||
Reference in New Issue
Block a user