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

Extricate PodAccount and state Account to own crates #10838

Merged
merged 5 commits into from
Jul 4, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
57 changes: 57 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",
]
2 changes: 2 additions & 0 deletions ethcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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 +62,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
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
9 changes: 3 additions & 6 deletions ethcore/src/account_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,12 @@ impl<'db> AccountDBMut<'db> {
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`.
ordian marked this conversation as resolved.
Show resolved Hide resolved
pub fn immutable(&'db self) -> AccountDB<'db> {
AccountDB { db: self.db, address_hash: self.address_hash.clone() }
}
Expand Down
7 changes: 3 additions & 4 deletions ethcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,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 +99,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 +122,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,16 +162,15 @@ 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;
pub mod state_db;
pub mod trace;
pub mod transaction_ext;
pub mod verification;
pub mod account_db;

mod account_db;
mod externalities;
mod factory;
mod tx_filter;
Expand Down
7 changes: 3 additions & 4 deletions ethcore/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ use bytes::Bytes;
use trie::{Trie, TrieError, Recorder};
use ethtrie::{TrieDB, Result as TrieResult};

mod account;
mod substate;

pub mod backend;

pub use self::account::Account;
pub use state_account::Account;
pub use self::backend::Backend;
pub use self::substate::Substate;

Expand Down Expand Up @@ -964,7 +963,7 @@ impl<B: Backend> State<B> {
assert!(self.checkpoints.borrow().is_empty());
PodState::from(self.cache.borrow().iter().fold(BTreeMap::new(), |mut m, (add, opt)| {
if let Some(ref acc) = opt.account {
m.insert(*add, PodAccount::from_account(acc));
m.insert(*add, acc.to_pod());
}
m
}))
Expand Down Expand Up @@ -1031,7 +1030,7 @@ impl<B: Backend> State<B> {
}
}

let mut pod_account = PodAccount::from_account(&account);
let mut pod_account = account.to_pod();
// cached one first
pod_storage.append(&mut pod_account.storage);
pod_account.storage = pod_storage;
Expand Down
30 changes: 30 additions & 0 deletions ethcore/state-account/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
description = "Ethereum accounts, keeps track of changes to the code and storage."
name = "state-account"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
common-types = { path = "../types"}
ethereum-types = "0.6.0"
ethtrie = { package = "patricia-trie-ethereum", path = "../../util/patricia-trie-ethereum" }
hash-db = "0.12.4"
keccak-hash = "0.2.0"
keccak-hasher = { path = "../../util/keccak-hasher" }
kvdb = "0.1.0"
log = "0.4"
lru-cache = "0.1.2"
parity-bytes = "0.1.0"
pod-account = { path = "../pod-account" }
rlp = "0.4.0"
serde = { version = "1.0", features = ["derive"] }
trie-db = "0.12.4"

[dev-dependencies]
ethcore = { path = ".." }
rlp_compress = { path = "../../util/rlp-compress" }
journaldb = { path = "../../util/journaldb" }
parity-bytes = "0.1.0"
Loading