Remove calls to heapsize (#10432)

* update memorydb trait
* use malloc_size_of instead of heapsize_of
* use jemalloc as default allocator for parity client.
This commit is contained in:
cheme
2019-06-19 13:54:05 +02:00
committed by GitHub
parent 859a41308c
commit 6fc5014b4d
84 changed files with 926 additions and 1074 deletions

View File

@@ -364,7 +364,7 @@ impl Account {
if self.is_cached() { return Some(self.code_cache.clone()); }
match db.get(&self.code_hash) {
match db.get(&self.code_hash, hash_db::EMPTY_PREFIX) {
Some(x) => {
self.code_size = Some(x.len());
self.code_cache = Arc::new(x.into_vec());
@@ -393,7 +393,7 @@ impl Account {
trace!("Account::cache_code_size: ic={}; self.code_hash={:?}, self.code_cache={}", self.is_cached(), self.code_hash, self.code_cache.pretty());
self.code_size.is_some() ||
if self.code_hash != KECCAK_EMPTY {
match db.get(&self.code_hash) {
match db.get(&self.code_hash, hash_db::EMPTY_PREFIX) {
Some(x) => {
self.code_size = Some(x.len());
true
@@ -507,7 +507,7 @@ impl Account {
self.code_filth = Filth::Clean;
},
(true, false) => {
db.emplace(self.code_hash.clone(), DBValue::from_slice(&*self.code_cache));
db.emplace(self.code_hash.clone(), hash_db::EMPTY_PREFIX, DBValue::from_slice(&*self.code_cache));
self.code_size = Some(self.code_cache.len());
self.code_filth = Filth::Clean;
},

View File

@@ -27,8 +27,8 @@ use std::sync::Arc;
use state::Account;
use parking_lot::Mutex;
use ethereum_types::{Address, H256};
use memory_db::MemoryDB;
use hash_db::{AsHashDB, HashDB};
use memory_db::{MemoryDB, HashKey};
use hash_db::{AsHashDB, HashDB, Prefix, EMPTY_PREFIX};
use kvdb::DBValue;
use keccak_hasher::KeccakHasher;
use journaldb::AsKeyedHashDB;
@@ -78,13 +78,13 @@ pub trait Backend: Send {
// TODO: when account lookup moved into backends, this won't rely as tenuously on intended
// usage.
#[derive(Clone, PartialEq)]
pub struct ProofCheck(MemoryDB<KeccakHasher, DBValue>);
pub struct ProofCheck(MemoryDB<KeccakHasher, HashKey<KeccakHasher>, DBValue>);
impl ProofCheck {
/// Create a new `ProofCheck` backend from the given state items.
pub fn new(proof: &[DBValue]) -> Self {
let mut db = journaldb::new_memory_db();
for item in proof { db.insert(item); }
for item in proof { db.insert(EMPTY_PREFIX, item); }
ProofCheck(db)
}
}
@@ -94,23 +94,23 @@ impl journaldb::KeyedHashDB for ProofCheck {
}
impl HashDB<KeccakHasher, DBValue> for ProofCheck {
fn get(&self, key: &H256) -> Option<DBValue> {
self.0.get(key)
fn get(&self, key: &H256, prefix: Prefix) -> Option<DBValue> {
self.0.get(key, prefix)
}
fn contains(&self, key: &H256) -> bool {
self.0.contains(key)
fn contains(&self, key: &H256, prefix: Prefix) -> bool {
self.0.contains(key, prefix)
}
fn insert(&mut self, value: &[u8]) -> H256 {
self.0.insert(value)
fn insert(&mut self, prefix: Prefix, value: &[u8]) -> H256 {
self.0.insert(prefix, value)
}
fn emplace(&mut self, key: H256, value: DBValue) {
self.0.emplace(key, value)
fn emplace(&mut self, key: H256, prefix: Prefix, value: DBValue) {
self.0.emplace(key, prefix, value)
}
fn remove(&mut self, _key: &H256) { }
fn remove(&mut self, _key: &H256, _prefix: Prefix) { }
}
impl AsHashDB<KeccakHasher, DBValue> for ProofCheck {
@@ -141,7 +141,7 @@ impl Backend for ProofCheck {
/// This doesn't cache anything or rely on the canonical state caches.
pub struct Proving<H> {
base: H, // state we're proving values from.
changed: MemoryDB<KeccakHasher, DBValue>, // changed state via insertions.
changed: MemoryDB<KeccakHasher, HashKey<KeccakHasher>, DBValue>, // changed state via insertions.
proof: Mutex<HashSet<DBValue>>,
}
@@ -163,32 +163,32 @@ impl<H: AsKeyedHashDB + Send + Sync> journaldb::KeyedHashDB for Proving<H> {
}
impl<H: AsHashDB<KeccakHasher, DBValue> + Send + Sync> HashDB<KeccakHasher, DBValue> for Proving<H> {
fn get(&self, key: &H256) -> Option<DBValue> {
match self.base.as_hash_db().get(key) {
fn get(&self, key: &H256, prefix: Prefix) -> Option<DBValue> {
match self.base.as_hash_db().get(key, prefix) {
Some(val) => {
self.proof.lock().insert(val.clone());
Some(val)
}
None => self.changed.get(key)
None => self.changed.get(key, prefix)
}
}
fn contains(&self, key: &H256) -> bool {
self.get(key).is_some()
fn contains(&self, key: &H256, prefix: Prefix) -> bool {
self.get(key, prefix).is_some()
}
fn insert(&mut self, value: &[u8]) -> H256 {
self.changed.insert(value)
fn insert(&mut self, prefix: Prefix, value: &[u8]) -> H256 {
self.changed.insert(prefix, value)
}
fn emplace(&mut self, key: H256, value: DBValue) {
self.changed.emplace(key, value)
fn emplace(&mut self, key: H256, prefix: Prefix, value: DBValue) {
self.changed.emplace(key, prefix, value)
}
fn remove(&mut self, key: &H256) {
fn remove(&mut self, key: &H256, prefix: Prefix) {
// only remove from `changed`
if self.changed.contains(key) {
self.changed.remove(key)
if self.changed.contains(key, prefix) {
self.changed.remove(key, prefix)
}
}
}

View File

@@ -381,7 +381,7 @@ impl<B: Backend> State<B> {
/// Creates new state with existing state root
pub fn from_existing(db: B, root: H256, account_start_nonce: U256, factories: Factories) -> TrieResult<State<B>> {
if !db.as_hash_db().contains(&root) {
if !db.as_hash_db().contains(&root, hash_db::EMPTY_PREFIX) {
return Err(Box::new(TrieError::InvalidStateRoot(root)));
}