diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index e5382f07d3dc8a346af6bc99de2f903521668b26..daab045b3f51fc4919f08a4e34245ad4af665738 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 f1b7a903ffc0bad036cca42cdd90012cdcdbf1dd..f85650eaa1a27ca740c6f530d14d16e2acb01485 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 13db1c67ebe81c7168bd2f75b3fcecc57f825121..8002f52b6f6d47b60e171d1f234d945c624c1d60 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<Header, Hasher, BlocksI, HashesI>( where Header: HeaderT, Hasher: hash_db::Hasher, - Hasher::Out: Ord + HeapSizeOf, + Hasher::Out: Ord, BlocksI: IntoIterator<Item=Header::Number>, HashesI: IntoIterator<Item=ClientResult<Option<Header::Hash>>>, { @@ -120,7 +119,7 @@ pub fn check_proof<Header, Hasher>( where Header: HeaderT, Hasher: hash_db::Hasher, - Hasher::Out: Ord + HeapSizeOf, + Hasher::Out: Ord, { do_check_proof::<Header, Hasher, _>(local_root, local_number, remote_hash, move |local_root, local_cht_key| read_proof_check::<Hasher>(local_root, remote_proof, @@ -137,7 +136,7 @@ pub fn check_proof_on_proving_backend<Header, Hasher>( where Header: HeaderT, Hasher: hash_db::Hasher, - Hasher::Out: Ord + HeapSizeOf, + Hasher::Out: Ord, { do_check_proof::<Header, Hasher, _>(local_root, local_number, remote_hash, |_, local_cht_key| read_proof_check_on_proving_backend::<Hasher>( @@ -154,7 +153,7 @@ fn do_check_proof<Header, Hasher, F>( where Header: HeaderT, Hasher: hash_db::Hasher, - Hasher::Out: Ord + HeapSizeOf, + Hasher::Out: Ord, F: FnOnce(Hasher::Out, &[u8]) -> ClientResult<Option<Vec<u8>>>, { 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 f6b69287a41c91d63251c3110412f82e2d5ab755..b02fbe462ea9dc0ca01de2f57801aafb29523e66 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<Out=Block::Hash>, - H::Out: HeapSizeOf + Ord, + H::Out: Ord, { type State = InMemory<H>; @@ -532,7 +531,7 @@ pub struct Backend<Block, H> where Block: BlockT, H: Hasher<Out=Block::Hash>, - H::Out: HeapSizeOf + Ord, + H::Out: Ord, { states: RwLock<HashMap<Block::Hash, InMemory<H>>>, changes_trie_storage: ChangesTrieStorage<H>, @@ -543,7 +542,7 @@ impl<Block, H> Backend<Block, H> where Block: BlockT, H: Hasher<Out=Block::Hash>, - H::Out: HeapSizeOf + Ord, + H::Out: Ord, { /// Create a new instance of in-mem backend. pub fn new() -> Backend<Block, H> { @@ -559,7 +558,7 @@ impl<Block, H> backend::AuxStore for Backend<Block, H> where Block: BlockT, H: Hasher<Out=Block::Hash>, - H::Out: HeapSizeOf + Ord, + H::Out: Ord, { fn insert_aux< 'a, @@ -580,7 +579,7 @@ impl<Block, H> backend::Backend<Block, H> for Backend<Block, H> where Block: BlockT, H: Hasher<Out=Block::Hash>, - H::Out: HeapSizeOf + Ord, + H::Out: Ord, { type BlockImportOperation = BlockImportOperation<Block, H>; type Blockchain = Blockchain<Block>; @@ -682,14 +681,14 @@ impl<Block, H> backend::LocalBackend<Block, H> for Backend<Block, H> where Block: BlockT, H: Hasher<Out=Block::Hash>, - H::Out: HeapSizeOf + Ord, + H::Out: Ord, {} impl<Block, H> backend::RemoteBackend<Block, H> for Backend<Block, H> where Block: BlockT, H: Hasher<Out=Block::Hash>, - H::Out: HeapSizeOf + Ord, + H::Out: Ord, { fn is_local_state_available(&self, block: &BlockId<Block>) -> bool { self.blockchain.expect_block_number_from_id(block) @@ -699,20 +698,20 @@ where } /// Prunable in-memory changes trie storage. -pub struct ChangesTrieStorage<H: Hasher>(InMemoryChangesTrieStorage<H>) where H::Out: HeapSizeOf; -impl<H: Hasher> backend::PrunableStateChangesTrieStorage<H> for ChangesTrieStorage<H> where H::Out: HeapSizeOf { +pub struct ChangesTrieStorage<H: Hasher>(InMemoryChangesTrieStorage<H>); +impl<H: Hasher> backend::PrunableStateChangesTrieStorage<H> for ChangesTrieStorage<H> { fn oldest_changes_trie_block(&self, _config: &ChangesTrieConfiguration, _best_finalized: u64) -> u64 { 0 } } -impl<H: Hasher> state_machine::ChangesTrieRootsStorage<H> for ChangesTrieStorage<H> where H::Out: HeapSizeOf { +impl<H: Hasher> state_machine::ChangesTrieRootsStorage<H> for ChangesTrieStorage<H> { fn root(&self, anchor: &ChangesTrieAnchorBlockId<H::Out>, block: u64) -> Result<Option<H::Out>, String> { self.0.root(anchor, block) } } -impl<H: Hasher> state_machine::ChangesTrieStorage<H> for ChangesTrieStorage<H> where H::Out: HeapSizeOf { +impl<H: Hasher> state_machine::ChangesTrieStorage<H> for ChangesTrieStorage<H> { fn get(&self, key: &H::Out, prefix: &[u8]) -> Result<Option<state_machine::DBValue>, 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 f22ee8a7620737596fe85ca1f701eaca19058288..52cdb6a626a11a872b039f8dfa4bf98d53da72cd 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<S, F, Block, H> ClientBackend<Block, H> for Backend<S, F, H> where S: BlockchainStorage<Block>, F: Fetcher<Block>, H: Hasher<Out=Block::Hash>, - H::Out: HeapSizeOf + Ord, + H::Out: Ord, { type BlockImportOperation = ImportOperation<Block, S, F, H>; type Blockchain = Blockchain<S, F>; @@ -222,7 +221,7 @@ where S: BlockchainStorage<Block>, F: Fetcher<Block>, H: Hasher<Out=Block::Hash>, - H::Out: HeapSizeOf + Ord, + H::Out: Ord, { fn is_local_state_available(&self, block: &BlockId<Block>) -> bool { self.genesis_state.read().is_some() @@ -238,7 +237,7 @@ where F: Fetcher<Block>, S: BlockchainStorage<Block>, H: Hasher<Out=Block::Hash>, - H::Out: HeapSizeOf + Ord, + H::Out: Ord, { type State = OnDemandOrGenesisState<Block, S, F, H>; @@ -390,7 +389,7 @@ where F: Fetcher<Block>, S: BlockchainStorage<Block>, H: Hasher<Out=Block::Hash>, - 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 0863b17aaaaa19b6ec63d79bf765208ce8b1d88b..47c11b93fae20d378cb202c8f7c45ee4b677bcc5 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, E, H>( Header: HeaderT, E: CodeExecutor<H>, 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 28df2f8bffdaaee42bc152bbd7d8ddd5c2790219..d62930b1ad5e619e81e79c8ca484e3dc5a9a71ce 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<E, H, B: BlockT, S: BlockchainStorage<B>, F> LightDataChecker<E, H, B, S, F ) -> ClientResult<Vec<(NumberFor<B>, 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<E, H, B: BlockT, S: BlockchainStorage<B>, F> LightDataChecker<E, H, B, S, F ) -> 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<E, Block, H, S, F> FetchChecker<Block> for LightDataChecker<E, H, Block, S, Block: BlockT, E: CodeExecutor<H>, H: Hasher, - H::Out: Ord + HeapSizeOf, + H::Out: Ord, S: BlockchainStorage<Block>, F: Send + Sync, { diff --git a/substrate/core/primitives/Cargo.toml b/substrate/core/primitives/Cargo.toml index 6d50c8be0e5f32a6247c76b38b0f339adfa11cb3..bb1a7edd88cb55e655354de93db2e0c45b6c1a0f 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 f3e3583be5771b3d0569753393cf232ad9a68cf4..c63463e32ae2b94fad78ff5789c500dbeeb11109 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::<H256>("\"0\"").unwrap_err().is_data()); assert!(ser::from_str::<H256>("\"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 171ae15b28a211c635bd33906871c17ac07dc768..66c94bd20860682e8c0318fd4b6ed0d15c228e0f 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 14e60b140a0e8a0ea8224f15c0371b70608c84f4..c93935a34746817831a4bca673a3018b40d897c3 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<H> PartialEq for InMemory<H> { } } -impl<H: Hasher> InMemory<H> where H::Out: HeapSizeOf { +impl<H: Hasher> InMemory<H> { /// Copy the state, with applied updates pub fn update(&self, changes: <Self as Backend<H>>::Transaction) -> Self { let mut inner: HashMap<_, _> = self.inner.clone(); @@ -214,7 +213,7 @@ impl<H> From<Vec<(Option<Vec<u8>>, Vec<u8>, Option<Vec<u8>>)>> for InMemory<H> { impl super::Error for Void {} -impl<H: Hasher> Backend<H> for InMemory<H> where H::Out: HeapSizeOf { +impl<H: Hasher> Backend<H> for InMemory<H> { type Error = Void; type Transaction = Vec<(Option<Vec<u8>>, Vec<u8>, Option<Vec<u8>>)>; type TrieBackendStorage = MemoryDB<H>; @@ -313,7 +312,6 @@ impl<H: Hasher> Backend<H> for InMemory<H> where H::Out: HeapSizeOf { pub(crate) fn insert_into_memory_db<H, I>(mdb: &mut MemoryDB<H>, input: I) -> Option<H::Out> where H: Hasher, - H::Out: HeapSizeOf, I: IntoIterator<Item=(Vec<u8>, Vec<u8>)>, { let mut root = <H as Hasher>::Out::default(); diff --git a/substrate/core/state-machine/src/basic.rs b/substrate/core/state-machine/src/basic.rs index a4863485b7c9ab6581eccd304b9dab78d2177a2e..3021ddfd28dee459e682d5f06df1f3aaa10078dd 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<u8>, Vec<u8>> > for BasicExternalities { } } -impl<H: Hasher> Externalities<H> for BasicExternalities where H::Out: Ord + HeapSizeOf { +impl<H: Hasher> Externalities<H> for BasicExternalities where H::Out: Ord { fn storage(&self, key: &[u8]) -> Option<Vec<u8>> { 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 9cb766874d8f847136093f334199c92046181d83..9af058515aca886b47680a5046435c7c2e888c91 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<H>, &'a S: TrieBackendStorage<H>, 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<H>, &'a S: TrieBackendStorage<H>, H: Hasher, - H::Out: 'a + HeapSizeOf, + H::Out: 'a, { let mut digest_map = BTreeMap::<Vec<u8>, BTreeSet<u64>>::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 8d56e6c8ff6bc6f5c4a7ad28d7cbca53f01ce037..c8d6216926a1997990f6f4db9fc6774fed209494 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>, H: Hasher>( end: &'a AnchorBlockId<H::Out>, max: u64, key: &'a [u8], -) -> Result<DrilldownIterator<'a, S, S, H>, String> where H::Out: HeapSizeOf { +) -> Result<DrilldownIterator<'a, S, S, H>, 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<S: Storage<H>, H: Hasher>( end: &AnchorBlockId<H::Out>, max: u64, key: &[u8], -) -> Result<Vec<Vec<u8>>, String> where H::Out: HeapSizeOf { +) -> Result<Vec<Vec<u8>>, 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<S: RootsStorage<H>, H: Hasher>( end: &AnchorBlockId<H::Out>, max: u64, key: &[u8] -) -> Result<Vec<(u64, u32)>, String> where H::Out: HeapSizeOf { +) -> Result<Vec<(u64, u32)>, 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<H>, S: 'a + Storage<H>, H impl<'a, RS: 'a + RootsStorage<H>, S: Storage<H>, 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<H>, S: Storage<H>, H: Hasher> ProvingDrilldownIte } } -impl<'a, RS: 'a + RootsStorage<H>, S: Storage<H>, H: Hasher> Iterator for ProvingDrilldownIterator<'a, RS, S, H> where H::Out: HeapSizeOf { +impl<'a, RS: 'a + RootsStorage<H>, S: Storage<H>, H: Hasher> Iterator for ProvingDrilldownIterator<'a, RS, S, H> { type Item = Result<(u64, u32), String>; fn next(&mut self) -> Option<Self::Item> { diff --git a/substrate/core/state-machine/src/changes_trie/mod.rs b/substrate/core/state-machine/src/changes_trie/mod.rs index bce0609bbbe8a13ee30ddcef9be76485cbb796d4..f82d8b33df3c5192864738b742df94cf1a07b21b 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<H>, S: Storage<H>, H: Hasher>( ) -> Option<(H::Out, Vec<(Vec<u8>, Vec<u8>)>)> where &'a S: TrieBackendStorage<H>, - H::Out: Ord + HeapSizeOf, + H::Out: Ord, { let input_pairs = prepare_input::<B, S, H>(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 7a8654971a47080a2d1e0fdd616cbe74f6e8ffb2..bbe5bb573b347c3ec17fb1716a3e295bfed5ce71 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<S: Storage<H>, H: Hasher, F: FnMut(H::Out)>( current_block: &AnchorBlockId<H::Out>, 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<H::Out> - where - H::Out: HeapSizeOf, - { + ) -> HashSet<H::Out> { 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 decc332c1a6187ea364eb4db2a2fb5e75a38a82c..8363ae422108a0fca727ba4ff7256cfa6ba0f559 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<H: Hasher> where H::Out: HeapSizeOf { +pub struct InMemoryStorage<H: Hasher> { data: RwLock<InMemoryStorageData<H>>, } @@ -43,12 +42,12 @@ pub struct TrieBackendAdapter<'a, H: Hasher, S: 'a + Storage<H>> { _hasher: ::std::marker::PhantomData<H>, } -struct InMemoryStorageData<H: Hasher> where H::Out: HeapSizeOf { +struct InMemoryStorageData<H: Hasher> { roots: HashMap<u64, H::Out>, mdb: MemoryDB<H>, } -impl<H: Hasher> InMemoryStorage<H> where H::Out: HeapSizeOf { +impl<H: Hasher> InMemoryStorage<H> { /// Create the storage from given in-memory database. pub fn with_db(mdb: MemoryDB<H>) -> Self { Self { @@ -109,13 +108,13 @@ impl<H: Hasher> InMemoryStorage<H> where H::Out: HeapSizeOf { } } -impl<H: Hasher> RootsStorage<H> for InMemoryStorage<H> where H::Out: HeapSizeOf { +impl<H: Hasher> RootsStorage<H> for InMemoryStorage<H> { fn root(&self, _anchor_block: &AnchorBlockId<H::Out>, block: u64) -> Result<Option<H::Out>, String> { Ok(self.data.read().roots.get(&block).cloned()) } } -impl<H: Hasher> Storage<H> for InMemoryStorage<H> where H::Out: HeapSizeOf { +impl<H: Hasher> Storage<H> for InMemoryStorage<H> { fn get(&self, key: &H::Out, prefix: &[u8]) -> Result<Option<DBValue>, String> { MemoryDB::<H>::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 a9f2ab9d0e6a27561094e7c9ad14ee9aff5780eb..0ab269784aa00252689bc11b9988e4279a4ba6ac 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<H>, T: 'a + ChangesTrieStorage<H>, 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<H>, T: 'a + ChangesTrieStorage<H>, O: 'a + OffchainExt, - H::Out: Ord + HeapSizeOf, + H::Out: Ord, { fn storage(&self, key: &[u8]) -> Option<Vec<u8>> { 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 b1d0b2472184c5471980176fc0739719a895ce79..00fa26c7f2f8ac9c406360d7e39f514429136cc0 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<H>, T: ChangesTrieStorage<H>, 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>, H: Hasher, Exec: CodeExecutor<H>, - H::Out: Ord + HeapSizeOf, + H::Out: Ord, { let trie_backend = backend.try_into_trie_backend() .ok_or_else(|| Box::new(ExecutionError::UnableToGenerateProof) as Box<Error>)?; @@ -596,7 +595,7 @@ where S: trie_backend_essence::TrieBackendStorage<H>, H: Hasher, Exec: CodeExecutor<H>, - 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<H, Exec>( where H: Hasher, Exec: CodeExecutor<H>, - H::Out: Ord + HeapSizeOf, + H::Out: Ord, { let trie_backend = proving_backend::create_proof_check_backend::<H>(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<H, Exec>( where H: Hasher, Exec: CodeExecutor<H>, - H::Out: Ord + HeapSizeOf, + H::Out: Ord, { let mut sm = StateMachine { backend: trie_backend, @@ -674,7 +673,7 @@ pub fn prove_read<B, H>( where B: Backend<H>, 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<Error>)?; @@ -689,7 +688,7 @@ pub fn prove_read_on_trie_backend<S, H>( where S: trie_backend_essence::TrieBackendStorage<H>, 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<Error>)?; @@ -704,7 +703,7 @@ pub fn read_proof_check<H>( ) -> Result<Option<Vec<u8>>, Box<Error>> where H: Hasher, - H::Out: Ord + HeapSizeOf + H::Out: Ord { let proving_backend = proving_backend::create_proof_check_backend::<H>(root, proof)?; read_proof_check_on_proving_backend(&proving_backend, key) @@ -717,7 +716,7 @@ pub fn read_proof_check_on_proving_backend<H>( ) -> Result<Option<Vec<u8>>, Box<Error>> where H: Hasher, - H::Out: Ord + HeapSizeOf + H::Out: Ord { proving_backend.storage(key).map_err(|e| Box::new(e) as Box<Error>) } diff --git a/substrate/core/state-machine/src/proving_backend.rs b/substrate/core/state-machine/src/proving_backend.rs index c869f61efef47d65cbaf3601f8d896098a158fba..73d41f2a61518cc83f0bfc8c2447ee120133aeca 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>, H: Hasher, - H::Out: HeapSizeOf, { pub fn storage(&mut self, key: &[u8]) -> Result<Option<Vec<u8>>, String> { let mut read_overlay = S::Overlay::default(); @@ -130,7 +128,7 @@ impl<'a, S, H> Backend<H> for ProvingBackend<'a, S, H> where S: 'a + TrieBackendStorage<H>, 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<H>( ) -> Result<TrieBackend<MemoryDB<H>, H>, Box<Error>> 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<H>( ) -> MemoryDB<H> 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 f8f81cfda13977e177e77ef5c41b07367bc2f757..a4f650bcf212aa9677d90590b21eefd96fcbc6de 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<H: Hasher> where H::Out: HeapSizeOf { +pub struct TestExternalities<H: Hasher> { inner: HashMap<Vec<u8>, Vec<u8>>, changes_trie_storage: ChangesTrieInMemoryStorage<H>, changes: OverlayedChanges, code: Option<Vec<u8>>, } -impl<H: Hasher> TestExternalities<H> where H::Out: HeapSizeOf { +impl<H: Hasher> TestExternalities<H> { /// Create a new instance of `TestExternalities` pub fn new(inner: HashMap<Vec<u8>, Vec<u8>>) -> Self { Self::new_with_code(&[], inner) @@ -66,19 +65,19 @@ impl<H: Hasher> TestExternalities<H> where H::Out: HeapSizeOf { } } -impl<H: Hasher> ::std::fmt::Debug for TestExternalities<H> where H::Out: HeapSizeOf { +impl<H: Hasher> ::std::fmt::Debug for TestExternalities<H> { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { write!(f, "{:?}", self.inner) } } -impl<H: Hasher> PartialEq for TestExternalities<H> where H::Out: HeapSizeOf { +impl<H: Hasher> PartialEq for TestExternalities<H> { fn eq(&self, other: &TestExternalities<H>) -> bool { self.inner.eq(&other.inner) } } -impl<H: Hasher> FromIterator<(Vec<u8>, Vec<u8>)> for TestExternalities<H> where H::Out: HeapSizeOf { +impl<H: Hasher> FromIterator<(Vec<u8>, Vec<u8>)> for TestExternalities<H> { fn from_iter<I: IntoIterator<Item=(Vec<u8>, Vec<u8>)>>(iter: I) -> Self { let mut t = Self::new(Default::default()); t.inner.extend(iter); @@ -86,17 +85,17 @@ impl<H: Hasher> FromIterator<(Vec<u8>, Vec<u8>)> for TestExternalities<H> where } } -impl<H: Hasher> Default for TestExternalities<H> where H::Out: HeapSizeOf { +impl<H: Hasher> Default for TestExternalities<H> { fn default() -> Self { Self::new(Default::default()) } } -impl<H: Hasher> From<TestExternalities<H>> for HashMap<Vec<u8>, Vec<u8>> where H::Out: HeapSizeOf { +impl<H: Hasher> From<TestExternalities<H>> for HashMap<Vec<u8>, Vec<u8>> { fn from(tex: TestExternalities<H>) -> Self { tex.inner.into() } } -impl<H: Hasher> From< HashMap<Vec<u8>, Vec<u8>> > for TestExternalities<H> where H::Out: HeapSizeOf { +impl<H: Hasher> From< HashMap<Vec<u8>, Vec<u8>> > for TestExternalities<H> { fn from(hashmap: HashMap<Vec<u8>, Vec<u8>>) -> Self { TestExternalities { inner: hashmap, @@ -110,7 +109,7 @@ impl<H: Hasher> From< HashMap<Vec<u8>, Vec<u8>> > for TestExternalities<H> 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<H: Hasher> Externalities<H> for TestExternalities<H> where H::Out: Ord + HeapSizeOf { +impl<H: Hasher> Externalities<H> for TestExternalities<H> where H::Out: Ord { fn storage(&self, key: &[u8]) -> Option<Vec<u8>> { 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 b152d7fea18578aedf032efb2ab482627d087f58..78f5cf3d52cbcd49c4a3a996830b3794c39c3acb 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<S: TrieBackendStorage<H>, H: Hasher> { essence: TrieBackendEssence<S, H>, } -impl<S: TrieBackendStorage<H>, H: Hasher> TrieBackend<S, H> where H::Out: HeapSizeOf { +impl<S: TrieBackendStorage<H>, H: Hasher> TrieBackend<S, H> { /// Create new trie-based backend. pub fn new(storage: S, root: H::Out) -> Self { TrieBackend { @@ -60,7 +59,7 @@ impl<S: TrieBackendStorage<H>, H: Hasher> TrieBackend<S, H> where H::Out: HeapSi impl super::Error for String {} impl<S: TrieBackendStorage<H>, H: Hasher> Backend<H> for TrieBackend<S, H> 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 8101126c39d78c7b386ae94a33a74195a8122d94..dfb6cae08cecfac408d0adc7f2a1c36b7e77fb8c 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<S: TrieBackendStorage<H>, H: Hasher> { root: H::Out, } -impl<S: TrieBackendStorage<H>, H: Hasher> TrieBackendEssence<S, H> where H::Out: HeapSizeOf { +impl<S: TrieBackendStorage<H>, H: Hasher> TrieBackendEssence<S, H> { /// 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<H::Out, DBValue> for Ephemeral<'a, S, H> - where H::Out: HeapSizeOf { fn as_plain_db<'b>(&'b self) -> &'b (hash_db::PlainDB<H::Out, DBValue> + 'b) { self } fn as_plain_db_mut<'b>(&'b mut self) -> &'b mut (hash_db::PlainDB<H::Out, DBValue> + 'b) { self } @@ -165,7 +163,6 @@ impl<'a, H: 'a + Hasher > hash_db::AsHashDB<H, DBValue> for Ephemeral<'a, S, H> - where H::Out: HeapSizeOf { fn as_hash_db<'b>(&'b self) -> &'b (hash_db::HashDB<H, DBValue> + 'b) { self } fn as_hash_db_mut<'b>(&'b mut self) -> &'b mut (hash_db::HashDB<H, DBValue> + 'b) { self } @@ -185,7 +182,6 @@ impl<'a, H: Hasher > hash_db::PlainDB<H::Out, DBValue> for Ephemeral<'a, S, H> - where H::Out: HeapSizeOf { fn get(&self, key: &H::Out) -> Option<DBValue> { if let Some(val) = hash_db::HashDB::get(self.overlay, key, &[]) { @@ -219,7 +215,6 @@ impl<'a, H: Hasher > hash_db::PlainDBRef<H::Out, DBValue> for Ephemeral<'a, S, H> - where H::Out: HeapSizeOf { fn get(&self, key: &H::Out) -> Option<DBValue> { 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<H, DBValue> for Ephemeral<'a, S, H> - where H::Out: HeapSizeOf { fn get(&self, key: &H::Out, prefix: &[u8]) -> Option<DBValue> { if let Some(val) = hash_db::HashDB::get(self.overlay, key, prefix) { @@ -268,7 +262,6 @@ impl<'a, H: Hasher > hash_db::HashDBRef<H, DBValue> for Ephemeral<'a, S, H> - where H::Out: HeapSizeOf { fn get(&self, key: &H::Out, prefix: &[u8]) -> Option<DBValue> { hash_db::HashDB::get(self, key, prefix) } fn contains(&self, key: &H::Out, prefix: &[u8]) -> bool { hash_db::HashDB::contains(self, key, prefix) }