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:
@@ -95,7 +95,7 @@ pub fn to_fat_rlps(
|
||||
} else if used_code.contains(&acc.code_hash) {
|
||||
account_stream.append(&CodeState::Hash.raw()).append(&acc.code_hash);
|
||||
} else {
|
||||
match acct_db.get(&acc.code_hash) {
|
||||
match acct_db.get(&acc.code_hash, hash_db::EMPTY_PREFIX) {
|
||||
Some(c) => {
|
||||
used_code.insert(acc.code_hash.clone());
|
||||
account_stream.append(&CodeState::Inline.raw()).append(&&*c);
|
||||
@@ -182,7 +182,7 @@ pub fn from_fat_rlp(
|
||||
CodeState::Empty => (KECCAK_EMPTY, None),
|
||||
CodeState::Inline => {
|
||||
let code: Bytes = rlp.val_at(3)?;
|
||||
let code_hash = acct_db.insert(&code);
|
||||
let code_hash = acct_db.insert(hash_db::EMPTY_PREFIX, &code);
|
||||
|
||||
(code_hash, Some(code))
|
||||
}
|
||||
@@ -228,7 +228,7 @@ mod tests {
|
||||
|
||||
use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP, keccak};
|
||||
use ethereum_types::{H256, Address};
|
||||
use hash_db::HashDB;
|
||||
use hash_db::{HashDB, EMPTY_PREFIX};
|
||||
use kvdb::DBValue;
|
||||
use rlp::Rlp;
|
||||
|
||||
@@ -324,12 +324,12 @@ mod tests {
|
||||
|
||||
let code_hash = {
|
||||
let mut acct_db = AccountDBMut::new(db.as_hash_db_mut(), &addr1);
|
||||
acct_db.insert(b"this is definitely code")
|
||||
acct_db.insert(EMPTY_PREFIX, b"this is definitely code")
|
||||
};
|
||||
|
||||
{
|
||||
let mut acct_db = AccountDBMut::new(db.as_hash_db_mut(), &addr2);
|
||||
acct_db.emplace(code_hash.clone(), DBValue::from_slice(b"this is definitely code"));
|
||||
acct_db.emplace(code_hash.clone(), EMPTY_PREFIX, DBValue::from_slice(b"this is definitely code"));
|
||||
}
|
||||
|
||||
let account1 = BasicAccount {
|
||||
|
||||
@@ -448,7 +448,7 @@ impl StateRebuilder {
|
||||
for (code_hash, code, first_with) in status.new_code {
|
||||
for addr_hash in self.missing_code.remove(&code_hash).unwrap_or_else(Vec::new) {
|
||||
let mut db = AccountDBMut::from_hash(self.db.as_hash_db_mut(), addr_hash);
|
||||
db.emplace(code_hash, DBValue::from_slice(&code));
|
||||
db.emplace(code_hash, hash_db::EMPTY_PREFIX, DBValue::from_slice(&code));
|
||||
}
|
||||
|
||||
self.known_code.insert(code_hash, first_with);
|
||||
@@ -545,11 +545,11 @@ fn rebuild_accounts(
|
||||
Some(&first_with) => {
|
||||
// if so, load it from the database.
|
||||
let code = AccountDB::from_hash(db, first_with)
|
||||
.get(&code_hash)
|
||||
.get(&code_hash, hash_db::EMPTY_PREFIX)
|
||||
.ok_or_else(|| Error::MissingCode(vec![first_with]))?;
|
||||
|
||||
// and write it again under a different mangled key
|
||||
AccountDBMut::from_hash(db, hash).emplace(code_hash, code);
|
||||
AccountDBMut::from_hash(db, hash).emplace(code_hash, hash_db::EMPTY_PREFIX, code);
|
||||
}
|
||||
// if not, queue it up to be filled later
|
||||
None => status.missing_code.push((hash, code_hash)),
|
||||
|
||||
@@ -40,7 +40,7 @@ const RNG_SEED: [u8; 16] = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16];
|
||||
|
||||
#[test]
|
||||
fn snap_and_restore() {
|
||||
use hash_db::HashDB;
|
||||
use hash_db::{HashDB, EMPTY_PREFIX};
|
||||
let mut producer = StateProducer::new();
|
||||
let mut rng = XorShiftRng::from_seed(RNG_SEED);
|
||||
let mut old_db = journaldb::new_memory_db();
|
||||
@@ -97,7 +97,7 @@ fn snap_and_restore() {
|
||||
let keys = old_db.keys();
|
||||
|
||||
for key in keys.keys() {
|
||||
assert_eq!(old_db.get(&key).unwrap(), new_db.as_hash_db().get(&key).unwrap());
|
||||
assert_eq!(old_db.get(&key, EMPTY_PREFIX).unwrap(), new_db.as_hash_db().get(&key, EMPTY_PREFIX).unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ fn get_code_from_prev_chunk() {
|
||||
use std::collections::HashSet;
|
||||
use rlp::RlpStream;
|
||||
use ethereum_types::{H256, U256};
|
||||
use hash_db::HashDB;
|
||||
use hash_db::{HashDB, EMPTY_PREFIX};
|
||||
|
||||
use account_db::{AccountDBMut, AccountDB};
|
||||
|
||||
@@ -128,7 +128,7 @@ fn get_code_from_prev_chunk() {
|
||||
|
||||
let mut make_chunk = |acc, hash| {
|
||||
let mut db = journaldb::new_memory_db();
|
||||
AccountDBMut::from_hash(&mut db, hash).insert(&code[..]);
|
||||
AccountDBMut::from_hash(&mut db, hash).insert(EMPTY_PREFIX, &code[..]);
|
||||
let p = Progress::default();
|
||||
let fat_rlp = account::to_fat_rlps(&hash, &acc, &AccountDB::from_hash(&db, hash), &mut used_code, usize::max_value(), usize::max_value(), &p).unwrap();
|
||||
let mut stream = RlpStream::new_list(1);
|
||||
|
||||
Reference in New Issue
Block a user