Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Extract AccountDB to account-db
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdplm committed Jul 4, 2019
1 parent d54ebab commit 7792810
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 25 deletions.
15 changes: 14 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ethcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ version = "1.12.0"
authors = ["Parity Technologies <admin@parity.io>"]

[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 }
Expand Down
14 changes: 14 additions & 0 deletions ethcore/account-db/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
description = "DB backend wrapper for Account trie"
name = "account-db"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
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"
20 changes: 4 additions & 16 deletions ethcore/src/account_db.rs → ethcore/account-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<KeccakHasher, DBValue>, 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<KeccakHasher, DBValue>, address_hash: H256) -> Self {
AccountDB {
db: db,
address_hash: address_hash,
}
AccountDB { db, address_hash }
}
}

Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
//! cargo build --release
//! ```

extern crate account_db;
extern crate ansi_term;
extern crate bn;
extern crate common_types as types;
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions ethcore/src/snapshot/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ mod tests {
let thin_rlp = ::rlp::encode(&account);
assert_eq!(::rlp::decode::<BasicAccount>(&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);
}
Expand All @@ -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);
}
Expand All @@ -304,7 +304,7 @@ mod tests {
assert_eq!(::rlp::decode::<BasicAccount>(&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 {
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion ethcore/state-account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion ethcore/state-account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 7792810

Please sign in to comment.