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

Extract AccountDB to account-db #10839

Merged
merged 10 commits into from
Jul 4, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,5 @@ members = [
"util/keccak-hasher",
"util/patricia-trie-ethereum",
"util/fastmap",
"util/time-utils"
"util/time-utils",
]
3 changes: 3 additions & 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 Expand Up @@ -52,6 +53,7 @@ parity-bytes = "0.1"
parity-crypto = "0.4.0"
parity-snappy = "0.1"
parking_lot = "0.7"
pod-account = { path = "pod-account" }
trie-db = "0.12.4"
patricia-trie-ethereum = { path = "../util/patricia-trie-ethereum" }
rand = "0.6"
Expand All @@ -61,6 +63,7 @@ rlp_derive = { path = "../util/rlp-derive" }
rustc-hex = "1.0"
serde = "1.0"
serde_derive = "1.0"
state-account = { path = "state-account" }
stats = { path = "../util/stats" }
tempdir = { version = "0.3", optional = true }
time-utils = { path = "../util/time-utils" }
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"
35 changes: 7 additions & 28 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 Expand Up @@ -137,21 +125,12 @@ pub struct AccountDBMut<'db> {
}

impl<'db> AccountDBMut<'db> {
/// Create a new AccountDB from an address.
#[cfg(test)]
pub fn new(db: &'db mut dyn HashDB<KeccakHasher, DBValue>, address: &Address) -> Self {
Self::from_hash(db, keccak(address))
}

/// Create a new AcountDB from an address' hash.
/// Create a new `AccountDBMut` from an address' hash.
pub fn from_hash(db: &'db mut dyn HashDB<KeccakHasher, DBValue>, address_hash: H256) -> Self {
AccountDBMut {
db: db,
address_hash: address_hash,
}
AccountDBMut { db, address_hash }
}

#[cfg(test)]
/// Create an `AccountDB` from an `AccountDBMut` (used in tests).
pub fn immutable(&'db self) -> AccountDB<'db> {
AccountDB { db: self.db, address_hash: self.address_hash.clone() }
}
Expand Down
27 changes: 27 additions & 0 deletions ethcore/pod-account/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
description = "Account system expressed in Plain Old Data."
name = "pod-account"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"

[dependencies]
common-types = { path = "../types" }
ethereum-types = "0.6"
ethjson = { path = "../../json" }
ethtrie = { package = "patricia-trie-ethereum", path = "../../util/patricia-trie-ethereum" }
hash-db = "0.12"
itertools = "0.8"
keccak-hash = "0.2.0"
keccak-hasher = { path = "../../util/keccak-hasher" }
kvdb = "0.1"
log = "0.4"
parity-bytes = "0.1.0"
rlp = "0.4"
rustc-hex = "1"
serde = { version = "1.0", features = ["derive"] }
trie-db = "0.12.4"
triehash = { package = "triehash-ethereum", version = "0.2", path = "../../util/triehash-ethereum" }

[dev-dependencies]
macros = { path = "../../util/macros" }
27 changes: 8 additions & 19 deletions ethcore/src/pod_account.rs → ethcore/pod-account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,22 @@
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.

//! Account system expressed in Plain Old Data.

use log::warn;
use std::collections::BTreeMap;
use itertools::Itertools;
use hash::{keccak};
use keccak_hash::keccak;
use ethereum_types::{H256, U256, BigEndianHash};
use hash_db::HashDB;
use kvdb::DBValue;
use keccak_hasher::KeccakHasher;
use triehash::sec_trie_root;
use bytes::Bytes;
use trie::TrieFactory;
use parity_bytes::Bytes;
use trie_db::TrieFactory;
use ethtrie::RlpCodec;
use state::Account;
use ethjson;
use types::account_diff::*;
use common_types::account_diff::*;
use rlp::{self, RlpStream};
use serde::Serializer;
use serde::{Serializer, Serialize};
use rustc_hex::ToHex;

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
Expand All @@ -57,17 +56,6 @@ fn opt_bytes_to_hex<S>(opt_bytes: &Option<Bytes>, serializer: S) -> Result<S::Ok
}

impl PodAccount {
/// Convert Account to a PodAccount.
/// NOTE: This will silently fail unless the account is fully cached.
pub fn from_account(acc: &Account) -> PodAccount {
PodAccount {
balance: *acc.balance(),
nonce: *acc.nonce(),
storage: acc.storage_changes().iter().fold(BTreeMap::new(), |mut m, (k, v)| {m.insert(k.clone(), v.clone()); m}),
code: acc.code().map(|x| x.to_vec()),
}
}

/// Returns the RLP for this account.
pub fn rlp(&self) -> Bytes {
let mut stream = RlpStream::new_list(4);
Expand Down Expand Up @@ -170,9 +158,10 @@ pub fn diff_pod(pre: Option<&PodAccount>, post: Option<&PodAccount>) -> Option<A
#[cfg(test)]
mod test {
use std::collections::BTreeMap;
use types::account_diff::*;
use common_types::account_diff::*;
use super::{PodAccount, diff_pod};
use ethereum_types::H256;
use macros::map;

#[test]
fn existence() {
Expand Down
7 changes: 3 additions & 4 deletions 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 @@ -88,6 +89,7 @@ extern crate parity_bytes as bytes;
extern crate parity_crypto;
extern crate parity_snappy as snappy;
extern crate parking_lot;
extern crate pod_account;
extern crate trie_db as trie;
extern crate patricia_trie_ethereum as ethtrie;
extern crate rand;
Expand All @@ -98,6 +100,7 @@ extern crate parity_util_mem as malloc_size_of;
extern crate rustc_hex;
extern crate serde;
extern crate stats;
extern crate state_account;
extern crate time_utils;
extern crate triehash_ethereum as triehash;
extern crate unexpected;
Expand All @@ -120,8 +123,6 @@ extern crate blooms_db;
#[cfg(any(test, feature = "env_logger"))]
extern crate env_logger;
#[cfg(test)]
extern crate rlp_compress;
#[cfg(test)]
extern crate serde_json;

#[macro_use]
Expand Down Expand Up @@ -162,7 +163,6 @@ pub mod executive;
pub mod machine;
pub mod miner;
pub mod pod_state;
pub mod pod_account;
pub mod snapshot;
pub mod spec;
pub mod state;
Expand All @@ -171,7 +171,6 @@ pub mod trace;
pub mod transaction_ext;
pub mod verification;

mod account_db;
mod externalities;
mod factory;
mod tx_filter;
Expand Down
Loading