diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index e5382f07d3..daab045b3f 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -3833,7 +3833,6 @@ dependencies = [ "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)", "kvdb-memorydb 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)", @@ -4253,7 +4252,6 @@ dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", "hash256-std-hasher 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "impl-serde 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4395,7 +4393,6 @@ name = "substrate-state-machine" version = "1.0.0" dependencies = [ "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/substrate/core/client/Cargo.toml b/substrate/core/client/Cargo.toml index f1b7a903ff..f85650eaa1 100644 --- a/substrate/core/client/Cargo.toml +++ b/substrate/core/client/Cargo.toml @@ -11,7 +11,6 @@ log = { version = "0.4", optional = true } parking_lot = { version = "0.7.1", optional = true } hex = { package = "hex-literal", version = "0.1", optional = true } futures = { version = "0.1.17", optional = true } -heapsize = { version = "0.4", optional = true } consensus = { package = "substrate-consensus-common", path = "../consensus/common", optional = true } executor = { package = "substrate-executor", path = "../executor", optional = true } state-machine = { package = "substrate-state-machine", path = "../state-machine", optional = true } @@ -49,7 +48,6 @@ std = [ "log", "hex", "futures", - "heapsize", "executor", "state-machine", "keyring", diff --git a/substrate/core/client/src/cht.rs b/substrate/core/client/src/cht.rs index 13db1c67eb..8002f52b6f 100644 --- a/substrate/core/client/src/cht.rs +++ b/substrate/core/client/src/cht.rs @@ -26,7 +26,6 @@ use std::collections::HashSet; use hash_db; -use heapsize::HeapSizeOf; use trie; use primitives::{H256, convert_hash}; @@ -88,7 +87,7 @@ pub fn build_proof( where Header: HeaderT, Hasher: hash_db::Hasher, - Hasher::Out: Ord + HeapSizeOf, + Hasher::Out: Ord, BlocksI: IntoIterator, HashesI: IntoIterator>>, { @@ -120,7 +119,7 @@ pub fn check_proof( where Header: HeaderT, Hasher: hash_db::Hasher, - Hasher::Out: Ord + HeapSizeOf, + Hasher::Out: Ord, { do_check_proof::(local_root, local_number, remote_hash, move |local_root, local_cht_key| read_proof_check::(local_root, remote_proof, @@ -137,7 +136,7 @@ pub fn check_proof_on_proving_backend( where Header: HeaderT, Hasher: hash_db::Hasher, - Hasher::Out: Ord + HeapSizeOf, + Hasher::Out: Ord, { do_check_proof::(local_root, local_number, remote_hash, |_, local_cht_key| read_proof_check_on_proving_backend::( @@ -154,7 +153,7 @@ fn do_check_proof( where Header: HeaderT, Hasher: hash_db::Hasher, - Hasher::Out: Ord + HeapSizeOf, + Hasher::Out: Ord, F: FnOnce(Hasher::Out, &[u8]) -> ClientResult>>, { let root: Hasher::Out = convert_hash(&local_root); diff --git a/substrate/core/client/src/in_mem.rs b/substrate/core/client/src/in_mem.rs index f6b69287a4..b02fbe462e 100644 --- a/substrate/core/client/src/in_mem.rs +++ b/substrate/core/client/src/in_mem.rs @@ -27,7 +27,6 @@ use runtime_primitives::{Justification, StorageOverlay, ChildrenStorageOverlay}; use state_machine::backend::{Backend as StateBackend, InMemory, Consolidate}; use state_machine::{self, InMemoryChangesTrieStorage, ChangesTrieAnchorBlockId}; use hash_db::Hasher; -use heapsize::HeapSizeOf; use trie::MemoryDB; use consensus::well_known_cache_keys::Id as CacheKeyId; @@ -446,7 +445,7 @@ where Block: BlockT, H: Hasher, - H::Out: HeapSizeOf + Ord, + H::Out: Ord, { type State = InMemory; @@ -532,7 +531,7 @@ pub struct Backend where Block: BlockT, H: Hasher, - H::Out: HeapSizeOf + Ord, + H::Out: Ord, { states: RwLock>>, changes_trie_storage: ChangesTrieStorage, @@ -543,7 +542,7 @@ impl Backend where Block: BlockT, H: Hasher, - H::Out: HeapSizeOf + Ord, + H::Out: Ord, { /// Create a new instance of in-mem backend. pub fn new() -> Backend { @@ -559,7 +558,7 @@ impl backend::AuxStore for Backend where Block: BlockT, H: Hasher, - H::Out: HeapSizeOf + Ord, + H::Out: Ord, { fn insert_aux< 'a, @@ -580,7 +579,7 @@ impl backend::Backend for Backend where Block: BlockT, H: Hasher, - H::Out: HeapSizeOf + Ord, + H::Out: Ord, { type BlockImportOperation = BlockImportOperation; type Blockchain = Blockchain; @@ -682,14 +681,14 @@ impl backend::LocalBackend for Backend where Block: BlockT, H: Hasher, - H::Out: HeapSizeOf + Ord, + H::Out: Ord, {} impl backend::RemoteBackend for Backend where Block: BlockT, H: Hasher, - H::Out: HeapSizeOf + Ord, + H::Out: Ord, { fn is_local_state_available(&self, block: &BlockId) -> bool { self.blockchain.expect_block_number_from_id(block) @@ -699,20 +698,20 @@ where } /// Prunable in-memory changes trie storage. -pub struct ChangesTrieStorage(InMemoryChangesTrieStorage) where H::Out: HeapSizeOf; -impl backend::PrunableStateChangesTrieStorage for ChangesTrieStorage where H::Out: HeapSizeOf { +pub struct ChangesTrieStorage(InMemoryChangesTrieStorage); +impl backend::PrunableStateChangesTrieStorage for ChangesTrieStorage { fn oldest_changes_trie_block(&self, _config: &ChangesTrieConfiguration, _best_finalized: u64) -> u64 { 0 } } -impl state_machine::ChangesTrieRootsStorage for ChangesTrieStorage where H::Out: HeapSizeOf { +impl state_machine::ChangesTrieRootsStorage for ChangesTrieStorage { fn root(&self, anchor: &ChangesTrieAnchorBlockId, block: u64) -> Result, String> { self.0.root(anchor, block) } } -impl state_machine::ChangesTrieStorage for ChangesTrieStorage where H::Out: HeapSizeOf { +impl state_machine::ChangesTrieStorage for ChangesTrieStorage { fn get(&self, key: &H::Out, prefix: &[u8]) -> Result, String> { self.0.get(key, prefix) } diff --git a/substrate/core/client/src/light/backend.rs b/substrate/core/client/src/light/backend.rs index f22ee8a762..52cdb6a626 100644 --- a/substrate/core/client/src/light/backend.rs +++ b/substrate/core/client/src/light/backend.rs @@ -33,7 +33,6 @@ use crate::light::blockchain::{Blockchain, Storage as BlockchainStorage}; use crate::light::fetcher::{Fetcher, RemoteReadRequest}; use hash_db::Hasher; use trie::MemoryDB; -use heapsize::HeapSizeOf; use consensus::well_known_cache_keys; const IN_MEMORY_EXPECT_PROOF: &str = "InMemory state backend has Void error type and always suceeds; qed"; @@ -108,7 +107,7 @@ impl ClientBackend for Backend where S: BlockchainStorage, F: Fetcher, H: Hasher, - H::Out: HeapSizeOf + Ord, + H::Out: Ord, { type BlockImportOperation = ImportOperation; type Blockchain = Blockchain; @@ -222,7 +221,7 @@ where S: BlockchainStorage, F: Fetcher, H: Hasher, - H::Out: HeapSizeOf + Ord, + H::Out: Ord, { fn is_local_state_available(&self, block: &BlockId) -> bool { self.genesis_state.read().is_some() @@ -238,7 +237,7 @@ where F: Fetcher, S: BlockchainStorage, H: Hasher, - H::Out: HeapSizeOf + Ord, + H::Out: Ord, { type State = OnDemandOrGenesisState; @@ -390,7 +389,7 @@ where F: Fetcher, S: BlockchainStorage, H: Hasher, - H::Out: HeapSizeOf + Ord, + H::Out: Ord, { type Error = ClientError; type Transaction = (); diff --git a/substrate/core/client/src/light/call_executor.rs b/substrate/core/client/src/light/call_executor.rs index 0863b17aaa..47c11b93fa 100644 --- a/substrate/core/client/src/light/call_executor.rs +++ b/substrate/core/client/src/light/call_executor.rs @@ -41,7 +41,6 @@ use crate::call_executor::CallExecutor; use crate::error::{Error as ClientError, Result as ClientResult}; use crate::light::fetcher::{Fetcher, RemoteCallRequest}; use executor::{RuntimeVersion, NativeVersion}; -use heapsize::HeapSizeOf; use trie::MemoryDB; /// Call executor that executes methods on remote node, querying execution proof @@ -436,7 +435,7 @@ pub fn check_execution_proof( Header: HeaderT, E: CodeExecutor, H: Hasher, - H::Out: Ord + HeapSizeOf, + H::Out: Ord, { let local_state_root = request.header.state_root(); let root: H::Out = convert_hash(&local_state_root); diff --git a/substrate/core/client/src/light/fetcher.rs b/substrate/core/client/src/light/fetcher.rs index 28df2f8bff..d62930b1ad 100644 --- a/substrate/core/client/src/light/fetcher.rs +++ b/substrate/core/client/src/light/fetcher.rs @@ -22,7 +22,6 @@ use std::marker::PhantomData; use futures::IntoFuture; use hash_db::{HashDB, Hasher}; -use heapsize::HeapSizeOf; use primitives::{ChangesTrieConfiguration, convert_hash}; use runtime_primitives::traits::{As, Block as BlockT, Header as HeaderT, NumberFor}; use state_machine::{CodeExecutor, ChangesTrieRootsStorage, ChangesTrieAnchorBlockId, @@ -188,7 +187,7 @@ impl, F> LightDataChecker ClientResult, u32)>> where H: Hasher, - H::Out: Ord + HeapSizeOf, + H::Out: Ord, { // since we need roots of all changes tries for the range begin..max // => remote node can't use max block greater that one that we have passed @@ -259,7 +258,7 @@ impl, F> LightDataChecker ClientResult<()> where H: Hasher, - H::Out: Ord + HeapSizeOf, + H::Out: Ord, { // all the checks are sharing the same storage let storage = create_proof_check_backend_storage(remote_roots_proof); @@ -309,7 +308,7 @@ impl FetchChecker for LightDataChecker, H: Hasher, - H::Out: Ord + HeapSizeOf, + H::Out: Ord, S: BlockchainStorage, F: Send + Sync, { diff --git a/substrate/core/primitives/Cargo.toml b/substrate/core/primitives/Cargo.toml index 6d50c8be0e..bb1a7edd88 100644 --- a/substrate/core/primitives/Cargo.toml +++ b/substrate/core/primitives/Cargo.toml @@ -31,7 +31,6 @@ regex = {version = "1.1", optional = true } [dev-dependencies] substrate-serializer = { path = "../serializer" } pretty_assertions = "0.6" -heapsize = "0.4" hex-literal = "0.2" rand = "0.6" diff --git a/substrate/core/primitives/src/hash.rs b/substrate/core/primitives/src/hash.rs index f3e3583be5..c63463e32a 100644 --- a/substrate/core/primitives/src/hash.rs +++ b/substrate/core/primitives/src/hash.rs @@ -78,11 +78,4 @@ mod tests { assert!(ser::from_str::("\"0\"").unwrap_err().is_data()); assert!(ser::from_str::("\"10\"").unwrap_err().is_data()); } - - #[test] - fn test_heapsizeof() { - use heapsize::HeapSizeOf; - let h = H256::zero(); - assert_eq!(h.heap_size_of_children(), 0); - } } diff --git a/substrate/core/state-machine/Cargo.toml b/substrate/core/state-machine/Cargo.toml index 171ae15b28..66c94bd208 100644 --- a/substrate/core/state-machine/Cargo.toml +++ b/substrate/core/state-machine/Cargo.toml @@ -8,7 +8,6 @@ edition = "2018" [dependencies] log = "0.4" parking_lot = "0.7.1" -heapsize = "0.4" hash-db = "0.12" trie-db = "0.12" trie-root = "0.12" diff --git a/substrate/core/state-machine/src/backend.rs b/substrate/core/state-machine/src/backend.rs index 14e60b140a..c93935a347 100644 --- a/substrate/core/state-machine/src/backend.rs +++ b/substrate/core/state-machine/src/backend.rs @@ -25,7 +25,6 @@ use hash_db::Hasher; use crate::trie_backend::TrieBackend; use crate::trie_backend_essence::TrieBackendStorage; use trie::{TrieDBMut, TrieMut, MemoryDB, trie_root, child_trie_root, default_child_trie_root}; -use heapsize::HeapSizeOf; /// A state backend is used to read state data and can have changes committed /// to it. @@ -165,7 +164,7 @@ impl PartialEq for InMemory { } } -impl InMemory where H::Out: HeapSizeOf { +impl InMemory { /// Copy the state, with applied updates pub fn update(&self, changes: >::Transaction) -> Self { let mut inner: HashMap<_, _> = self.inner.clone(); @@ -214,7 +213,7 @@ impl From>, Vec, Option>)>> for InMemory { impl super::Error for Void {} -impl Backend for InMemory where H::Out: HeapSizeOf { +impl Backend for InMemory { type Error = Void; type Transaction = Vec<(Option>, Vec, Option>)>; type TrieBackendStorage = MemoryDB; @@ -313,7 +312,6 @@ impl Backend for InMemory where H::Out: HeapSizeOf { pub(crate) fn insert_into_memory_db(mdb: &mut MemoryDB, input: I) -> Option where H: Hasher, - H::Out: HeapSizeOf, I: IntoIterator, Vec)>, { let mut root = ::Out::default(); diff --git a/substrate/core/state-machine/src/basic.rs b/substrate/core/state-machine/src/basic.rs index a4863485b7..3021ddfd28 100644 --- a/substrate/core/state-machine/src/basic.rs +++ b/substrate/core/state-machine/src/basic.rs @@ -19,7 +19,6 @@ use std::collections::HashMap; use std::iter::FromIterator; use hash_db::Hasher; -use heapsize::HeapSizeOf; use trie::trie_root; use primitives::storage::well_known_keys::{CHANGES_TRIE_CONFIG, CODE, HEAP_PAGES}; use parity_codec::Encode; @@ -103,7 +102,7 @@ impl From< HashMap, Vec> > for BasicExternalities { } } -impl Externalities for BasicExternalities where H::Out: Ord + HeapSizeOf { +impl Externalities for BasicExternalities where H::Out: Ord { fn storage(&self, key: &[u8]) -> Option> { match key { CODE => self.code.clone(), diff --git a/substrate/core/state-machine/src/changes_trie/build.rs b/substrate/core/state-machine/src/changes_trie/build.rs index 9cb766874d..9af058515a 100644 --- a/substrate/core/state-machine/src/changes_trie/build.rs +++ b/substrate/core/state-machine/src/changes_trie/build.rs @@ -19,7 +19,6 @@ use std::collections::{BTreeMap, BTreeSet}; use parity_codec::Decode; use hash_db::Hasher; -use heapsize::HeapSizeOf; use crate::backend::Backend; use crate::overlayed_changes::OverlayedChanges; use crate::trie_backend_essence::{TrieBackendStorage, TrieBackendEssence}; @@ -44,7 +43,6 @@ pub fn prepare_input<'a, B, S, H>( S: Storage, &'a S: TrieBackendStorage, H: Hasher, - H::Out: HeapSizeOf, { let (storage, config) = match (storage, changes.changes_trie_config.as_ref()) { (Some(storage), Some(config)) => (storage, config), @@ -110,7 +108,7 @@ fn prepare_digest_input<'a, S, H>( S: Storage, &'a S: TrieBackendStorage, H: Hasher, - H::Out: 'a + HeapSizeOf, + H::Out: 'a, { let mut digest_map = BTreeMap::, BTreeSet>::new(); for digest_build_block in digest_build_iterator(config, parent.number + 1) { diff --git a/substrate/core/state-machine/src/changes_trie/changes_iterator.rs b/substrate/core/state-machine/src/changes_trie/changes_iterator.rs index 8d56e6c8ff..c8d6216926 100644 --- a/substrate/core/state-machine/src/changes_trie/changes_iterator.rs +++ b/substrate/core/state-machine/src/changes_trie/changes_iterator.rs @@ -21,7 +21,6 @@ use std::cell::RefCell; use std::collections::VecDeque; use parity_codec::{Decode, Encode}; use hash_db::{HashDB, Hasher}; -use heapsize::HeapSizeOf; use trie::{Recorder, MemoryDB}; use crate::changes_trie::{AnchorBlockId, Configuration, RootsStorage, Storage}; use crate::changes_trie::input::{DigestIndex, ExtrinsicIndex, DigestIndexValue, ExtrinsicIndexValue}; @@ -39,7 +38,7 @@ pub fn key_changes<'a, S: Storage, H: Hasher>( end: &'a AnchorBlockId, max: u64, key: &'a [u8], -) -> Result, String> where H::Out: HeapSizeOf { +) -> Result, String> { // we can't query any roots before root let max = ::std::cmp::min(max, end.number); @@ -69,7 +68,7 @@ pub fn key_changes_proof, H: Hasher>( end: &AnchorBlockId, max: u64, key: &[u8], -) -> Result>, String> where H::Out: HeapSizeOf { +) -> Result>, String> { // we can't query any roots before root let max = ::std::cmp::min(max, end.number); @@ -109,7 +108,7 @@ pub fn key_changes_proof_check, H: Hasher>( end: &AnchorBlockId, max: u64, key: &[u8] -) -> Result, String> where H::Out: HeapSizeOf { +) -> Result, String> { // we can't query any roots before root let max = ::std::cmp::min(max, end.number); @@ -278,7 +277,6 @@ pub struct DrilldownIterator<'a, RS: 'a + RootsStorage, S: 'a + Storage, H impl<'a, RS: 'a + RootsStorage, S: Storage, H: Hasher> Iterator for DrilldownIterator<'a, RS, S, H> - where H::Out: HeapSizeOf { type Item = Result<(u64, u32), String>; @@ -305,7 +303,7 @@ impl<'a, RS: 'a + RootsStorage, S: Storage, H: Hasher> ProvingDrilldownIte } } -impl<'a, RS: 'a + RootsStorage, S: Storage, H: Hasher> Iterator for ProvingDrilldownIterator<'a, RS, S, H> where H::Out: HeapSizeOf { +impl<'a, RS: 'a + RootsStorage, S: Storage, H: Hasher> Iterator for ProvingDrilldownIterator<'a, RS, S, H> { type Item = Result<(u64, u32), String>; fn next(&mut self) -> Option { diff --git a/substrate/core/state-machine/src/changes_trie/mod.rs b/substrate/core/state-machine/src/changes_trie/mod.rs index bce0609bbb..f82d8b33df 100644 --- a/substrate/core/state-machine/src/changes_trie/mod.rs +++ b/substrate/core/state-machine/src/changes_trie/mod.rs @@ -47,7 +47,6 @@ pub use self::changes_iterator::{key_changes, key_changes_proof, key_changes_pro pub use self::prune::{prune, oldest_non_pruned_trie}; use hash_db::Hasher; -use heapsize::HeapSizeOf; use crate::backend::Backend; use primitives; use crate::changes_trie::build::prepare_input; @@ -93,7 +92,7 @@ pub fn compute_changes_trie_root<'a, B: Backend, S: Storage, H: Hasher>( ) -> Option<(H::Out, Vec<(Vec, Vec)>)> where &'a S: TrieBackendStorage, - H::Out: Ord + HeapSizeOf, + H::Out: Ord, { let input_pairs = prepare_input::(backend, storage, changes, parent) .expect("storage is not allowed to fail within runtime")?; diff --git a/substrate/core/state-machine/src/changes_trie/prune.rs b/substrate/core/state-machine/src/changes_trie/prune.rs index 7a8654971a..bbe5bb573b 100644 --- a/substrate/core/state-machine/src/changes_trie/prune.rs +++ b/substrate/core/state-machine/src/changes_trie/prune.rs @@ -17,7 +17,6 @@ //! Changes trie pruning-related functions. use hash_db::Hasher; -use heapsize::HeapSizeOf; use trie::Recorder; use log::warn; use crate::proving_backend::ProvingBackendEssence; @@ -53,8 +52,6 @@ pub fn prune, H: Hasher, F: FnMut(H::Out)>( current_block: &AnchorBlockId, mut remove_trie_node: F, ) - where - H::Out: HeapSizeOf, { // select range for pruning let (first, last) = match pruning_range(config, min_blocks_to_keep, current_block.number) { @@ -169,10 +166,7 @@ mod tests { storage: &S, min_blocks_to_keep: u64, current_block: u64, - ) -> HashSet - where - H::Out: HeapSizeOf, - { + ) -> HashSet { let mut pruned_trie_nodes = HashSet::new(); prune(config, storage, min_blocks_to_keep, &AnchorBlockId { hash: Default::default(), number: current_block }, |node| { pruned_trie_nodes.insert(node); }); diff --git a/substrate/core/state-machine/src/changes_trie/storage.rs b/substrate/core/state-machine/src/changes_trie/storage.rs index decc332c1a..8363ae4221 100644 --- a/substrate/core/state-machine/src/changes_trie/storage.rs +++ b/substrate/core/state-machine/src/changes_trie/storage.rs @@ -19,7 +19,6 @@ use std::collections::HashMap; use hash_db::Hasher; use trie::DBValue; -use heapsize::HeapSizeOf; use trie::MemoryDB; use parking_lot::RwLock; use crate::changes_trie::{AnchorBlockId, RootsStorage, Storage}; @@ -33,7 +32,7 @@ use crate::backend::insert_into_memory_db; use crate::changes_trie::input::InputPair; /// In-memory implementation of changes trie storage. -pub struct InMemoryStorage where H::Out: HeapSizeOf { +pub struct InMemoryStorage { data: RwLock>, } @@ -43,12 +42,12 @@ pub struct TrieBackendAdapter<'a, H: Hasher, S: 'a + Storage> { _hasher: ::std::marker::PhantomData, } -struct InMemoryStorageData where H::Out: HeapSizeOf { +struct InMemoryStorageData { roots: HashMap, mdb: MemoryDB, } -impl InMemoryStorage where H::Out: HeapSizeOf { +impl InMemoryStorage { /// Create the storage from given in-memory database. pub fn with_db(mdb: MemoryDB) -> Self { Self { @@ -109,13 +108,13 @@ impl InMemoryStorage where H::Out: HeapSizeOf { } } -impl RootsStorage for InMemoryStorage where H::Out: HeapSizeOf { +impl RootsStorage for InMemoryStorage { fn root(&self, _anchor_block: &AnchorBlockId, block: u64) -> Result, String> { Ok(self.data.read().roots.get(&block).cloned()) } } -impl Storage for InMemoryStorage where H::Out: HeapSizeOf { +impl Storage for InMemoryStorage { fn get(&self, key: &H::Out, prefix: &[u8]) -> Result, String> { MemoryDB::::get(&self.data.read().mdb, key, prefix) } diff --git a/substrate/core/state-machine/src/ext.rs b/substrate/core/state-machine/src/ext.rs index a9f2ab9d0e..0ab269784a 100644 --- a/substrate/core/state-machine/src/ext.rs +++ b/substrate/core/state-machine/src/ext.rs @@ -24,7 +24,6 @@ use crate::{Externalities, OverlayedChanges, OffchainExt, ChildStorageKey}; use hash_db::Hasher; use primitives::storage::well_known_keys::is_child_storage_key; use trie::{MemoryDB, TrieDBMut, TrieMut, default_child_trie_root}; -use heapsize::HeapSizeOf; const EXT_NOT_ALLOWED_TO_FAIL: &str = "Externalities not allowed to fail within runtime"; @@ -92,7 +91,7 @@ where B: 'a + Backend, T: 'a + ChangesTrieStorage, O: 'a + OffchainExt, - H::Out: Ord + HeapSizeOf, + H::Out: Ord, { /// Create a new `Ext` from overlayed changes and read-only backend pub fn new( @@ -190,7 +189,7 @@ where B: 'a + Backend, T: 'a + ChangesTrieStorage, O: 'a + OffchainExt, - H::Out: Ord + HeapSizeOf, + H::Out: Ord, { fn storage(&self, key: &[u8]) -> Option> { let _guard = panic_handler::AbortGuard::new(true); diff --git a/substrate/core/state-machine/src/lib.rs b/substrate/core/state-machine/src/lib.rs index b1d0b24721..00fa26c7f2 100644 --- a/substrate/core/state-machine/src/lib.rs +++ b/substrate/core/state-machine/src/lib.rs @@ -22,7 +22,6 @@ use std::{fmt, panic::UnwindSafe, result, marker::PhantomData}; use std::borrow::Cow; use log::warn; use hash_db::Hasher; -use heapsize::HeapSizeOf; use parity_codec::{Decode, Encode}; use primitives::{ storage::well_known_keys, NativeOrEncoded, NeverNativeValue, OffchainExt @@ -378,7 +377,7 @@ impl<'a, H, B, T, O, Exec> StateMachine<'a, H, B, T, O, Exec> where B: Backend, T: ChangesTrieStorage, O: OffchainExt, - H::Out: Ord + HeapSizeOf, + H::Out: Ord, { /// Execute a call using the given state backend, overlayed changes, and call executor. /// Produces a state-backend-specific "transaction" which can be used to apply the changes @@ -569,7 +568,7 @@ where B: Backend, H: Hasher, Exec: CodeExecutor, - H::Out: Ord + HeapSizeOf, + H::Out: Ord, { let trie_backend = backend.try_into_trie_backend() .ok_or_else(|| Box::new(ExecutionError::UnableToGenerateProof) as Box)?; @@ -596,7 +595,7 @@ where S: trie_backend_essence::TrieBackendStorage, H: Hasher, Exec: CodeExecutor, - H::Out: Ord + HeapSizeOf, + H::Out: Ord, { let proving_backend = proving_backend::ProvingBackend::new(trie_backend); let mut sm = StateMachine { @@ -630,7 +629,7 @@ pub fn execution_proof_check( where H: Hasher, Exec: CodeExecutor, - H::Out: Ord + HeapSizeOf, + H::Out: Ord, { let trie_backend = proving_backend::create_proof_check_backend::(root.into(), proof)?; execution_proof_check_on_trie_backend(&trie_backend, overlay, exec, method, call_data) @@ -647,7 +646,7 @@ pub fn execution_proof_check_on_trie_backend( where H: Hasher, Exec: CodeExecutor, - H::Out: Ord + HeapSizeOf, + H::Out: Ord, { let mut sm = StateMachine { backend: trie_backend, @@ -674,7 +673,7 @@ pub fn prove_read( where B: Backend, H: Hasher, - H::Out: Ord + HeapSizeOf + H::Out: Ord { let trie_backend = backend.try_into_trie_backend() .ok_or_else(|| Box::new(ExecutionError::UnableToGenerateProof) as Box)?; @@ -689,7 +688,7 @@ pub fn prove_read_on_trie_backend( where S: trie_backend_essence::TrieBackendStorage, H: Hasher, - H::Out: Ord + HeapSizeOf + H::Out: Ord { let proving_backend = proving_backend::ProvingBackend::<_, H>::new(trie_backend); let result = proving_backend.storage(key).map_err(|e| Box::new(e) as Box)?; @@ -704,7 +703,7 @@ pub fn read_proof_check( ) -> Result>, Box> where H: Hasher, - H::Out: Ord + HeapSizeOf + H::Out: Ord { let proving_backend = proving_backend::create_proof_check_backend::(root, proof)?; read_proof_check_on_proving_backend(&proving_backend, key) @@ -717,7 +716,7 @@ pub fn read_proof_check_on_proving_backend( ) -> Result>, Box> where H: Hasher, - H::Out: Ord + HeapSizeOf + H::Out: Ord { proving_backend.storage(key).map_err(|e| Box::new(e) as Box) } diff --git a/substrate/core/state-machine/src/proving_backend.rs b/substrate/core/state-machine/src/proving_backend.rs index c869f61efe..73d41f2a61 100644 --- a/substrate/core/state-machine/src/proving_backend.rs +++ b/substrate/core/state-machine/src/proving_backend.rs @@ -19,7 +19,6 @@ use std::{cell::RefCell, rc::Rc}; use log::debug; use hash_db::Hasher; -use heapsize::HeapSizeOf; use hash_db::HashDB; use trie::{ MemoryDB, PrefixedMemoryDB, TrieError, default_child_trie_root, @@ -41,7 +40,6 @@ impl<'a, S, H> ProvingBackendEssence<'a, S, H> where S: TrieBackendStorage, H: Hasher, - H::Out: HeapSizeOf, { pub fn storage(&mut self, key: &[u8]) -> Result>, String> { let mut read_overlay = S::Overlay::default(); @@ -130,7 +128,7 @@ impl<'a, S, H> Backend for ProvingBackend<'a, S, H> where S: 'a + TrieBackendStorage, H: 'a + Hasher, - H::Out: Ord + HeapSizeOf, + H::Out: Ord, { type Error = String; type Transaction = S::Overlay; @@ -194,7 +192,6 @@ pub fn create_proof_check_backend( ) -> Result, H>, Box> where H: Hasher, - H::Out: HeapSizeOf, { let db = create_proof_check_backend_storage(proof); @@ -211,7 +208,6 @@ pub fn create_proof_check_backend_storage( ) -> MemoryDB where H: Hasher, - H::Out: HeapSizeOf, { let mut db = MemoryDB::default(); for item in proof { diff --git a/substrate/core/state-machine/src/testing.rs b/substrate/core/state-machine/src/testing.rs index f8f81cfda1..a4f650bcf2 100644 --- a/substrate/core/state-machine/src/testing.rs +++ b/substrate/core/state-machine/src/testing.rs @@ -19,7 +19,6 @@ use std::collections::HashMap; use std::iter::FromIterator; use hash_db::Hasher; -use heapsize::HeapSizeOf; use trie::trie_root; use crate::backend::InMemory; use crate::changes_trie::{compute_changes_trie_root, InMemoryStorage as ChangesTrieInMemoryStorage, AnchorBlockId}; @@ -28,14 +27,14 @@ use parity_codec::Encode; use super::{ChildStorageKey, Externalities, OverlayedChanges}; /// Simple HashMap-based Externalities impl. -pub struct TestExternalities where H::Out: HeapSizeOf { +pub struct TestExternalities { inner: HashMap, Vec>, changes_trie_storage: ChangesTrieInMemoryStorage, changes: OverlayedChanges, code: Option>, } -impl TestExternalities where H::Out: HeapSizeOf { +impl TestExternalities { /// Create a new instance of `TestExternalities` pub fn new(inner: HashMap, Vec>) -> Self { Self::new_with_code(&[], inner) @@ -66,19 +65,19 @@ impl TestExternalities where H::Out: HeapSizeOf { } } -impl ::std::fmt::Debug for TestExternalities where H::Out: HeapSizeOf { +impl ::std::fmt::Debug for TestExternalities { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { write!(f, "{:?}", self.inner) } } -impl PartialEq for TestExternalities where H::Out: HeapSizeOf { +impl PartialEq for TestExternalities { fn eq(&self, other: &TestExternalities) -> bool { self.inner.eq(&other.inner) } } -impl FromIterator<(Vec, Vec)> for TestExternalities where H::Out: HeapSizeOf { +impl FromIterator<(Vec, Vec)> for TestExternalities { fn from_iter, Vec)>>(iter: I) -> Self { let mut t = Self::new(Default::default()); t.inner.extend(iter); @@ -86,17 +85,17 @@ impl FromIterator<(Vec, Vec)> for TestExternalities where } } -impl Default for TestExternalities where H::Out: HeapSizeOf { +impl Default for TestExternalities { fn default() -> Self { Self::new(Default::default()) } } -impl From> for HashMap, Vec> where H::Out: HeapSizeOf { +impl From> for HashMap, Vec> { fn from(tex: TestExternalities) -> Self { tex.inner.into() } } -impl From< HashMap, Vec> > for TestExternalities where H::Out: HeapSizeOf { +impl From< HashMap, Vec> > for TestExternalities { fn from(hashmap: HashMap, Vec>) -> Self { TestExternalities { inner: hashmap, @@ -110,7 +109,7 @@ impl From< HashMap, Vec> > for TestExternalities where // TODO child test primitives are currently limited to `changes` (for non child the way // things are defined seems utterly odd to (put changes in changes but never make them // available for read through inner) -impl Externalities for TestExternalities where H::Out: Ord + HeapSizeOf { +impl Externalities for TestExternalities where H::Out: Ord { fn storage(&self, key: &[u8]) -> Option> { match key { CODE => self.code.clone(), diff --git a/substrate/core/state-machine/src/trie_backend.rs b/substrate/core/state-machine/src/trie_backend.rs index b152d7fea1..78f5cf3d52 100644 --- a/substrate/core/state-machine/src/trie_backend.rs +++ b/substrate/core/state-machine/src/trie_backend.rs @@ -18,7 +18,6 @@ use log::{warn, debug}; use hash_db::Hasher; -use heapsize::HeapSizeOf; use trie::{TrieDB, TrieError, Trie, delta_trie_root, default_child_trie_root, child_delta_trie_root}; use crate::trie_backend_essence::{TrieBackendEssence, TrieBackendStorage, Ephemeral}; use crate::Backend; @@ -28,7 +27,7 @@ pub struct TrieBackend, H: Hasher> { essence: TrieBackendEssence, } -impl, H: Hasher> TrieBackend where H::Out: HeapSizeOf { +impl, H: Hasher> TrieBackend { /// Create new trie-based backend. pub fn new(storage: S, root: H::Out) -> Self { TrieBackend { @@ -60,7 +59,7 @@ impl, H: Hasher> TrieBackend where H::Out: HeapSi impl super::Error for String {} impl, H: Hasher> Backend for TrieBackend where - H::Out: Ord + HeapSizeOf, + H::Out: Ord, { type Error = String; type Transaction = S::Overlay; diff --git a/substrate/core/state-machine/src/trie_backend_essence.rs b/substrate/core/state-machine/src/trie_backend_essence.rs index 8101126c39..dfb6cae08c 100644 --- a/substrate/core/state-machine/src/trie_backend_essence.rs +++ b/substrate/core/state-machine/src/trie_backend_essence.rs @@ -21,7 +21,6 @@ use std::ops::Deref; use std::sync::Arc; use log::{debug, warn}; use hash_db::{self, Hasher}; -use heapsize::HeapSizeOf; use trie::{TrieDB, Trie, MemoryDB, PrefixedMemoryDB, DBValue, TrieError, default_child_trie_root, read_trie_value, read_child_trie_value, for_keys_in_child_trie}; use crate::changes_trie::Storage as ChangesTrieStorage; use crate::backend::Consolidate; @@ -38,7 +37,7 @@ pub struct TrieBackendEssence, H: Hasher> { root: H::Out, } -impl, H: Hasher> TrieBackendEssence where H::Out: HeapSizeOf { +impl, H: Hasher> TrieBackendEssence { /// Create new trie-based backend. pub fn new(storage: S, root: H::Out) -> Self { TrieBackendEssence { @@ -154,7 +153,6 @@ impl<'a, H: 'a + Hasher > hash_db::AsPlainDB for Ephemeral<'a, S, H> - where H::Out: HeapSizeOf { fn as_plain_db<'b>(&'b self) -> &'b (hash_db::PlainDB + 'b) { self } fn as_plain_db_mut<'b>(&'b mut self) -> &'b mut (hash_db::PlainDB + 'b) { self } @@ -165,7 +163,6 @@ impl<'a, H: 'a + Hasher > hash_db::AsHashDB for Ephemeral<'a, S, H> - where H::Out: HeapSizeOf { fn as_hash_db<'b>(&'b self) -> &'b (hash_db::HashDB + 'b) { self } fn as_hash_db_mut<'b>(&'b mut self) -> &'b mut (hash_db::HashDB + 'b) { self } @@ -185,7 +182,6 @@ impl<'a, H: Hasher > hash_db::PlainDB for Ephemeral<'a, S, H> - where H::Out: HeapSizeOf { fn get(&self, key: &H::Out) -> Option { if let Some(val) = hash_db::HashDB::get(self.overlay, key, &[]) { @@ -219,7 +215,6 @@ impl<'a, H: Hasher > hash_db::PlainDBRef for Ephemeral<'a, S, H> - where H::Out: HeapSizeOf { fn get(&self, key: &H::Out) -> Option { hash_db::PlainDB::get(self, key) } fn contains(&self, key: &H::Out) -> bool { hash_db::PlainDB::contains(self, key) } @@ -230,7 +225,6 @@ impl<'a, H: Hasher > hash_db::HashDB for Ephemeral<'a, S, H> - where H::Out: HeapSizeOf { fn get(&self, key: &H::Out, prefix: &[u8]) -> Option { if let Some(val) = hash_db::HashDB::get(self.overlay, key, prefix) { @@ -268,7 +262,6 @@ impl<'a, H: Hasher > hash_db::HashDBRef for Ephemeral<'a, S, H> - where H::Out: HeapSizeOf { fn get(&self, key: &H::Out, prefix: &[u8]) -> Option { hash_db::HashDB::get(self, key, prefix) } fn contains(&self, key: &H::Out, prefix: &[u8]) -> bool { hash_db::HashDB::contains(self, key, prefix) }