diff --git a/Cargo.lock b/Cargo.lock index d5c2ba0d4..b58980f6b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,17 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "account-db" +version = "0.1.0" +dependencies = [ + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hasher 0.1.1", + "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "aes" version = "0.3.2" @@ -864,6 +876,7 @@ dependencies = [ name = "ethcore" version = "1.12.0" dependencies = [ + "account-db 0.1.0", "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "blooms-db 0.1.0", "bn 0.4.4 (git+https://github.com/paritytech/bn)", @@ -3935,8 +3948,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "state-account" version = "0.1.0" dependencies = [ + "account-db 0.1.0", "common-types 0.1.0", - "ethcore 1.12.0", "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", "journaldb 0.2.0", diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index 3a1f17e90..55e0c8b60 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -7,6 +7,7 @@ version = "1.12.0" authors = ["Parity Technologies "] [dependencies] +account-db = { path = "account-db" } ansi_term = "0.11" blooms-db = { path = "../util/blooms-db", optional = true } bn = { git = "https://github.com/paritytech/bn", default-features = false } diff --git a/ethcore/account-db/Cargo.toml b/ethcore/account-db/Cargo.toml new file mode 100644 index 000000000..e3d0dea21 --- /dev/null +++ b/ethcore/account-db/Cargo.toml @@ -0,0 +1,14 @@ +[package] +description = "DB backend wrapper for Account trie" +name = "account-db" +version = "0.1.0" +authors = ["Parity Technologies "] +edition = "2018" + +[dependencies] +ethereum-types = "0.6" +hash-db = "0.12.4" +keccak-hash = "0.2.0" +keccak-hasher = { path = "../../util/keccak-hasher" } +kvdb = "0.1" +rlp = "0.4" diff --git a/ethcore/src/account_db.rs b/ethcore/account-db/src/lib.rs similarity index 94% rename from ethcore/src/account_db.rs rename to ethcore/account-db/src/lib.rs index 57c24e5b0..e88464dab 100644 --- a/ethcore/src/account_db.rs +++ b/ethcore/account-db/src/lib.rs @@ -16,16 +16,13 @@ //! DB backend wrapper for Account trie use ethereum_types::H256; -use hash::{KECCAK_NULL_RLP, keccak}; +use keccak_hash::{KECCAK_NULL_RLP, keccak}; use hash_db::{HashDB, AsHashDB, Prefix}; use keccak_hasher::KeccakHasher; use kvdb::DBValue; use rlp::NULL_RLP; -#[cfg(test)] -use ethereum_types::Address; - -// combines a key with an address hash to ensure uniqueness. +// Combines a key with an address hash to ensure uniqueness. // leaves the first 96 bits untouched in order to support partial key lookup. #[inline] fn combine_key<'a>(address_hash: &'a H256, key: &'a H256) -> H256 { @@ -82,18 +79,9 @@ pub struct AccountDB<'db> { } impl<'db> AccountDB<'db> { - /// Create a new AccountDB from an address. - #[cfg(test)] - pub fn new(db: &'db dyn HashDB, address: &Address) -> Self { - Self::from_hash(db, keccak(address)) - } - - /// Create a new AcountDB from an address' hash. + /// Create a new AccountDB from an address' hash. pub fn from_hash(db: &'db dyn HashDB, address_hash: H256) -> Self { - AccountDB { - db: db, - address_hash: address_hash, - } + AccountDB { db, address_hash } } } diff --git a/ethcore/src/lib.rs b/ethcore/src/lib.rs index ea3347ffd..d6835c348 100644 --- a/ethcore/src/lib.rs +++ b/ethcore/src/lib.rs @@ -53,6 +53,7 @@ //! cargo build --release //! ``` +extern crate account_db; extern crate ansi_term; extern crate bn; extern crate common_types as types; @@ -169,7 +170,6 @@ pub mod state_db; pub mod trace; pub mod transaction_ext; pub mod verification; -pub mod account_db; mod externalities; mod factory; diff --git a/ethcore/src/snapshot/account.rs b/ethcore/src/snapshot/account.rs index 1b437388c..72bf2b66a 100644 --- a/ethcore/src/snapshot/account.rs +++ b/ethcore/src/snapshot/account.rs @@ -251,7 +251,7 @@ mod tests { let thin_rlp = ::rlp::encode(&account); assert_eq!(::rlp::decode::(&thin_rlp).unwrap(), account); let p = Progress::default(); - let fat_rlps = to_fat_rlps(&keccak(&addr), &account, &AccountDB::new(db.as_hash_db(), &addr), &mut Default::default(), usize::max_value(), usize::max_value(), &p).unwrap(); + let fat_rlps = to_fat_rlps(&keccak(&addr), &account, &AccountDB::from_hash(db.as_hash_db(), keccak(addr)), &mut Default::default(), usize::max_value(), usize::max_value(), &p).unwrap(); let fat_rlp = Rlp::new(&fat_rlps[0]).at(1).unwrap(); assert_eq!(from_fat_rlp(&mut AccountDBMut::from_hash(db.as_hash_db_mut(), keccak(addr)), fat_rlp, H256::zero()).unwrap().0, account); } @@ -278,7 +278,7 @@ mod tests { let p = Progress::default(); - let fat_rlp = to_fat_rlps(&keccak(&addr), &account, &AccountDB::new(db.as_hash_db(), &addr), &mut Default::default(), usize::max_value(), usize::max_value(), &p).unwrap(); + let fat_rlp = to_fat_rlps(&keccak(&addr), &account, &AccountDB::from_hash(db.as_hash_db(), keccak(addr)), &mut Default::default(), usize::max_value(), usize::max_value(), &p).unwrap(); let fat_rlp = Rlp::new(&fat_rlp[0]).at(1).unwrap(); assert_eq!(from_fat_rlp(&mut AccountDBMut::from_hash(db.as_hash_db_mut(), keccak(addr)), fat_rlp, H256::zero()).unwrap().0, account); } @@ -304,7 +304,7 @@ mod tests { assert_eq!(::rlp::decode::(&thin_rlp).unwrap(), account); let p = Progress::default(); - let fat_rlps = to_fat_rlps(&keccak(addr), &account, &AccountDB::new(db.as_hash_db(), &addr), &mut Default::default(), 500, 1000, &p).unwrap(); + let fat_rlps = to_fat_rlps(&keccak(addr), &account, &AccountDB::from_hash(db.as_hash_db(), keccak(addr)), &mut Default::default(), 500, 1000, &p).unwrap(); let mut root = KECCAK_NULL_RLP; let mut restored_account = None; for rlp in fat_rlps { @@ -349,8 +349,8 @@ mod tests { let mut used_code = HashSet::new(); let p1 = Progress::default(); let p2 = Progress::default(); - let fat_rlp1 = to_fat_rlps(&keccak(&addr1), &account1, &AccountDB::new(db.as_hash_db(), &addr1), &mut used_code, usize::max_value(), usize::max_value(), &p1).unwrap(); - let fat_rlp2 = to_fat_rlps(&keccak(&addr2), &account2, &AccountDB::new(db.as_hash_db(), &addr2), &mut used_code, usize::max_value(), usize::max_value(), &p2).unwrap(); + let fat_rlp1 = to_fat_rlps(&keccak(&addr1), &account1, &AccountDB::from_hash(db.as_hash_db(), keccak(addr1)), &mut used_code, usize::max_value(), usize::max_value(), &p1).unwrap(); + let fat_rlp2 = to_fat_rlps(&keccak(&addr2), &account2, &AccountDB::from_hash(db.as_hash_db(), keccak(addr2)), &mut used_code, usize::max_value(), usize::max_value(), &p2).unwrap(); assert_eq!(used_code.len(), 1); let fat_rlp1 = Rlp::new(&fat_rlp1[0]).at(1).unwrap(); diff --git a/ethcore/state-account/Cargo.toml b/ethcore/state-account/Cargo.toml index 3e2d8bc6a..e50c23fc7 100644 --- a/ethcore/state-account/Cargo.toml +++ b/ethcore/state-account/Cargo.toml @@ -22,7 +22,7 @@ serde = { version = "1.0", features = ["derive"] } trie-db = "0.12.4" [dev-dependencies] -ethcore = { path = ".." } +account-db = { path = "../account-db" } rlp_compress = { path = "../../util/rlp-compress" } journaldb = { path = "../../util/journaldb" } parity-bytes = "0.1.0" diff --git a/ethcore/state-account/src/lib.rs b/ethcore/state-account/src/lib.rs index 24e136d1e..d2f773c3c 100644 --- a/ethcore/state-account/src/lib.rs +++ b/ethcore/state-account/src/lib.rs @@ -632,7 +632,7 @@ mod tests { use journaldb::new_memory_db; use parity_bytes::Bytes; use super::*; - use ethcore::account_db::*; + use account_db::*; use std::str::FromStr; #[test]