From 6279ff32f5ea2b854e50b34f3274d28eb35687e7 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 10 Oct 2017 20:01:27 +0200 Subject: [PATCH] Separate migrations from util (#6690) * separate migration from util and make its dependencies into libs: * snappy * kvdb * error * common * renamed common -> macros * util error does not depend on snappy module * ethsync does not depend on util nor ethcore_error * nibbleslice and nibblevec merged with patricia_trie crate * removed unused dependencies from util * util journaldb traits does not need to be public * util_error * fixed ethcore compile error * ignore .swo files * Update chain.rs --- .gitignore | 1 + Cargo.lock | 86 ++++++++++++++----- 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 | 18 +++- 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 | 8 +- 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 | 2 + sync/src/blocks.rs | 3 +- sync/src/chain.rs | 4 +- sync/src/lib.rs | 8 +- sync/src/tests/consensus.rs | 3 +- sync/src/tests/helpers.rs | 2 +- util/Cargo.toml | 6 +- util/error/Cargo.toml | 10 +++ util/{src/error.rs => error/src/lib.rs} | 10 ++- util/kvdb/Cargo.toml | 17 ++++ util/{src/kvdb.rs => kvdb/src/lib.rs} | 40 +++++++-- util/{nibbleslice => macros}/Cargo.toml | 3 +- util/{src/common.rs => macros/src/lib.rs} | 4 +- util/migration/Cargo.toml | 10 +++ .../migration/mod.rs => migration/src/lib.rs} | 10 ++- .../{src/migration => migration/src}/tests.rs | 4 +- util/patricia_trie/Cargo.toml | 2 - util/patricia_trie/src/lib.rs | 4 +- .../src/nibbleslice.rs} | 6 +- .../lib.rs => patricia_trie/src/nibblevec.rs} | 6 +- util/patricia_trie/src/node.rs | 2 +- util/patricia_trie/src/triedb.rs | 2 +- util/{nibblevec => snappy}/Cargo.toml | 5 +- util/{src/snappy.rs => snappy/src/lib.rs} | 3 +- util/src/journaldb/mod.rs | 2 +- util/src/journaldb/refcounteddb.rs | 2 +- util/src/journaldb/traits.rs | 2 +- util/src/lib.rs | 14 +-- 86 files changed, 322 insertions(+), 170 deletions(-) create mode 100644 util/error/Cargo.toml rename util/{src/error.rs => error/src/lib.rs} (92%) create mode 100644 util/kvdb/Cargo.toml rename util/{src/kvdb.rs => kvdb/src/lib.rs} (97%) rename util/{nibbleslice => macros}/Cargo.toml (69%) rename util/{src/common.rs => macros/src/lib.rs} (93%) 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%) rename util/{nibbleslice/src/lib.rs => patricia_trie/src/nibbleslice.rs} (98%) rename util/{nibblevec/src/lib.rs => patricia_trie/src/nibblevec.rs} (98%) rename util/{nibblevec => snappy}/Cargo.toml (53%) rename util/{src/snappy.rs => snappy/src/lib.rs} (99%) diff --git a/.gitignore b/.gitignore index 994559bb1..0138d3efd 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ # vim stuff *.swp +*.swo # mac stuff .DS_Store diff --git a/Cargo.lock b/Cargo.lock index bd46ffb95..09e6a4f23 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -600,11 +600,14 @@ 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)", + "macros 0.1.0", "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 +622,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)", @@ -626,6 +630,7 @@ dependencies = [ "triehash 0.1.0", "unexpected 0.1.0", "using_queue 0.1.0", + "util-error 0.1.0", "vm 0.1.0", "wasm 0.1.0", ] @@ -752,6 +757,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 +843,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", @@ -885,22 +892,19 @@ dependencies = [ "error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "eth-secp256k1 0.5.6 (git+https://github.com/paritytech/rust-secp256k1)", "ethcore-bigint 0.1.3", - "ethcore-bloom-journal 0.1.0", "ethcore-bytes 0.1.0", "ethcore-devtools 1.8.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", - "nibbleslice 0.1.0", - "nibblevec 0.1.0", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "patricia_trie 0.1.0", - "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)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -908,6 +912,7 @@ dependencies = [ "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", + "util-error 0.1.0", "vergen 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1018,7 +1023,9 @@ 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)", + "macros 0.1.0", "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)", "rlp 0.2.0", @@ -1501,6 +1508,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)", + "error-chain 0.11.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", + "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" @@ -1582,6 +1606,10 @@ dependencies = [ "linked-hash-map 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "macros" +version = "0.1.0" + [[package]] name = "magenta" version = "0.1.1" @@ -1636,6 +1664,16 @@ dependencies = [ "rlp 0.2.0", ] +[[package]] +name = "migration" +version = "0.1.0" +dependencies = [ + "ethcore-devtools 1.8.0", + "kvdb 0.1.0", + "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "macros 0.1.0", +] + [[package]] name = "mime" version = "0.2.6" @@ -1810,21 +1848,6 @@ dependencies = [ "ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "nibbleslice" -version = "0.1.0" -dependencies = [ - "elastic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "nibblevec" -version = "0.1.0" -dependencies = [ - "elastic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "nibbleslice 0.1.0", -] - [[package]] name = "node-filter" version = "1.8.0" @@ -1836,6 +1859,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 +2090,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 +2236,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)", @@ -2267,7 +2294,9 @@ 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)", + "macros 0.1.0", "multihash 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "node-health 0.1.0", "order-stat 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2456,8 +2485,6 @@ dependencies = [ "hashdb 0.1.0", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "memorydb 0.1.0", - "nibbleslice 0.1.0", - "nibblevec 0.1.0", "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.2.0", "triehash 0.1.0", @@ -3070,6 +3097,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" @@ -3480,6 +3514,16 @@ name = "utf8-ranges" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "util-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)", +] + [[package]] name = "vcpkg" version = "0.2.2" diff --git a/Cargo.toml b/Cargo.toml index 65f8aed15..cf208330d 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 4d7851b07..e7d63703d 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" } +util-error = { path = "../util/error" } +snappy = { path = "../util/snappy" } +migration = { path = "../util/migration" } +macros = { path = "../util/macros" } 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 477b7077a..734eb7432 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 7320eddb4..c31fd4787 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 1b32fe11d..fb0ec3917 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 20aea69ce..f20d0ad90 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 09eade4e7..edf655e4d 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 6043c0e5d..c95e83091 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 fb098f60f..e92dba61d 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 63df5d47b..a55cf669f 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 109038ef2..6184a2f47 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 d79ac5580..263145e88 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 util_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 43a7a821a..e629732d5 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 2bb5b46d4..aaa9fa83f 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 util_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 c6e43fff1..ff03554f9 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 87c4c6001..82f969320 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 e60b77b2e..d11adc771 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 9c7f7b4e2..0146c684a 100644 --- a/ethcore/src/error.rs +++ b/ethcore/src/error.rs @@ -17,9 +17,12 @@ //! General error types for use in ethcore. use std::fmt; +use kvdb; use bigint::prelude::U256; use bigint::hash::H256; use util::*; +use util_error::UtilError; +use snappy::InvalidInput; use unexpected::{Mismatch, OutOfBounds}; use trie::TrieError; use io::*; @@ -299,6 +302,8 @@ impl From for TransactionImportError { pub enum Error { /// Client configuration error. Client(ClientError), + /// Database error. + Database(kvdb::Error), /// Error concerning a utility. Util(UtilError), /// Error concerning block processing. @@ -322,7 +327,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. @@ -337,6 +342,7 @@ impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { Error::Client(ref err) => err.fmt(f), + Error::Database(ref err) => err.fmt(f), Error::Util(ref err) => err.fmt(f), Error::Io(ref err) => err.fmt(f), Error::Block(ref err) => err.fmt(f), @@ -370,6 +376,12 @@ impl From for Error { } } +impl From for Error { + fn from(err: kvdb::Error) -> Error { + Error::Database(err) + } +} + impl From for Error { fn from(err: TransactionError) -> Error { Error::Transaction(err) @@ -434,8 +446,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 9ae55f73d..87869799b 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 5faf5bf82..a67eb879a 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 util_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 macros; #[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 ddade6847..6c5441c97 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 638a64a83..7dfc5427e 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 76b10fd19..fc4975f10 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 4a9d850ad..cbf517d1d 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 d2f6952d4..155d6f4c0 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 08f83f132..7c28054fa 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 ca283b0aa..90f6810aa 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 efb30635d..ce15fed95 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 baff16940..bb2f5a5cc 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 5ef1b197c..eea2a5cce 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 4931d500d..e33c47e2c 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 ab551f154..a53824b1f 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 util_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 d946d7e47..cdd51a63c 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 7c00c8197..9634fd531 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 91f2753d4..8002e4362 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 64a8407aa..d391883a9 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 460dd77b5..175ae4eb8 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 54c966615..e643e1210 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 34279a382..6d2885a5a 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 util_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 4e44573e2..06005e66d 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 30e74e179..52a0dedc6 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 0d57ff97d..270d29597 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 267acc45a..087acdcc9 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 0a255b357..f86daf13f 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 25c6ed64b..ac40b8ab6 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 d7b957fd7..db9830c40 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 5077fbe01..61fe54976 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 9bcaf897e..da54f6763 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 cd269b00b..97ffbca5f 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 c4e5f5ac6..508491a0a 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 0b393f16d..59f5a117c 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -57,12 +57,14 @@ rlp = { path = "../util/rlp" } stats = { path = "../util/stats" } vm = { path = "../ethcore/vm" } hash = { path = "../util/hash" } +kvdb = { path = "../util/kvdb" } hardware-wallet = { path = "../hw" } clippy = { version = "0.0.103", optional = true} pretty_assertions = "0.1" [dev-dependencies] +macros = { path = "../util/macros" } ethcore-network = { path = "../util/network" } [features] diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index c37ebad1f..2e6d6148f 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -50,6 +50,7 @@ extern crate ethcore_devtools as devtools; extern crate ethcore_io as io; extern crate ethcore_ipc; extern crate ethcore_light as light; +extern crate ethcore_util as util; extern crate ethcrypto as crypto; extern crate ethkey; extern crate ethstore; @@ -64,11 +65,10 @@ extern crate rlp; extern crate stats; extern crate hash; extern crate hardware_wallet; +extern crate kvdb; #[macro_use] extern crate log; -#[cfg_attr(test, macro_use)] -extern crate ethcore_util as util; #[macro_use] extern crate jsonrpc_macros; #[macro_use] @@ -81,6 +81,10 @@ extern crate ethjson; #[macro_use] extern crate pretty_assertions; +#[cfg(test)] +#[macro_use] +extern crate macros; + pub extern crate jsonrpc_ws_server as ws; mod authcodes; diff --git a/rpc/src/v1/tests/eth.rs b/rpc/src/v1/tests/eth.rs index 4563f76e3..a2b23f52e 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 4354ea2e3..3e98c62e7 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 6143b4a31..ca408dfc1 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 fb6cc0e68..6aa3bd708 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 d5ef8ed3c..9260f99ce 100644 --- a/sync/Cargo.toml +++ b/sync/Cargo.toml @@ -22,6 +22,8 @@ ethcore = { path = "../ethcore" } rlp = { path = "../util/rlp" } hash = { path = "../util/hash" } triehash = { path = "../util/triehash" } +kvdb = { path = "../util/kvdb" } +macros = { path = "../util/macros" } 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 f7e616c6f..44f693159 100644 --- a/sync/src/blocks.rs +++ b/sync/src/blocks.rs @@ -21,7 +21,6 @@ use hash::{keccak, KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP}; use heapsize::HeapSizeOf; use bigint::hash::H256; use triehash::ordered_trie_root; -use util::*; use bytes::Bytes; use rlp::*; use network::NetworkError; @@ -406,7 +405,7 @@ impl BlockCollection { } } - fn insert_header(&mut self, header: Bytes) -> Result { + fn insert_header(&mut self, header: Bytes) -> Result { let info: BlockHeader = UntrustedRlp::new(&header).as_val()?; let hash = info.hash(); if self.blocks.contains_key(&hash) { diff --git a/sync/src/chain.rs b/sync/src/chain.rs index 7423f8254..8e2b9e9f5 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -14,7 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -/// /// `BlockChain` synchronization strategy. /// Syncs to peers and keeps up to date. /// This implementation uses ethereum protocol v63 @@ -2230,19 +2229,18 @@ fn accepts_service_transaction(client_id: &str) -> bool { #[cfg(test)] mod tests { use std::collections::{HashSet, VecDeque}; + use {ethkey, Address}; use network::PeerId; use tests::helpers::*; use tests::snapshot::TestSnapshotService; use bigint::prelude::U256; use bigint::hash::H256; - use util::Address; use parking_lot::RwLock; use bytes::Bytes; use rlp::{Rlp, RlpStream, UntrustedRlp}; use super::*; use ::SyncConfig; use super::{PeerInfo, PeerAsking}; - use ethkey; use ethcore::header::*; use ethcore::client::{BlockChainClient, EachBlockWith, TestBlockChainClient}; use ethcore::transaction::UnverifiedTransaction; diff --git a/sync/src/lib.rs b/sync/src/lib.rs index 6a65ec663..33b1d021f 100644 --- a/sync/src/lib.rs +++ b/sync/src/lib.rs @@ -42,6 +42,7 @@ extern crate rlp; extern crate ipnetwork; extern crate hash; extern crate triehash; +extern crate kvdb; extern crate ethcore_light as light; @@ -49,9 +50,9 @@ extern crate ethcore_light as light; #[cfg(test)] extern crate ethkey; #[macro_use] -extern crate log; +extern crate macros; #[macro_use] -extern crate ethcore_util as util; +extern crate log; #[macro_use] extern crate heapsize; #[macro_use] @@ -82,6 +83,9 @@ pub use api::*; pub use chain::{SyncStatus, SyncState}; pub use network::{is_valid_node_url, NonReservedPeerMode, NetworkError, ConnectionFilter, ConnectionDirection}; +#[cfg(test)] +pub(crate) type Address = bigint::hash::H160; + /// IPC interfaces #[cfg(feature="ipc")] pub mod remote { diff --git a/sync/src/tests/consensus.rs b/sync/src/tests/consensus.rs index f45e614d7..b65a72152 100644 --- a/sync/src/tests/consensus.rs +++ b/sync/src/tests/consensus.rs @@ -17,7 +17,6 @@ use std::sync::Arc; use hash::keccak; use bigint::prelude::U256; -use util::*; use io::{IoHandler, IoContext, IoChannel}; use ethcore::client::{BlockChainClient, Client}; use ethcore::service::ClientIoMessage; @@ -27,7 +26,7 @@ use ethcore::transaction::*; use ethcore::account_provider::AccountProvider; use ethkey::{KeyPair, Secret}; use super::helpers::*; -use SyncConfig; +use {SyncConfig, Address}; struct TestIoHandler { client: Arc, diff --git a/sync/src/tests/helpers.rs b/sync/src/tests/helpers.rs index 6fb104ef7..1fe4fde46 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 28d53c6e5..d9faa1786 100644 --- a/util/Cargo.toml +++ b/util/Cargo.toml @@ -24,18 +24,16 @@ target_info = "0.1" ethcore-bigint = { path = "bigint", features = ["heapsizeof"] } parking_lot = "0.4" tiny-keccak= "1.0" -ethcore-bloom-journal = { path = "bloom" } -regex = "0.2" lru-cache = "0.1.0" ethcore-logger = { path = "../logger" } triehash = { path = "triehash" } error-chain = "0.11.0-rc.2" hashdb = { path = "hashdb" } patricia_trie = { path = "patricia_trie" } -nibbleslice = { path = "nibbleslice" } -nibblevec = { path = "nibblevec" } ethcore-bytes = { path = "bytes" } memorydb = { path = "memorydb" } +util-error = { path = "error" } +kvdb = { path = "kvdb" } [features] default = [] diff --git a/util/error/Cargo.toml b/util/error/Cargo.toml new file mode 100644 index 000000000..5c51a78ca --- /dev/null +++ b/util/error/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "util-error" +version = "0.1.0" +authors = ["Parity Technologies "] + +[dependencies] +rlp = { path = "../rlp" } +ethcore-bigint = { path = "../bigint" } +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 92% rename from util/src/error.rs rename to util/error/src/lib.rs index 59496f86f..3b314456e 100644 --- a/util/src/error.rs +++ b/util/error/src/lib.rs @@ -19,7 +19,14 @@ #![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; + +use std::fmt; use rustc_hex::FromHexError; use rlp::DecoderError; use bigint::hash::H256; @@ -59,7 +66,6 @@ error_chain! { Io(::std::io::Error); FromHex(FromHexError); Decoder(DecoderError); - Snappy(::snappy::InvalidInput); BaseData(BaseDataError); } } diff --git a/util/kvdb/Cargo.toml b/util/kvdb/Cargo.toml new file mode 100644 index 000000000..16c3cb86d --- /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-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" } +error-chain = "0.11.0-rc.2" diff --git a/util/src/kvdb.rs b/util/kvdb/src/lib.rs similarity index 97% rename from util/src/kvdb.rs rename to util/kvdb/src/lib.rs index 4f394b2d4..d10d663ba 100644 --- a/util/src/kvdb.rs +++ b/util/kvdb/src/lib.rs @@ -16,9 +16,23 @@ //! Key-Value store abstraction with `RocksDB` backend. -use std::{mem, fs}; +#[macro_use] +extern crate log; +#[macro_use] +extern crate error_chain; + +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, io}; use std::collections::{HashMap, BTreeMap}; -use std::io::ErrorKind; use std::marker::PhantomData; use std::path::{PathBuf, Path}; use parking_lot::{Mutex, MutexGuard, RwLock}; @@ -28,10 +42,8 @@ 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 bytes::Bytes; - #[cfg(target_os = "linux")] use regex::Regex; #[cfg(target_os = "linux")] @@ -46,6 +58,16 @@ const DB_WRITE_BUFFER_SIZE: usize = 2048 * 1000; /// Required length of prefixes. pub const PREFIX_LEN: usize = 12; +error_chain! { + types { + Error, ErrorKind, ResultExt; + } + + foreign_links { + Io(io::Error); + } +} + /// Write transaction. Batches a sequence of put/delete operations for efficiency. #[derive(Default, Clone, PartialEq)] pub struct DBTransaction { @@ -182,7 +204,7 @@ pub trait KeyValueDB: Sync + Send { -> Box, Box<[u8]>)> + 'a>; /// Attempt to replace this database with a new one located at the given path. - fn restore(&self, new_db: &str) -> Result<(), UtilError>; + fn restore(&self, new_db: &str) -> Result<(), Error>; } /// A key-value database fulfilling the `KeyValueDB` trait, living in memory. @@ -279,7 +301,7 @@ impl KeyValueDB for InMemory { } } - fn restore(&self, _new_db: &str) -> Result<(), UtilError> { + fn restore(&self, _new_db: &str) -> Result<(), Error> { Err("Attempted to restore in-memory database".into()) } } @@ -777,7 +799,7 @@ impl Database { } /// Restore the database from a copy at given path. - pub fn restore(&self, new_db: &str) -> Result<(), UtilError> { + pub fn restore(&self, new_db: &str) -> Result<(), Error> { self.close(); let mut backup_db = PathBuf::from(&self.path); @@ -786,7 +808,7 @@ impl Database { let existed = match fs::rename(&self.path, &backup_db) { Ok(_) => true, - Err(e) => if let ErrorKind::NotFound = e.kind() { + Err(e) => if let io::ErrorKind::NotFound = e.kind() { false } else { return Err(e.into()); @@ -889,7 +911,7 @@ impl KeyValueDB for Database { Box::new(unboxed.into_iter().flat_map(|inner| inner)) } - fn restore(&self, new_db: &str) -> Result<(), UtilError> { + fn restore(&self, new_db: &str) -> Result<(), Error> { Database::restore(self, new_db) } } diff --git a/util/nibbleslice/Cargo.toml b/util/macros/Cargo.toml similarity index 69% rename from util/nibbleslice/Cargo.toml rename to util/macros/Cargo.toml index 0d0021d85..01d85935c 100644 --- a/util/nibbleslice/Cargo.toml +++ b/util/macros/Cargo.toml @@ -1,7 +1,6 @@ [package] -name = "nibbleslice" +name = "macros" version = "0.1.0" authors = ["Parity Technologies "] [dependencies] -elastic-array = "0.9" diff --git a/util/src/common.rs b/util/macros/src/lib.rs similarity index 93% rename from util/src/common.rs rename to util/macros/src/lib.rs index 4bf3a06ed..78bcd0397 100644 --- a/util/src/common.rs +++ b/util/macros/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/migration/Cargo.toml b/util/migration/Cargo.toml new file mode 100644 index 000000000..927ea232d --- /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" +macros = { path = "../macros" } +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 3e6b898ff..e854c12f2 100644 --- a/util/src/migration/mod.rs +++ b/util/migration/src/lib.rs @@ -18,13 +18,21 @@ #[cfg(test)] mod tests; +#[macro_use] +extern crate log; +#[macro_use] +extern crate macros; + +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 64f2d976a..6445d58f7 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/patricia_trie/Cargo.toml b/util/patricia_trie/Cargo.toml index 0dcd74e09..5886a4e35 100644 --- a/util/patricia_trie/Cargo.toml +++ b/util/patricia_trie/Cargo.toml @@ -12,8 +12,6 @@ ethcore-bigint = { path = "../bigint" } hash = { path = "../hash" } hashdb = { path = "../hashdb" } rlp = { path = "../rlp" } -nibbleslice = { path = "../nibbleslice" } -nibblevec = { path = "../nibblevec" } triehash = { path = "../triehash" } memorydb = { path = "../memorydb" } ethcore-logger = { path = "../../logger" } diff --git a/util/patricia_trie/src/lib.rs b/util/patricia_trie/src/lib.rs index b927437d6..745549f42 100644 --- a/util/patricia_trie/src/lib.rs +++ b/util/patricia_trie/src/lib.rs @@ -21,8 +21,6 @@ extern crate hash as keccak; extern crate rlp; extern crate hashdb; extern crate ethcore_bytes as bytes; -extern crate nibbleslice; -extern crate nibblevec; extern crate elastic_array; extern crate memorydb; extern crate ethcore_logger; @@ -54,6 +52,8 @@ pub mod recorder; mod fatdb; mod fatdbmut; mod lookup; +mod nibbleslice; +mod nibblevec; pub use self::standardmap::{Alphabet, StandardMap, ValueMode}; pub use self::triedbmut::TrieDBMut; diff --git a/util/nibbleslice/src/lib.rs b/util/patricia_trie/src/nibbleslice.rs similarity index 98% rename from util/nibbleslice/src/lib.rs rename to util/patricia_trie/src/nibbleslice.rs index 60fa11227..c2dd6611e 100644 --- a/util/nibbleslice/src/lib.rs +++ b/util/patricia_trie/src/nibbleslice.rs @@ -15,7 +15,6 @@ // along with Parity. If not, see . //! Nibble-orientated view onto byte-slice, allowing nibble-precision offsets. -extern crate elastic_array; use std::cmp::*; use std::fmt; @@ -26,9 +25,8 @@ use elastic_array::ElasticArray36; /// This is an immutable struct. No operations actually change it. /// /// # Example -/// ```rust -/// extern crate nibbleslice; -/// use nibbleslice::*; +/// ```snippet +/// use patricia_trie::nibbleslice::NibbleSlice; /// fn main() { /// let d1 = &[0x01u8, 0x23, 0x45]; /// let d2 = &[0x34u8, 0x50, 0x12]; diff --git a/util/nibblevec/src/lib.rs b/util/patricia_trie/src/nibblevec.rs similarity index 98% rename from util/nibblevec/src/lib.rs rename to util/patricia_trie/src/nibblevec.rs index c33056467..fbe97496a 100644 --- a/util/nibblevec/src/lib.rs +++ b/util/patricia_trie/src/nibblevec.rs @@ -14,13 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . - //! An owning, nibble-oriented byte vector. -extern crate nibbleslice; -extern crate elastic_array; - -use nibbleslice::NibbleSlice; use elastic_array::ElasticArray36; +use nibbleslice::NibbleSlice; /// Owning, nibble-oriented byte vector. Counterpart to `NibbleSlice`. #[derive(Clone, PartialEq, Eq, Debug)] diff --git a/util/patricia_trie/src/node.rs b/util/patricia_trie/src/node.rs index d44890bd0..70f529c53 100644 --- a/util/patricia_trie/src/node.rs +++ b/util/patricia_trie/src/node.rs @@ -15,7 +15,7 @@ // along with Parity. If not, see . use elastic_array::ElasticArray36; -use nibbleslice::*; +use nibbleslice::NibbleSlice; use nibblevec::NibbleVec; use bytes::*; use rlp::*; diff --git a/util/patricia_trie/src/triedb.rs b/util/patricia_trie/src/triedb.rs index 6c1a0da01..939957a65 100644 --- a/util/patricia_trie/src/triedb.rs +++ b/util/patricia_trie/src/triedb.rs @@ -16,7 +16,7 @@ use std::fmt; use hashdb::*; -use nibbleslice::*; +use nibbleslice::NibbleSlice; use rlp::*; use super::node::{Node, OwnedNode}; use super::lookup::Lookup; diff --git a/util/nibblevec/Cargo.toml b/util/snappy/Cargo.toml similarity index 53% rename from util/nibblevec/Cargo.toml rename to util/snappy/Cargo.toml index df8e990d4..c65e9824d 100644 --- a/util/nibblevec/Cargo.toml +++ b/util/snappy/Cargo.toml @@ -1,8 +1,7 @@ [package] -name = "nibblevec" +name = "snappy" version = "0.1.0" authors = ["Parity Technologies "] [dependencies] -elastic-array = "0.9" -nibbleslice = { path = "../nibbleslice" } +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 bfb68129a..545ff1e5b 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/mod.rs b/util/src/journaldb/mod.rs index 4f0f2fb1b..c048342b2 100644 --- a/util/src/journaldb/mod.rs +++ b/util/src/journaldb/mod.rs @@ -20,7 +20,7 @@ use std::{fmt, str}; use std::sync::Arc; /// Export the journaldb module. -pub mod traits; +mod traits; mod archivedb; mod earlymergedb; mod overlayrecentdb; diff --git a/util/src/journaldb/refcounteddb.rs b/util/src/journaldb/refcounteddb.rs index bcdcdabb5..eeca11085 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 c4cd2ad16..a7667124b 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 d4b1e544d..863f811c4 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -100,7 +100,6 @@ extern crate ethcore_bytes as bytes; extern crate parking_lot; extern crate tiny_keccak; extern crate rlp; -extern crate regex; extern crate lru_cache; extern crate heapsize; extern crate ethcore_logger; @@ -108,22 +107,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 util_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 +123,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;