From 445ad2a7a527cf9449d1466a925ec4e8210fa630 Mon Sep 17 00:00:00 2001 From: Hawstein Date: Fri, 22 Sep 2017 22:11:29 +0800 Subject: [PATCH] separate migration from util and make its dependencies into libs: * snappy * kvdb * error * common --- Cargo.lock | 70 +++++++++++++++++++ Cargo.toml | 2 + ethcore/Cargo.toml | 5 ++ ethcore/light/Cargo.toml | 1 + ethcore/light/src/client/header_chain.rs | 7 +- ethcore/light/src/client/mod.rs | 4 +- ethcore/light/src/client/service.rs | 2 +- ethcore/light/src/lib.rs | 1 + ethcore/node_filter/Cargo.toml | 1 + ethcore/node_filter/src/lib.rs | 3 +- ethcore/src/blockchain/blockchain.rs | 6 +- ethcore/src/blockchain/extras.rs | 2 +- ethcore/src/client/client.rs | 8 +-- ethcore/src/client/config.rs | 3 +- ethcore/src/client/error.rs | 2 +- ethcore/src/client/evm_test_client.rs | 2 +- ethcore/src/client/test_client.rs | 1 + ethcore/src/db.rs | 2 +- ethcore/src/error.rs | 8 ++- ethcore/src/json_tests/chain.rs | 2 +- ethcore/src/lib.rs | 9 ++- ethcore/src/migrations/blocks/v8.rs | 2 +- ethcore/src/migrations/extras/v6.rs | 2 +- ethcore/src/migrations/mod.rs | 2 +- ethcore/src/migrations/state/v7.rs | 4 +- ethcore/src/migrations/v10.rs | 4 +- ethcore/src/migrations/v9.rs | 4 +- ethcore/src/service.rs | 2 +- ethcore/src/snapshot/consensus/authority.rs | 2 +- ethcore/src/snapshot/consensus/mod.rs | 2 +- ethcore/src/snapshot/consensus/work.rs | 2 +- ethcore/src/snapshot/mod.rs | 5 +- ethcore/src/snapshot/service.rs | 8 +-- ethcore/src/snapshot/tests/helpers.rs | 5 +- .../src/snapshot/tests/proof_of_authority.rs | 2 +- ethcore/src/snapshot/tests/proof_of_work.rs | 4 +- ethcore/src/snapshot/tests/service.rs | 2 +- ethcore/src/snapshot/tests/state.rs | 6 +- ethcore/src/spec/spec.rs | 3 +- ethcore/src/state_db.rs | 8 ++- ethcore/src/tests/client.rs | 1 + ethcore/src/tests/helpers.rs | 4 +- ethcore/src/tests/trace.rs | 2 +- ethcore/src/trace/db.rs | 9 +-- ethcore/src/trace/mod.rs | 3 +- ethcore/src/tx_filter.rs | 2 +- local-store/Cargo.toml | 3 +- local-store/src/lib.rs | 9 +-- parity/helpers.rs | 3 +- parity/main.rs | 2 + parity/migration.rs | 8 +-- rpc/Cargo.toml | 2 + rpc/src/lib.rs | 3 + rpc/src/v1/tests/eth.rs | 3 +- secret_store/Cargo.toml | 1 + secret_store/src/key_storage.rs | 8 +-- secret_store/src/lib.rs | 1 + sync/Cargo.toml | 3 + sync/src/blocks.rs | 1 + sync/src/lib.rs | 4 ++ sync/src/tests/helpers.rs | 2 +- util/Cargo.toml | 5 ++ util/common/Cargo.toml | 6 ++ util/{src/common.rs => common/src/lib.rs} | 4 +- util/error/Cargo.toml | 11 +++ util/{src/error.rs => error/src/lib.rs} | 12 +++- util/kvdb/Cargo.toml | 17 +++++ util/{src/kvdb.rs => kvdb/src/lib.rs} | 16 ++++- util/migration/Cargo.toml | 10 +++ .../migration/mod.rs => migration/src/lib.rs} | 11 ++- .../{src/migration => migration/src}/tests.rs | 4 +- util/snappy/Cargo.toml | 7 ++ util/{src/snappy.rs => snappy/src/lib.rs} | 3 +- util/src/journaldb/refcounteddb.rs | 2 +- util/src/journaldb/traits.rs | 2 +- util/src/lib.rs | 13 +--- 76 files changed, 303 insertions(+), 104 deletions(-) create mode 100644 util/common/Cargo.toml rename util/{src/common.rs => common/src/lib.rs} (93%) create mode 100644 util/error/Cargo.toml rename util/{src/error.rs => error/src/lib.rs} (90%) create mode 100644 util/kvdb/Cargo.toml rename util/{src/kvdb.rs => kvdb/src/lib.rs} (98%) create mode 100644 util/migration/Cargo.toml rename util/{src/migration/mod.rs => migration/src/lib.rs} (98%) rename util/{src/migration => migration/src}/tests.rs (98%) create mode 100644 util/snappy/Cargo.toml rename util/{src/snappy.rs => snappy/src/lib.rs} (99%) diff --git a/Cargo.lock b/Cargo.lock index bd46ffb958c..00dae42561d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -367,6 +367,10 @@ dependencies = [ "scopeguard 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "common" +version = "0.1.0" + [[package]] name = "common-types" version = "0.1.0" @@ -575,6 +579,7 @@ dependencies = [ "bn 0.4.4 (git+https://github.com/paritytech/bn)", "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "clippy 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)", + "common 0.1.0", "common-types 0.1.0", "crossbeam 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "ethash 1.8.0", @@ -582,6 +587,7 @@ dependencies = [ "ethcore-bloom-journal 0.1.0", "ethcore-bytes 0.1.0", "ethcore-devtools 1.8.0", + "ethcore-error 0.1.0", "ethcore-io 1.8.0", "ethcore-ipc 1.8.0", "ethcore-ipc-codegen 1.8.0", @@ -600,11 +606,13 @@ dependencies = [ "heapsize 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.10.0-a.0 (git+https://github.com/paritytech/hyper)", "itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", + "kvdb 0.1.0", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "linked-hash-map 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "lru-cache 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "memorydb 0.1.0", + "migration 0.1.0", "native-contracts 0.1.0", "num 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -619,6 +627,7 @@ dependencies = [ "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", + "snappy 0.1.0", "stats 0.1.0", "table 0.1.0", "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", @@ -660,6 +669,17 @@ dependencies = [ "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ethcore-error" +version = "0.1.0" +dependencies = [ + "error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethcore-bigint 0.1.3", + "rlp 0.2.0", + "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "snappy 0.1.0", +] + [[package]] name = "ethcore-io" version = "1.8.0" @@ -752,6 +772,7 @@ dependencies = [ "hash 0.1.0", "heapsize 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", + "kvdb 0.1.0", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "memorydb 0.1.0", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -837,6 +858,7 @@ dependencies = [ "futures-cpupool 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "hash 0.1.0", "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", + "kvdb 0.1.0", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "native-contracts 0.1.0", @@ -880,6 +902,7 @@ name = "ethcore-util" version = "1.8.0" dependencies = [ "clippy 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)", + "common 0.1.0", "elastic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -888,14 +911,17 @@ dependencies = [ "ethcore-bloom-journal 0.1.0", "ethcore-bytes 0.1.0", "ethcore-devtools 1.8.0", + "ethcore-error 0.1.0", "ethcore-logger 1.8.0", "hash 0.1.0", "hashdb 0.1.0", "heapsize 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "kvdb 0.1.0", "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "lru-cache 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "memorydb 0.1.0", + "migration 0.1.0", "nibbleslice 0.1.0", "nibblevec 0.1.0", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -905,6 +931,7 @@ dependencies = [ "rocksdb 0.4.5 (git+https://github.com/paritytech/rust-rocksdb)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "snappy 0.1.0", "target_info 0.1.0 (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", @@ -1002,11 +1029,13 @@ name = "ethsync" version = "1.8.0" dependencies = [ "clippy 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)", + "common 0.1.0", "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.8.0", "ethcore-bigint 0.1.3", "ethcore-bytes 0.1.0", "ethcore-devtools 1.8.0", + "ethcore-error 0.1.0", "ethcore-io 1.8.0", "ethcore-ipc 1.8.0", "ethcore-ipc-codegen 1.8.0", @@ -1018,6 +1047,7 @@ dependencies = [ "hash 0.1.0", "heapsize 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "ipnetwork 0.12.7 (registry+https://github.com/rust-lang/crates.io-index)", + "kvdb 0.1.0", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1501,6 +1531,23 @@ dependencies = [ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "kvdb" +version = "0.1.0" +dependencies = [ + "elastic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethcore-bigint 0.1.3", + "ethcore-bytes 0.1.0", + "ethcore-devtools 1.8.0", + "ethcore-error 0.1.0", + "hashdb 0.1.0", + "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.2.0", + "rocksdb 0.4.5 (git+https://github.com/paritytech/rust-rocksdb)", +] + [[package]] name = "language-tags" version = "0.2.2" @@ -1636,6 +1683,16 @@ dependencies = [ "rlp 0.2.0", ] +[[package]] +name = "migration" +version = "0.1.0" +dependencies = [ + "common 0.1.0", + "ethcore-devtools 1.8.0", + "kvdb 0.1.0", + "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "mime" version = "0.2.6" @@ -1836,6 +1893,7 @@ dependencies = [ "ethcore-network 1.8.0", "ethcore-util 1.8.0", "futures 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", + "kvdb 0.1.0", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "native-contracts 0.1.0", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2066,7 +2124,9 @@ dependencies = [ "ipnetwork 0.12.7 (registry+https://github.com/rust-lang/crates.io-index)", "isatty 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 8.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.8)", + "kvdb 0.1.0", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "migration 0.1.0", "node-filter 1.8.0", "node-health 0.1.0", "num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2210,6 +2270,7 @@ dependencies = [ "ethcore-io 1.8.0", "ethcore-util 1.8.0", "ethkey 0.2.0", + "kvdb 0.1.0", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.2.0", "serde 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2240,6 +2301,7 @@ 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)", + "common 0.1.0", "ethash 1.8.0", "ethcore 1.8.0", "ethcore-bigint 0.1.3", @@ -2267,6 +2329,7 @@ dependencies = [ "jsonrpc-macros 8.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.8)", "jsonrpc-pubsub 8.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.8)", "jsonrpc-ws-server 8.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.8)", + "kvdb 0.1.0", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "multihash 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "node-health 0.1.0", @@ -3070,6 +3133,13 @@ dependencies = [ "heapsize 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "snappy" +version = "0.1.0" +dependencies = [ + "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "spmc" version = "0.2.2" diff --git a/Cargo.toml b/Cargo.toml index 65f8aed15f9..cf208330d3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,6 +62,8 @@ parity-whisper = { path = "whisper" } path = { path = "util/path" } panic_hook = { path = "panic_hook" } hash = { path = "util/hash" } +migration = { path = "util/migration" } +kvdb = { path = "util/kvdb" } parity-dapps = { path = "dapps", optional = true } clippy = { version = "0.0.103", optional = true} diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index 4d7851b0773..863086b4648 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -55,6 +55,11 @@ rayon = "0.8" rand = "0.3" rlp = { path = "../util/rlp" } rlp_derive = { path = "../util/rlp_derive" } +kvdb = { path = "../util/kvdb" } +ethcore-error = { path = "../util/error" } +snappy = { path = "../util/snappy" } +migration = { path = "../util/migration" } +common = { path = "../util/common" } rust-crypto = "0.2.34" rustc-hex = "1.0" stats = { path = "../util/stats" } diff --git a/ethcore/light/Cargo.toml b/ethcore/light/Cargo.toml index 477b7077a7c..734eb743214 100644 --- a/ethcore/light/Cargo.toml +++ b/ethcore/light/Cargo.toml @@ -39,6 +39,7 @@ parking_lot = "0.4" stats = { path = "../../util/stats" } hash = { path = "../../util/hash" } triehash = { path = "../../util/triehash" } +kvdb = { path = "../../util/kvdb" } [features] default = [] diff --git a/ethcore/light/src/client/header_chain.rs b/ethcore/light/src/client/header_chain.rs index 7320eddb412..c31fd4787cc 100644 --- a/ethcore/light/src/client/header_chain.rs +++ b/ethcore/light/src/client/header_chain.rs @@ -45,7 +45,7 @@ use rlp::{Encodable, Decodable, DecoderError, RlpStream, Rlp, UntrustedRlp}; use heapsize::HeapSizeOf; use bigint::prelude::U256; use bigint::hash::{H256, H256FastMap, H264}; -use util::kvdb::{DBTransaction, KeyValueDB}; +use kvdb::{DBTransaction, KeyValueDB}; use cache::Cache; use parking_lot::{Mutex, RwLock}; @@ -728,12 +728,13 @@ mod tests { use ethcore::header::Header; use ethcore::spec::Spec; use cache::Cache; + use kvdb::{in_memory, KeyValueDB}; use time::Duration; use parking_lot::Mutex; - fn make_db() -> Arc<::util::KeyValueDB> { - Arc::new(::util::kvdb::in_memory(0)) + fn make_db() -> Arc { + Arc::new(in_memory(0)) } #[test] diff --git a/ethcore/light/src/client/mod.rs b/ethcore/light/src/client/mod.rs index 1b32fe11d62..fb0ec3917f1 100644 --- a/ethcore/light/src/client/mod.rs +++ b/ethcore/light/src/client/mod.rs @@ -36,7 +36,7 @@ use bigint::prelude::U256; use bigint::hash::H256; use futures::{IntoFuture, Future}; -use util::kvdb::{KeyValueDB, CompactionProfile}; +use kvdb::{KeyValueDB, CompactionProfile}; use self::fetch::ChainDataFetcher; use self::header_chain::{AncestryIter, HeaderChain}; @@ -214,7 +214,7 @@ impl Client { io_channel: IoChannel, cache: Arc> ) -> Self { - let db = ::util::kvdb::in_memory(0); + let db = ::kvdb::in_memory(0); Client::new( config, diff --git a/ethcore/light/src/client/service.rs b/ethcore/light/src/client/service.rs index 20aea69ce90..f20d0ad9043 100644 --- a/ethcore/light/src/client/service.rs +++ b/ethcore/light/src/client/service.rs @@ -25,7 +25,7 @@ use ethcore::db; use ethcore::service::ClientIoMessage; use ethcore::spec::Spec; use io::{IoContext, IoError, IoHandler, IoService}; -use util::kvdb::{Database, DatabaseConfig}; +use kvdb::{Database, DatabaseConfig}; use cache::Cache; use parking_lot::Mutex; diff --git a/ethcore/light/src/lib.rs b/ethcore/light/src/lib.rs index 09eade4e768..edf655e4d74 100644 --- a/ethcore/light/src/lib.rs +++ b/ethcore/light/src/lib.rs @@ -91,6 +91,7 @@ extern crate time; extern crate vm; extern crate hash; extern crate triehash; +extern crate kvdb; #[cfg(feature = "ipc")] extern crate ethcore_ipc as ipc; diff --git a/ethcore/node_filter/Cargo.toml b/ethcore/node_filter/Cargo.toml index 6043c0e5d5f..c95e83091cc 100644 --- a/ethcore/node_filter/Cargo.toml +++ b/ethcore/node_filter/Cargo.toml @@ -13,6 +13,7 @@ ethcore-bigint = { path = "../../util/bigint" } ethcore-bytes = { path = "../../util/bytes" } ethcore-io = { path = "../../util/io" } ethcore-network = { path = "../../util/network" } +kvdb = { path = "../../util/kvdb" } native-contracts = { path = "../native_contracts" } futures = "0.1" log = "0.3" diff --git a/ethcore/node_filter/src/lib.rs b/ethcore/node_filter/src/lib.rs index fb098f60f2d..e92dba61de9 100644 --- a/ethcore/node_filter/src/lib.rs +++ b/ethcore/node_filter/src/lib.rs @@ -24,6 +24,7 @@ extern crate ethcore_network as network; extern crate native_contracts; extern crate futures; extern crate parking_lot; +extern crate kvdb; #[cfg(test)] extern crate ethcore_io as io; #[macro_use] extern crate log; @@ -134,7 +135,7 @@ mod test { let contract_addr = Address::from_str("0000000000000000000000000000000000000005").unwrap(); let data = include_bytes!("../res/node_filter.json"); let spec = Spec::load(&::std::env::temp_dir(), &data[..]).unwrap(); - let client_db = Arc::new(::util::kvdb::in_memory(::ethcore::db::NUM_COLUMNS.unwrap_or(0))); + let client_db = Arc::new(::kvdb::in_memory(::ethcore::db::NUM_COLUMNS.unwrap_or(0))); let client = Client::new( ClientConfig::default(), diff --git a/ethcore/src/blockchain/blockchain.rs b/ethcore/src/blockchain/blockchain.rs index 63df5d47b26..a55cf669f4b 100644 --- a/ethcore/src/blockchain/blockchain.rs +++ b/ethcore/src/blockchain/blockchain.rs @@ -26,7 +26,6 @@ use bigint::prelude::U256; use bigint::hash::{H256, H2048}; use parking_lot::{Mutex, RwLock}; use bytes::Bytes; -use util::*; use rlp::*; use header::*; use super::extras::*; @@ -47,6 +46,7 @@ use encoded; use engines::epoch::{Transition as EpochTransition, PendingTransition as PendingEpochTransition}; use rayon::prelude::*; use ansi_term::Colour; +use kvdb::{DBTransaction, KeyValueDB}; const LOG_BLOOMS_LEVELS: usize = 3; const LOG_BLOOMS_ELEMENTS_PER_INDEX: usize = 16; @@ -1479,7 +1479,7 @@ mod tests { use std::sync::Arc; use rustc_hex::FromHex; use hash::keccak; - use util::kvdb::KeyValueDB; + use kvdb::{in_memory, KeyValueDB}; use bigint::hash::*; use receipt::{Receipt, TransactionOutcome}; use blockchain::{BlockProvider, BlockChain, Config, ImportRoute}; @@ -1493,7 +1493,7 @@ mod tests { use header::BlockNumber; fn new_db() -> Arc { - Arc::new(::util::kvdb::in_memory(::db::NUM_COLUMNS.unwrap_or(0))) + Arc::new(in_memory(::db::NUM_COLUMNS.unwrap_or(0))) } fn new_chain(genesis: &[u8], db: Arc) -> BlockChain { diff --git a/ethcore/src/blockchain/extras.rs b/ethcore/src/blockchain/extras.rs index 109038ef283..6184a2f4713 100644 --- a/ethcore/src/blockchain/extras.rs +++ b/ethcore/src/blockchain/extras.rs @@ -28,7 +28,7 @@ use receipt::Receipt; use heapsize::HeapSizeOf; use bigint::prelude::U256; use bigint::hash::{H256, H264}; -use util::kvdb::PREFIX_LEN as DB_PREFIX_LEN; +use kvdb::PREFIX_LEN as DB_PREFIX_LEN; /// Represents index of extra data in database #[derive(Copy, Debug, Hash, Eq, PartialEq, Clone)] diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index d79ac5580e0..3c6268b5096 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -26,10 +26,10 @@ use itertools::Itertools; use hash::keccak; use timer::PerfTimer; use bytes::Bytes; -use util::{journaldb, DBValue}; -use util::{Address, UtilError}; +use util::{Address, journaldb, DBValue}; +use ethcore_error::UtilError; use trie::{TrieSpec, TrieFactory, Trie}; -use util::kvdb::*; +use kvdb::*; // other use bigint::prelude::U256; @@ -2090,7 +2090,7 @@ mod tests { use std::time::Duration; use std::sync::Arc; use std::sync::atomic::{AtomicBool, Ordering}; - use util::kvdb::DBTransaction; + use kvdb::DBTransaction; let client = generate_dummy_client(0); let genesis = client.chain_info().best_block_hash; diff --git a/ethcore/src/client/config.rs b/ethcore/src/client/config.rs index 43a7a821ae2..e629732d554 100644 --- a/ethcore/src/client/config.rs +++ b/ethcore/src/client/config.rs @@ -20,7 +20,8 @@ use std::fmt::{Display, Formatter, Error as FmtError}; use mode::Mode as IpcMode; use verification::{VerifierType, QueueConfig}; -use util::{journaldb, CompactionProfile}; +use util::journaldb; +use kvdb::CompactionProfile; pub use std::time::Duration; pub use blockchain::Config as BlockChainConfig; diff --git a/ethcore/src/client/error.rs b/ethcore/src/client/error.rs index 2bb5b46d4b4..8360e5665cd 100644 --- a/ethcore/src/client/error.rs +++ b/ethcore/src/client/error.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use util::UtilError; +use ethcore_error::UtilError; use std::fmt::{Display, Formatter, Error as FmtError}; use trie::TrieError; diff --git a/ethcore/src/client/evm_test_client.rs b/ethcore/src/client/evm_test_client.rs index c6e43fff1e6..ff03554f929 100644 --- a/ethcore/src/client/evm_test_client.rs +++ b/ethcore/src/client/evm_test_client.rs @@ -23,7 +23,7 @@ use bigint::hash::H256; use util::journaldb; use trie; use bytes; -use util::kvdb::{self, KeyValueDB}; +use kvdb::{self, KeyValueDB}; use {state, state_db, client, executive, trace, transaction, db, spec, pod_state}; use factory::Factories; use evm::{self, VMType, FinalizationResult}; diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index 87c4c600180..82f9693200b 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -27,6 +27,7 @@ use bigint::prelude::U256; use bigint::hash::H256; use parking_lot::RwLock; use util::*; +use kvdb::{Database, DatabaseConfig}; use bytes::Bytes; use rlp::*; use ethkey::{Generator, Random}; diff --git a/ethcore/src/db.rs b/ethcore/src/db.rs index e60b77b2e09..d11adc7710d 100644 --- a/ethcore/src/db.rs +++ b/ethcore/src/db.rs @@ -20,7 +20,7 @@ use std::ops::Deref; use std::hash::Hash; use std::collections::HashMap; use parking_lot::RwLock; -use util::{DBTransaction, KeyValueDB}; +use kvdb::{DBTransaction, KeyValueDB}; use rlp; diff --git a/ethcore/src/error.rs b/ethcore/src/error.rs index 9c7f7b4e2c4..a75ac0f46fa 100644 --- a/ethcore/src/error.rs +++ b/ethcore/src/error.rs @@ -20,6 +20,8 @@ use std::fmt; use bigint::prelude::U256; use bigint::hash::H256; use util::*; +use ethcore_error::UtilError; +use snappy::InvalidInput; use unexpected::{Mismatch, OutOfBounds}; use trie::TrieError; use io::*; @@ -322,7 +324,7 @@ pub enum Error { /// Standard io error. StdIo(::std::io::Error), /// Snappy error. - Snappy(::util::snappy::InvalidInput), + Snappy(InvalidInput), /// Snapshot error. Snapshot(SnapshotError), /// Consensus vote error. @@ -434,8 +436,8 @@ impl From for Error { } } -impl From for Error { - fn from(err: snappy::InvalidInput) -> Error { +impl From<::snappy::InvalidInput> for Error { + fn from(err: ::snappy::InvalidInput) -> Error { Error::Snappy(err) } } diff --git a/ethcore/src/json_tests/chain.rs b/ethcore/src/json_tests/chain.rs index 9ae55f73d5c..87869799b67 100644 --- a/ethcore/src/json_tests/chain.rs +++ b/ethcore/src/json_tests/chain.rs @@ -57,7 +57,7 @@ pub fn json_chain_test(json_data: &[u8]) -> Vec { }; { - let db = Arc::new(::util::kvdb::in_memory(::db::NUM_COLUMNS.unwrap_or(0))); + let db = Arc::new(::kvdb::in_memory(::db::NUM_COLUMNS.unwrap_or(0))); let client = Client::new( ClientConfig::default(), &spec, diff --git a/ethcore/src/lib.rs b/ethcore/src/lib.rs index 5faf5bf82e0..aa0f8d4d058 100644 --- a/ethcore/src/lib.rs +++ b/ethcore/src/lib.rs @@ -112,6 +112,10 @@ extern crate triehash; extern crate ansi_term; extern crate semantic_version; extern crate unexpected; +extern crate kvdb; +extern crate ethcore_error; +extern crate snappy; +extern crate migration; #[macro_use] extern crate rlp_derive; @@ -124,11 +128,12 @@ extern crate table; extern crate bloomable; extern crate vm; extern crate wasm; +extern crate ethcore_util as util; #[macro_use] -extern crate log; +extern crate common; #[macro_use] -extern crate ethcore_util as util; +extern crate log; #[macro_use] extern crate lazy_static; #[macro_use] diff --git a/ethcore/src/migrations/blocks/v8.rs b/ethcore/src/migrations/blocks/v8.rs index ddade6847df..6c5441c9729 100644 --- a/ethcore/src/migrations/blocks/v8.rs +++ b/ethcore/src/migrations/blocks/v8.rs @@ -16,7 +16,7 @@ //! This migration compresses the state db. -use util::migration::{SimpleMigration, Progress}; +use migration::{SimpleMigration, Progress}; use rlp::{Compressible, UntrustedRlp, RlpType}; /// Compressing migration. diff --git a/ethcore/src/migrations/extras/v6.rs b/ethcore/src/migrations/extras/v6.rs index 638a64a838b..7dfc5427ea5 100644 --- a/ethcore/src/migrations/extras/v6.rs +++ b/ethcore/src/migrations/extras/v6.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use util::migration::SimpleMigration; +use migration::SimpleMigration; /// This migration reduces the sizes of keys and moves `ExtrasIndex` byte from back to the front. pub struct ToV6; diff --git a/ethcore/src/migrations/mod.rs b/ethcore/src/migrations/mod.rs index 76b10fd1915..fc4975f10ec 100644 --- a/ethcore/src/migrations/mod.rs +++ b/ethcore/src/migrations/mod.rs @@ -16,7 +16,7 @@ //! Database migrations. -use util::migration::ChangeColumns; +use migration::ChangeColumns; pub mod state; pub mod blocks; diff --git a/ethcore/src/migrations/state/v7.rs b/ethcore/src/migrations/state/v7.rs index 4a9d850ad23..cbf517d1dcb 100644 --- a/ethcore/src/migrations/state/v7.rs +++ b/ethcore/src/migrations/state/v7.rs @@ -22,8 +22,8 @@ use std::collections::HashMap; use bigint::hash::H256; use util::Address; use bytes::Bytes; -use util::kvdb::Database; -use util::migration::{Batch, Config, Error, Migration, SimpleMigration, Progress}; +use kvdb::Database; +use migration::{Batch, Config, Error, Migration, SimpleMigration, Progress}; use hash::keccak; use std::sync::Arc; diff --git a/ethcore/src/migrations/v10.rs b/ethcore/src/migrations/v10.rs index d2f6952d402..155d6f4c061 100644 --- a/ethcore/src/migrations/v10.rs +++ b/ethcore/src/migrations/v10.rs @@ -22,11 +22,11 @@ use state_db::{ACCOUNT_BLOOM_SPACE, DEFAULT_ACCOUNT_PRESET, StateDB}; use trie::TrieDB; use views::HeaderView; use bloom_journal::Bloom; -use util::migration::{Error, Migration, Progress, Batch, Config}; +use migration::{Error, Migration, Progress, Batch, Config}; use util::journaldb; use bigint::hash::H256; use trie::Trie; -use util::{Database, DBTransaction}; +use kvdb::{Database, DBTransaction}; /// Account bloom upgrade routine. If bloom already present, does nothing. /// If database empty (no best block), does nothing. diff --git a/ethcore/src/migrations/v9.rs b/ethcore/src/migrations/v9.rs index 08f83f1320f..7c28054fad5 100644 --- a/ethcore/src/migrations/v9.rs +++ b/ethcore/src/migrations/v9.rs @@ -18,8 +18,8 @@ //! This migration consolidates all databases into single one using Column Families. use rlp::{Rlp, RlpStream}; -use util::kvdb::Database; -use util::migration::{Batch, Config, Error, Migration, Progress}; +use kvdb::Database; +use migration::{Batch, Config, Error, Migration, Progress}; use std::sync::Arc; /// Which part of block to preserve diff --git a/ethcore/src/service.rs b/ethcore/src/service.rs index ca283b0aa16..90f6810aaa3 100644 --- a/ethcore/src/service.rs +++ b/ethcore/src/service.rs @@ -19,7 +19,7 @@ use std::sync::Arc; use std::path::Path; use bigint::hash::H256; -use util::*; +use kvdb::{Database, DatabaseConfig, KeyValueDB}; use bytes::Bytes; use io::*; use spec::Spec; diff --git a/ethcore/src/snapshot/consensus/authority.rs b/ethcore/src/snapshot/consensus/authority.rs index efb30635d0d..ce15fed9587 100644 --- a/ethcore/src/snapshot/consensus/authority.rs +++ b/ethcore/src/snapshot/consensus/authority.rs @@ -35,7 +35,7 @@ use snapshot::{Error, ManifestData}; use itertools::{Position, Itertools}; use rlp::{RlpStream, UntrustedRlp}; use bigint::hash::H256; -use util::KeyValueDB; +use kvdb::KeyValueDB; use bytes::Bytes; /// Snapshot creation and restoration for PoA chains. diff --git a/ethcore/src/snapshot/consensus/mod.rs b/ethcore/src/snapshot/consensus/mod.rs index baff16940f1..bb2f5a5cc2c 100644 --- a/ethcore/src/snapshot/consensus/mod.rs +++ b/ethcore/src/snapshot/consensus/mod.rs @@ -25,7 +25,7 @@ use engines::EthEngine; use snapshot::{Error, ManifestData}; use bigint::hash::H256; -use util::kvdb::KeyValueDB; +use kvdb::KeyValueDB; mod authority; mod work; diff --git a/ethcore/src/snapshot/consensus/work.rs b/ethcore/src/snapshot/consensus/work.rs index 5ef1b197c3c..eea2a5cce13 100644 --- a/ethcore/src/snapshot/consensus/work.rs +++ b/ethcore/src/snapshot/consensus/work.rs @@ -31,7 +31,7 @@ use engines::EthEngine; use snapshot::{Error, ManifestData}; use snapshot::block::AbridgedBlock; use bigint::hash::H256; -use util::KeyValueDB; +use kvdb::KeyValueDB; use bytes::Bytes; use rlp::{RlpStream, UntrustedRlp}; use rand::OsRng; diff --git a/ethcore/src/snapshot/mod.rs b/ethcore/src/snapshot/mod.rs index 4931d500dfc..e33c47e2c6f 100644 --- a/ethcore/src/snapshot/mod.rs +++ b/ethcore/src/snapshot/mod.rs @@ -32,11 +32,12 @@ use ids::BlockId; use bigint::prelude::U256; use bigint::hash::H256; -use util::{HashDB, DBValue, snappy}; +use util::{HashDB, DBValue}; +use snappy; use bytes::Bytes; use parking_lot::Mutex; use util::journaldb::{self, Algorithm, JournalDB}; -use util::kvdb::KeyValueDB; +use kvdb::KeyValueDB; use trie::{TrieDB, TrieDBMut, Trie, TrieMut}; use rlp::{RlpStream, UntrustedRlp}; use bloom_journal::Bloom; diff --git a/ethcore/src/snapshot/service.rs b/ethcore/src/snapshot/service.rs index ab551f154e9..1a7f863eca6 100644 --- a/ethcore/src/snapshot/service.rs +++ b/ethcore/src/snapshot/service.rs @@ -37,11 +37,11 @@ use io::IoChannel; use bigint::hash::H256; use parking_lot::{Mutex, RwLock, RwLockReadGuard}; -use util::UtilError; +use ethcore_error::UtilError; use bytes::Bytes; use util::journaldb::Algorithm; -use util::kvdb::{Database, DatabaseConfig}; -use util::snappy; +use kvdb::{Database, DatabaseConfig}; +use snappy; /// Helper for removing directories in case of error. struct Guard(bool, PathBuf); @@ -682,7 +682,7 @@ mod tests { #[test] fn cannot_finish_with_invalid_chunks() { use bigint::hash::H256; - use util::kvdb::DatabaseConfig; + use kvdb::DatabaseConfig; let spec = get_test_spec(); let dir = RandomTempPath::new(); diff --git a/ethcore/src/snapshot/tests/helpers.rs b/ethcore/src/snapshot/tests/helpers.rs index d946d7e4799..cdd51a63cb8 100644 --- a/ethcore/src/snapshot/tests/helpers.rs +++ b/ethcore/src/snapshot/tests/helpers.rs @@ -31,7 +31,8 @@ use snapshot::io::{SnapshotReader, PackedWriter, PackedReader}; use devtools::{RandomTempPath, GuardedTempResult}; use rand::Rng; -use util::{DBValue, KeyValueDB}; +use util::DBValue; +use kvdb::KeyValueDB; use bigint::hash::H256; use hashdb::HashDB; use util::journaldb; @@ -165,7 +166,7 @@ pub fn restore( genesis: &[u8], ) -> Result<(), ::error::Error> { use std::sync::atomic::AtomicBool; - use util::snappy; + use snappy; let flag = AtomicBool::new(true); let components = engine.snapshot_components().unwrap(); diff --git a/ethcore/src/snapshot/tests/proof_of_authority.rs b/ethcore/src/snapshot/tests/proof_of_authority.rs index 7c00c819734..9634fd53102 100644 --- a/ethcore/src/snapshot/tests/proof_of_authority.rs +++ b/ethcore/src/snapshot/tests/proof_of_authority.rs @@ -31,7 +31,7 @@ use tests::helpers; use transaction::{Transaction, Action, SignedTransaction}; use util::Address; -use util::kvdb; +use kvdb; const PASS: &'static str = ""; const TRANSITION_BLOCK_1: usize = 2; // block at which the contract becomes activated. diff --git a/ethcore/src/snapshot/tests/proof_of_work.rs b/ethcore/src/snapshot/tests/proof_of_work.rs index 91f2753d43d..8002e436227 100644 --- a/ethcore/src/snapshot/tests/proof_of_work.rs +++ b/ethcore/src/snapshot/tests/proof_of_work.rs @@ -25,8 +25,8 @@ use snapshot::{chunk_secondary, Error as SnapshotError, Progress, SnapshotCompon use snapshot::io::{PackedReader, PackedWriter, SnapshotReader, SnapshotWriter}; use parking_lot::Mutex; -use util::snappy; -use util::kvdb::{self, KeyValueDB, DBTransaction}; +use snappy; +use kvdb::{self, KeyValueDB, DBTransaction}; use std::sync::Arc; use std::sync::atomic::AtomicBool; diff --git a/ethcore/src/snapshot/tests/service.rs b/ethcore/src/snapshot/tests/service.rs index 64a8407aa94..d391883a905 100644 --- a/ethcore/src/snapshot/tests/service.rs +++ b/ethcore/src/snapshot/tests/service.rs @@ -27,7 +27,7 @@ use tests::helpers::generate_dummy_client_with_spec_and_data; use devtools::RandomTempPath; use io::IoChannel; -use util::kvdb::{Database, DatabaseConfig}; +use kvdb::{Database, DatabaseConfig}; struct NoopDBRestore; diff --git a/ethcore/src/snapshot/tests/state.rs b/ethcore/src/snapshot/tests/state.rs index 460dd77b50a..175ae4eb86d 100644 --- a/ethcore/src/snapshot/tests/state.rs +++ b/ethcore/src/snapshot/tests/state.rs @@ -27,7 +27,7 @@ use error::Error; use rand::{XorShiftRng, SeedableRng}; use bigint::hash::H256; use util::journaldb::{self, Algorithm}; -use util::kvdb::{Database, DatabaseConfig}; +use kvdb::{Database, DatabaseConfig}; use memorydb::MemoryDB; use parking_lot::Mutex; use devtools::RandomTempPath; @@ -76,7 +76,7 @@ fn snap_and_restore() { for chunk_hash in &reader.manifest().state_hashes { let raw = reader.chunk(*chunk_hash).unwrap(); - let chunk = ::util::snappy::decompress(&raw).unwrap(); + let chunk = ::snappy::decompress(&raw).unwrap(); rebuilder.feed(&chunk, &flag).unwrap(); } @@ -190,7 +190,7 @@ fn checks_flag() { for chunk_hash in &reader.manifest().state_hashes { let raw = reader.chunk(*chunk_hash).unwrap(); - let chunk = ::util::snappy::decompress(&raw).unwrap(); + let chunk = ::snappy::decompress(&raw).unwrap(); match rebuilder.feed(&chunk, &flag) { Err(Error::Snapshot(SnapshotError::RestorationAborted)) => {}, diff --git a/ethcore/src/spec/spec.rs b/ethcore/src/spec/spec.rs index 54c966615f9..e643e12108b 100644 --- a/ethcore/src/spec/spec.rs +++ b/ethcore/src/spec/spec.rs @@ -667,7 +667,8 @@ impl Spec { /// constructor. pub fn genesis_epoch_data(&self) -> Result, String> { use transaction::{Action, Transaction}; - use util::{journaldb, kvdb}; + use util::journaldb; + use kvdb; let genesis = self.genesis_header(); diff --git a/ethcore/src/state_db.rs b/ethcore/src/state_db.rs index 34279a382cb..a89cc42fa5e 100644 --- a/ethcore/src/state_db.rs +++ b/ethcore/src/state_db.rs @@ -19,14 +19,15 @@ use std::sync::Arc; use lru_cache::LruCache; use util::cache::MemoryLruCache; use util::journaldb::JournalDB; -use util::kvdb::KeyValueDB; +use kvdb::{KeyValueDB, DBTransaction}; use bigint::hash::H256; use hashdb::HashDB; use state::{self, Account}; use header::BlockNumber; use hash::keccak; use parking_lot::Mutex; -use util::{Address, DBTransaction, UtilError}; +use util::Address; +use ethcore_error::UtilError; use bloom_journal::{Bloom, BloomJournal}; use db::COL_ACCOUNT_BLOOM; use byteorder::{LittleEndian, ByteOrder}; @@ -460,7 +461,8 @@ impl state::Backend for StateDB { mod tests { use bigint::prelude::U256; use bigint::hash::H256; - use util::{Address, DBTransaction}; + use util::Address; + use kvdb::DBTransaction; use tests::helpers::*; use state::{Account, Backend}; use ethcore_logger::init_log; diff --git a/ethcore/src/tests/client.rs b/ethcore/src/tests/client.rs index 4e44573e276..06005e66ddc 100644 --- a/ethcore/src/tests/client.rs +++ b/ethcore/src/tests/client.rs @@ -27,6 +27,7 @@ use tests::helpers::*; use types::filter::Filter; use bigint::prelude::U256; use util::*; +use kvdb::{Database, DatabaseConfig}; use devtools::*; use miner::Miner; use spec::Spec; diff --git a/ethcore/src/tests/helpers.rs b/ethcore/src/tests/helpers.rs index 30e74e17986..52a0dedc6a8 100644 --- a/ethcore/src/tests/helpers.rs +++ b/ethcore/src/tests/helpers.rs @@ -231,8 +231,8 @@ pub fn get_test_client_with_blocks(blocks: Vec) -> Arc { client } -fn new_db() -> Arc { - Arc::new(::util::kvdb::in_memory(::db::NUM_COLUMNS.unwrap_or(0))) +fn new_db() -> Arc<::kvdb::KeyValueDB> { + Arc::new(::kvdb::in_memory(::db::NUM_COLUMNS.unwrap_or(0))) } pub fn generate_dummy_blockchain(block_number: u32) -> BlockChain { diff --git a/ethcore/src/tests/trace.rs b/ethcore/src/tests/trace.rs index 0d57ff97d64..270d29597a2 100644 --- a/ethcore/src/tests/trace.rs +++ b/ethcore/src/tests/trace.rs @@ -27,7 +27,7 @@ use client::*; use tests::helpers::*; use devtools::RandomTempPath; use client::{BlockChainClient, Client, ClientConfig}; -use util::kvdb::{Database, DatabaseConfig}; +use kvdb::{Database, DatabaseConfig}; use std::sync::Arc; use header::Header; use miner::Miner; diff --git a/ethcore/src/trace/db.rs b/ethcore/src/trace/db.rs index 267acc45a2c..087acdcc98d 100644 --- a/ethcore/src/trace/db.rs +++ b/ethcore/src/trace/db.rs @@ -22,7 +22,7 @@ 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}; +use kvdb::{KeyValueDB, DBTransaction}; use parking_lot::RwLock; use header::BlockNumber; use trace::{LocalizedTrace, Config, Filter, Database as TraceDatabase, ImportRequest, DatabaseExtras}; @@ -415,7 +415,8 @@ mod tests { use std::sync::Arc; use bigint::prelude::U256; use bigint::hash::H256; - use util::{Address, DBTransaction}; + use util::Address; + use kvdb::{DBTransaction, in_memory, KeyValueDB}; use header::BlockNumber; use trace::{Config, TraceDB, Database as TraceDatabase, DatabaseExtras, ImportRequest}; use trace::{Filter, LocalizedTrace, AddressesFilter, TraceError}; @@ -465,8 +466,8 @@ mod tests { } } - fn new_db() -> Arc<::util::kvdb::KeyValueDB> { - Arc::new(::util::kvdb::in_memory(::db::NUM_COLUMNS.unwrap_or(0))) + fn new_db() -> Arc { + Arc::new(in_memory(::db::NUM_COLUMNS.unwrap_or(0))) } #[test] diff --git a/ethcore/src/trace/mod.rs b/ethcore/src/trace/mod.rs index 0a255b3577f..f86daf13fe9 100644 --- a/ethcore/src/trace/mod.rs +++ b/ethcore/src/trace/mod.rs @@ -39,7 +39,8 @@ pub use self::types::filter::{Filter, AddressesFilter}; use bigint::prelude::U256; use bigint::hash::H256; -use util::{Address, DBTransaction}; +use util::Address; +use kvdb::DBTransaction; use bytes::Bytes; use self::trace::{Call, Create}; use vm::ActionParams; diff --git a/ethcore/src/tx_filter.rs b/ethcore/src/tx_filter.rs index 25c6ed64b9d..ac40b8ab6bf 100644 --- a/ethcore/src/tx_filter.rs +++ b/ethcore/src/tx_filter.rs @@ -178,7 +178,7 @@ mod test { "#; let spec = Spec::load(&::std::env::temp_dir(), spec_data.as_bytes()).unwrap(); - let client_db = Arc::new(::util::kvdb::in_memory(::db::NUM_COLUMNS.unwrap_or(0))); + let client_db = Arc::new(::kvdb::in_memory(::db::NUM_COLUMNS.unwrap_or(0))); let client = Client::new( ClientConfig::default(), diff --git a/local-store/Cargo.toml b/local-store/Cargo.toml index d7b957fd718..db9830c4098 100644 --- a/local-store/Cargo.toml +++ b/local-store/Cargo.toml @@ -8,7 +8,8 @@ authors = ["Parity Technologies "] ethcore-util = { path = "../util" } ethcore-io = { path = "../util/io" } ethcore = { path = "../ethcore" } -rlp = {path = "../util/rlp" } +rlp = { path = "../util/rlp" } +kvdb = { path = "../util/kvdb" } serde = "1.0" serde_derive = "1.0" serde_json = "1.0" diff --git a/local-store/src/lib.rs b/local-store/src/lib.rs index 5077fbe010d..61fe549767f 100644 --- a/local-store/src/lib.rs +++ b/local-store/src/lib.rs @@ -26,7 +26,7 @@ use ethcore::transaction::{ use ethcore::service::ClientIoMessage; use io::IoHandler; use rlp::UntrustedRlp; -use util::kvdb::KeyValueDB; +use kvdb::KeyValueDB; extern crate ethcore; extern crate ethcore_util as util; @@ -34,6 +34,7 @@ extern crate ethcore_io as io; extern crate rlp; extern crate serde_json; extern crate serde; +extern crate kvdb; #[macro_use] extern crate serde_derive; @@ -242,7 +243,7 @@ mod tests { #[test] fn twice_empty() { - let db = Arc::new(::util::kvdb::in_memory(0)); + let db = Arc::new(::kvdb::in_memory(0)); { let store = super::create(db.clone(), None, Dummy(vec![])); @@ -271,7 +272,7 @@ mod tests { PendingTransaction::new(signed, condition) }).collect(); - let db = Arc::new(::util::kvdb::in_memory(0)); + let db = Arc::new(::kvdb::in_memory(0)); { // nothing written yet, will write pending. @@ -310,7 +311,7 @@ mod tests { PendingTransaction::new(signed, None) }); - let db = Arc::new(::util::kvdb::in_memory(0)); + let db = Arc::new(::kvdb::in_memory(0)); { // nothing written, will write bad. let store = super::create(db.clone(), None, Dummy(transactions.clone())); diff --git a/parity/helpers.rs b/parity/helpers.rs index 9bcaf897ee2..da54f6763fe 100644 --- a/parity/helpers.rs +++ b/parity/helpers.rs @@ -20,7 +20,8 @@ use std::time::Duration; use std::fs::File; use bigint::prelude::U256; use bigint::hash::clean_0x; -use util::{Address, CompactionProfile}; +use util::Address; +use kvdb::CompactionProfile; use util::journaldb::Algorithm; use ethcore::client::{Mode, BlockId, VMType, DatabaseCompactionProfile, ClientConfig, VerifierType}; use ethcore::miner::{PendingSet, GasLimit, PrioritizationStrategy}; diff --git a/parity/main.rs b/parity/main.rs index cd269b00b61..97ffbca5fef 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -61,6 +61,8 @@ extern crate ethcore_util as util; extern crate ethcore_bigint as bigint; extern crate ethcore_bytes as bytes; extern crate ethcore_network as network; +extern crate migration as migr; +extern crate kvdb; extern crate ethkey; extern crate ethsync; extern crate node_health; diff --git a/parity/migration.rs b/parity/migration.rs index c4e5f5ac67c..508491a0a3c 100644 --- a/parity/migration.rs +++ b/parity/migration.rs @@ -21,8 +21,8 @@ use std::path::{Path, PathBuf}; use std::fmt::{Display, Formatter, Error as FmtError}; use std::sync::Arc; use util::journaldb::Algorithm; -use util::migration::{Manager as MigrationManager, Config as MigrationConfig, Error as MigrationError, Migration}; -use util::kvdb::{CompactionProfile, Database, DatabaseConfig}; +use migr::{Manager as MigrationManager, Config as MigrationConfig, Error as MigrationError, Migration}; +use kvdb::{CompactionProfile, Database, DatabaseConfig}; use ethcore::migrations; use ethcore::db; use ethcore::migrations::Extract; @@ -282,8 +282,8 @@ mod legacy { use super::*; use std::path::{Path, PathBuf}; use util::journaldb::Algorithm; - use util::migration::{Manager as MigrationManager}; - use util::kvdb::CompactionProfile; + use migr::{Manager as MigrationManager}; + use kvdb::CompactionProfile; use ethcore::migrations; /// Blocks database path. diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index 0b393f16d8e..495120eb3ca 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -57,6 +57,8 @@ rlp = { path = "../util/rlp" } stats = { path = "../util/stats" } vm = { path = "../ethcore/vm" } hash = { path = "../util/hash" } +kvdb = { path = "../util/kvdb" } +common = { path = "../util/common" } hardware-wallet = { path = "../hw" } clippy = { version = "0.0.103", optional = true} diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index c37ebad1f26..d2808503d86 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -64,7 +64,10 @@ extern crate rlp; extern crate stats; extern crate hash; extern crate hardware_wallet; +extern crate kvdb; +#[macro_use] +extern crate common; #[macro_use] extern crate log; #[cfg_attr(test, macro_use)] diff --git a/rpc/src/v1/tests/eth.rs b/rpc/src/v1/tests/eth.rs index 4563f76e3a5..a2b23f52ecf 100644 --- a/rpc/src/v1/tests/eth.rs +++ b/rpc/src/v1/tests/eth.rs @@ -33,6 +33,7 @@ use io::IoChannel; use bigint::prelude::U256; use bigint::hash::H256; use util::Address; +use kvdb::in_memory; use jsonrpc_core::IoHandler; use v1::impls::{EthClient, SigningUnsafeClient}; @@ -130,7 +131,7 @@ impl EthTester { let client = Client::new( ClientConfig::default(), &spec, - Arc::new(::util::kvdb::in_memory(::ethcore::db::NUM_COLUMNS.unwrap_or(0))), + Arc::new(in_memory(::ethcore::db::NUM_COLUMNS.unwrap_or(0))), miner_service.clone(), IoChannel::disconnected(), ).unwrap(); diff --git a/secret_store/Cargo.toml b/secret_store/Cargo.toml index 4354ea2e330..3e98c62e7a3 100644 --- a/secret_store/Cargo.toml +++ b/secret_store/Cargo.toml @@ -32,6 +32,7 @@ ethcore-bytes = { path = "../util/bytes" } ethcore-devtools = { path = "../devtools" } ethcore-util = { path = "../util" } ethcore-bigint = { path = "../util/bigint" } +kvdb = { path = "../util/kvdb" } hash = { path = "../util/hash" } ethcore-ipc = { path = "../ipc/rpc" } ethcore-ipc-nano = { path = "../ipc/nano" } diff --git a/secret_store/src/key_storage.rs b/secret_store/src/key_storage.rs index 6143b4a31c9..ca408dfc14f 100644 --- a/secret_store/src/key_storage.rs +++ b/secret_store/src/key_storage.rs @@ -18,7 +18,7 @@ use std::path::PathBuf; use std::collections::BTreeMap; use serde_json; use ethkey::{Secret, Public}; -use util::{Database, DatabaseIterator}; +use kvdb::{Database, DatabaseIterator}; use types::all::{Error, ServiceConfiguration, ServerKeyId, NodeId}; use serialization::{SerializablePublic, SerializableSecret}; @@ -153,7 +153,7 @@ fn upgrade_db(db: Database) -> Result { let v2_key = CurrentSerializableDocumentKeyShare { // author is used in separate generation + encrypt sessions. // in v0 there have been only simultaneous GenEnc sessions. - author: Public::default().into(), // added in v1 + author: Public::default().into(), // added in v1 threshold: v0_key.threshold, id_numbers: v0_key.id_numbers, secret_share: v0_key.secret_share, @@ -293,7 +293,7 @@ pub mod tests { use serde_json; use devtools::RandomTempPath; use ethkey::{Random, Generator, Public, Secret}; - use util::Database; + use kvdb::Database; use types::all::{Error, NodeAddress, ServiceConfiguration, ClusterConfiguration, ServerKeyId}; use super::{DB_META_KEY_VERSION, CURRENT_VERSION, KeyStorage, PersistentKeyStorage, DocumentKeyShare, SerializableDocumentKeyShareV0, SerializableDocumentKeyShareV1, @@ -352,7 +352,7 @@ pub mod tests { admin_public: None, }, }; - + let key1 = ServerKeyId::from(1); let value1 = DocumentKeyShare { author: Public::default(), diff --git a/secret_store/src/lib.rs b/secret_store/src/lib.rs index fb6cc0e6821..6aa3bd70802 100644 --- a/secret_store/src/lib.rs +++ b/secret_store/src/lib.rs @@ -48,6 +48,7 @@ extern crate ethcrypto; extern crate ethkey; extern crate native_contracts; extern crate hash; +extern crate kvdb; mod key_server_cluster; mod types; diff --git a/sync/Cargo.toml b/sync/Cargo.toml index d5ef8ed3cae..b32d50c60fa 100644 --- a/sync/Cargo.toml +++ b/sync/Cargo.toml @@ -22,6 +22,9 @@ ethcore = { path = "../ethcore" } rlp = { path = "../util/rlp" } hash = { path = "../util/hash" } triehash = { path = "../util/triehash" } +kvdb = { path = "../util/kvdb" } +ethcore-error = { path = "../util/error" } +common = { path = "../util/common" } 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 f7e616c6fbd..4c784da2cb8 100644 --- a/sync/src/blocks.rs +++ b/sync/src/blocks.rs @@ -22,6 +22,7 @@ use heapsize::HeapSizeOf; use bigint::hash::H256; use triehash::ordered_trie_root; use util::*; +use ethcore_error::UtilError; use bytes::Bytes; use rlp::*; use network::NetworkError; diff --git a/sync/src/lib.rs b/sync/src/lib.rs index 6a65ec663d1..9b77f77de98 100644 --- a/sync/src/lib.rs +++ b/sync/src/lib.rs @@ -42,12 +42,16 @@ extern crate rlp; extern crate ipnetwork; extern crate hash; extern crate triehash; +extern crate kvdb; +extern crate ethcore_error; extern crate ethcore_light as light; #[cfg(test)] extern crate ethcore_devtools as devtools; #[cfg(test)] extern crate ethkey; +#[macro_use] +extern crate common; #[macro_use] extern crate log; #[macro_use] diff --git a/sync/src/tests/helpers.rs b/sync/src/tests/helpers.rs index 6fb104ef707..1fe4fde46ce 100644 --- a/sync/src/tests/helpers.rs +++ b/sync/src/tests/helpers.rs @@ -291,7 +291,7 @@ impl TestNet> { let client = EthcoreClient::new( ClientConfig::default(), &spec, - Arc::new(::util::kvdb::in_memory(::ethcore::db::NUM_COLUMNS.unwrap_or(0))), + Arc::new(::kvdb::in_memory(::ethcore::db::NUM_COLUMNS.unwrap_or(0))), Arc::new(Miner::with_spec_and_accounts(&spec, accounts)), IoChannel::disconnected(), ).unwrap(); diff --git a/util/Cargo.toml b/util/Cargo.toml index 28d53c6e565..c675b298643 100644 --- a/util/Cargo.toml +++ b/util/Cargo.toml @@ -36,6 +36,11 @@ nibbleslice = { path = "nibbleslice" } nibblevec = { path = "nibblevec" } ethcore-bytes = { path = "bytes" } memorydb = { path = "memorydb" } +ethcore-error = { path = "error" } +migration = { path = "migration" } +kvdb = { path = "kvdb" } +snappy = { path = "snappy" } +common = { path = "common" } [features] default = [] diff --git a/util/common/Cargo.toml b/util/common/Cargo.toml new file mode 100644 index 00000000000..2875378db06 --- /dev/null +++ b/util/common/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "common" +version = "0.1.0" +authors = ["Parity Technologies "] + +[dependencies] diff --git a/util/src/common.rs b/util/common/src/lib.rs similarity index 93% rename from util/src/common.rs rename to util/common/src/lib.rs index 4bf3a06ed0c..78bcd0397ef 100644 --- a/util/src/common.rs +++ b/util/common/src/lib.rs @@ -82,8 +82,8 @@ macro_rules! map_into { #[macro_export] macro_rules! flush { - ($arg:expr) => ($crate::common::flush($arg.into())); - ($($arg:tt)*) => ($crate::common::flush(format!("{}", format_args!($($arg)*)))); + ($arg:expr) => ($crate::flush($arg.into())); + ($($arg:tt)*) => ($crate::flush(format!("{}", format_args!($($arg)*)))); } #[macro_export] diff --git a/util/error/Cargo.toml b/util/error/Cargo.toml new file mode 100644 index 00000000000..551bb09f7f8 --- /dev/null +++ b/util/error/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "ethcore-error" +version = "0.1.0" +authors = ["Parity Technologies "] + +[dependencies] +rlp = { path = "../rlp" } +ethcore-bigint = { path = "../bigint" } +snappy = { path = "../snappy" } +error-chain = "0.11.0-rc.2" +rustc-hex = "1.0" diff --git a/util/src/error.rs b/util/error/src/lib.rs similarity index 90% rename from util/src/error.rs rename to util/error/src/lib.rs index 59496f86fa2..1c816b2eaa2 100644 --- a/util/src/error.rs +++ b/util/error/src/lib.rs @@ -19,7 +19,15 @@ #![allow(missing_docs)] #![allow(unknown_lints)] -use std::{self, fmt}; +#[macro_use] +extern crate error_chain; + +extern crate ethcore_bigint as bigint; +extern crate rlp; +extern crate rustc_hex; +extern crate snappy; + +use std::fmt; use rustc_hex::FromHexError; use rlp::DecoderError; use bigint::hash::H256; @@ -59,7 +67,7 @@ error_chain! { Io(::std::io::Error); FromHex(FromHexError); Decoder(DecoderError); - Snappy(::snappy::InvalidInput); + Snappy(snappy::InvalidInput); BaseData(BaseDataError); } } diff --git a/util/kvdb/Cargo.toml b/util/kvdb/Cargo.toml new file mode 100644 index 00000000000..1f7405e7023 --- /dev/null +++ b/util/kvdb/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "kvdb" +version = "0.1.0" +authors = ["Parity Technologies "] + +[dependencies] +log = "0.3" +ethcore-error = { path = "../error" } +ethcore-bytes = { path = "../bytes" } +ethcore-bigint = { path = "../bigint" } +ethcore-devtools = { path = "../../devtools" } +elastic-array = "0.9" +hashdb = { path = "../hashdb" } +parking_lot = "0.4" +regex = "0.2" +rlp = { path = "../rlp" } +rocksdb = { git = "https://github.com/paritytech/rust-rocksdb" } diff --git a/util/src/kvdb.rs b/util/kvdb/src/lib.rs similarity index 98% rename from util/src/kvdb.rs rename to util/kvdb/src/lib.rs index 4f394b2d42c..e75a8ff007a 100644 --- a/util/src/kvdb.rs +++ b/util/kvdb/src/lib.rs @@ -16,6 +16,20 @@ //! Key-Value store abstraction with `RocksDB` backend. +#[macro_use] +extern crate log; + +extern crate ethcore_error as error; +extern crate ethcore_bytes as bytes; +extern crate ethcore_bigint as bigint; +extern crate ethcore_devtools as devtools; +extern crate elastic_array; +extern crate hashdb; +extern crate parking_lot; +extern crate rlp; +extern crate rocksdb; +extern crate regex; + use std::{mem, fs}; use std::collections::{HashMap, BTreeMap}; use std::io::ErrorKind; @@ -28,7 +42,7 @@ use hashdb::DBValue; use rlp::{UntrustedRlp, RlpType, Compressible}; use rocksdb::{DB, Writable, WriteBatch, WriteOptions, IteratorMode, DBIterator, Options, DBCompactionStyle, BlockBasedOptions, Direction, Cache, Column, ReadOptions}; -use UtilError; +use error::UtilError; use bytes::Bytes; diff --git a/util/migration/Cargo.toml b/util/migration/Cargo.toml new file mode 100644 index 00000000000..5d8b20d171d --- /dev/null +++ b/util/migration/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "migration" +version = "0.1.0" +authors = ["Parity Technologies "] + +[dependencies] +log = "0.3" +common = { path = "../common" } +kvdb = { path = "../kvdb" } +ethcore-devtools = { path = "../../devtools" } diff --git a/util/src/migration/mod.rs b/util/migration/src/lib.rs similarity index 98% rename from util/src/migration/mod.rs rename to util/migration/src/lib.rs index 3e6b898ff67..fd09759cb28 100644 --- a/util/src/migration/mod.rs +++ b/util/migration/src/lib.rs @@ -18,13 +18,22 @@ #[cfg(test)] mod tests; +#[macro_use] +extern crate log; +#[macro_use] +extern crate common; + +extern crate ethcore_devtools as devtools; +extern crate kvdb; + + use std::collections::BTreeMap; use std::fs; use std::fmt; use std::path::{Path, PathBuf}; use std::sync::Arc; -use ::kvdb::{CompactionProfile, Database, DatabaseConfig, DBTransaction}; +use kvdb::{CompactionProfile, Database, DatabaseConfig, DBTransaction}; /// Migration config. #[derive(Clone)] diff --git a/util/src/migration/tests.rs b/util/migration/src/tests.rs similarity index 98% rename from util/src/migration/tests.rs rename to util/migration/src/tests.rs index 64f2d976acb..6445d58f773 100644 --- a/util/src/migration/tests.rs +++ b/util/migration/src/tests.rs @@ -21,7 +21,7 @@ use std::collections::BTreeMap; use std::sync::Arc; use std::path::{Path, PathBuf}; -use migration::{Batch, Config, Error, SimpleMigration, Migration, Manager}; +use {Batch, Config, Error, SimpleMigration, Migration, Manager, ChangeColumns}; use kvdb::Database; use devtools::RandomTempPath; @@ -232,7 +232,7 @@ fn change_columns() { use kvdb::DatabaseConfig; let mut manager = Manager::new(Config::default()); - manager.add_migration(::migration::ChangeColumns { + manager.add_migration(ChangeColumns { pre_columns: None, post_columns: Some(4), version: 1, diff --git a/util/snappy/Cargo.toml b/util/snappy/Cargo.toml new file mode 100644 index 00000000000..c65e9824dce --- /dev/null +++ b/util/snappy/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "snappy" +version = "0.1.0" +authors = ["Parity Technologies "] + +[dependencies] +libc = "0.2.7" diff --git a/util/src/snappy.rs b/util/snappy/src/lib.rs similarity index 99% rename from util/src/snappy.rs rename to util/snappy/src/lib.rs index bfb68129a55..545ff1e5b96 100644 --- a/util/src/snappy.rs +++ b/util/snappy/src/lib.rs @@ -15,8 +15,9 @@ // along with Parity. If not, see . //! Snappy compression bindings. +extern crate libc; -use std::{self, fmt}; +use std::fmt; use libc::{c_char, c_int, size_t}; const SNAPPY_OK: c_int = 0; diff --git a/util/src/journaldb/refcounteddb.rs b/util/src/journaldb/refcounteddb.rs index bcdcdabb5bd..eeca1108538 100644 --- a/util/src/journaldb/refcounteddb.rs +++ b/util/src/journaldb/refcounteddb.rs @@ -27,7 +27,7 @@ use super::{DB_PREFIX_LEN, LATEST_ERA_KEY}; use super::traits::JournalDB; use kvdb::{KeyValueDB, DBTransaction}; use bigint::hash::H256; -use UtilError; +use error::UtilError; use bytes::Bytes; /// Implementation of the `HashDB` trait for a disk-backed database with a memory overlay diff --git a/util/src/journaldb/traits.rs b/util/src/journaldb/traits.rs index c4cd2ad1679..a7667124ba6 100644 --- a/util/src/journaldb/traits.rs +++ b/util/src/journaldb/traits.rs @@ -20,7 +20,7 @@ use std::sync::Arc; use hashdb::*; use kvdb::{self, DBTransaction}; use bigint::hash::H256; -use UtilError; +use error::UtilError; use bytes::Bytes; /// A `HashDB` which can manage a short-term journal potentially containing many forks of mutually diff --git a/util/src/lib.rs b/util/src/lib.rs index d4b1e544d02..369fe294f61 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -108,22 +108,15 @@ extern crate hash as keccak; extern crate hashdb; extern crate memorydb; extern crate patricia_trie as trie; - -#[macro_use] -extern crate error_chain; +extern crate kvdb; +extern crate ethcore_error as error; #[macro_use] extern crate log as rlog; -#[macro_use] -pub mod common; -pub mod error; pub mod misc; -pub mod migration; pub mod overlaydb; pub mod journaldb; -pub mod kvdb; -pub mod snappy; pub mod cache; pub use misc::*; @@ -131,8 +124,6 @@ pub use hashdb::*; pub use memorydb::MemoryDB; pub use overlaydb::*; pub use journaldb::JournalDB; -pub use kvdb::*; -pub use error::UtilError; /// 160-bit integer representing account address pub type Address = bigint::hash::H160;