Skip to content

Commit 43dc815

Browse files
Seulgi Kimmergify[bot]
authored andcommitted
Merge crates related databases into util/db
This patch merges hashdb, journaldb and memorydb.
1 parent fc6fec0 commit 43dc815

30 files changed

+194
-223
lines changed

Cargo.lock

Lines changed: 17 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2018"
66

77
[dependencies]
88
codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.1" }
9+
codechain-db = { path = "../util/db" }
910
codechain-io = { path = "../util/io" }
1011
codechain-json = { path = "../json" }
1112
codechain-key = { path = "../key" }
@@ -20,16 +21,13 @@ codechain-stratum = { path = "../stratum" }
2021
codechain-vm = { path = "../vm" }
2122
crossbeam-channel = "0.3"
2223
cuckoo = { git = "https://github.com/CodeChain-io/rust-cuckoo.git", rev = "280cab9c" }
23-
hashdb = { path = "../util/hashdb" }
2424
hyper = { git = "https://github.com/paritytech/hyper", default-features = false }
25-
journaldb = { path = "../util/journaldb" }
2625
kvdb = "0.1"
2726
kvdb-rocksdb = "0.1"
2827
kvdb-memorydb = "0.1"
2928
linked-hash-map = "0.5"
3029
log = "0.4.6"
3130
lru-cache = "0.1.2"
32-
memorydb = { path = "../util/memorydb" }
3331
num-rational = "0.2.1"
3432
parking_lot = "0.6.0"
3533
primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.4" }

core/src/client/client.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use std::ops::Range;
1818
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering};
1919
use std::sync::{Arc, Weak};
2020

21+
use cdb::{new_journaldb, Algorithm, AsHashDB};
2122
use cio::IoChannel;
2223
use ckey::{Address, NetworkId, PlatformAddress, Public};
2324
use cmerkle::Result as TrieResult;
@@ -29,8 +30,6 @@ use ctimer::{TimeoutHandler, TimerApi, TimerScheduleError, TimerToken};
2930
use ctypes::transaction::{AssetTransferInput, PartialHashing, ShardTransaction};
3031
use ctypes::{BlockHash, BlockNumber, CommonParams, ShardId, Tracker, TxHash};
3132
use cvm::{decode, execute, ChainTimeInfo, ScriptResult, VMConfig};
32-
use hashdb::AsHashDB;
33-
use journaldb;
3433
use kvdb::{DBTransaction, KeyValueDB};
3534
use parking_lot::{Mutex, RwLock, RwLockReadGuard};
3635
use primitives::{Bytes, H160, H256, U256};
@@ -91,7 +90,7 @@ impl Client {
9190
message_channel: IoChannel<ClientIoMessage>,
9291
reseal_timer: TimerApi,
9392
) -> Result<Arc<Client>, Error> {
94-
let journal_db = journaldb::new(Arc::clone(&db), journaldb::Algorithm::Archive, crate::db::COL_STATE);
93+
let journal_db = new_journaldb(Arc::clone(&db), Algorithm::Archive, crate::db::COL_STATE);
9594
let mut state_db = StateDB::new(journal_db);
9695
if !scheme.check_genesis_root(state_db.as_hashdb()) {
9796
return Err(SchemeError::InvalidState.into())

core/src/client/test_client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use std::ops::Range;
3636
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrder};
3737
use std::sync::Arc;
3838

39+
use cdb;
3940
use ckey::{public_to_address, Address, Generator, KeyPair, NetworkId, PlatformAddress, Private, Public, Random};
4041
use cmerkle::skewed_merkle_root;
4142
use cnetwork::NodeId;
@@ -45,7 +46,6 @@ use ctimer::{TimeoutHandler, TimerToken};
4546
use ctypes::transaction::{Action, Transaction};
4647
use ctypes::{BlockHash, BlockNumber, CommonParams, Header as BlockHeader, Tracker, TxHash};
4748
use cvm::ChainTimeInfo;
48-
use journaldb;
4949
use kvdb::KeyValueDB;
5050
use kvdb_memorydb;
5151
use parking_lot::RwLock;
@@ -338,7 +338,7 @@ impl TestBlockChainClient {
338338

339339
pub fn get_temp_state_db() -> StateDB {
340340
let db = kvdb_memorydb::create(NUM_COLUMNS.unwrap_or(0));
341-
let journal_db = journaldb::new(Arc::new(db), journaldb::Algorithm::Archive, COL_STATE);
341+
let journal_db = cdb::new_journaldb(Arc::new(db), cdb::Algorithm::Archive, COL_STATE);
342342
StateDB::new(journal_db)
343343
}
344344

core/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#![cfg_attr(feature = "nightly", feature(test))]
1818

1919
extern crate codechain_crypto as ccrypto;
20+
extern crate codechain_db as cdb;
2021
extern crate codechain_io as cio;
2122
extern crate codechain_json as cjson;
2223
extern crate codechain_key as ckey;
@@ -32,14 +33,11 @@ extern crate codechain_types as ctypes;
3233
extern crate codechain_vm as cvm;
3334
extern crate crossbeam_channel;
3435
extern crate cuckoo;
35-
extern crate hashdb;
36-
extern crate journaldb;
3736
extern crate kvdb;
3837
extern crate kvdb_memorydb;
3938
extern crate kvdb_rocksdb;
4039
extern crate linked_hash_map;
4140
extern crate lru_cache;
42-
extern crate memorydb;
4341
extern crate num_rational;
4442
extern crate primitives;
4543
extern crate rand;

core/src/scheme/scheme.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ use std::io::Read;
1818
use std::sync::Arc;
1919

2020
use ccrypto::{blake256, BLAKE_NULL_RLP};
21+
use cdb::{AsHashDB, HashDB};
2122
use cjson;
2223
use ckey::Address;
2324
use cmerkle::{TrieFactory, TrieMut};
2425
use cstate::{Metadata, MetadataAddress, Shard, ShardAddress, StateDB, StateResult, StateWithCache, TopLevelState};
2526
use ctypes::errors::SyntaxError;
2627
use ctypes::{BlockHash, CommonParams, Header, ShardId};
27-
use hashdb::{AsHashDB, HashDB};
2828
use parking_lot::RwLock;
2929
use primitives::{Bytes, H256, U256};
3030
use rlp::{Encodable, Rlp, RlpStream};

state/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ edition = "2018"
66

77
[dependencies]
88
codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.1" }
9+
codechain-db = { path = "../util/db" }
910
codechain-logger = { path = "../util/logger" }
1011
codechain-merkle = { path = "../util/merkle" }
1112
codechain-key = { path = "../key" }
1213
codechain-types = { path = "../types" }
1314
codechain-vm = { path = "../vm" }
14-
hashdb = { path = "../util/hashdb" }
15-
journaldb = { path = "../util/journaldb" }
1615
kvdb = "0.1"
1716
kvdb-memorydb = "0.1"
1817
log = "0.4.6"

state/src/db/state_db.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@
3333
use std::collections::HashMap;
3434
use std::sync::Arc;
3535

36+
use cdb::{new_journaldb, Algorithm, AsHashDB, HashDB, JournalDB};
3637
use ctypes::ShardId;
37-
use hashdb::{AsHashDB, HashDB};
38-
use journaldb::{self, Algorithm, JournalDB};
3938
use kvdb::DBTransaction;
4039
use kvdb_memorydb;
4140
use primitives::H256;
@@ -64,7 +63,7 @@ impl StateDB {
6463

6564
pub fn new_with_memorydb() -> Self {
6665
let memorydb = Arc::new(kvdb_memorydb::create(0));
67-
let db = journaldb::new(memorydb, Algorithm::Archive, None);
66+
let db = new_journaldb(memorydb, Algorithm::Archive, None);
6867
Self::new(db)
6968
}
7069

state/src/impls/shard_level.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::collections::HashSet;
1919
use std::iter::{once, FromIterator};
2020

2121
use ccrypto::{Blake, BLAKE_NULL_RLP};
22+
use cdb::AsHashDB;
2223
use ckey::Address;
2324
use cmerkle::{self, TrieError, TrieFactory};
2425
use ctypes::errors::{RuntimeError, UnlockFailureReason};
@@ -29,7 +30,6 @@ use ctypes::transaction::{
2930
use ctypes::util::unexpected::Mismatch;
3031
use ctypes::{BlockNumber, ShardId, Tracker};
3132
use cvm::{decode, execute, ChainTimeInfo, ScriptResult, VMConfig};
32-
use hashdb::AsHashDB;
3333
use primitives::{Bytes, H160, H256};
3434

3535
use crate::cache::ShardCache;

state/src/impls/top_level.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use std::cell::{RefCell, RefMut};
3939
use std::collections::HashMap;
4040

4141
use ccrypto::BLAKE_NULL_RLP;
42+
use cdb::AsHashDB;
4243
use ckey::{public_to_address, recover, verify_address, Address, NetworkId, Public, Signature};
4344
use cmerkle::{Result as TrieResult, TrieError, TrieFactory};
4445
use ctypes::errors::RuntimeError;
@@ -50,7 +51,6 @@ use ctypes::util::unexpected::Mismatch;
5051
use ctypes::Tracker;
5152
use ctypes::{BlockNumber, CommonParams, ShardId, TxHash};
5253
use cvm::ChainTimeInfo;
53-
use hashdb::AsHashDB;
5454
use kvdb::DBTransaction;
5555
#[cfg(test)]
5656
use primitives::H160;
@@ -1012,7 +1012,7 @@ fn is_active_account(state: &dyn TopStateView, address: &Address) -> TrieResult<
10121012
mod tests_state {
10131013
use std::sync::Arc;
10141014

1015-
use journaldb::{self, Algorithm};
1015+
use cdb::{new_journaldb, Algorithm};
10161016

10171017
use super::*;
10181018
use crate::tests::helpers::{empty_top_state, get_memory_db, get_temp_state, get_temp_state_db};
@@ -1077,7 +1077,7 @@ mod tests_state {
10771077
#[test]
10781078
fn get_from_database() {
10791079
let memory_db = get_memory_db();
1080-
let jorunal = journaldb::new(Arc::clone(&memory_db), Algorithm::Archive, Some(0));
1080+
let jorunal = new_journaldb(Arc::clone(&memory_db), Algorithm::Archive, Some(0));
10811081
let db = StateDB::new(jorunal.boxed_clone());
10821082
let a = Address::default();
10831083
let root = {
@@ -1108,7 +1108,7 @@ mod tests_state {
11081108
#[test]
11091109
fn get_from_cache() {
11101110
let memory_db = get_memory_db();
1111-
let jorunal = journaldb::new(Arc::clone(&memory_db), Algorithm::Archive, Some(0));
1111+
let jorunal = new_journaldb(Arc::clone(&memory_db), Algorithm::Archive, Some(0));
11121112
let mut db = StateDB::new(jorunal.boxed_clone());
11131113
let a = Address::default();
11141114
let root = {
@@ -1180,7 +1180,7 @@ mod tests_state {
11801180
fn remove_from_database() {
11811181
let a = Address::default();
11821182
let memory_db = get_memory_db();
1183-
let jorunal = journaldb::new(Arc::clone(&memory_db), Algorithm::Archive, Some(0));
1183+
let jorunal = new_journaldb(Arc::clone(&memory_db), Algorithm::Archive, Some(0));
11841184
let mut db = StateDB::new(jorunal.boxed_clone());
11851185
let root = {
11861186
let mut state = empty_top_state(StateDB::new(jorunal));

state/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

1717
extern crate codechain_crypto as ccrypto;
18+
extern crate codechain_db as cdb;
1819
extern crate codechain_merkle as cmerkle;
1920
#[macro_use]
2021
extern crate codechain_logger as clogger;
2122
extern crate codechain_key as ckey;
2223
extern crate codechain_types as ctypes;
2324
extern crate codechain_vm as cvm;
24-
extern crate hashdb;
25-
extern crate journaldb;
2625
extern crate kvdb;
2726
extern crate kvdb_memorydb;
2827
extern crate lru_cache;

state/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
pub mod helpers {
1818
use std::sync::Arc;
1919

20+
use cdb::AsHashDB;
2021
use cmerkle::{TrieFactory, TrieMut};
2122
use ctypes::{BlockNumber, Tracker};
2223
use cvm::ChainTimeInfo;
23-
use hashdb::AsHashDB;
2424
use kvdb::KeyValueDB;
2525
use kvdb_memorydb;
2626
use primitives::H256;

0 commit comments

Comments
 (0)