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

Extract state-db from ethcore #10858

Merged
merged 78 commits into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
f144f88
WIP move errors, pod_account and state account to own crates
dvdplm Jul 3, 2019
c8bf87f
Sort out dependencies, fix broken code and tests
dvdplm Jul 4, 2019
47bc6fb
remove template line
dvdplm Jul 4, 2019
f8756bb
fix review feedback
dvdplm Jul 4, 2019
d54ebab
Remove test-only AccountDBMut::new
dvdplm Jul 4, 2019
7792810
Extract AccountDB to account-db
dvdplm Jul 4, 2019
a55ca1e
Move Substate to state-account – wip
dvdplm Jul 4, 2019
201dac7
Add lib.rs
dvdplm Jul 4, 2019
e23acad
cleanup
dvdplm Jul 4, 2019
b7c7aae
Merge branch 'master' into dp/chore/extricate-account-db-into-own-crate
dvdplm Jul 4, 2019
e0701e4
test failure
dvdplm Jul 4, 2019
b42d16a
test failure 2
dvdplm Jul 4, 2019
e45d13f
third time's the charm
dvdplm Jul 4, 2019
9553c8c
Merge branch 'dp/chore/extricate-account-db-into-own-crate' into dp/c…
dvdplm Jul 4, 2019
9b60a57
Merge branch 'master' into dp/chore/extricate-state-backend
dvdplm Jul 4, 2019
c55e6b1
Merge branch 'master' into dp/chore/extricate-state-backend
dvdplm Jul 4, 2019
1c0722b
Add factories crate
dvdplm Jul 4, 2019
2114c12
Use new factories crate
dvdplm Jul 4, 2019
80ededa
Use factories crate
dvdplm Jul 4, 2019
d9ceaa6
Extract trace
dvdplm Jul 4, 2019
9f3aa73
Fix tests
dvdplm Jul 4, 2019
a6a25ba
Sort out parity-util-mem and parking_lot
dvdplm Jul 4, 2019
44a0904
cleanup
dvdplm Jul 4, 2019
ce3a211
WIP port over the rest of state from ethcore
dvdplm Jul 4, 2019
9ed1d47
Collect all impls for Machine
dvdplm Jul 5, 2019
67332d7
some notes
dvdplm Jul 5, 2019
0a42ea8
Rename pod-account to pod
dvdplm Jul 5, 2019
d9ce43d
Move PodState to pod crate
dvdplm Jul 5, 2019
aebee1d
Use PodState from pod crate
dvdplm Jul 5, 2019
6344f9d
Fix use clause for json tests
dvdplm Jul 5, 2019
63564de
Sort out evmbin
dvdplm Jul 5, 2019
147bde5
Add missing code and use PodState
dvdplm Jul 5, 2019
ceda5f8
Move code that depends on Machine and Executive to own module
dvdplm Jul 5, 2019
fefd892
Sort out cloning errors, fix ethcore to use new state crate
dvdplm Jul 5, 2019
d41f5d4
Do without funky From impls
dvdplm Jul 5, 2019
ffec0b0
Fix ethcore tests
dvdplm Jul 5, 2019
849c73f
Fixes around the project to use new state crate
dvdplm Jul 5, 2019
c772639
Add back the more specific impls of StateOrBlock From conversions
dvdplm Jul 5, 2019
ffda775
Move execute to freestanding function and remove it from trait
dvdplm Jul 5, 2019
2f9526b
cleanup
dvdplm Jul 5, 2019
6f8a1a7
Fix "error: enum variants on type aliases are experimental"
dvdplm Jul 5, 2019
b11e078
Bring back the state tests
dvdplm Jul 5, 2019
06a37ba
remove ethcore/state/mod.rs
dvdplm Jul 5, 2019
10ab382
cleanup
dvdplm Jul 5, 2019
cff4280
cleanup
dvdplm Jul 5, 2019
cf4d8d5
Cleanup state-account errors
dvdplm Jul 5, 2019
e4a5176
Fix more todos
dvdplm Jul 5, 2019
618276d
Add error.rs
dvdplm Jul 5, 2019
4be6fe0
Merge branch 'master' into dp/chore/extricate-state-backend
dvdplm Jul 5, 2019
3a0db5e
Fixup Cargo.lock
dvdplm Jul 5, 2019
a61f135
Smaller ethcore API is fine
dvdplm Jul 5, 2019
14e475f
Add `to-pod-full` feature to state-account
dvdplm Jul 5, 2019
6d0df41
Fix a few more test failures
dvdplm Jul 5, 2019
5363b45
Fix RPC test build
dvdplm Jul 6, 2019
234e986
Baptize the new trait
dvdplm Jul 6, 2019
7eb04e0
Remove resolved TODOs
dvdplm Jul 6, 2019
0cab314
Rename state-account to account-state
dvdplm Jul 6, 2019
a42720b
Do not re-export the trace crate
dvdplm Jul 6, 2019
515abdf
Don't export state_db from ethcore
dvdplm Jul 6, 2019
e3d98b7
Merge branch 'master' into dp/chore/extricate-state-backend
dvdplm Jul 6, 2019
081e678
Let private-tx use StateDB. :(
dvdplm Jul 6, 2019
659440a
Remove ethcore/src/pod_state.rs
dvdplm Jul 6, 2019
2f839f8
Inner type does not need to be pub/pub(crate)
dvdplm Jul 7, 2019
df23dcc
optimise imports
dvdplm Jul 7, 2019
e23cb6a
Revert "Inner type does not need to be pub/pub(crate)"
dvdplm Jul 7, 2019
de2aa80
Move DatabaseExtras to ethcore-blockchain
dvdplm Jul 7, 2019
b4ea86a
Add database_extra module to ethcore-blockchain
dvdplm Jul 7, 2019
1cf8254
Merge branch 'master' into dp/chore/extricate-state-backend
dvdplm Jul 7, 2019
a57517c
Remove to-pod-full feature
dvdplm Jul 7, 2019
5a28340
cosmetics
dvdplm Jul 8, 2019
40aef44
New crate: state-db
dvdplm Jul 8, 2019
0b1a692
Add new crate
dvdplm Jul 8, 2019
75efc47
Merge branch 'master' into dp/chore/extricate-state-backend
dvdplm Jul 8, 2019
994424e
Sort out the merge
dvdplm Jul 8, 2019
cd9167e
Merge branch 'dp/chore/extricate-state-backend' into dp/chore/extract…
dvdplm Jul 8, 2019
d51cede
Merge branch 'master' into dp/chore/extract-state-db
dvdplm Jul 8, 2019
38d4c09
Fix unclean merge
dvdplm Jul 8, 2019
1bf91f2
Add license
dvdplm Jul 8, 2019
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
24 changes: 24 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions ethcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ serde = "1.0"
serde_derive = "1.0"
account-state = { path = "account-state" }
stats = { path = "../util/stats" }
state-db = { path = "state-db" }
tempdir = { version = "0.3", optional = true }
time-utils = { path = "../util/time-utils" }
trace = { path = "trace" }
Expand Down
3 changes: 2 additions & 1 deletion ethcore/private-tx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ license = "GPL-3.0"
authors = ["Parity Technologies <[email protected]>"]

[dependencies]
account-state = { path = "../account-state" }
common-types = { path = "../types" }
derive_more = "0.14.0"
ethabi = "8.0"
Expand Down Expand Up @@ -35,7 +36,7 @@ rustc-hex = "1.0"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
account-state = { path = "../account-state" }
state-db = { path = "../state-db" }
time-utils = { path = "../../util/time-utils" }
tiny-keccak = "1.4"
trace = { path = "../trace" }
Expand Down
5 changes: 3 additions & 2 deletions ethcore/private-tx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ mod messages;
mod error;
mod log;

extern crate account_state;
extern crate common_types as types;
extern crate ethabi;
extern crate ethcore;
Expand All @@ -46,8 +47,8 @@ extern crate rlp;
extern crate serde_derive;
extern crate serde;
extern crate serde_json;
extern crate account_state;
extern crate rustc_hex;
extern crate state_db;
extern crate trace;
extern crate transaction_pool as txpool;
extern crate url;
Expand Down Expand Up @@ -94,7 +95,7 @@ use ethcore::client::{
Call, BlockInfo
};
use ethcore::miner::{self, Miner, MinerService, pool_client::NonceCache};
use ethcore::StateDB;
use state_db::StateDB;
use account_state::State;
use trace::{Tracer, VMTracer};
use call_contract::CallContract;
Expand Down
4 changes: 2 additions & 2 deletions ethcore/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ impl ClientService {
let snapshot_params = SnapServiceParams {
engine: spec.engine.clone(),
genesis_block: spec.genesis_block(),
restoration_db_handler: restoration_db_handler,
pruning: pruning,
restoration_db_handler,
pruning,
channel: io_service.channel(),
snapshot_root: snapshot_path.into(),
client: client.clone(),
Expand Down
5 changes: 2 additions & 3 deletions ethcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
//! ```

extern crate account_db;
extern crate account_state;
extern crate ansi_term;
extern crate common_types as types;
extern crate crossbeam_utils;
Expand Down Expand Up @@ -97,8 +98,8 @@ extern crate parity_util_mem;
extern crate parity_util_mem as malloc_size_of;
extern crate rustc_hex;
extern crate serde;
extern crate state_db;
extern crate stats;
extern crate account_state;
extern crate time_utils;
extern crate trace;
extern crate triehash_ethereum as triehash;
Expand Down Expand Up @@ -163,7 +164,6 @@ pub mod spec;
pub mod verification;

mod externalities;
mod state_db;
mod transaction_ext;
mod tx_filter;

Expand All @@ -177,4 +177,3 @@ pub mod test_helpers;
pub use executive::contract_address;
pub use evm::CreateContractAddress;
pub use trie::TrieSpec;
pub use state_db::StateDB;
4 changes: 2 additions & 2 deletions ethcore/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ impl Machine {
pub fn regular(params: CommonParams, builtins: BTreeMap<Address, Builtin>) -> Machine {
let tx_filter = TransactionFilter::from_params(&params).map(Arc::new);
Machine {
params: params,
params,
builtins: Arc::new(builtins),
tx_filter: tx_filter,
tx_filter,
ethash_extensions: None,
schedule_rules: None,
}
Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/spec/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,8 @@ fn load_from(spec_params: SpecParams, s: ethjson::spec::Spec) -> Result<Spec, Er
gas_used: g.gas_used,
timestamp: g.timestamp,
extra_data: g.extra_data,
seal_rlp: seal_rlp,
hardcoded_sync: hardcoded_sync,
seal_rlp,
hardcoded_sync,
constructors: s.accounts
.constructors()
.into_iter()
Expand Down
28 changes: 28 additions & 0 deletions ethcore/state-db/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
description = "State database"
name = "state-db"
version = "0.1.0"
authors = ["Parity Technologies <[email protected]>"]
license = "GPL-3.0"
edition = "2018"

[dependencies]
account-state = { path = "../account-state" }
bloom_journal = { package = "ethcore-bloom-journal", path = "../../util/bloom" }
common-types = { path = "../types"}
ethcore-db = { path = "../db" }
ethereum-types = "0.6.0"
hash-db = "0.12.4"
keccak-hash = "0.2.0"
keccak-hasher = { path = "../../util/keccak-hasher" }
journaldb = { path = "../../util/journaldb" }
kvdb = "0.1.0"
log = "0.4.6"
lru-cache = "0.1.2"
memory-cache = { path = "../../util/memory-cache" }
parking_lot = "0.8.0"

[dev-dependencies]
env_logger = "0.5"
# Used for test helpers
ethcore = { path = "..", features = ["test-helpers"] }
44 changes: 23 additions & 21 deletions ethcore/src/state_db.rs → ethcore/state-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,25 @@

//! State database abstraction. For more info, see the doc for `StateDB`

use std::collections::{VecDeque, HashSet};
use std::collections::{HashSet, VecDeque};
use std::io;
use std::sync::Arc;

use bloom_journal::{Bloom, BloomJournal};
use db::COL_ACCOUNT_BLOOM;
use ethereum_types::{H256, Address};
use hash::keccak;
use ethereum_types::{Address, H256};
use hash_db::HashDB;
use journaldb::JournalDB;
use keccak_hasher::KeccakHasher;
use kvdb::{KeyValueDB, DBTransaction, DBValue};
use keccak_hash::keccak;
use kvdb::{DBTransaction, DBValue, KeyValueDB};
use log::trace;
use lru_cache::LruCache;
use memory_cache::MemoryLruCache;
use parking_lot::Mutex;
use types::BlockNumber;

use account_state::{self, Account};
use bloom_journal::{Bloom, BloomJournal};
use common_types::BlockNumber;
use ethcore_db::COL_ACCOUNT_BLOOM;
use journaldb::JournalDB;
use keccak_hasher::KeccakHasher;
use memory_cache::MemoryLruCache;

/// Value used to initialize bloom bitmap size.
///
Expand Down Expand Up @@ -68,7 +69,7 @@ struct AccountCache {
struct CacheQueueItem {
/// Account address.
address: Address,
/// Acccount data or `None` if account does not exist.
/// Account data or `None` if account does not exist.
account: SyncAccount,
/// Indicates that the account was modified before being
/// added to the cache.
Expand Down Expand Up @@ -143,23 +144,23 @@ impl StateDB {
let cache_items = acc_cache_size / ::std::mem::size_of::<Option<Account>>();

StateDB {
db: db,
db,
account_cache: Arc::new(Mutex::new(AccountCache {
accounts: LruCache::new(cache_items),
modifications: VecDeque::new(),
})),
code_cache: Arc::new(Mutex::new(MemoryLruCache::new(code_cache_size))),
local_cache: Vec::new(),
account_bloom: Arc::new(Mutex::new(bloom)),
cache_size: cache_size,
cache_size,
parent_hash: None,
commit_hash: None,
commit_number: None,
}
}

/// Loads accounts bloom from the database
/// This bloom is used to handle request for the non-existant account fast
/// This bloom is used to handle request for the non-existent account fast
pub fn load_bloom(db: &dyn KeyValueDB) -> Bloom {
let hash_count_entry = db.get(COL_ACCOUNT_BLOOM, ACCOUNT_BLOOM_HASHCOUNT_KEY)
.expect("Low-level database error");
Expand All @@ -177,7 +178,7 @@ impl StateDB {
let key: [u8; 8] = (i as u64).to_le_bytes();
bloom_parts[i] = db.get(COL_ACCOUNT_BLOOM, &key).expect("low-level database error")
.map(|val| {
assert!(val.len() == 8, "low-level database error");
assert_eq!(val.len(), 8, "low-level database error");
let mut buff = [0u8; 8];
buff.copy_from_slice(&*val);
u64::from_le_bytes(buff)
Expand Down Expand Up @@ -233,7 +234,7 @@ impl StateDB {
let cache = &mut *cache;

// Purge changes from re-enacted and retracted blocks.
// Filter out commiting block if any.
// Filter out committing block if any.
let mut clear = false;
for block in enacted.iter().filter(|h| self.commit_hash.as_ref().map_or(true, |p| *h != p)) {
clear = clear || {
Expand Down Expand Up @@ -419,11 +420,11 @@ impl account_state::Backend for StateDB {
self.db.as_hash_db_mut()
}

fn add_to_account_cache(&mut self, addr: Address, data: Option<Account>, modified: bool) {
fn add_to_account_cache(&mut self, address: Address, data: Option<Account>, modified: bool) {
self.local_cache.push(CacheQueueItem {
address: addr,
address,
account: SyncAccount(data),
modified: modified,
modified,
})
}

Expand Down Expand Up @@ -484,10 +485,11 @@ unsafe impl Sync for SyncAccount {}

#[cfg(test)]
mod tests {
use ethereum_types::{H256, U256, Address};
use ethereum_types::{Address, H256, U256};
use kvdb::DBTransaction;
use test_helpers::get_temp_state_db;

use account_state::{Account, Backend};
use ethcore::test_helpers::get_temp_state_db;

#[test]
fn state_db_smoke() {
Expand Down