Merge pull request #6801 from paritytech/refactoring/journal-6693

Refactors journaldb as a separate crate
This commit is contained in:
Marek Kotewicz 2017-10-18 16:10:28 +02:00 committed by GitHub
commit 5281e09828
35 changed files with 102 additions and 39 deletions

22
Cargo.lock generated
View File

@ -539,6 +539,7 @@ 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)",
"journaldb 0.1.0",
"kvdb 0.1.0",
"kvdb-memorydb 0.1.0",
"kvdb-rocksdb 0.1.0",
@ -772,6 +773,7 @@ dependencies = [
"hash 0.1.0",
"hashdb 0.1.0",
"heapsize 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"journaldb 0.1.0",
"kvdb 0.1.0",
"kvdb-memorydb 0.1.0",
"libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1252,6 +1254,25 @@ name = "itoa"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "journaldb"
version = "0.1.0"
dependencies = [
"ethcore-bigint 0.1.3",
"ethcore-bytes 0.1.0",
"ethcore-logger 1.9.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",
"kvdb-memorydb 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)",
"rlp 0.2.0",
"util-error 0.1.0",
]
[[package]]
name = "jsonrpc-core"
version = "8.0.0"
@ -1941,6 +1962,7 @@ dependencies = [
"hash 0.1.0",
"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)",
"journaldb 0.1.0",
"jsonrpc-core 8.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.8)",
"kvdb 0.1.0",
"kvdb-rocksdb 0.1.0",

View File

@ -62,6 +62,7 @@ hash = { path = "util/hash" }
migration = { path = "util/migration" }
kvdb = { path = "util/kvdb" }
kvdb-rocksdb = { path = "util/kvdb-rocksdb" }
journaldb = { path = "util/journaldb" }
parity-dapps = { path = "dapps", optional = true }
clippy = { version = "0.0.103", optional = true}

View File

@ -71,6 +71,7 @@ hash = { path = "../util/hash" }
triehash = { path = "../util/triehash" }
semantic_version = { path = "../util/semantic_version" }
unexpected = { path = "../util/unexpected" }
journaldb = { path = "../util/journaldb" }
[dev-dependencies]
native-contracts = { path = "native_contracts", features = ["test_contracts"] }

View File

@ -26,7 +26,8 @@ use itertools::Itertools;
use hash::keccak;
use timer::PerfTimer;
use bytes::Bytes;
use util::{Address, journaldb, DBValue};
use util::{Address, DBValue};
use journaldb;
use util_error::UtilError;
use trie::{TrieSpec, TrieFactory, Trie};
use kvdb::{KeyValueDB, DBTransaction};

View File

@ -20,7 +20,7 @@ use std::fmt::{Display, Formatter, Error as FmtError};
use mode::Mode as IpcMode;
use verification::{VerifierType, QueueConfig};
use util::journaldb;
use journaldb;
use kvdb_rocksdb::CompactionProfile;
pub use std::time::Duration;

View File

@ -20,7 +20,7 @@ use std::fmt;
use std::sync::Arc;
use bigint::prelude::U256;
use bigint::hash::H256;
use util::journaldb;
use journaldb;
use {trie, kvdb_memorydb, bytes};
use kvdb::{self, KeyValueDB};
use {state, state_db, client, executive, trace, transaction, db, spec, pod_state};

View File

@ -26,7 +26,8 @@ use hash::keccak;
use bigint::prelude::U256;
use bigint::hash::H256;
use parking_lot::RwLock;
use util::*;
use journaldb;
use util::{Address, DBValue};
use kvdb_rocksdb::{Database, DatabaseConfig};
use bytes::Bytes;
use rlp::*;

View File

@ -131,6 +131,7 @@ extern crate vm;
extern crate wasm;
extern crate ethcore_util as util;
extern crate memory_cache;
extern crate journaldb;
#[macro_use]
extern crate macros;

View File

@ -23,7 +23,7 @@ use trie::TrieDB;
use views::HeaderView;
use bloom_journal::Bloom;
use migration::{Error, Migration, Progress, Batch, Config, ErrorKind};
use util::journaldb;
use journaldb;
use bigint::hash::H256;
use trie::Trie;
use kvdb::{DBTransaction, ResultExt};

View File

@ -36,7 +36,7 @@ use util::{HashDB, DBValue};
use snappy;
use bytes::Bytes;
use parking_lot::Mutex;
use util::journaldb::{self, Algorithm, JournalDB};
use journaldb::{self, Algorithm, JournalDB};
use kvdb::KeyValueDB;
use trie::{TrieDB, TrieDBMut, Trie, TrieMut};
use rlp::{RlpStream, UntrustedRlp};

View File

@ -39,7 +39,7 @@ use bigint::hash::H256;
use parking_lot::{Mutex, RwLock, RwLockReadGuard};
use util_error::UtilError;
use bytes::Bytes;
use util::journaldb::Algorithm;
use journaldb::Algorithm;
use kvdb_rocksdb::{Database, DatabaseConfig};
use snappy;
@ -625,7 +625,7 @@ mod tests {
use io::{IoService};
use devtools::RandomTempPath;
use tests::helpers::get_test_spec;
use util::journaldb::Algorithm;
use journaldb::Algorithm;
use error::Error;
use snapshot::{ManifestData, RestorationStatus, SnapshotService};
use super::*;

View File

@ -35,7 +35,7 @@ use util::DBValue;
use kvdb::KeyValueDB;
use bigint::hash::H256;
use hashdb::HashDB;
use util::journaldb;
use journaldb;
use trie::{Alphabet, StandardMap, SecTrieDBMut, TrieMut, ValueMode};
use trie::{TrieDB, TrieDBMut, Trie};

View File

@ -69,7 +69,7 @@ fn restored_is_equivalent() {
engine: spec.engine.clone(),
genesis_block: spec.genesis_block(),
db_config: db_config,
pruning: ::util::journaldb::Algorithm::Archive,
pruning: ::journaldb::Algorithm::Archive,
channel: IoChannel::disconnected(),
snapshot_root: path,
db_restore: client2.clone(),
@ -112,7 +112,7 @@ fn guards_delete_folders() {
engine: spec.engine.clone(),
genesis_block: spec.genesis_block(),
db_config: DatabaseConfig::with_columns(::db::NUM_COLUMNS),
pruning: ::util::journaldb::Algorithm::Archive,
pruning: ::journaldb::Algorithm::Archive,
channel: IoChannel::disconnected(),
snapshot_root: path.clone(),
db_restore: Arc::new(NoopDBRestore),

View File

@ -26,7 +26,7 @@ use error::Error;
use rand::{XorShiftRng, SeedableRng};
use bigint::hash::H256;
use util::journaldb::{self, Algorithm};
use journaldb::{self, Algorithm};
use kvdb_rocksdb::{Database, DatabaseConfig};
use memorydb::MemoryDB;
use parking_lot::Mutex;

View File

@ -670,7 +670,7 @@ impl Spec {
/// constructor.
pub fn genesis_epoch_data(&self) -> Result<Vec<u8>, String> {
use transaction::{Action, Transaction};
use util::journaldb;
use journaldb;
use kvdb_memorydb;
let genesis = self.genesis_header();

View File

@ -18,7 +18,7 @@ use std::collections::{VecDeque, HashSet};
use std::sync::Arc;
use lru_cache::LruCache;
use memory_cache::MemoryLruCache;
use util::journaldb::JournalDB;
use journaldb::JournalDB;
use kvdb::{KeyValueDB, DBTransaction};
use bigint::hash::H256;
use hashdb::HashDB;

View File

@ -36,7 +36,6 @@ use state_db::StateDB;
use state::*;
use std::sync::Arc;
use transaction::{Action, Transaction, SignedTransaction};
use util::*;
use views::BlockView;
// TODO: move everything over to get_null_spec.
@ -282,7 +281,7 @@ pub fn get_temp_state_with_factory(factory: EvmFactory) -> State<::state_db::Sta
pub fn get_temp_state_db() -> StateDB {
let db = new_db();
let journal_db = journaldb::new(db, journaldb::Algorithm::EarlyMerge, ::db::COL_STATE);
let journal_db = ::journaldb::new(db, ::journaldb::Algorithm::EarlyMerge, ::db::COL_STATE);
StateDB::new(journal_db, 5 * 1024 * 1024)
}

View File

@ -17,7 +17,7 @@
use std::fs;
use std::path::{PathBuf, Path};
use bigint::hash::{H64, H256};
use util::journaldb::Algorithm;
use journaldb::Algorithm;
use helpers::{replace_home, replace_home_and_local};
use app_dirs::{AppInfo, get_app_root, AppDataType};

View File

@ -22,7 +22,7 @@ use bigint::prelude::U256;
use bigint::hash::clean_0x;
use util::Address;
use kvdb_rocksdb::CompactionProfile;
use util::journaldb::Algorithm;
use journaldb::Algorithm;
use ethcore::client::{Mode, BlockId, VMType, DatabaseCompactionProfile, ClientConfig, VerifierType};
use ethcore::miner::{PendingSet, GasLimit, PrioritizationStrategy};
use cache::CacheConfig;

View File

@ -76,6 +76,7 @@ extern crate path;
extern crate rpc_cli;
extern crate node_filter;
extern crate hash;
extern crate journaldb;
#[macro_use]
extern crate log as rlog;

View File

@ -20,7 +20,7 @@ use std::io::{Read, Write, Error as IoError, ErrorKind};
use std::path::{Path, PathBuf};
use std::fmt::{Display, Formatter, Error as FmtError};
use std::sync::Arc;
use util::journaldb::Algorithm;
use journaldb::Algorithm;
use migr::{self, Manager as MigrationManager, Config as MigrationConfig, Migration};
use kvdb;
use kvdb_rocksdb::{CompactionProfile, Database, DatabaseConfig};
@ -282,7 +282,6 @@ pub fn migrate(path: &Path, pruning: Algorithm, compaction_profile: CompactionPr
mod legacy {
use super::*;
use std::path::{Path, PathBuf};
use util::journaldb::Algorithm;
use migr::{Manager as MigrationManager};
use kvdb_rocksdb::CompactionProfile;
use ethcore::migrations;

View File

@ -18,7 +18,7 @@ use std::{str, fs, fmt};
use std::time::Duration;
use bigint::prelude::U256;
use util::{Address, version_data};
use util::journaldb::Algorithm;
use journaldb::Algorithm;
use ethcore::spec::{Spec, SpecParams};
use ethcore::ethereum;
use ethcore::client::Mode;
@ -326,7 +326,7 @@ pub fn mode_switch_to_bool(switch: Option<Mode>, user_defaults: &UserDefaults) -
#[cfg(test)]
mod tests {
use util::journaldb::Algorithm;
use journaldb::Algorithm;
use user_defaults::UserDefaults;
use super::{SpecType, Pruning, ResealPolicy, Switch, tracing_switch_to_bool};

View File

@ -42,7 +42,7 @@ use ansi_term::Colour;
use util::version;
use parking_lot::{Condvar, Mutex};
use node_filter::NodeFilter;
use util::journaldb::Algorithm;
use journaldb::Algorithm;
use params::{
SpecType, Pruning, AccountsConfig, GasPricerConfig, MinerExtras, Switch,

View File

@ -25,7 +25,7 @@ use std::io::{Read, Write};
use std::path::{PathBuf, Path};
use dir::{DatabaseDirectories, default_data_path};
use helpers::replace_home;
use util::journaldb::Algorithm;
use journaldb::Algorithm;
#[cfg_attr(feature="dev", allow(enum_variant_names))]
#[derive(Debug)]

View File

@ -26,7 +26,7 @@ use serde::de::value::MapAccessDeserializer;
use serde_json::Value;
use serde_json::de::from_reader;
use serde_json::ser::to_string;
use util::journaldb::Algorithm;
use journaldb::Algorithm;
use ethcore::client::Mode;
pub struct UserDefaults {

View File

@ -32,6 +32,7 @@ ethcore-bytes = { path = "bytes" }
memorydb = { path = "memorydb" }
util-error = { path = "error" }
kvdb = { path = "kvdb" }
journaldb = { path = "journaldb" }
[dev-dependencies]
kvdb-memorydb = { path = "kvdb-memorydb" }

23
util/journaldb/Cargo.toml Normal file
View File

@ -0,0 +1,23 @@
[package]
name = "journaldb"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
description = "A `HashDB` which can manage a short-term journal potentially containing many forks of mutually exclusive actions"
license = "GPL3"
[dependencies]
ethcore-bigint = { path = "../bigint", features = ["heapsizeof"] }
ethcore-bytes = { path = "../bytes" }
hashdb = { path = "../hashdb" }
heapsize = "0.4"
kvdb = { path = "../kvdb" }
log = "0.3"
memorydb = { path = "../memorydb" }
parking_lot = "0.4"
rlp = { path = "../rlp" }
util-error = { path = "../error" }
[dev-dependencies]
ethcore-logger = { path = "../../logger" }
hash = { path = "../hash" }
kvdb-memorydb = { path = "../kvdb-memorydb" }

View File

@ -21,9 +21,9 @@ use std::collections::hash_map::Entry;
use std::sync::Arc;
use rlp::*;
use hashdb::*;
use super::super::memorydb::*;
use super::memorydb::*;
use super::{DB_PREFIX_LEN, LATEST_ERA_KEY};
use super::traits::JournalDB;
use traits::JournalDB;
use kvdb::{KeyValueDB, DBTransaction};
use bigint::hash::H256;
use error::{BaseDataError, UtilError};
@ -202,8 +202,7 @@ mod tests {
use keccak::keccak;
use hashdb::{HashDB, DBValue};
use super::*;
use journaldb::traits::JournalDB;
use kvdb_memorydb;
use {kvdb_memorydb, JournalDB};
#[test]
fn insert_same_in_fork() {

View File

@ -16,6 +16,26 @@
//! `JournalDB` interface and implementation.
extern crate heapsize;
#[macro_use]
extern crate log;
extern crate ethcore_bigint as bigint;
extern crate ethcore_bytes as bytes;
extern crate hashdb;
extern crate kvdb;
extern crate memorydb;
extern crate parking_lot;
extern crate rlp;
extern crate util_error as error;
#[cfg(test)]
extern crate ethcore_logger;
#[cfg(test)]
extern crate hash as keccak;
#[cfg(test)]
extern crate kvdb_memorydb;
use std::{fmt, str};
use std::sync::Arc;
@ -26,6 +46,8 @@ mod earlymergedb;
mod overlayrecentdb;
mod refcounteddb;
pub mod overlaydb;
/// Export the `JournalDB` trait.
pub use self::traits::JournalDB;

View File

@ -459,8 +459,7 @@ mod tests {
use super::*;
use hashdb::{HashDB, DBValue};
use ethcore_logger::init_log;
use journaldb::JournalDB;
use kvdb_memorydb;
use {kvdb_memorydb, JournalDB};
fn new_db() -> OverlayRecentDB {
let backing = Arc::new(kvdb_memorydb::create(0));

View File

@ -210,9 +210,8 @@ mod tests {
use keccak::keccak;
use hashdb::{HashDB, DBValue};
use kvdb_memorydb;
use super::*;
use super::super::traits::JournalDB;
use {JournalDB, kvdb_memorydb};
fn new_db() -> RefCountedDB {
let backing = Arc::new(kvdb_memorydb::create(0));

View File

@ -112,18 +112,12 @@ extern crate util_error as error;
#[cfg(test)]
extern crate kvdb_memorydb;
#[macro_use]
extern crate log as rlog;
pub mod misc;
pub mod overlaydb;
pub mod journaldb;
pub use misc::*;
pub use hashdb::*;
pub use memorydb::MemoryDB;
pub use overlaydb::*;
pub use journaldb::JournalDB;
/// 160-bit integer representing account address
pub type Address = bigint::hash::H160;