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

Update to latest trie version. #10972

Merged
merged 20 commits into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Switch to 'trie' crates, there is an unpublished deps to staging
parity-common triehash still.
  • Loading branch information
cheme committed Feb 7, 2019
commit a9d65b105026ab575672b3cbf8b316141669a71e
106 changes: 58 additions & 48 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions ethcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ethjson = { path = "../json" }
ethkey = { path = "../accounts/ethkey" }
ethstore = { path = "../accounts/ethstore" }
evm = { path = "evm" }
hashdb = "0.3.0"
hash-db = "0.11.0"
heapsize = "0.4"
itertools = "0.5"
journaldb = { path = "../util/journaldb" }
Expand All @@ -46,15 +46,15 @@ log = "0.4"
lru-cache = "0.1"
macros = { path = "../util/macros" }
memory-cache = { path = "../util/memory-cache" }
memorydb = "0.3.0"
memory-db = "0.11.0"
num = { version = "0.1", default-features = false, features = ["bigint"] }
num_cpus = "1.2"
parity-bytes = "0.1"
parity-crypto = "0.3.0"
parity-machine = { path = "../machine" }
parity-snappy = "0.1"
parking_lot = "0.7"
patricia-trie = "0.3.0"
trie-db = "0.11.0"
patricia-trie-ethereum = { path = "../util/patricia-trie-ethereum" }
rand = "0.4"
rayon = "1.0"
Expand Down
7 changes: 4 additions & 3 deletions ethcore/light/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ ethcore = { path = ".."}
ethcore-db = { path = "../db" }
ethcore-blockchain = { path = "../blockchain" }
ethereum-types = "0.4"
memorydb = "0.3.0"
patricia-trie = "0.3.0"
memory-db = "0.11.0"
trie-db = "0.11.0"
patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" }
ethcore-network = { path = "../../util/network" }
ethcore-io = { path = "../../util/io" }
hashdb = "0.3.0"
hash-db = "0.11.0"
heapsize = "0.4"
vm = { path = "../vm" }
fastmap = { path = "../../util/fastmap" }
Expand All @@ -41,6 +41,7 @@ triehash-ethereum = { version = "0.2", path = "../../util/triehash-ethereum" }
kvdb = "0.1"
memory-cache = { path = "../../util/memory-cache" }
error-chain = { version = "0.12", default-features = false }
journaldb = { path = "../../util/journaldb" }

[dev-dependencies]
ethcore = { path = "..", features = ["test-helpers"] }
Expand Down
12 changes: 7 additions & 5 deletions ethcore/light/src/cht.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@

use common_types::ids::BlockId;
use ethereum_types::{H256, U256};
use hashdb::HashDB;
use hash_db::HashDB;
use keccak_hasher::KeccakHasher;
use kvdb::DBValue;
use memorydb::MemoryDB;
use memory_db::MemoryDB;
use journaldb::new_memory_db;
use bytes::Bytes;
use trie::{TrieMut, Trie, Recorder};
use ethtrie::{self, TrieDB, TrieDBMut};
Expand Down Expand Up @@ -73,7 +74,8 @@ impl<DB: HashDB<KeccakHasher, DBValue>> CHT<DB> {
if block_to_cht_number(num) != Some(self.number) { return Ok(None) }

let mut recorder = Recorder::with_depth(from_level);
let t = TrieDB::new(&self.db, &self.root)?;
let db: &HashDB<_,_> = &self.db;
let t = TrieDB::new(&db, &self.root)?;
t.get_with(&key!(num), &mut recorder)?;

Ok(Some(recorder.drain().into_iter().map(|x| x.data).collect()))
Expand All @@ -96,7 +98,7 @@ pub struct BlockInfo {
pub fn build<F>(cht_num: u64, mut fetcher: F) -> Option<CHT<MemoryDB<KeccakHasher, DBValue>>>
where F: FnMut(BlockId) -> Option<BlockInfo>
{
let mut db = MemoryDB::<KeccakHasher, DBValue>::new();
let mut db = new_memory_db();

// start from the last block by number and work backwards.
let last_num = start_number(cht_num + 1) - 1;
Expand Down Expand Up @@ -150,7 +152,7 @@ pub fn compute_root<I>(cht_num: u64, iterable: I) -> Option<H256>
/// verify the given trie branch and extract the canonical hash and total difficulty.
// TODO: better support for partially-checked queries.
pub fn check_proof(proof: &[Bytes], num: u64, root: H256) -> Option<(H256, U256)> {
let mut db = MemoryDB::<KeccakHasher, DBValue>::new();
let mut db = new_memory_db();

for node in proof { db.insert(&node[..]); }
let res = match TrieDB::new(&db, &root) {
Expand Down
7 changes: 4 additions & 3 deletions ethcore/light/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ extern crate ethcore_network as network;
extern crate parity_bytes as bytes;
extern crate ethereum_types;
extern crate ethcore;
extern crate hashdb;
extern crate hash_db;
extern crate heapsize;
extern crate failsafe;
extern crate futures;
extern crate itertools;
extern crate keccak_hasher;
extern crate memorydb;
extern crate patricia_trie as trie;
extern crate memory_db;
extern crate trie_db as trie;
extern crate patricia_trie_ethereum as ethtrie;
extern crate fastmap;
extern crate rand;
Expand All @@ -92,3 +92,4 @@ extern crate error_chain;
extern crate kvdb_memorydb;
#[cfg(test)]
extern crate tempdir;
extern crate journaldb;
8 changes: 3 additions & 5 deletions ethcore/light/src/on_demand/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ use ethcore::state::{self, ProvedExecution};
use ethereum_types::{H256, U256, Address};
use ethtrie::{TrieError, TrieDB};
use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY, KECCAK_EMPTY_LIST_RLP, keccak};
use hashdb::HashDB;
use hash_db::HashDB;
use kvdb::DBValue;
use memorydb::MemoryDB;
use parking_lot::Mutex;
use request::{self as net_request, IncompleteRequest, CompleteRequest, Output, OutputKind, Field};
use rlp::{RlpStream, Rlp};
Expand Down Expand Up @@ -981,7 +980,7 @@ impl Account {
let header = self.header.as_ref()?;
let state_root = header.state_root();

let mut db = MemoryDB::new();
let mut db = journaldb::new_memory_db();
for node in proof { db.insert(&node[..]); }

match TrieDB::new(&db, &state_root).and_then(|t| t.get(&keccak(&self.address)))? {
Expand Down Expand Up @@ -1101,7 +1100,6 @@ mod tests {
use super::*;
use std::time::Duration;
use ethereum_types::{H256, Address};
use memorydb::MemoryDB;
use parking_lot::Mutex;
use trie::{Trie, TrieMut};
use ethtrie::{SecTrieDB, SecTrieDBMut};
Expand Down Expand Up @@ -1281,7 +1279,7 @@ mod tests {
use rlp::RlpStream;

let mut root = H256::default();
let mut db = MemoryDB::new();
let mut db = journaldb::new_memory_db();
let mut header = Header::new();
header.set_number(123_456);
header.set_extra_data(b"test_header".to_vec());
Expand Down
2 changes: 1 addition & 1 deletion ethcore/private-tx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ log = "0.4"
parity-bytes = "0.1"
parity-crypto = "0.3.0"
parking_lot = "0.7"
patricia-trie = "0.3.0"
trie-db = "0.11.0"
patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" }
rand = "0.3"
rlp = { version = "0.3.0", features = ["ethereum"] }
Expand Down
2 changes: 1 addition & 1 deletion ethcore/private-tx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern crate keccak_hash as hash;
extern crate parity_bytes as bytes;
extern crate parity_crypto as crypto;
extern crate parking_lot;
extern crate patricia_trie as trie;
extern crate trie_db as trie;
extern crate patricia_trie_ethereum as ethtrie;
extern crate rlp;
extern crate rustc_hex;
Expand Down
35 changes: 9 additions & 26 deletions ethcore/src/account_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
//! DB backend wrapper for Account trie
use ethereum_types::H256;
use hash::{KECCAK_NULL_RLP, keccak};
use hashdb::{HashDB, AsHashDB};
use hash_db::{HashDB, AsHashDB};
use keccak_hasher::KeccakHasher;
use kvdb::DBValue;
use rlp::NULL_RLP;
use std::collections::HashMap;

#[cfg(test)]
use ethereum_types::Address;
Expand Down Expand Up @@ -99,15 +98,11 @@ impl<'db> AccountDB<'db> {
}

impl<'db> AsHashDB<KeccakHasher, DBValue> for AccountDB<'db> {
fn as_hashdb(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
}

impl<'db> HashDB<KeccakHasher, DBValue> for AccountDB<'db> {
fn keys(&self) -> HashMap<H256, i32> {
unimplemented!()
}

fn get(&self, key: &H256) -> Option<DBValue> {
if key == &KECCAK_NULL_RLP {
return Some(DBValue::from_slice(&NULL_RLP));
Expand Down Expand Up @@ -163,10 +158,6 @@ impl<'db> AccountDBMut<'db> {
}

impl<'db> HashDB<KeccakHasher, DBValue> for AccountDBMut<'db>{
fn keys(&self) -> HashMap<H256, i32> {
unimplemented!()
}

fn get(&self, key: &H256) -> Option<DBValue> {
if key == &KECCAK_NULL_RLP {
return Some(DBValue::from_slice(&NULL_RLP));
Expand Down Expand Up @@ -209,22 +200,18 @@ impl<'db> HashDB<KeccakHasher, DBValue> for AccountDBMut<'db>{
}

impl<'db> AsHashDB<KeccakHasher, DBValue> for AccountDBMut<'db> {
fn as_hashdb(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
}

struct Wrapping<'db>(&'db HashDB<KeccakHasher, DBValue>);

impl<'db> AsHashDB<KeccakHasher, DBValue> for Wrapping<'db> {
fn as_hashdb(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
}

impl<'db> HashDB<KeccakHasher, DBValue> for Wrapping<'db> {
fn keys(&self) -> HashMap<H256, i32> {
unimplemented!()
}

fn get(&self, key: &H256) -> Option<DBValue> {
if key == &KECCAK_NULL_RLP {
return Some(DBValue::from_slice(&NULL_RLP));
Expand Down Expand Up @@ -254,15 +241,11 @@ impl<'db> HashDB<KeccakHasher, DBValue> for Wrapping<'db> {

struct WrappingMut<'db>(&'db mut HashDB<KeccakHasher, DBValue>);
impl<'db> AsHashDB<KeccakHasher, DBValue> for WrappingMut<'db> {
fn as_hashdb(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
}

impl<'db> HashDB<KeccakHasher, DBValue> for WrappingMut<'db>{
fn keys(&self) -> HashMap<H256, i32> {
unimplemented!()
}

fn get(&self, key: &H256) -> Option<DBValue> {
if key == &KECCAK_NULL_RLP {
return Some(DBValue::from_slice(&NULL_RLP));
Expand Down
14 changes: 8 additions & 6 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,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_hashdb_mut());
let backend = ::state::backend::Proving::new(state_db.as_hash_db_mut());

let transaction =
client.contract_call_tx(BlockId::Hash(*header.parent_hash()), addr, data);
Expand Down Expand Up @@ -1178,7 +1178,7 @@ impl Client {
};

let processing_threads = self.config.snapshot.processing_threads;
snapshot::take_snapshot(&*self.engine, &self.chain.read(), start_hash, db.as_hashdb(), writer, p, processing_threads)?;
snapshot::take_snapshot(&*self.engine, &self.chain.read(), start_hash, db.as_hash_db(), writer, p, processing_threads)?;

Ok(())
}
Expand Down Expand Up @@ -1783,7 +1783,8 @@ impl BlockChainClient for Client {
};

let (root, db) = state.drop();
let trie = match self.factories.trie.readonly(db.as_hashdb(), &root) {
let db = &db.as_hash_db();
let trie = match self.factories.trie.readonly(db, &root) {
Ok(trie) => trie,
_ => {
trace!(target: "fatdb", "list_accounts: Couldn't open the DB");
Expand Down Expand Up @@ -1829,8 +1830,9 @@ impl BlockChainClient for Client {
};

let (_, db) = state.drop();
let account_db = self.factories.accountdb.readonly(db.as_hashdb(), keccak(account));
let trie = match self.factories.trie.readonly(account_db.as_hashdb(), &root) {
let account_db = &self.factories.accountdb.readonly(db.as_hash_db(), keccak(account));
let account_db = &account_db.as_hash_db();
let trie = match self.factories.trie.readonly(account_db, &root) {
Ok(trie) => trie,
_ => {
trace!(target: "fatdb", "list_storage: Couldn't open the DB");
Expand Down Expand Up @@ -2488,7 +2490,7 @@ impl ProvingBlockChainClient for Client {
let mut jdb = self.state_db.read().journal_db().boxed_clone();

state::prove_transaction_virtual(
jdb.as_hashdb_mut(),
jdb.as_hash_db_mut(),
header.state_root().clone(),
&transaction,
self.engine.machine(),
Expand Down
5 changes: 1 addition & 4 deletions ethcore/src/json_tests/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ use ethjson;
use trie::{TrieFactory, TrieSpec};
use ethtrie::RlpCodec;
use ethereum_types::H256;
use memorydb::MemoryDB;
use keccak_hasher::KeccakHasher;
use kvdb::DBValue;

use super::HookType;

Expand All @@ -37,7 +34,7 @@ fn test_trie<H: FnMut(&str, HookType)>(json: &[u8], trie: TrieSpec, start_stop_h
for (name, test) in tests.into_iter() {
start_stop_hook(&name, HookType::OnStart);

let mut memdb = MemoryDB::<KeccakHasher, DBValue>::new();
let mut memdb = journaldb::new_memory_db();
let mut root = H256::default();
let mut t = factory.create(&mut memdb, &mut root);

Expand Down
6 changes: 3 additions & 3 deletions ethcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ extern crate ethereum_types;
extern crate ethjson;
extern crate ethkey;
extern crate ethstore;
extern crate hashdb;
extern crate hash_db;
extern crate heapsize;
extern crate itertools;
extern crate journaldb;
Expand All @@ -85,15 +85,15 @@ extern crate kvdb_memorydb;
extern crate len_caching_lock;
extern crate lru_cache;
extern crate memory_cache;
extern crate memorydb;
extern crate memory_db;
extern crate num;
extern crate num_cpus;
extern crate parity_bytes as bytes;
extern crate parity_crypto;
extern crate parity_machine;
extern crate parity_snappy as snappy;
extern crate parking_lot;
extern crate patricia_trie as trie;
extern crate trie_db as trie;
extern crate patricia_trie_ethereum as ethtrie;
extern crate rand;
extern crate rayon;
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/pod_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::collections::BTreeMap;
use itertools::Itertools;
use hash::{keccak};
use ethereum_types::{H256, U256};
use hashdb::HashDB;
use hash_db::HashDB;
use kvdb::DBValue;
use keccak_hasher::KeccakHasher;
use triehash::sec_trie_root;
Expand Down
Loading