Move more code into state-account (#10840)

* WIP move errors, pod_account and state account to own crates

* Sort out dependencies, fix broken code and tests
Remove botched ethcore-error crate

* remove template line

* fix review feedback

* Remove test-only AccountDBMut::new

* Extract AccountDB to account-db

* Move Substate to state-account – wip

* Add lib.rs

* cleanup

* test failure

* test failure 2

* third time's the charm

* Add factories crate

* Use new factories crate

* Use factories crate

* Extract trace

* Fix tests

* Sort out parity-util-mem and parking_lot

* cleanup

* WIP port over the rest of state from ethcore

* Collect all impls for Machine

* some notes

* Rename pod-account to pod

* Move PodState to pod crate

* Use PodState from pod crate

* Fix use clause for json tests

* Sort out evmbin

* Add missing code and use PodState

* Move code that depends on Machine and Executive to own module

* Sort out cloning errors, fix ethcore to use new state crate

* Do without funky From impls

* Fix ethcore tests

* Fixes around the project to use new state crate

* Add back the more specific impls of StateOrBlock From conversions

* Move execute to freestanding function and remove it from trait
Sort out the error handling in executive_state by moving the result types from state to ethcore
Undo the verbose code added to work around the StateOrBlock From conversions

* cleanup

* Fix "error: enum variants on type aliases are experimental"

* Bring back the state tests
Fix whitespace

* remove ethcore/state/mod.rs

* cleanup

* cleanup

* Cleanup state-account errors

* Fix more todos
Add module docs

* Add error.rs

* Fixup Cargo.lock

* Smaller ethcore API is fine

* Add `to-pod-full` feature to state-account
Fix evmbin

* Fix a few more test failures

* Fix RPC test build

* Baptize the new trait

* Remove resolved TODOs

* Rename state-account to account-state

* Do not re-export the trace crate

* Don't export state_db from ethcore

* Let private-tx use StateDB. :(

* Remove ethcore/src/pod_state.rs

* Inner type does not need to be pub/pub(crate)

* optimise imports

* Revert "Inner type does not need to be pub/pub(crate)"

This reverts commit 2f839f8a0f72f71334da64620f57e6dd6039f06b.

* Move DatabaseExtras to ethcore-blockchain

* Add database_extra module to ethcore-blockchain

* Remove to-pod-full feature

* Sort out the merge

* sort imports

* address grumbles

* rename crate

* address more grumbles
This commit is contained in:
David 2019-07-08 18:17:48 +02:00 committed by GitHub
parent d5c19bae1c
commit 44cc442d12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
76 changed files with 1907 additions and 1556 deletions

120
Cargo.lock generated
View File

@ -12,6 +12,37 @@ dependencies = [
"rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "account-state"
version = "0.1.0"
dependencies = [
"account-db 0.1.0",
"common-types 0.1.0",
"derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"evm 0.1.0",
"hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
"journaldb 0.2.0",
"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)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"memory-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-util-mem 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"patricia-trie-ethereum 0.1.0",
"pod 0.1.0",
"rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rlp_compress 0.1.0",
"serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
"trace 0.1.0",
"trie-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-vm-factories 0.1.0",
"vm 0.1.0",
]
[[package]]
name = "aes"
version = "0.3.2"
@ -612,6 +643,19 @@ dependencies = [
"syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "derive_more"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "difference"
version = "1.0.0"
@ -811,6 +855,7 @@ name = "ethcore"
version = "1.12.0"
dependencies = [
"account-db 0.1.0",
"account-state 0.1.0",
"ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"blooms-db 0.1.0",
"common-types 0.1.0",
@ -851,7 +896,6 @@ dependencies = [
"lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"macros 0.1.0",
"memory-cache 0.1.0",
"memory-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-runtime 0.1.0",
@ -859,7 +903,7 @@ dependencies = [
"parity-util-mem 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"patricia-trie-ethereum 0.1.0",
"pod-account 0.1.0",
"pod 0.1.0",
"rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -870,18 +914,18 @@ dependencies = [
"serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
"state-account 0.1.0",
"stats 0.1.0",
"tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"time-utils 0.1.0",
"trace 0.1.0",
"trace-time 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-standardmap 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-vm-factories 0.1.0",
"triehash-ethereum 0.2.0",
"unexpected 0.1.0",
"using_queue 0.1.0",
"vm 0.1.0",
"wasm 0.1.0",
]
[[package]]
@ -992,6 +1036,7 @@ dependencies = [
name = "ethcore-light"
version = "1.12.0"
dependencies = [
"account-state 0.1.0",
"bincode 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"common-types 0.1.0",
"derive_more 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1142,6 +1187,7 @@ dependencies = [
name = "ethcore-private-tx"
version = "1.0.0"
dependencies = [
"account-state 0.1.0",
"common-types 0.1.0",
"derive_more 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1173,6 +1219,7 @@ dependencies = [
"serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
"time-utils 0.1.0",
"tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"trace 0.1.0",
"transaction-pool 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1412,6 +1459,7 @@ dependencies = [
name = "evmbin"
version = "0.1.0"
dependencies = [
"account-state 0.1.0",
"common-types 0.1.0",
"docopt 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1421,12 +1469,14 @@ dependencies = [
"evm 0.1.0",
"panic_hook 0.1.0",
"parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pod 0.1.0",
"pretty_assertions 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
"tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"trace 0.1.0",
"vm 0.1.0",
]
@ -2787,6 +2837,7 @@ dependencies = [
name = "parity-rpc"
version = "1.12.0"
dependencies = [
"account-state 0.1.0",
"ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cid 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"common-types 0.1.0",
@ -2827,6 +2878,7 @@ dependencies = [
"parity-updater 1.12.0",
"parity-version 2.7.0",
"parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"patricia-trie-ethereum 0.1.0",
"pretty_assertions 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2840,6 +2892,7 @@ dependencies = [
"tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-timer 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"trace 0.1.0",
"transaction-pool 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"transient-hashmap 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"vm 0.1.0",
@ -3159,7 +3212,7 @@ dependencies = [
]
[[package]]
name = "pod-account"
name = "pod"
version = "0.1.0"
dependencies = [
"common-types 0.1.0",
@ -3880,29 +3933,6 @@ name = "stable_deref_trait"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "state-account"
version = "0.1.0"
dependencies = [
"account-db 0.1.0",
"common-types 0.1.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",
"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)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"patricia-trie-ethereum 0.1.0",
"pod-account 0.1.0",
"rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rlp_compress 0.1.0",
"serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "static_assertions"
version = "0.2.5"
@ -4333,6 +4363,26 @@ dependencies = [
"fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "trace"
version = "0.1.0"
dependencies = [
"common-types 0.1.0",
"ethcore 1.12.0",
"ethcore-blockchain 0.1.0",
"ethcore-db 0.1.0",
"ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"evm 0.1.0",
"kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-util-mem 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rlp_derive 0.1.0",
"vm 0.1.0",
]
[[package]]
name = "trace-time"
version = "0.1.1"
@ -4377,6 +4427,19 @@ dependencies = [
"keccak-hasher 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "trie-vm-factories"
version = "0.1.0"
dependencies = [
"account-db 0.1.0",
"evm 0.1.0",
"keccak-hasher 0.1.1",
"patricia-trie-ethereum 0.1.0",
"trie-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
"vm 0.1.0",
"wasm 0.1.0",
]
[[package]]
name = "triehash"
version = "0.6.0"
@ -4833,6 +4896,7 @@ dependencies = [
"checksum ctr 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "022cd691704491df67d25d006fe8eca083098253c4d43516c2206479c58c6736"
"checksum ctrlc 1.1.1 (git+https://github.com/paritytech/rust-ctrlc.git)" = "<none>"
"checksum derive_more 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fbe9f11be34f800b3ecaaed0ec9ec2e015d1d0ba0c8644c1310f73d6e8994615"
"checksum derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a141330240c921ec6d074a3e188a7c7ef95668bb95e7d44fa0e5778ec2a7afe"
"checksum difference 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b3304d19798a8e067e48d8e69b2c37f0b5e9b4e462504ad9e27e9f3fce02bba8"
"checksum digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "03b072242a8cbaf9c145665af9d250c59af3b958f83ed6824e13533cf76d5b90"
"checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c"

View File

@ -30,6 +30,7 @@ ethereum-types = "0.6.0"
ethjson = { path = "../json" }
ethkey = { path = "../accounts/ethkey" }
evm = { path = "evm" }
trie-vm-factories = { path = "trie-vm-factories" }
futures = "0.1"
hash-db = "0.12.4"
parity-util-mem = "0.1"
@ -46,12 +47,11 @@ log = "0.4"
lru-cache = "0.1"
macros = { path = "../util/macros" }
memory-cache = { path = "../util/memory-cache" }
memory-db = "0.12.4"
num_cpus = "1.2"
parity-bytes = "0.1"
parity-snappy = "0.1"
parking_lot = "0.8"
pod-account = { path = "pod-account" }
pod = { path = "pod" }
trie-db = "0.12.4"
patricia-trie-ethereum = { path = "../util/patricia-trie-ethereum" }
rand = "0.6"
@ -61,16 +61,16 @@ rlp_derive = { path = "../util/rlp-derive" }
rustc-hex = "1.0"
serde = "1.0"
serde_derive = "1.0"
state-account = { path = "state-account" }
account-state = { path = "account-state" }
stats = { path = "../util/stats" }
tempdir = { version = "0.3", optional = true }
time-utils = { path = "../util/time-utils" }
trace = { path = "trace" }
trace-time = "0.1"
triehash-ethereum = { version = "0.2", path = "../util/triehash-ethereum" }
unexpected = { path = "../util/unexpected" }
using_queue = { path = "../miner/using-queue" }
vm = { path = "vm" }
wasm = { path = "wasm" }
rand_xorshift = "0.1.1"
[dev-dependencies]
@ -108,15 +108,13 @@ evm-debug-tests = ["evm-debug", "evm/evm-debug-tests"]
# EVM debug traces are printed.
slow-blocks = []
# Run JSON consensus tests.
json-tests = ["env_logger", "test-helpers", "to-pod-full"]
json-tests = ["env_logger", "test-helpers"]
# Skip JSON consensus tests with pending issues.
ci-skip-tests = []
# Run memory/cpu heavy tests.
test-heavy = []
# Compile test helpers
test-helpers = ["tempdir", "kvdb-rocksdb", "blooms-db"]
# Enables slow 'to-pod-full' method for use in tests and evmbin.
to-pod-full = []
[[bench]]
name = "builtin"

View File

@ -1,28 +1,37 @@
[package]
description = "Ethereum accounts, keeps track of changes to the code and storage."
name = "state-account"
description = "Ethereum accounts, keeps track of changes to the code and storage"
name = "account-state"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
common-types = { path = "../types"}
derive_more = "0.15.0"
ethereum-types = "0.6.0"
ethtrie = { package = "patricia-trie-ethereum", path = "../../util/patricia-trie-ethereum" }
evm = { path = "../evm" }
trie-vm-factories = { path = "../trie-vm-factories" }
hash-db = "0.12.4"
journaldb = { path = "../../util/journaldb" }
keccak-hash = "0.2.0"
keccak-hasher = { path = "../../util/keccak-hasher" }
kvdb = "0.1.0"
log = "0.4"
lru-cache = "0.1.2"
memory-db = "0.12.4"
parity-bytes = "0.1.0"
pod-account = { path = "../pod-account" }
parity-util-mem = "0.1.0"
parking_lot = "0.8.0"
pod = { path = "../pod" }
rlp = "0.4.0"
serde = { version = "1.0", features = ["derive"] }
trace = { path = "../trace" }
trie-db = "0.12.4"
vm = { path = "../vm" }
[dev-dependencies]
account-db = { path = "../account-db" }
rlp_compress = { path = "../../util/rlp-compress" }
journaldb = { path = "../../util/journaldb" }
parity-bytes = "0.1.0"
rlp_compress = { path = "../../util/rlp-compress" }

View File

@ -15,24 +15,25 @@
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
//! Single account in the system.
use log::{warn, trace};
use std::cell::{Cell, RefCell};
use std::collections::{BTreeMap, HashMap};
use std::fmt;
use std::sync::Arc;
use std::collections::{HashMap, BTreeMap};
use keccak_hash::{KECCAK_EMPTY, KECCAK_NULL_RLP, keccak};
use ethereum_types::{H256, U256, Address, BigEndianHash};
use hash_db::HashDB;
use keccak_hasher::KeccakHasher;
use kvdb::DBValue;
use parity_bytes::{Bytes, ToPretty};
use trie_db::{Trie, Recorder};
use ethtrie::{TrieFactory, TrieDB, SecTrieDB, Result as TrieResult};
use pod_account::PodAccount;
use rlp::{RlpStream, DecoderError, encode};
use lru_cache::LruCache;
use common_types::basic_account::BasicAccount;
use std::cell::{RefCell, Cell};
use ethereum_types::{Address, BigEndianHash, H256, U256};
use hash_db::HashDB;
use keccak_hash::{keccak, KECCAK_EMPTY, KECCAK_NULL_RLP};
use kvdb::DBValue;
use log::{trace, warn};
use lru_cache::LruCache;
use parity_bytes::{Bytes, ToPretty};
use rlp::{DecoderError, encode};
use trie_db::{Recorder, Trie};
use common_types::basic_account::BasicAccount;
use ethtrie::{Result as TrieResult, SecTrieDB, TrieDB, TrieFactory};
use keccak_hasher::KeccakHasher;
use pod::PodAccount;
const STORAGE_CACHE_ITEMS: usize = 8192;
@ -183,8 +184,8 @@ impl Account {
/// NOTE: make sure you use `init_code` on this before `commit`ing.
pub fn new_contract(balance: U256, nonce: U256, version: U256, original_storage_root: H256) -> Account {
Account {
balance: balance,
nonce: nonce,
balance,
nonce,
storage_root: KECCAK_NULL_RLP,
storage_cache: Self::empty_storage_cache(),
original_storage_cache: if original_storage_root == KECCAK_NULL_RLP {
@ -643,14 +644,17 @@ impl fmt::Debug for Account {
#[cfg(test)]
mod tests {
use rlp_compress::{compress, decompress, snapshot_swapper};
use ethereum_types::{H256, Address};
use journaldb::new_memory_db;
use parity_bytes::Bytes;
use super::*;
use account_db::*;
use std::str::FromStr;
use ethereum_types::{Address, H256};
use parity_bytes::Bytes;
use account_db::*;
use journaldb::new_memory_db;
use rlp_compress::{compress, decompress, snapshot_swapper};
use super::*;
#[test]
fn account_compress() {
let raw = Account::new_basic(2.into(), 4.into()).rlp();

View File

@ -21,17 +21,19 @@
//! should become general over time to the point where not even a
//! merkle trie is strictly necessary.
use std::collections::{HashSet, HashMap};
use std::collections::{HashMap, HashSet};
use std::sync::Arc;
use state::Account;
use parking_lot::Mutex;
use ethereum_types::{Address, H256};
use memory_db::{MemoryDB, HashKey};
use hash_db::{AsHashDB, HashDB, Prefix, EMPTY_PREFIX};
use hash_db::{AsHashDB, EMPTY_PREFIX, HashDB, Prefix};
use kvdb::DBValue;
use keccak_hasher::KeccakHasher;
use memory_db::{HashKey, MemoryDB};
use parking_lot::Mutex;
use journaldb::AsKeyedHashDB;
use keccak_hasher::KeccakHasher;
use crate::account::Account;
/// State backend. See module docs for more details.
pub trait Backend: Send {

View File

@ -0,0 +1,35 @@
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity Ethereum.
// Parity Ethereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity Ethereum is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
//! State related errors
use derive_more::{Display, From};
#[derive(Debug, Display, From)]
pub enum Error {
/// Trie error.
Trie(ethtrie::TrieError),
/// Decoder error.
Decoder(rlp::DecoderError),
}
impl std::error::Error for Error {}
impl<E> From<Box<E>> for Error where Error: From<E> {
fn from(err: Box<E>) -> Self {
Error::from(*err)
}
}

View File

@ -0,0 +1,37 @@
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity Ethereum.
// Parity Ethereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity Ethereum is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
//! Account state
//! This crate contains code used to create, convert, and update Accounts and the code and storage
//! associated with it. It also defines the trait used to construct a backend to build a complete
//! caching state database.
//! Note: the code that needs access to `ethcore` types such as `Machine` and `Executive` is found in
//! the `executive_state` module in `ethcore`. Most tests for the `State` module in this crate are
//! also found in `executive_state` (for the same reason).
pub mod account;
pub mod backend;
pub mod substate;
pub mod state;
pub mod error;
pub use {
account::Account,
backend::Backend,
error::Error,
substate::Substate,
state::{State, CleanupMode},
};

File diff suppressed because it is too large Load Diff

View File

@ -16,10 +16,12 @@
//! Execution environment substate.
use std::collections::HashSet;
use common_types::log_entry::LogEntry;
use ethereum_types::Address;
use types::log_entry::LogEntry;
use evm::{Schedule, CleanDustMode};
use super::CleanupMode;
use evm::{CleanDustMode, Schedule};
use crate::state::CleanupMode;
/// State changes which should be applied in finalize,
/// after transaction is fully executed.
@ -68,8 +70,9 @@ impl Substate {
#[cfg(test)]
mod tests {
use super::{Substate, Address};
use types::log_entry::LogEntry;
use common_types::log_entry::LogEntry;
use ethereum_types::Address;
use super::Substate;
#[test]
fn created() {

View File

@ -14,14 +14,27 @@
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
//! Bridge between Tracedb and Blockchain.
//! Provides a `DatabaseExtras` trait that defines an interface to query for block data not
//! contained in a TraceDB.
use blockchain::{BlockChain, BlockProvider, TransactionAddress};
use common_types::BlockNumber;
use ethereum_types::H256;
use trace::DatabaseExtras as TraceDatabaseExtras;
use types::BlockNumber;
use ethcore_db::keys::TransactionAddress;
impl TraceDatabaseExtras for BlockChain {
use crate::blockchain::{BlockProvider, BlockChain};
/// `DatabaseExtras` provides an interface to query extra data which is not stored in TraceDB,
/// but necessary to work correctly.
pub trait DatabaseExtras {
/// Returns hash of given block number.
fn block_hash(&self, block_number: BlockNumber) -> Option<H256>;
/// Returns hash of transaction at given position.
fn transaction_hash(&self, block_number: BlockNumber, tx_position: usize) -> Option<H256>;
}
/// Bridge between TraceDB and Blockchain.
impl DatabaseExtras for BlockChain {
fn block_hash(&self, block_number: BlockNumber) -> Option<H256> {
(self as &dyn BlockProvider).block_hash(block_number)
}
@ -30,7 +43,7 @@ impl TraceDatabaseExtras for BlockChain {
(self as &dyn BlockProvider).block_hash(block_number)
.and_then(|block_hash| {
let tx_address = TransactionAddress {
block_hash: block_hash,
block_hash,
index: tx_position
};
self.transaction(&tx_address)

View File

@ -28,13 +28,18 @@ mod cache;
mod config;
mod import_route;
mod update;
mod database_extras;
pub mod generator;
pub use self::blockchain::{BlockProvider, BlockChain, BlockChainDB, BlockChainDBHandler};
pub use self::cache::CacheSize;
pub use self::config::Config;
pub use self::import_route::ImportRoute;
pub use self::update::ExtrasInsert;
pub use crate::{
blockchain::{BlockProvider, BlockChain, BlockChainDB, BlockChainDBHandler},
cache::CacheSize,
config::Config,
database_extras::DatabaseExtras,
import_route::ImportRoute,
update::ExtrasInsert,
};
pub use ethcore_db::keys::{BlockReceipts, BlockDetails, TransactionAddress, BlockNumberKey};
pub use common_types::tree_route::TreeRoute;

View File

@ -35,6 +35,7 @@ itertools = "0.5"
bincode = "1.1"
serde = "1.0"
serde_derive = "1.0"
account-state = { path = "../account-state" }
parking_lot = "0.8"
stats = { path = "../../util/stats" }
keccak-hash = "0.2.0"

View File

@ -89,6 +89,7 @@ extern crate triehash_ethereum as triehash;
extern crate kvdb;
extern crate memory_cache;
extern crate derive_more;
extern crate account_state;
#[cfg(test)]
extern crate kvdb_memorydb;

View File

@ -25,7 +25,8 @@ use common_types::encoded;
use common_types::receipt::Receipt;
use common_types::transaction::SignedTransaction;
use ethcore::engines::{Engine, StateDependentProof};
use ethcore::state::{self, ProvedExecution};
use ethcore::executive_state::{ProvedExecution, self};
use account_state;
use ethereum_types::{H256, U256, Address};
use ethtrie::{TrieError, TrieDB};
use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY, KECCAK_EMPTY_LIST_RLP, keccak};
@ -1042,7 +1043,7 @@ impl TransactionProof {
let mut env_info = self.env_info.clone();
env_info.gas_limit = self.tx.gas;
let proved_execution = state::check_proof(
let proved_execution = executive_state::check_proof(
state_items,
root,
&self.tx,

View File

@ -1,6 +1,6 @@
[package]
description = "Account system expressed in Plain Old Data."
name = "pod-account"
description = "State/Account system expressed in Plain Old Data."
name = "pod"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"

23
ethcore/pod/src/lib.rs Normal file
View File

@ -0,0 +1,23 @@
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity Ethereum.
// Parity Ethereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity Ethereum is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
pub mod account;
pub mod state;
pub use {
account::PodAccount,
state::PodState,
};

View File

@ -19,9 +19,11 @@
use std::collections::BTreeMap;
use ethereum_types::{H256, Address};
use triehash::sec_trie_root;
use pod_account::{self, PodAccount};
use types::state_diff::StateDiff;
use common_types::state_diff::StateDiff;
use ethjson;
use serde::Serialize;
use crate::account::PodAccount;
/// State of all accounts in the system expressed in Plain Old Data.
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize)]
@ -68,7 +70,7 @@ pub fn diff_pod(pre: &PodState, post: &PodState) -> StateDiff {
StateDiff {
raw: pre.0.keys()
.chain(post.0.keys())
.filter_map(|acc| pod_account::diff_pod(pre.0.get(acc), post.0.get(acc)).map(|d| (*acc, d)))
.filter_map(|acc| crate::account::diff_pod(pre.0.get(acc), post.0.get(acc)).map(|d| (*acc, d)))
.collect()
}
}
@ -76,10 +78,14 @@ pub fn diff_pod(pre: &PodState, post: &PodState) -> StateDiff {
#[cfg(test)]
mod test {
use std::collections::BTreeMap;
use pod_account::PodAccount;
use types::account_diff::{AccountDiff, Diff};
use types::state_diff::StateDiff;
use super::{PodState, Address};
use common_types::{
account_diff::{AccountDiff, Diff},
state_diff::StateDiff,
};
use ethereum_types::Address;
use crate::account::PodAccount;
use super::PodState;
use macros::map;
#[test]
fn create_delete() {

View File

@ -35,8 +35,10 @@ rustc-hex = "1.0"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
account-state = { path = "../account-state" }
time-utils = { path = "../../util/time-utils" }
tiny-keccak = "1.4"
trace = { path = "../trace" }
transaction-pool = "2.0"
url = "1"

View File

@ -46,7 +46,9 @@ extern crate rlp;
extern crate serde_derive;
extern crate serde;
extern crate serde_json;
extern crate account_state;
extern crate rustc_hex;
extern crate trace;
extern crate transaction_pool as txpool;
extern crate url;
#[macro_use]
@ -92,8 +94,9 @@ use ethcore::client::{
Call, BlockInfo
};
use ethcore::miner::{self, Miner, MinerService, pool_client::NonceCache};
use ethcore::{state, state_db};
use ethcore::trace::{Tracer, VMTracer};
use ethcore::StateDB;
use account_state::State;
use trace::{Tracer, VMTracer};
use call_contract::CallContract;
use rustc_hex::FromHex;
use ethabi::FunctionOutputDecoder;
@ -539,7 +542,7 @@ impl Provider {
raw
}
fn patch_account_state(&self, contract_address: &Address, block: BlockId, state: &mut state::State<state_db::StateDB>) -> Result<(), Error> {
fn patch_account_state(&self, contract_address: &Address, block: BlockId, state: &mut State<StateDB>) -> Result<(), Error> {
let contract_code = Arc::new(self.get_decrypted_code(contract_address, block)?);
let contract_state = self.get_decrypted_state(contract_address, block)?;
trace!(target: "privatetx", "Patching contract at {:?}, code: {:?}, state: {:?}", contract_address, contract_code, contract_state);

View File

@ -35,7 +35,7 @@ use types::ids::BlockId;
use types::transaction::{Transaction, Action};
use ethcore::CreateContractAddress;
use ethcore::client::BlockChainClient;
use ethcore::executive::{contract_address};
use ethcore::executive::contract_address;
use ethcore::miner::Miner;
use ethcore::test_helpers::{generate_dummy_client, push_block_with_transactions};
use ethkey::{Secret, KeyPair, Signature};

View File

@ -22,7 +22,7 @@
//! and can be appended to with transactions and uncles.
//!
//! When ready, `OpenBlock` can be closed and turned into a `ClosedBlock`. A `ClosedBlock` can
//! be re-opend again by a miner under certain circumstances. On block close, state commit is
//! be re-opened again by a miner under certain circumstances. On block close, state commit is
//! performed.
//!
//! `LockedBlock` is a version of a `ClosedBlock` that cannot be reopened. It can be sealed
@ -40,9 +40,9 @@ use ethereum_types::{H256, U256, Address, Bloom};
use engines::Engine;
use error::{Error, BlockError};
use factory::Factories;
use trie_vm_factories::Factories;
use state_db::StateDB;
use state::State;
use account_state::State;
use trace::Tracing;
use triehash::ordered_trie_root;
use unexpected::{Mismatch, OutOfBounds};
@ -54,6 +54,7 @@ use rlp::{RlpStream, Encodable, encode_list};
use types::transaction::{SignedTransaction, Error as TransactionError};
use types::header::Header;
use types::receipt::{Receipt, TransactionOutcome};
use executive_state::ExecutiveState;
/// Block that is ready for transactions to be added.
///
@ -550,7 +551,7 @@ mod tests {
use engines::Engine;
use vm::LastHashes;
use error::Error;
use factory::Factories;
use trie_vm_factories::Factories;
use state_db::StateDB;
use ethereum_types::Address;
use std::sync::Arc;

View File

@ -66,11 +66,12 @@ use error::{
Error as EthcoreError, EthcoreResult,
};
use executive::{Executive, Executed, TransactOptions, contract_address};
use factory::{Factories, VmFactory};
use trie_vm_factories::{Factories, VmFactory};
use miner::{Miner, MinerService};
use snapshot::{self, io as snapshot_io, SnapshotClient};
use spec::Spec;
use state::{self, State};
use account_state::State;
use executive_state;
use state_db::StateDB;
use trace::{self, TraceDB, ImportRequest as TraceImportRequest, LocalizedTrace, Database as TraceDatabase};
use transaction_ext::Transaction;
@ -622,7 +623,7 @@ impl Importer {
let call = move |addr, data| {
let mut state_db = state_db.boxed_clone();
let backend = ::state::backend::Proving::new(state_db.as_hash_db_mut());
let backend = account_state::backend::Proving::new(state_db.as_hash_db_mut());
let transaction =
client.contract_call_tx(BlockId::Hash(*header.parent_hash()), addr, data);
@ -2540,7 +2541,7 @@ impl ProvingBlockChainClient for Client {
env_info.gas_limit = transaction.gas.clone();
let mut jdb = self.state_db.read().journal_db().boxed_clone();
state::prove_transaction_virtual(
executive_state::prove_transaction_virtual(
jdb.as_hash_db_mut(),
header.state_root().clone(),
&transaction,

View File

@ -19,14 +19,18 @@
use std::fmt;
use std::sync::Arc;
use ethereum_types::{H256, U256, H160};
use {factory, journaldb, trie, kvdb_memorydb};
use {trie_vm_factories, journaldb, trie, kvdb_memorydb};
use kvdb::{self, KeyValueDB};
use {state, state_db, client, executive, trace, db, spec, pod_state};
use {state_db, client, executive, trace, db, spec};
use pod::PodState;
use types::{log_entry, receipt, transaction};
use factory::Factories;
use trie_vm_factories::Factories;
use evm::{VMType, FinalizationResult};
use vm::{self, ActionParams};
use ethtrie;
use account_state::{CleanupMode, Substate, State};
use executive_state::ExecutiveState;
/// EVM test Error.
#[derive(Debug)]
@ -65,15 +69,19 @@ use ethjson::spec::ForkSpec;
/// Simplified, single-block EVM test client.
pub struct EvmTestClient<'a> {
state: state::State<state_db::StateDB>,
state: State<state_db::StateDB>,
spec: &'a spec::Spec,
dump_state: fn(&state::State<state_db::StateDB>) -> Option<pod_state::PodState>,
dump_state: fn(&State<state_db::StateDB>) -> Option<PodState>,
}
fn no_dump_state(_: &state::State<state_db::StateDB>) -> Option<pod_state::PodState> {
fn no_dump_state(_: &State<state_db::StateDB>) -> Option<PodState> {
None
}
fn dump_state(state: &State<state_db::StateDB>) -> Option<PodState> {
state.to_pod_full().ok()
}
impl<'a> fmt::Debug for EvmTestClient<'a> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct("EvmTestClient")
@ -100,7 +108,7 @@ impl<'a> EvmTestClient<'a> {
}
/// Change default function for dump state (default does not dump)
pub fn set_dump_state_fn(&mut self, dump_state: fn(&state::State<state_db::StateDB>) -> Option<pod_state::PodState>) {
pub fn set_dump_state(&mut self) {
self.dump_state = dump_state;
}
@ -124,7 +132,7 @@ impl<'a> EvmTestClient<'a> {
/// Creates new EVM test client with an in-memory DB initialized with given PodState.
/// Takes a `TrieSpec` to set the type of trie.
pub fn from_pod_state_with_trie(spec: &'a spec::Spec, pod_state: pod_state::PodState, trie_spec: trie::TrieSpec) -> Result<Self, EvmTestError> {
pub fn from_pod_state_with_trie(spec: &'a spec::Spec, pod_state: PodState, trie_spec: trie::TrieSpec) -> Result<Self, EvmTestError> {
let factories = Self::factories(trie_spec);
let state = Self::state_from_pod(spec, &factories, pod_state)?;
@ -136,19 +144,19 @@ impl<'a> EvmTestClient<'a> {
}
/// Creates new EVM test client with an in-memory DB initialized with given PodState.
pub fn from_pod_state(spec: &'a spec::Spec, pod_state: pod_state::PodState) -> Result<Self, EvmTestError> {
pub fn from_pod_state(spec: &'a spec::Spec, pod_state: PodState) -> Result<Self, EvmTestError> {
Self::from_pod_state_with_trie(spec, pod_state, trie::TrieSpec::Secure)
}
fn factories(trie_spec: trie::TrieSpec) -> Factories {
Factories {
vm: factory::VmFactory::new(VMType::Interpreter, 5 * 1024),
vm: trie_vm_factories::VmFactory::new(VMType::Interpreter, 5 * 1024),
trie: trie::TrieFactory::new(trie_spec),
accountdb: Default::default(),
}
}
fn state_from_spec(spec: &'a spec::Spec, factories: &Factories) -> Result<state::State<state_db::StateDB>, EvmTestError> {
fn state_from_spec(spec: &'a spec::Spec, factories: &Factories) -> Result<State<state_db::StateDB>, EvmTestError> {
let db = Arc::new(kvdb_memorydb::create(db::NUM_COLUMNS.expect("We use column-based DB; qed")));
let journal_db = journaldb::new(db.clone(), journaldb::Algorithm::EarlyMerge, db::COL_STATE);
let mut state_db = state_db::StateDB::new(journal_db, 5 * 1024 * 1024);
@ -162,7 +170,7 @@ impl<'a> EvmTestClient<'a> {
db.write(batch)?;
}
state::State::from_existing(
State::from_existing(
state_db,
*genesis.state_root(),
spec.engine.account_start_nonce(0),
@ -170,11 +178,11 @@ impl<'a> EvmTestClient<'a> {
).map_err(EvmTestError::Trie)
}
fn state_from_pod(spec: &'a spec::Spec, factories: &Factories, pod_state: pod_state::PodState) -> Result<state::State<state_db::StateDB>, EvmTestError> {
fn state_from_pod(spec: &'a spec::Spec, factories: &Factories, pod_state: PodState) -> Result<State<state_db::StateDB>, EvmTestError> {
let db = Arc::new(kvdb_memorydb::create(db::NUM_COLUMNS.expect("We use column-based DB; qed")));
let journal_db = journaldb::new(db.clone(), journaldb::Algorithm::EarlyMerge, db::COL_STATE);
let state_db = state_db::StateDB::new(journal_db, 5 * 1024 * 1024);
let mut state = state::State::new(
let mut state = State::new(
state_db,
spec.engine.account_start_nonce(0),
factories.clone(),
@ -185,7 +193,7 @@ impl<'a> EvmTestClient<'a> {
}
/// Return current state.
pub fn state(&self) -> &state::State<state_db::StateDB> {
pub fn state(&self) -> &State<state_db::StateDB> {
&self.state
}
@ -221,7 +229,7 @@ impl<'a> EvmTestClient<'a> {
info: client::EnvInfo,
) -> Result<FinalizationResult, EvmTestError>
{
let mut substate = state::Substate::new();
let mut substate = Substate::new();
let machine = self.spec.engine.machine();
let schedule = machine.schedule(info.number);
let mut executive = executive::Executive::new(&mut self.state, &info, &machine, &schedule);
@ -263,9 +271,9 @@ impl<'a> EvmTestClient<'a> {
// Details: https://github.com/paritytech/parity-ethereum/issues/9431
let schedule = self.spec.engine.machine().schedule(env_info.number);
self.state.add_balance(&env_info.author, &0.into(), if schedule.no_empty {
state::CleanupMode::NoEmpty
CleanupMode::NoEmpty
} else {
state::CleanupMode::ForceCreate
CleanupMode::ForceCreate
}).ok();
// Touching also means that we should remove the account if it's within eip161
// conditions.
@ -300,11 +308,7 @@ impl<'a> EvmTestClient<'a> {
end_state,
}
)},
Err(error) => Err(TransactErr {
state_root,
error,
end_state,
}),
Err(e) => Err(TransactErr {state_root, error: e.into(), end_state}),
}
}
}
@ -330,7 +334,7 @@ pub struct TransactSuccess<T, V> {
/// outcome
pub outcome: receipt::TransactionOutcome,
/// end state if needed
pub end_state: Option<pod_state::PodState>,
pub end_state: Option<PodState>,
}
/// To be returned inside a std::result::Result::Err after a failed
@ -342,5 +346,5 @@ pub struct TransactErr {
/// Execution error
pub error: ::error::Error,
/// end state if needed
pub end_state: Option<pod_state::PodState>,
pub end_state: Option<PodState>,
}

View File

@ -25,7 +25,6 @@ mod evm_test_client;
mod io_message;
#[cfg(any(test, feature = "test-helpers"))]
mod test_client;
mod trace;
pub use self::client::*;
pub use self::config::{Mode, ClientConfig, DatabaseCompactionProfile, BlockChainConfig, VMType};
@ -33,14 +32,14 @@ pub use self::config::{Mode, ClientConfig, DatabaseCompactionProfile, BlockChain
pub use self::evm_test_client::{EvmTestClient, EvmTestError, TransactErr, TransactSuccess};
pub use self::io_message::ClientIoMessage;
#[cfg(any(test, feature = "test-helpers"))]
pub use self::test_client::{TestBlockChainClient, EachBlockWith};
pub use self::test_client::{TestBlockChainClient, EachBlockWith, TestState};
pub use self::chain_notify::{ChainNotify, NewBlocks, ChainRoute, ChainRouteType, ChainMessageType};
pub use self::traits::{
Nonce, Balance, ChainInfo, BlockInfo, ReopenBlock, PrepareOpenBlock, TransactionInfo, ScheduleInfo, ImportSealedBlock, BroadcastProposalBlock, ImportBlock,
StateOrBlock, StateClient, Call, EngineInfo, AccountData, BlockChain, BlockProducer, SealedBlockImporter, BadBlocks,
BlockChainReset
};
pub use state::StateInfo;
pub use account_state::state::StateInfo;
pub use self::traits::{BlockChainClient, EngineClient, ProvingBlockChainClient, IoClient};
pub use types::ids::*;

View File

@ -66,7 +66,7 @@ use executive::Executed;
use journaldb;
use miner::{self, Miner, MinerService};
use spec::Spec;
use state::StateInfo;
use account_state::state::StateInfo;
use state_db::StateDB;
use trace::LocalizedTrace;
use verification::queue::QueueInfo as BlockQueueInfo;
@ -586,7 +586,7 @@ impl ImportBlock for TestBlockChainClient {
impl Call for TestBlockChainClient {
// State will not be used by test client anyway, since all methods that accept state are mocked
type State = ();
type State = TestState;
fn call(&self, _t: &SignedTransaction, _analytics: CallAnalytics, _state: &mut Self::State, _header: &Header) -> Result<Executed, CallError> {
self.execution_result.read().clone().unwrap()
@ -605,23 +605,27 @@ impl Call for TestBlockChainClient {
}
}
impl StateInfo for () {
/// NewType wrapper around `()` to impersonate `State` in trait impls. State will not be used by
/// test client, since all methods that accept state are mocked.
pub struct TestState;
impl StateInfo for TestState {
fn nonce(&self, _address: &Address) -> ethtrie::Result<U256> { unimplemented!() }
fn balance(&self, _address: &Address) -> ethtrie::Result<U256> { unimplemented!() }
fn storage_at(&self, _address: &Address, _key: &H256) -> ethtrie::Result<H256> { unimplemented!() }
fn code(&self, _address: &Address) -> ethtrie::Result<Option<Arc<Bytes>>> { unimplemented!() }
}
impl StateClient for TestBlockChainClient {
// State will not be used by test client anyway, since all methods that accept state are mocked
type State = ();
type State = TestState;
fn latest_state(&self) -> Self::State {
()
TestState
}
fn state_at(&self, _id: BlockId) -> Option<Self::State> {
Some(())
Some(TestState)
}
}

View File

@ -47,7 +47,7 @@ use engines::Engine;
use error::{Error, EthcoreResult};
use executed::CallError;
use executive::Executed;
use state::StateInfo;
use account_state::state::StateInfo;
use trace::LocalizedTrace;
use verification::queue::QueueInfo as BlockQueueInfo;
use verification::queue::kind::blocks::Unverified;
@ -61,12 +61,6 @@ pub enum StateOrBlock {
Block(BlockId)
}
impl<S: StateInfo + 'static> From<S> for StateOrBlock {
fn from(info: S) -> StateOrBlock {
StateOrBlock::State(Box::new(info) as Box<_>)
}
}
impl From<Box<dyn StateInfo>> for StateOrBlock {
fn from(info: Box<dyn StateInfo>) -> StateOrBlock {
StateOrBlock::State(info)
@ -195,7 +189,7 @@ pub trait IoClient: Sync + Send {
/// Queue block import with transaction receipts. Does no sealing and transaction validation.
fn queue_ancient_block(&self, block_bytes: Unverified, receipts_bytes: Bytes) -> EthcoreResult<H256>;
/// Queue conensus engine message.
/// Queue consensus engine message.
fn queue_consensus_message(&self, message: Bytes);
}

View File

@ -129,7 +129,7 @@ fn check_first_proof(machine: &Machine, contract_address: Address, old_header: H
data,
}.fake_sign(from);
let res = ::state::check_proof(
let res = ::executive_state::check_proof(
state_items,
*old_header.state_root(),
&tx,
@ -138,9 +138,9 @@ fn check_first_proof(machine: &Machine, contract_address: Address, old_header: H
);
match res {
::state::ProvedExecution::BadProof => Err("Bad proof".into()),
::state::ProvedExecution::Failed(e) => Err(format!("Failed call: {}", e)),
::state::ProvedExecution::Complete(e) => decoder.decode(&e.output).map_err(|e| e.to_string()),
::executive_state::ProvedExecution::BadProof => Err("Bad proof".into()),
::executive_state::ProvedExecution::Failed(e) => Err(format!("Failed call: {}", e)),
::executive_state::ProvedExecution::Complete(e) => decoder.decode(&e.output).map_err(|e| e.to_string()),
}
}

View File

@ -220,6 +220,9 @@ pub enum Error {
/// A convenient variant for String.
#[display(fmt = "{}", _0)]
Msg(String),
/// State errors
#[display(fmt = "State error ({})", _0)]
State(account_state::Error),
}
impl error::Error for Error {
@ -236,6 +239,7 @@ impl error::Error for Error {
Error::Ethkey(e) => Some(e),
Error::Decoder(e) => Some(e),
Error::Snapshot(e) => Some(e),
Error::State(e) => Some(e),
_ => None,
}
}

View File

@ -189,7 +189,7 @@ pub fn new_kovan_wasm_test_machine() -> Machine { load_machine(include_bytes!(".
mod tests {
use std::str::FromStr;
use ethereum_types::{U256, H256, Address};
use state::*;
use account_state::*;
use super::*;
use test_helpers::get_temp_state_db;
use types::view;

View File

@ -21,7 +21,7 @@ use std::sync::Arc;
use hash::keccak;
use ethereum_types::{H256, U256, U512, Address};
use bytes::{Bytes, BytesRef};
use state::{Backend as StateBackend, State, Substate, CleanupMode};
use account_state::{Backend as StateBackend, State, Substate, CleanupMode};
use executed::ExecutionError;
use machine::Machine;
use evm::{CallType, Finalize, FinalizationResult};
@ -29,7 +29,7 @@ use vm::{
self, EnvInfo, CreateContractAddress, ReturnData, CleanDustMode, ActionParams,
ActionValue, Schedule, TrapError, ResumeCall, ResumeCreate
};
use factory::VmFactory;
use trie_vm_factories::VmFactory;
use externalities::*;
use trace::{self, Tracer, VMTracer};
use types::transaction::{Action, SignedTransaction};
@ -1202,7 +1202,7 @@ mod tests {
use evm::{Factory, VMType};
use error::ExecutionError;
use machine::Machine;
use state::{Substate, CleanupMode};
use account_state::{Substate, CleanupMode};
use test_helpers::{get_temp_state_with_factory, get_temp_state};
use trace::trace;
use trace::{FlatTrace, Tracer, NoopTracer, ExecutiveTracer};

File diff suppressed because it is too large Load Diff

View File

@ -19,7 +19,7 @@ use std::cmp;
use std::sync::Arc;
use ethereum_types::{H256, U256, Address, BigEndianHash};
use bytes::Bytes;
use state::{Backend as StateBackend, State, Substate, CleanupMode};
use account_state::{Backend as StateBackend, State, Substate, CleanupMode};
use machine::Machine;
use executive::*;
use vm::{
@ -435,7 +435,7 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for Externalities<'a, T, V, B>
mod tests {
use ethereum_types::{U256, Address};
use evm::{EnvInfo, Ext, CallType};
use state::{State, Substate};
use account_state::{State, Substate};
use test_helpers::get_temp_state;
use super::*;
use trace::{NoopTracer, NoopVMTracer};

View File

@ -17,7 +17,7 @@
use std::path::Path;
use std::sync::Arc;
use super::test_common::*;
use state::{Backend as StateBackend, State, Substate};
use account_state::{Backend as StateBackend, State, Substate};
use executive::*;
use evm::{VMType, Finalize};
use vm::{

View File

@ -16,7 +16,7 @@
use std::path::Path;
use super::test_common::*;
use pod_state::PodState;
use pod::PodState;
use trace;
use client::{EvmTestClient, EvmTestError, TransactErr, TransactSuccess};
use ethjson;

View File

@ -69,6 +69,7 @@ extern crate ethcore_miner;
extern crate ethereum_types;
extern crate ethjson;
extern crate ethkey;
extern crate trie_vm_factories;
extern crate futures;
extern crate hash_db;
extern crate itertools;
@ -82,12 +83,11 @@ extern crate kvdb_memorydb;
extern crate len_caching_lock;
extern crate lru_cache;
extern crate memory_cache;
extern crate memory_db;
extern crate num_cpus;
extern crate parity_bytes as bytes;
extern crate parity_snappy as snappy;
extern crate parking_lot;
extern crate pod_account;
extern crate pod;
extern crate trie_db as trie;
extern crate patricia_trie_ethereum as ethtrie;
extern crate rand;
@ -98,13 +98,13 @@ 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 account_state;
extern crate time_utils;
extern crate trace;
extern crate triehash_ethereum as triehash;
extern crate unexpected;
extern crate using_queue;
extern crate vm;
extern crate wasm;
#[cfg(test)]
extern crate rand_xorshift;
@ -138,8 +138,6 @@ extern crate macros;
extern crate rlp_derive;
#[macro_use]
extern crate trace_time;
#[macro_use]
extern crate serde_derive;
#[cfg_attr(test, macro_use)]
extern crate evm;
@ -157,19 +155,16 @@ pub mod error;
pub mod ethereum;
pub mod executed;
pub mod executive;
pub mod executive_state;
pub mod machine;
pub mod miner;
pub mod pod_state;
pub mod snapshot;
pub mod spec;
pub mod state;
pub mod state_db;
pub mod trace;
pub mod transaction_ext;
pub mod verification;
mod externalities;
mod factory;
mod state_db;
mod transaction_ext;
mod tx_filter;
#[cfg(test)]
@ -182,3 +177,4 @@ pub mod test_helpers;
pub use executive::contract_address;
pub use evm::CreateContractAddress;
pub use trie::TrieSpec;
pub use state_db::StateDB;

View File

@ -35,7 +35,7 @@ use client::BlockInfo;
use error::Error;
use executive::Executive;
use spec::CommonParams;
use state::{CleanupMode, Substate};
use account_state::{CleanupMode, Substate};
use trace::{NoopTracer, NoopVMTracer};
use tx_filter::TransactionFilter;
@ -108,9 +108,7 @@ impl Machine {
pub fn ethash_extensions(&self) -> Option<&EthashExtensions> {
self.ethash_extensions.as_ref()
}
}
impl Machine {
/// Execute a call as the system address. Block environment information passed to the
/// VM is modified to have its gas limit bounded at the upper limit of possible used
/// gases including this system call, capped at the maximum value able to be
@ -395,8 +393,18 @@ impl Machine {
}
rlp.as_val().map_err(|e| transaction::Error::InvalidRlp(e.to_string()))
}
}
/// Get the balance, in base units, associated with an account.
/// Extracts data from the live block.
pub fn balance(&self, live: &ExecutedBlock, address: &Address) -> Result<U256, Error> {
live.state.balance(address).map_err(Into::into)
}
/// Increment the balance of an account in the state of the live block.
pub fn add_balance(&self, live: &mut ExecutedBlock, address: &Address, amount: &U256) -> Result<(), Error> {
live.state_mut().add_balance(address, amount, CleanupMode::NoEmpty).map_err(Into::into)
}
}
/// Auxiliary data fetcher for an Ethereum machine. In Ethereum-like machines
/// there are two kinds of auxiliary data: bodies and receipts.
#[derive(Default, Clone)]
@ -422,19 +430,6 @@ pub enum AuxiliaryRequest {
Both,
}
impl Machine {
/// Get the balance, in base units, associated with an account.
/// Extracts data from the live block.
pub fn balance(&self, live: &ExecutedBlock, address: &Address) -> Result<U256, Error> {
live.state.balance(address).map_err(Into::into)
}
/// Increment the balance of an account in the state of the live block.
pub fn add_balance(&self, live: &mut ExecutedBlock, address: &Address, amount: &U256) -> Result<(), Error> {
live.state_mut().add_balance(address, amount, CleanupMode::NoEmpty).map_err(Into::into)
}
}
// Try to round gas_limit a bit so that:
// 1) it will still be in desired range
// 2) it will be a nearest (with tendency to increase) multiple of PARITY_GAS_LIMIT_DETERMINANT

View File

@ -59,7 +59,7 @@ use error::Error;
use executed::ExecutionError;
use executive::contract_address;
use spec::Spec;
use state::State;
use account_state::State;
/// Different possible definitions for pending transaction set.
#[derive(Debug, PartialEq)]

View File

@ -50,7 +50,7 @@ use client::{
AccountData, Nonce,
};
use error::Error;
use state::StateInfo;
use account_state::state::StateInfo;
/// Provides methods to verify incoming external transactions
pub trait TransactionVerifierClient: Send + Sync

View File

@ -48,7 +48,7 @@ use num_cpus;
use self::io::SnapshotWriter;
use super::state_db::StateDB;
use super::state::Account as StateAccount;
use account_state::Account as StateAccount;
use crossbeam_utils::thread;
use rand::{Rng, rngs::OsRng};

View File

@ -97,7 +97,7 @@ impl StateProducer {
let address_hash = H256(rng.gen());
let balance: usize = rng.gen();
let nonce: usize = rng.gen();
let acc = ::state::Account::new_basic(balance.into(), nonce.into()).rlp();
let acc = account_state::Account::new_basic(balance.into(), nonce.into()).rlp();
trie.insert(&address_hash[..], &acc).unwrap();
}
}

View File

@ -40,13 +40,12 @@ use engines::{
};
use error::Error;
use executive::Executive;
use factory::Factories;
use trie_vm_factories::Factories;
use machine::Machine;
use pod_state::PodState;
use pod::PodState;
use spec::Genesis;
use spec::seal::Generic as GenericSeal;
use state::backend::Basic as BasicBackend;
use state::{Backend, State, Substate};
use account_state::{Backend, State, Substate, backend::Basic as BasicBackend};
use trace::{NoopTracer, NoopVMTracer};
pub use ethash::OptimizeFor;
@ -890,7 +889,7 @@ impl Spec {
data: d,
}.fake_sign(from);
let res = ::state::prove_transaction_virtual(
let res = ::executive_state::prove_transaction_virtual(
db.as_hash_db_mut(),
*genesis.state_root(),
&tx,
@ -999,7 +998,7 @@ impl Spec {
#[cfg(test)]
mod tests {
use super::*;
use state::State;
use account_state::State;
use test_helpers::get_temp_state_db;
use tempdir::TempDir;
use types::view;

View File

@ -33,7 +33,7 @@ use memory_cache::MemoryLruCache;
use parking_lot::Mutex;
use types::BlockNumber;
use state::{self, Account};
use account_state::{self, Account};
/// Value used to initialize bloom bitmap size.
///
@ -125,8 +125,13 @@ pub struct StateDB {
commit_number: Option<BlockNumber>,
}
impl StateDB {
impl Clone for StateDB {
fn clone(&self) -> Self {
self.boxed_clone()
}
}
impl StateDB {
/// Create a new instance wrapping `JournalDB` and the maximum allowed size
/// of the LRU cache in bytes. Actual used memory may (read: will) be higher due to bookkeeping.
// TODO: make the cache size actually accurate by moving the account storage cache
@ -284,7 +289,7 @@ impl StateDB {
if is_best {
let acc = account.account.0;
if let Some(&mut Some(ref mut existing)) = cache.accounts.get_mut(&account.address) {
if let Some(new) = acc {
if let Some(new) = acc {
if account.modified {
existing.overwrite_with(new);
}
@ -407,7 +412,7 @@ impl StateDB {
}
}
impl state::Backend for StateDB {
impl account_state::Backend for StateDB {
fn as_hash_db(&self) -> &dyn HashDB<KeccakHasher, DBValue> { self.db.as_hash_db() }
fn as_hash_db_mut(&mut self) -> &mut dyn HashDB<KeccakHasher, DBValue> {
@ -482,7 +487,7 @@ mod tests {
use ethereum_types::{H256, U256, Address};
use kvdb::DBTransaction;
use test_helpers::get_temp_state_db;
use state::{Account, Backend};
use account_state::{Account, Backend};
#[test]
fn state_db_smoke() {

View File

@ -41,10 +41,10 @@ use types::views::BlockView;
use block::{OpenBlock, Drain};
use client::{Client, ClientConfig, ChainInfo, ImportBlock, ChainNotify, ChainMessageType, PrepareOpenBlock};
use factory::Factories;
use trie_vm_factories::Factories;
use miner::Miner;
use spec::Spec;
use state::*;
use account_state::*;
use state_db::StateDB;
use verification::queue::kind::blocks::Unverified;

View File

@ -32,7 +32,7 @@ use ethereum;
use executive::{Executive, TransactOptions};
use miner::{Miner, PendingOrdering, MinerService};
use spec::Spec;
use state::{self, State, CleanupMode};
use account_state::{State, CleanupMode, backend};
use test_helpers::{
self,
generate_dummy_client, push_blocks_to_client, get_test_client_with_blocks, get_good_dummy_block_seq,
@ -347,9 +347,9 @@ fn transaction_proof() {
}.fake_sign(address);
let proof = client.prove_transaction(transaction.clone(), BlockId::Latest).unwrap().1;
let backend = state::backend::ProofCheck::new(&proof);
let backend = backend::ProofCheck::new(&proof);
let mut factories = ::factory::Factories::default();
let mut factories = ::trie_vm_factories::Factories::default();
factories.accountdb = ::account_db::Factory::Plain; // raw state values, no mangled keys.
let root = *client.best_block_header().state_root();

View File

@ -21,7 +21,7 @@ use hash::keccak;
use vm::{EnvInfo, ActionParams, ActionValue, CallType, ParamsType};
use evm::{Factory, VMType};
use executive::Executive;
use state::Substate;
use account_state::Substate;
use test_helpers::get_temp_state_with_factory;
use trace::{NoopVMTracer, NoopTracer};
use types::transaction::SYSTEM_ADDRESS;

View File

@ -109,7 +109,7 @@ use rlp::{RlpStream, DecoderError};
use network::{self, PeerId, PacketId};
use network::client_version::ClientVersion;
use ethcore::client::{BlockChainClient, BlockStatus, BlockId, BlockChainInfo, BlockQueueInfo};
use ethcore::snapshot::{RestorationStatus};
use ethcore::snapshot::RestorationStatus;
use sync_io::SyncIo;
use super::{WarpSync, SyncConfig};
use block_sync::{BlockDownloader, DownloadAction};

View File

@ -21,7 +21,7 @@ use types::transaction::{Transaction, Action};
use types::ids::BlockId;
use ethcore::CreateContractAddress;
use ethcore::client::{ClientIoMessage, BlockChainClient};
use ethcore::executive::{contract_address};
use ethcore::executive::contract_address;
use ethcore::engines;
use ethcore::miner::{self, MinerService};
use ethcore::spec::Spec;

25
ethcore/trace/Cargo.toml Normal file
View File

@ -0,0 +1,25 @@
[package]
description = "Transaction tracing"
name = "trace"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
common-types = { path = "../types"}
ethcore-blockchain = { path = "../blockchain" }
ethcore-db = { path = "../db" }
ethereum-types = "0.6"
evm = { path = "../evm" }
kvdb = "0.1.0"
log = "0.4"
parity-bytes = "0.1.0"
parity-util-mem = "0.1"
parking_lot = "0.8.0"
rlp = "0.4.0"
rlp_derive = { path = "../../util/rlp-derive" }
vm = { path = "../vm" }
[dev-dependencies]
# Used for test helpers
ethcore = { path = "..", features = ["test-helpers"] }

View File

@ -22,7 +22,7 @@ pub struct Config {
/// Indicates if tracing should be enabled or not.
/// If it's None, it will be automatically configured.
pub enabled: bool,
/// Preferef cache-size.
/// Preferred cache-size.
pub pref_cache_size: usize,
/// Max cache-size.
pub max_cache_size: usize,

View File

@ -17,18 +17,23 @@
//! Trace database.
use std::collections::HashMap;
use std::sync::Arc;
use parity_util_mem::MallocSizeOfExt;
use blockchain::BlockChainDB;
use db::cache_manager::CacheManager;
use db::{self, Key, Writable, Readable, CacheUpdatePolicy};
use common_types::BlockNumber;
use ethcore_blockchain::{BlockChainDB, DatabaseExtras};
use ethcore_db::{
self as db,
cache_manager::CacheManager,
Key, Writable, Readable, CacheUpdatePolicy,
};
use ethereum_types::{H256, H264};
use kvdb::{DBTransaction};
use kvdb::DBTransaction;
use parity_util_mem::MallocSizeOfExt;
use parking_lot::RwLock;
use types::BlockNumber;
use trace::{LocalizedTrace, Config, Filter, Database as TraceDatabase, ImportRequest, DatabaseExtras};
use trace::flat::{FlatTrace, FlatBlockTraces, FlatTransactionTraces};
use crate::{
LocalizedTrace, Config, Filter, Database as TraceDatabase, ImportRequest,
flat::{FlatTrace, FlatBlockTraces, FlatTransactionTraces},
};
const TRACE_DB_VER: &'static [u8] = b"1.0";
@ -334,17 +339,23 @@ impl<T> TraceDatabase for TraceDB<T> where T: DatabaseExtras {
#[cfg(test)]
mod tests {
use std::collections::HashMap;
use std::sync::Arc;
use std::{
collections::HashMap,
sync::Arc,
};
use common_types::BlockNumber;
use ethcore_blockchain::DatabaseExtras;
use ethcore::test_helpers::new_db;
use ethereum_types::{H256, U256, Address};
use kvdb::{DBTransaction};
use types::BlockNumber;
use trace::{Config, TraceDB, Database as TraceDatabase, DatabaseExtras, ImportRequest};
use trace::{Filter, LocalizedTrace, AddressesFilter, TraceError};
use trace::trace::{Call, Action, Res};
use trace::flat::{FlatTrace, FlatBlockTraces, FlatTransactionTraces};
use evm::CallType;
use test_helpers::new_db;
use kvdb::DBTransaction;
use crate::{
Config, TraceDB, Database as TraceDatabase, ImportRequest,
Filter, LocalizedTrace, AddressesFilter, TraceError,
trace::{Call, Action, Res},
flat::{FlatTrace, FlatBlockTraces, FlatTransactionTraces}
};
struct NoopExtras;

View File

@ -18,8 +18,11 @@
use ethereum_types::{U256, Address};
use vm::{Error as VmError, ActionParams};
use trace::trace::{Call, Create, Action, Res, CreateResult, CallResult, VMTrace, VMOperation, VMExecutedOperation, MemoryDiff, StorageDiff, Suicide, Reward, RewardType};
use trace::{Tracer, VMTracer, FlatTrace};
use log::debug;
use crate::{
Tracer, VMTracer, FlatTrace,
trace::{Call, Create, Action, Res, CreateResult, CallResult, VMTrace, VMOperation, VMExecutedOperation, MemoryDiff, StorageDiff, Suicide, Reward, RewardType},
};
/// Simple executive tracer. Traces all calls and creates. Ignores delegatecalls.
#[derive(Default)]

View File

@ -16,9 +16,9 @@
//! Traces import request.
use ethereum_types::H256;
use types::BlockNumber;
use common_types::BlockNumber;
use trace::FlatBlockTraces;
use crate::FlatBlockTraces;
/// Traces import request.
pub struct ImportRequest {

View File

@ -16,6 +16,13 @@
//! Tracing
use common_types::BlockNumber;
use ethereum_types::{U256, Address};
use kvdb::DBTransaction;
use vm::{Error as VmError, ActionParams};
// The MallocSizeOf derive looks for this in the root
use parity_util_mem as malloc_size_of;
mod config;
mod db;
mod executive_tracer;
@ -23,23 +30,22 @@ mod import;
mod noop_tracer;
mod types;
pub use self::config::Config;
pub use self::db::TraceDB;
pub use self::noop_tracer::{NoopTracer, NoopVMTracer};
pub use self::executive_tracer::{ExecutiveTracer, ExecutiveVMTracer};
pub use self::import::ImportRequest;
pub use self::localized::LocalizedTrace;
pub use self::types::{filter, flat, localized, trace, Tracing};
pub use self::types::error::Error as TraceError;
pub use self::types::trace::{VMTrace, VMOperation, VMExecutedOperation, MemoryDiff, StorageDiff, RewardType};
pub use self::types::flat::{FlatTrace, FlatTransactionTraces, FlatBlockTraces};
pub use self::types::filter::{Filter, AddressesFilter};
use ethereum_types::{H256, U256, Address};
use kvdb::DBTransaction;
use vm::{Error as VmError, ActionParams};
use types::BlockNumber;
pub use crate::{
config::Config,
db::TraceDB,
localized::LocalizedTrace,
executive_tracer::{ExecutiveTracer, ExecutiveVMTracer},
import::ImportRequest,
noop_tracer::{NoopTracer, NoopVMTracer},
types::{
Tracing,
error::Error as TraceError,
localized,
trace::{self, VMTrace, VMOperation, VMExecutedOperation, MemoryDiff, StorageDiff, RewardType},
flat::{self, FlatTrace, FlatTransactionTraces, FlatBlockTraces},
filter::{self, Filter, AddressesFilter},
}
};
/// This trait is used by executive to build traces.
pub trait Tracer: Send {
@ -99,16 +105,6 @@ pub trait VMTracer: Send {
}
/// `DbExtras` provides an interface to query extra data which is not stored in tracesdb,
/// but necessary to work correctly.
pub trait DatabaseExtras {
/// Returns hash of given block number.
fn block_hash(&self, block_number: BlockNumber) -> Option<H256>;
/// Returns hash of transaction at given position.
fn transaction_hash(&self, block_number: BlockNumber, tx_position: usize) -> Option<H256>;
}
/// Db provides an interface to query tracesdb.
pub trait Database {
/// Returns true if tracing is enabled. Otherwise false.

View File

@ -18,8 +18,10 @@
use ethereum_types::{U256, Address};
use vm::{Error as VmError, ActionParams};
use trace::{Tracer, VMTracer, FlatTrace};
use trace::trace::{VMTrace, RewardType};
use crate::{
Tracer, VMTracer, FlatTrace,
trace::{VMTrace, RewardType}
};
/// Nonoperative tracer. Does not trace anything.
pub struct NoopTracer;

View File

@ -137,7 +137,7 @@ impl Decodable for Error {
#[cfg(test)]
mod tests {
use rlp::*;
use rlp::RlpStream;
use super::Error;
#[test]

View File

@ -18,8 +18,7 @@
use std::ops::Range;
use ethereum_types::{Address, Bloom, BloomInput};
use trace::flat::FlatTrace;
use super::trace::{Action, Res};
use crate::{flat::FlatTrace, trace::{Action, Res}};
/// Addresses filter.
///
@ -126,10 +125,12 @@ impl Filter {
#[cfg(test)]
mod tests {
use ethereum_types::{Address, Bloom, BloomInput};
use trace::trace::{Action, Call, Res, Create, CreateResult, Suicide, Reward};
use trace::flat::FlatTrace;
use trace::{Filter, AddressesFilter, TraceError, RewardType};
use evm::CallType;
use crate::{
Filter, AddressesFilter, TraceError, RewardType,
trace::{Action, Call, Res, Create, CreateResult, Suicide, Reward},
flat::FlatTrace,
};
#[test]
fn empty_trace_filter_bloom_possibilities() {
@ -386,42 +387,40 @@ mod tests {
assert!(f2.matches(&trace));
}
#[test]
fn filter_match_failed_contract_creation_fix_9822() {
#[test]
fn filter_match_failed_contract_creation_fix_9822() {
let f0 = Filter {
range: (0..0),
from_address: vec![Address::from_low_u64_be(1)].into(),
to_address: vec![].into(),
};
let f0 = Filter {
range: (0..0),
from_address: vec![Address::from_low_u64_be(1)].into(),
to_address: vec![].into(),
};
let f1 = Filter {
range: (0..0),
from_address: vec![].into(),
to_address: vec![].into(),
};
let f1 = Filter {
range: (0..0),
from_address: vec![].into(),
to_address: vec![].into(),
};
let f2 = Filter {
range: (0..0),
from_address: vec![].into(),
to_address: vec![Address::from_low_u64_be(2)].into(),
};
let f2 = Filter {
range: (0..0),
from_address: vec![].into(),
to_address: vec![Address::from_low_u64_be(2)].into(),
};
let trace = FlatTrace {
action: Action::Create(Create {
from: Address::from_low_u64_be(1),
gas: 4.into(),
init: vec![0x5],
value: 3.into(),
}),
result: Res::FailedCall(TraceError::BadInstruction),
trace_address: vec![].into_iter().collect(),
subtraces: 0
};
assert!(f0.matches(&trace));
assert!(f1.matches(&trace));
assert!(!f2.matches(&trace));
}
let trace = FlatTrace {
action: Action::Create(Create {
from: Address::from_low_u64_be(1),
gas: 4.into(),
init: vec![0x5],
value: 3.into(),
}),
result: Res::FailedCall(TraceError::BadInstruction),
trace_address: vec![].into_iter().collect(),
subtraces: 0
};
assert!(f0.matches(&trace));
assert!(f1.matches(&trace));
assert!(!f2.matches(&trace));
}
}

View File

@ -17,6 +17,7 @@
//! Flat trace module
use rlp::{Rlp, RlpStream, Decodable, Encodable, DecoderError};
use rlp_derive::{RlpEncodableWrapper, RlpDecodableWrapper};
use parity_util_mem::MallocSizeOf;
use ethereum_types::Bloom;
use super::trace::{Action, Res};
@ -73,7 +74,7 @@ impl Decodable for FlatTrace {
/// Represents all traces produced by a single transaction.
#[derive(Debug, PartialEq, Clone, RlpEncodableWrapper, RlpDecodableWrapper, MallocSizeOf)]
pub struct FlatTransactionTraces(Vec<FlatTrace>);
pub struct FlatTransactionTraces(pub(crate) Vec<FlatTrace>);
impl From<Vec<FlatTrace>> for FlatTransactionTraces {
fn from(v: Vec<FlatTrace>) -> Self {
@ -96,7 +97,7 @@ impl Into<Vec<FlatTrace>> for FlatTransactionTraces {
/// Represents all traces produced by transactions in a single block.
#[derive(Debug, PartialEq, Clone, Default, RlpEncodableWrapper, RlpDecodableWrapper, MallocSizeOf)]
pub struct FlatBlockTraces(Vec<FlatTransactionTraces>);
pub struct FlatBlockTraces(pub(crate) Vec<FlatTransactionTraces>);
impl From<Vec<FlatTransactionTraces>> for FlatBlockTraces {
fn from(v: Vec<FlatTransactionTraces>) -> Self {
@ -120,10 +121,11 @@ impl Into<Vec<FlatTransactionTraces>> for FlatBlockTraces {
#[cfg(test)]
mod tests {
use rlp::*;
use super::{FlatBlockTraces, FlatTransactionTraces, FlatTrace};
use trace::trace::{Action, Res, CallResult, Call, Suicide, Reward};
use crate::{
FlatBlockTraces, FlatTransactionTraces, FlatTrace,
trace::{Action, Res, CallResult, Call, Suicide, Reward, RewardType}
};
use evm::CallType;
use trace::RewardType;
#[test]
fn encode_flat_transaction_traces() {

View File

@ -18,7 +18,7 @@
use ethereum_types::H256;
use super::trace::{Action, Res};
use types::BlockNumber;
use common_types::BlockNumber;
/// Localized trace.
#[derive(Debug, PartialEq, Clone)]

View File

@ -14,12 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
//! Tracing datatypes.
//! Tracing data types.
use ethereum_types::{U256, Address, Bloom, BloomInput};
use bytes::Bytes;
use parity_bytes::Bytes;
use rlp::{Rlp, RlpStream, Encodable, DecoderError, Decodable};
use rlp_derive::{RlpEncodable, RlpDecodable};
use vm::ActionParams;
use evm::CallType;
use super::error::Error;

View File

@ -0,0 +1,15 @@
[package]
description = "Collection of factories for VM and Tries"
name = "trie-vm-factories"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
trie-db = "0.12.4"
ethtrie = { package = "patricia-trie-ethereum", path = "../../util/patricia-trie-ethereum" }
account-db = { path = "../account-db" }
evm = { path = "../evm" }
vm = { path = "../vm" }
wasm = { path = "../wasm" }
keccak-hasher = { path = "../../util/keccak-hasher" }

View File

@ -14,10 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
use trie::TrieFactory;
use trie_db::TrieFactory;
use ethtrie::RlpCodec;
use account_db::Factory as AccountFactory;
use ethereum_types::U256;
use evm::{Factory as EvmFactory, VMType};
use vm::{Exec, ActionParams, VersionedSchedule, Schedule};
use wasm::WasmInterpreter;

View File

@ -12,16 +12,19 @@ path = "./src/main.rs"
common-types = { path = "../ethcore/types" }
docopt = "1.0"
env_logger = "0.5"
ethcore = { path = "../ethcore", features = ["test-helpers", "json-tests", "to-pod-full"] }
ethcore = { path = "../ethcore", features = ["test-helpers", "json-tests"] }
ethereum-types = "0.6.0"
ethjson = { path = "../json" }
evm = { path = "../ethcore/evm" }
panic_hook = { path = "../util/panic-hook" }
parity-bytes = "0.1"
pod = { path = "../ethcore/pod" }
rustc-hex = "1.0"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
account-state = { path = "../ethcore/account-state" }
trace = { path = "../ethcore/trace" }
vm = { path = "../ethcore/vm" }
[dev-dependencies]

View File

@ -21,7 +21,7 @@ use std::mem;
use ethereum_types::{U256, H256, BigEndianHash};
use bytes::ToPretty;
use ethcore::trace;
use trace;
use display;
use info as vm;

View File

@ -16,7 +16,7 @@
//! Simple VM output.
use ethcore::trace;
use trace;
use bytes::ToPretty;
use display;

View File

@ -21,8 +21,8 @@ use std::io;
use ethereum_types::{H256, U256, BigEndianHash};
use bytes::ToPretty;
use ethcore::{trace, pod_state};
use trace;
use pod::PodState;
use display;
use info as vm;
@ -101,7 +101,7 @@ pub struct MessageFailure<'a> {
#[derive(Serialize, Debug)]
pub struct DumpData<'a> {
root: &'a H256,
accounts: &'a pod_state::PodState,
accounts: &'a PodState,
}
#[derive(Serialize, Debug)]
@ -154,7 +154,7 @@ impl<Trace: Writer, Out: Writer> Informant<Trace, Out> {
}
}
fn dump_state_into(trace_sink: &mut Trace, root: H256, end_state: &Option<pod_state::PodState>) {
fn dump_state_into(trace_sink: &mut Trace, root: H256, end_state: &Option<PodState>) {
if let Some(ref end_state) = end_state {
let dump_data =
DumpData {

View File

@ -19,10 +19,13 @@
use std::time::{Instant, Duration};
use ethereum_types::{H256, U256};
use ethcore::client::{self, EvmTestClient, EvmTestError, TransactErr, TransactSuccess};
use ethcore::{state, state_db, trace, spec, pod_state, TrieSpec};
use ethcore::{spec, TrieSpec};
use trace;
use ethjson;
use pod::PodState;
use types::transaction;
use vm::ActionParams;
use account_state::State;
/// VM execution informant
pub trait Informant: trace::VMTracer {
@ -52,7 +55,7 @@ pub struct Success<T> {
/// Traces
pub traces: Option<T>,
/// Optional end state dump
pub end_state: Option<pod_state::PodState>,
pub end_state: Option<PodState>,
}
/// Execution failed
@ -69,7 +72,7 @@ pub struct Failure<T> {
/// Traces
pub traces: Option<T>,
/// Optional end state dump
pub end_state: Option<pod_state::PodState>,
pub end_state: Option<PodState>,
}
/// EVM Execution result
@ -105,7 +108,7 @@ pub fn run_transaction<T: Informant>(
name: &str,
idx: usize,
spec: &ethjson::spec::ForkSpec,
pre_state: &pod_state::PodState,
pre_state: &PodState,
post_root: H256,
env_info: &client::EnvInfo,
transaction: transaction::SignedTransaction,
@ -152,19 +155,15 @@ pub fn run_transaction<T: Informant>(
T::finish(result, &mut sink)
}
fn dump_state(state: &state::State<state_db::StateDB>) -> Option<pod_state::PodState> {
state.to_pod_full().ok()
}
/// Execute VM with given `ActionParams`
pub fn run<'a, F, X>(
spec: &'a spec::Spec,
trie_spec: TrieSpec,
initial_gas: U256,
pre_state: &'a pod_state::PodState,
pre_state: &'a PodState,
run: F,
) -> RunResult<X> where
F: FnOnce(EvmTestClient) -> (Result<Vec<u8>, EvmTestError>, H256, Option<pod_state::PodState>, Option<U256>, Option<X>),
F: FnOnce(EvmTestClient) -> (Result<Vec<u8>, EvmTestError>, H256, Option<PodState>, Option<U256>, Option<X>),
{
let do_dump = trie_spec == TrieSpec::Fat;
@ -179,7 +178,7 @@ pub fn run<'a, F, X>(
})?;
if do_dump {
test_client.set_dump_state_fn(dump_state);
test_client.set_dump_state();
}
let start = Instant::now();

View File

@ -41,7 +41,6 @@ extern crate rustc_hex;
extern crate serde;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate serde_json;
extern crate docopt;
extern crate parity_bytes as bytes;
@ -49,7 +48,10 @@ extern crate ethereum_types;
extern crate vm;
extern crate evm;
extern crate panic_hook;
extern crate pod;
extern crate env_logger;
extern crate account_state;
extern crate trace;
#[cfg(test)]
#[macro_use]

View File

@ -60,7 +60,9 @@ parity-runtime = { path = "../util/runtime" }
parity-updater = { path = "../updater" }
parity-version = { path = "../util/version" }
rlp = "0.4.0"
account-state = { path = "../ethcore/account-state" }
stats = { path = "../util/stats" }
trace = { path = "../ethcore/trace" }
vm = { path = "../ethcore/vm" }
[dev-dependencies]
@ -68,6 +70,7 @@ ethcore = { path = "../ethcore", features = ["test-helpers"] }
ethcore-accounts = { path = "../accounts" }
ethcore-io = { path = "../util/io" }
ethcore-network = { path = "../util/network" }
patricia-trie-ethereum = { path = "../util/patricia-trie-ethereum" }
fake-fetch = { path = "../util/fake-fetch" }
macros = { path = "../util/macros" }
pretty_assertions = "0.1"

View File

@ -82,8 +82,10 @@ extern crate parity_updater as updater;
extern crate parity_version as version;
extern crate eip_712;
extern crate rlp;
extern crate account_state;
extern crate stats;
extern crate tempdir;
extern crate trace;
extern crate vm;
#[cfg(any(test, feature = "ethcore-accounts"))]
@ -103,6 +105,8 @@ extern crate rand_xorshift;
#[cfg(test)]
extern crate ethjson;
#[cfg(test)]
extern crate patricia_trie_ethereum as ethtrie;
#[cfg(test)]
extern crate transaction_pool as txpool;
#[cfg(test)]

View File

@ -23,7 +23,7 @@ use ethereum_types::{H64, H160, H256, H512, U64, U256};
use ethcore::client::{BlockChainClient, StateClient, Call};
use ethcore::miner::{self, MinerService, FilterOptions};
use ethcore::snapshot::{SnapshotService, RestorationStatus};
use ethcore::state::StateInfo;
use account_state::state::StateInfo;
use ethcore_logger::RotatingLogger;
use ethkey::{crypto::ecies, Brain, Generator};
use ethstore::random_phrase;

View File

@ -21,14 +21,16 @@ use std::collections::{BTreeMap, BTreeSet, HashMap};
use bytes::Bytes;
use ethcore::block::SealedBlock;
use ethcore::client::{Nonce, PrepareOpenBlock, StateClient, EngineInfo};
use ethcore::client::{Nonce, PrepareOpenBlock, StateClient, EngineInfo, TestState};
use ethcore::engines::{Engine, signer::EngineSigner};
use ethcore::error::Error;
use ethcore::miner::{self, MinerService, AuthoringParams, FilterOptions};
use ethereum_types::{H256, U256, Address};
use ethtrie;
use miner::pool::local_transactions::Status as LocalTransactionStatus;
use miner::pool::{verifier, VerifiedTransaction, QueueStatus};
use parking_lot::{RwLock, Mutex};
use account_state::state::StateInfo;
use types::transaction::{self, UnverifiedTransaction, SignedTransaction, PendingTransaction};
use txpool;
use types::BlockNumber;
@ -87,14 +89,14 @@ impl TestMinerService {
impl StateClient for TestMinerService {
// State will not be used by test client anyway, since all methods that accept state are mocked
type State = ();
type State = TestState;
fn latest_state(&self) -> Self::State {
()
TestState
}
fn state_at(&self, _id: BlockId) -> Option<Self::State> {
Some(())
Some(TestState)
}
}
@ -105,7 +107,7 @@ impl EngineInfo for TestMinerService {
}
impl MinerService for TestMinerService {
type State = ();
type State = TestState;
fn pending_state(&self, _latest_block_number: BlockNumber) -> Option<Self::State> {
None

View File

@ -100,13 +100,13 @@ impl EthTester {
EthTester {
runtime,
client: client,
sync: sync,
client,
sync,
accounts_provider: ap,
miner: miner,
snapshot: snapshot,
io: io,
hashrates: hashrates,
miner,
snapshot,
io,
hashrates,
}
}

View File

@ -17,8 +17,8 @@
use std::sync::Arc;
use ethcore::executed::{Executed, CallError};
use ethcore::trace::trace::{Action, Res, Call};
use ethcore::trace::LocalizedTrace;
use trace::trace::{Action, Res, Call};
use trace::LocalizedTrace;
use ethcore::client::TestBlockChainClient;
use ethereum_types::{Address, H256};

View File

@ -17,8 +17,8 @@
use std::collections::BTreeMap;
use ethcore::client::Executed;
use ethcore::trace as et;
use ethcore::trace::{FlatTrace, LocalizedTrace as EthLocalizedTrace, trace, TraceError};
use trace as et;
use trace::{FlatTrace, LocalizedTrace as EthLocalizedTrace, trace, TraceError};
use ethereum_types::{H160, H256, U256};
use serde::ser::SerializeStruct;
use serde::{Serialize, Serializer};
@ -656,7 +656,7 @@ mod tests {
use serde_json;
use std::collections::BTreeMap;
use v1::types::Bytes;
use ethcore::trace::TraceError;
use trace::TraceError;
use ethereum_types::Address;
use super::*;