From c2e19fc19bfd07cefd28a217b36d0881d8f95053 Mon Sep 17 00:00:00 2001 From: cheme Date: Fri, 22 Feb 2019 11:03:54 +0100 Subject: [PATCH 01/12] use parity-util-mem to get heapsize of memory db --- memory-db/Cargo.toml | 3 ++- memory-db/src/lib.rs | 17 +++++++++++++++++ test-support/trie-bench/Cargo.toml | 2 +- trie-db/Cargo.toml | 2 +- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/memory-db/Cargo.toml b/memory-db/Cargo.toml index d6800084..1bb024cd 100644 --- a/memory-db/Cargo.toml +++ b/memory-db/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "memory-db" -version = "0.11.0" +version = "0.12.0" authors = ["Parity Technologies "] description = "In-memory implementation of hash-db, useful for tests" repository = "https://github.com/paritytech/parity-common" @@ -8,6 +8,7 @@ license = "Apache-2.0" [dependencies] heapsize = "0.4" +parity-util-mem = { version = "0.1", path = "../../parity-common/parity-util-mem" } hash-db = { path = "../hash-db", version = "0.11.0"} [dev-dependencies] diff --git a/memory-db/src/lib.rs b/memory-db/src/lib.rs index 96051340..3cf2a947 100644 --- a/memory-db/src/lib.rs +++ b/memory-db/src/lib.rs @@ -15,10 +15,12 @@ //! Reference-counted memory-based `HashDB` implementation. extern crate hash_db; +extern crate parity_util_mem as malloc_size_of; extern crate heapsize; #[cfg(test)] extern crate keccak_hasher; use hash_db::{HashDB, HashDBRef, PlainDB, PlainDBRef, Hasher as KeyHasher, AsHashDB, AsPlainDB}; +use malloc_size_of::{MallocSizeOf, MallocSizeOfOps}; use heapsize::HeapSizeOf; use std::collections::hash_map::Entry; use std::collections::HashMap; @@ -221,6 +223,7 @@ where H: KeyHasher, T: HeapSizeOf, { + #[deprecated(since="0.12.0", note="please use `malloc_size_of` instead")] /// Returns the size of allocated heap memory pub fn mem_used(&self) -> usize { 0//self.data.heap_size_of_children() @@ -228,6 +231,20 @@ where } } +impl MallocSizeOf for MemoryDB +where + H: KeyHasher, + H::Out: MallocSizeOf, + T: MallocSizeOf, +{ + fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + self.data.size_of(ops) + + self.null_node_data.size_of(ops) + + self.hashed_null_node.size_of(ops) + } +} + + impl PlainDB for MemoryDB where H: KeyHasher, diff --git a/test-support/trie-bench/Cargo.toml b/test-support/trie-bench/Cargo.toml index 5e7d83c2..a3ea0a46 100644 --- a/test-support/trie-bench/Cargo.toml +++ b/test-support/trie-bench/Cargo.toml @@ -9,7 +9,7 @@ license = "Apache-2.0" keccak-hasher = { path = "../keccak-hasher", version = "0.11.0" } trie-standardmap = { path = "../trie-standardmap", version = "0.11.0" } hash-db = { path = "../../hash-db" , version = "0.11.0"} -memory-db = { path = "../../memory-db", version = "0.11.0" } +memory-db = { path = "../../memory-db", version = "0.12.0" } trie-root = { path = "../../trie-root", version = "0.11.0" } trie-db = { path = "../../trie-db", version = "0.11.0" } criterion = "0.2.8" diff --git a/trie-db/Cargo.toml b/trie-db/Cargo.toml index 856f2be6..ccea37a4 100644 --- a/trie-db/Cargo.toml +++ b/trie-db/Cargo.toml @@ -14,7 +14,7 @@ hash-db = { path = "../hash-db" , version = "0.11.0"} [dev-dependencies] env_logger = "0.6" -memory-db = { path = "../memory-db", version = "0.11.0" } +memory-db = { path = "../memory-db", version = "0.12.0" } trie-root = { path = "../trie-root", version = "0.11.0"} trie-standardmap = { path = "../test-support/trie-standardmap", version = "0.11.0" } keccak-hasher = { path = "../test-support/keccak-hasher", version = "0.11.0" } From 4284b8540c114bed8016752c814f8a1f2c09afbe Mon Sep 17 00:00:00 2001 From: cheme Date: Wed, 27 Feb 2019 12:09:28 +0100 Subject: [PATCH 02/12] Use github temp instead of local --- memory-db/Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/memory-db/Cargo.toml b/memory-db/Cargo.toml index 1bb024cd..7b5be72a 100644 --- a/memory-db/Cargo.toml +++ b/memory-db/Cargo.toml @@ -8,7 +8,8 @@ license = "Apache-2.0" [dependencies] heapsize = "0.4" -parity-util-mem = { version = "0.1", path = "../../parity-common/parity-util-mem" } +#parity-util-mem = { version = "0.1", path = "../../parity-common/parity-util-mem" } +parity-util-mem = { version = "0.1", git = "https://github.com/cheme/parity-common", branch = "deprecate_heapsize" } hash-db = { path = "../hash-db", version = "0.11.0"} [dev-dependencies] From cba8e5e2600beff862e5c57638886369dd8cba20 Mon Sep 17 00:00:00 2001 From: cheme Date: Wed, 27 Feb 2019 12:38:10 +0100 Subject: [PATCH 03/12] keep version update for later (first need to get util-mem published) --- memory-db/Cargo.toml | 2 +- test-support/trie-bench/Cargo.toml | 2 +- trie-db/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/memory-db/Cargo.toml b/memory-db/Cargo.toml index 7b5be72a..0dba2c9e 100644 --- a/memory-db/Cargo.toml +++ b/memory-db/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "memory-db" -version = "0.12.0" +version = "0.11.0" authors = ["Parity Technologies "] description = "In-memory implementation of hash-db, useful for tests" repository = "https://github.com/paritytech/parity-common" diff --git a/test-support/trie-bench/Cargo.toml b/test-support/trie-bench/Cargo.toml index a3ea0a46..5e7d83c2 100644 --- a/test-support/trie-bench/Cargo.toml +++ b/test-support/trie-bench/Cargo.toml @@ -9,7 +9,7 @@ license = "Apache-2.0" keccak-hasher = { path = "../keccak-hasher", version = "0.11.0" } trie-standardmap = { path = "../trie-standardmap", version = "0.11.0" } hash-db = { path = "../../hash-db" , version = "0.11.0"} -memory-db = { path = "../../memory-db", version = "0.12.0" } +memory-db = { path = "../../memory-db", version = "0.11.0" } trie-root = { path = "../../trie-root", version = "0.11.0" } trie-db = { path = "../../trie-db", version = "0.11.0" } criterion = "0.2.8" diff --git a/trie-db/Cargo.toml b/trie-db/Cargo.toml index ccea37a4..856f2be6 100644 --- a/trie-db/Cargo.toml +++ b/trie-db/Cargo.toml @@ -14,7 +14,7 @@ hash-db = { path = "../hash-db" , version = "0.11.0"} [dev-dependencies] env_logger = "0.6" -memory-db = { path = "../memory-db", version = "0.12.0" } +memory-db = { path = "../memory-db", version = "0.11.0" } trie-root = { path = "../trie-root", version = "0.11.0"} trie-standardmap = { path = "../test-support/trie-standardmap", version = "0.11.0" } keccak-hasher = { path = "../test-support/keccak-hasher", version = "0.11.0" } From 2a1d3bb33a46237096b408f229489e47b6471d8c Mon Sep 17 00:00:00 2001 From: cheme Date: Wed, 27 Feb 2019 14:36:20 +0100 Subject: [PATCH 04/12] Deprecated heapsize only if feature activated (note the value was already disabled) --- memory-db/Cargo.toml | 6 +++++- memory-db/src/lib.rs | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/memory-db/Cargo.toml b/memory-db/Cargo.toml index 0dba2c9e..095c63b7 100644 --- a/memory-db/Cargo.toml +++ b/memory-db/Cargo.toml @@ -7,7 +7,7 @@ repository = "https://github.com/paritytech/parity-common" license = "Apache-2.0" [dependencies] -heapsize = "0.4" +heapsize = { version = "0.4", optional = true } #parity-util-mem = { version = "0.1", path = "../../parity-common/parity-util-mem" } parity-util-mem = { version = "0.1", git = "https://github.com/cheme/parity-common", branch = "deprecate_heapsize" } hash-db = { path = "../hash-db", version = "0.11.0"} @@ -19,3 +19,7 @@ criterion = "0.2.8" [[bench]] name = "bench" harness = false + +[features] +default = [ ] +deprecated = [ "heapsize" ] diff --git a/memory-db/src/lib.rs b/memory-db/src/lib.rs index 3cf2a947..be6f71a9 100644 --- a/memory-db/src/lib.rs +++ b/memory-db/src/lib.rs @@ -16,11 +16,13 @@ extern crate hash_db; extern crate parity_util_mem as malloc_size_of; +#[cfg(feature = "deprecated")] extern crate heapsize; #[cfg(test)] extern crate keccak_hasher; use hash_db::{HashDB, HashDBRef, PlainDB, PlainDBRef, Hasher as KeyHasher, AsHashDB, AsPlainDB}; use malloc_size_of::{MallocSizeOf, MallocSizeOfOps}; +#[cfg(feature = "deprecated")] use heapsize::HeapSizeOf; use std::collections::hash_map::Entry; use std::collections::HashMap; @@ -218,6 +220,7 @@ impl<'a, H: KeyHasher, T> MemoryDB where T: From<&'a [u8]> { } } +#[cfg(feature = "deprecated")] impl MemoryDB where H: KeyHasher, From 0112297052b3cbd59808d62c3d1d01fef4946529 Mon Sep 17 00:00:00 2001 From: cheme Date: Fri, 31 May 2019 18:49:39 +0200 Subject: [PATCH 05/12] improve import of malloc, and change deprecated message. --- memory-db/Cargo.toml | 1 - memory-db/src/lib.rs | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/memory-db/Cargo.toml b/memory-db/Cargo.toml index 04d76e38..88355684 100644 --- a/memory-db/Cargo.toml +++ b/memory-db/Cargo.toml @@ -8,7 +8,6 @@ license = "Apache-2.0" [dependencies] heapsize = { version = "0.4", optional = true } -#parity-util-mem = { version = "0.1", path = "../../parity-common/parity-util-mem" } parity-util-mem = { version = "0.1", git = "https://github.com/cheme/parity-common", branch = "deprecate_heapsize" } hash-db = { path = "../hash-db", default-features = false, version = "0.12.2"} hashmap_core = { version = "0.1" } diff --git a/memory-db/src/lib.rs b/memory-db/src/lib.rs index 6c48ca9d..94178fe4 100644 --- a/memory-db/src/lib.rs +++ b/memory-db/src/lib.rs @@ -18,7 +18,7 @@ #![cfg_attr(not(feature = "std"), feature(alloc))] extern crate hash_db; -extern crate parity_util_mem as malloc_size_of; +extern crate parity_util_mem; #[cfg(feature = "deprecated")] #[cfg(feature = "std")] extern crate heapsize; @@ -29,7 +29,7 @@ extern crate alloc; #[cfg(test)] extern crate keccak_hasher; use hash_db::{HashDB, HashDBRef, PlainDB, PlainDBRef, Hasher as KeyHasher, AsHashDB, AsPlainDB}; -use malloc_size_of::{MallocSizeOf, MallocSizeOfOps}; +use parity_util_mem::{MallocSizeOf, MallocSizeOfOps}; #[cfg(feature = "deprecated")] #[cfg(feature = "std")] use heapsize::HeapSizeOf; @@ -308,7 +308,7 @@ where T: HeapSizeOf, KF: KeyFunction, { - #[deprecated(since="0.12.0", note="please use `malloc_size_of` instead")] + #[deprecated(since="0.12.0", note="please use `size_of` instead")] /// Returns the size of allocated heap memory pub fn mem_used(&self) -> usize { 0//self.data.heap_size_of_children() From 6c01e71932bec7c24c7c117930066fe6716c17d8 Mon Sep 17 00:00:00 2001 From: cheme Date: Fri, 31 May 2019 21:32:49 +0200 Subject: [PATCH 06/12] Use published crate --- memory-db/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/memory-db/Cargo.toml b/memory-db/Cargo.toml index 88355684..0a61abdd 100644 --- a/memory-db/Cargo.toml +++ b/memory-db/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "memory-db" -version = "0.12.2" +version = "0.12.3" authors = ["Parity Technologies "] description = "In-memory implementation of hash-db, useful for tests" repository = "https://github.com/paritytech/trie" @@ -8,7 +8,7 @@ license = "Apache-2.0" [dependencies] heapsize = { version = "0.4", optional = true } -parity-util-mem = { version = "0.1", git = "https://github.com/cheme/parity-common", branch = "deprecate_heapsize" } +parity-util-mem = { version = "0.1" } hash-db = { path = "../hash-db", default-features = false, version = "0.12.2"} hashmap_core = { version = "0.1" } From ecef806bc20747b6e4a0d0d17ac572d0c8c46a48 Mon Sep 17 00:00:00 2001 From: cheme Date: Mon, 3 Jun 2019 10:39:47 +0200 Subject: [PATCH 07/12] Full crate version update (mem db is use by hash and trie so updating everything is safer and probably needed). --- hash-db/Cargo.toml | 2 +- hash256-std-hasher/Cargo.toml | 2 +- memory-db/Cargo.toml | 4 ++-- test-support/keccak-hasher/Cargo.toml | 6 +++--- test-support/reference-trie/Cargo.toml | 14 +++++++------- test-support/trie-bench/Cargo.toml | 14 +++++++------- test-support/trie-standardmap/Cargo.toml | 4 ++-- trie-db/Cargo.toml | 14 +++++++------- trie-root/Cargo.toml | 10 +++++----- 9 files changed, 35 insertions(+), 35 deletions(-) diff --git a/hash-db/Cargo.toml b/hash-db/Cargo.toml index 04d7c506..398ed562 100644 --- a/hash-db/Cargo.toml +++ b/hash-db/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hash-db" -version = "0.12.2" +version = "0.12.3" authors = ["Parity Technologies "] description = "Trait for hash-keyed databases." license = "Apache-2.0" diff --git a/hash256-std-hasher/Cargo.toml b/hash256-std-hasher/Cargo.toml index a7cdf8dc..e7b8d5c9 100644 --- a/hash256-std-hasher/Cargo.toml +++ b/hash256-std-hasher/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "hash256-std-hasher" description = "Standard library hasher for 256-bit prehashed keys." -version = "0.12.2" +version = "0.12.3" authors = ["Parity Technologies "] license = "Apache-2.0" homepage = "https://github.com/paritytech/trie" diff --git a/memory-db/Cargo.toml b/memory-db/Cargo.toml index 0a61abdd..406befb5 100644 --- a/memory-db/Cargo.toml +++ b/memory-db/Cargo.toml @@ -9,11 +9,11 @@ license = "Apache-2.0" [dependencies] heapsize = { version = "0.4", optional = true } parity-util-mem = { version = "0.1" } -hash-db = { path = "../hash-db", default-features = false, version = "0.12.2"} +hash-db = { path = "../hash-db", default-features = false, version = "0.12.3"} hashmap_core = { version = "0.1" } [dev-dependencies] -keccak-hasher = { path = "../test-support/keccak-hasher", version = "0.12.2"} +keccak-hasher = { path = "../test-support/keccak-hasher", version = "0.12.3"} criterion = "0.2.8" [features] diff --git a/test-support/keccak-hasher/Cargo.toml b/test-support/keccak-hasher/Cargo.toml index 8992135c..3ed75357 100644 --- a/test-support/keccak-hasher/Cargo.toml +++ b/test-support/keccak-hasher/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "keccak-hasher" -version = "0.12.2" +version = "0.12.3" authors = ["Parity Technologies "] description = "Keccak-256 implementation of the Hasher trait" repository = "https://github.com/paritytech/parity/" @@ -8,8 +8,8 @@ license = "Apache-2.0" [dependencies] tiny-keccak = "1.4.2" -hash-db = { path = "../../hash-db", default-features = false, version = "0.12.2" } -hash256-std-hasher = { path = "../../hash256-std-hasher", version = "0.12.2" } +hash-db = { path = "../../hash-db", default-features = false, version = "0.12.3" } +hash256-std-hasher = { path = "../../hash256-std-hasher", version = "0.12.3" } [features] default = ["std"] diff --git a/test-support/reference-trie/Cargo.toml b/test-support/reference-trie/Cargo.toml index ef20bda1..76107199 100644 --- a/test-support/reference-trie/Cargo.toml +++ b/test-support/reference-trie/Cargo.toml @@ -1,22 +1,22 @@ [package] name = "reference-trie" -version = "0.12.2" +version = "0.12.3" authors = ["Parity Technologies "] description = "Simple reference trie format" repository = "https://github.com/paritytech/trie/" license = "Apache-2.0" [dependencies] -hash-db = { path = "../../hash-db" , version = "0.12.2"} -hash256-std-hasher = { path = "../../hash256-std-hasher", version = "0.12.2" } -keccak-hasher = { path = "../keccak-hasher", version = "0.12.2" } -trie-db = { path = "../../trie-db", default-features = false, version = "0.12.2"} -trie-root = { path = "../../trie-root", default-features = false, version = "0.12.2" } +hash-db = { path = "../../hash-db" , version = "0.12.3"} +hash256-std-hasher = { path = "../../hash256-std-hasher", version = "0.12.3" } +keccak-hasher = { path = "../keccak-hasher", version = "0.12.3" } +trie-db = { path = "../../trie-db", default-features = false, version = "0.12.3"} +trie-root = { path = "../../trie-root", default-features = false, version = "0.12.3" } parity-codec = "3.0" parity-codec-derive = "3.0" [dev-dependencies] -trie-bench = { path = "../trie-bench", version = "0.12.2" } +trie-bench = { path = "../trie-bench", version = "0.12.3" } criterion = "0.2.8" [[bench]] diff --git a/test-support/trie-bench/Cargo.toml b/test-support/trie-bench/Cargo.toml index 78f8070e..df12f5f5 100644 --- a/test-support/trie-bench/Cargo.toml +++ b/test-support/trie-bench/Cargo.toml @@ -1,16 +1,16 @@ [package] name = "trie-bench" description = "Standard benchmarking suite for tries" -version = "0.12.2" +version = "0.12.3" authors = ["Parity Technologies "] license = "Apache-2.0" [dependencies] -keccak-hasher = { path = "../keccak-hasher", version = "0.12.2" } -trie-standardmap = { path = "../trie-standardmap", version = "0.12.2" } -hash-db = { path = "../../hash-db" , version = "0.12.2"} -memory-db = { path = "../../memory-db", version = "0.12.2" } -trie-root = { path = "../../trie-root", version = "0.12.2" } -trie-db = { path = "../../trie-db", version = "0.12.2" } +keccak-hasher = { path = "../keccak-hasher", version = "0.12.3" } +trie-standardmap = { path = "../trie-standardmap", version = "0.12.3" } +hash-db = { path = "../../hash-db" , version = "0.12.3"} +memory-db = { path = "../../memory-db", version = "0.12.3" } +trie-root = { path = "../../trie-root", version = "0.12.3" } +trie-db = { path = "../../trie-db", version = "0.12.3" } criterion = "0.2.8" parity-codec = "3.0" diff --git a/test-support/trie-standardmap/Cargo.toml b/test-support/trie-standardmap/Cargo.toml index ae90d508..68418275 100644 --- a/test-support/trie-standardmap/Cargo.toml +++ b/test-support/trie-standardmap/Cargo.toml @@ -6,5 +6,5 @@ authors = ["Parity Technologies "] license = "Apache-2.0" [dependencies] -keccak-hasher = { path = "../keccak-hasher", version = "0.12.2"} -hash-db = { path = "../../hash-db" , version = "0.12.2"} +keccak-hasher = { path = "../keccak-hasher", version = "0.12.3"} +hash-db = { path = "../../hash-db" , version = "0.12.3"} diff --git a/trie-db/Cargo.toml b/trie-db/Cargo.toml index b6a075b6..1f2cdf89 100644 --- a/trie-db/Cargo.toml +++ b/trie-db/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "trie-db" -version = "0.12.2" +version = "0.12.3" authors = ["Parity Technologies "] description = "Merkle-Patricia Trie generic over key hasher and node encoding" repository = "https://github.com/paritytech/trie" @@ -10,17 +10,17 @@ license = "Apache-2.0" log = "0.4" rand = { version = "0.6", default-features = false } elastic-array = { version = "0.10", default-features = false } -hash-db = { path = "../hash-db", default-features = false, version = "0.12.2"} +hash-db = { path = "../hash-db", default-features = false, version = "0.12.3"} hashmap_core = { version = "0.1" } [dev-dependencies] env_logger = "0.6" -memory-db = { path = "../memory-db", version = "0.12.2" } -trie-root = { path = "../trie-root", version = "0.12.2"} -trie-standardmap = { path = "../test-support/trie-standardmap", version = "0.12.2" } -keccak-hasher = { path = "../test-support/keccak-hasher", version = "0.12.2" } +memory-db = { path = "../memory-db", version = "0.12.3" } +trie-root = { path = "../trie-root", version = "0.12.3"} +trie-standardmap = { path = "../test-support/trie-standardmap", version = "0.12.3" } +keccak-hasher = { path = "../test-support/keccak-hasher", version = "0.12.3" } # DISABLE the following line when publishing until cyclic dependencies are resolved https://github.com/rust-lang/cargo/issues/4242 -reference-trie = { path = "../test-support/reference-trie", version = "0.12.2" } +reference-trie = { path = "../test-support/reference-trie", version = "0.12.3" } hex-literal = "0.1" criterion = "0.2.8" diff --git a/trie-root/Cargo.toml b/trie-root/Cargo.toml index 637d8a1e..8c5a3411 100644 --- a/trie-root/Cargo.toml +++ b/trie-root/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "trie-root" -version = "0.12.2" +version = "0.12.3" authors = ["Parity Technologies "] description = "In-memory patricia trie operations" repository = "https://github.com/paritytech/trie" @@ -8,14 +8,14 @@ license = "Apache-2.0" categories = [ "no-std" ] [dependencies] -hash-db = { path = "../hash-db", default-features = false, version = "0.12.2"} +hash-db = { path = "../hash-db", default-features = false, version = "0.12.3"} [dev-dependencies] hex-literal = "0.1" -keccak-hasher = { path = "../test-support/keccak-hasher", version = "0.12.2" } -trie-standardmap = { path = "../test-support/trie-standardmap", version = "0.12.2" } +keccak-hasher = { path = "../test-support/keccak-hasher", version = "0.12.3" } +trie-standardmap = { path = "../test-support/trie-standardmap", version = "0.12.3" } # DISABLE the following line when publishing until cyclic dependencies are resolved https://github.com/rust-lang/cargo/issues/4242 -reference-trie = { path = "../test-support/reference-trie", version = "0.12.2" } +reference-trie = { path = "../test-support/reference-trie", version = "0.12.3" } [features] default = ["std"] From 4fbc1105e9fc9d42d05666b3ec0ac682ff2cc5ac Mon Sep 17 00:00:00 2001 From: cheme Date: Mon, 3 Jun 2019 10:56:54 +0200 Subject: [PATCH 08/12] no_std for parity util mem --- memory-db/Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/memory-db/Cargo.toml b/memory-db/Cargo.toml index 406befb5..5a11cd11 100644 --- a/memory-db/Cargo.toml +++ b/memory-db/Cargo.toml @@ -8,7 +8,7 @@ license = "Apache-2.0" [dependencies] heapsize = { version = "0.4", optional = true } -parity-util-mem = { version = "0.1" } +parity-util-mem = { version = "0.1", default-features = false } hash-db = { path = "../hash-db", default-features = false, version = "0.12.3"} hashmap_core = { version = "0.1" } @@ -21,6 +21,7 @@ default = ["std"] std = [ "hash-db/std", "hashmap_core/disable", + "parity-util-mem/std", ] deprecated = [ "heapsize" ] From cfe6c0bf018323dd710a7bfed1b9d6795761e804 Mon Sep 17 00:00:00 2001 From: cheme Date: Thu, 6 Jun 2019 16:38:33 +0200 Subject: [PATCH 09/12] Add prefix and empty prefix. --- hash-db/src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hash-db/src/lib.rs b/hash-db/src/lib.rs index c6aff276..723971b4 100644 --- a/hash-db/src/lib.rs +++ b/hash-db/src/lib.rs @@ -32,6 +32,13 @@ pub trait MaybeDebug {} #[cfg(not(feature = "std"))] impl MaybeDebug for T {} + +/// Empty prefix constant. +pub static EMPTY_PREFIX: Prefix<'static> = &[]; + +/// Prefix byte information for avoding rc. +pub type Prefix<'a> = &'a[u8]; + /// Trait describing an object that can hash a slice of bytes. Used to abstract /// other types over the hashing algorithm. Defines a single `hash` method and an /// `Out` associated type with the necessary bounds. From e670d380ef6119ba72e20941b4751df8c550ca3a Mon Sep 17 00:00:00 2001 From: cheme Date: Thu, 6 Jun 2019 18:06:30 +0200 Subject: [PATCH 10/12] Needed clone on kf --- memory-db/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/memory-db/src/lib.rs b/memory-db/src/lib.rs index 94178fe4..1ebdfc99 100644 --- a/memory-db/src/lib.rs +++ b/memory-db/src/lib.rs @@ -140,6 +140,7 @@ pub fn hash_key(key: &H::Out, _prefix: &[u8]) -> H::Out { key.clone() } +#[derive(Clone,Debug)] /// Key function that only uses the hash pub struct HashKey(PhantomData); @@ -151,6 +152,7 @@ impl KeyFunction for HashKey { } } +#[derive(Clone,Debug)] /// Key function that concatenates prefix and hash. pub struct PrefixedKey(PhantomData); From 2ec922a503d39b5da5763bc8e205bf9cd7188a2f Mon Sep 17 00:00:00 2001 From: cheme Date: Thu, 6 Jun 2019 18:09:03 +0200 Subject: [PATCH 11/12] manually implement partialeq to memorydb --- memory-db/src/lib.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/memory-db/src/lib.rs b/memory-db/src/lib.rs index 1ebdfc99..9f5ca20f 100644 --- a/memory-db/src/lib.rs +++ b/memory-db/src/lib.rs @@ -109,7 +109,7 @@ use alloc::vec::Vec; /// assert!(!m.contains(&k, &[])); /// } /// ``` -#[derive(Clone, PartialEq)] +#[derive(Clone)] pub struct MemoryDB where H: KeyHasher, @@ -121,6 +121,33 @@ pub struct MemoryDB _kf: PhantomData, } +impl PartialEq> for MemoryDB + where + H: KeyHasher, + KF: KeyFunction, + >::Key: Eq + MaybeDebug, + T: Eq + MaybeDebug, +{ + fn eq(&self, other: &MemoryDB) -> bool { + for a in self.data.iter() { + match other.data.get(&a.0) { + Some(v) if v != a.1 => return false, + None => return false, + _ => (), + } + } + true + } +} + +impl Eq for MemoryDB + where + H: KeyHasher, + KF: KeyFunction, + >::Key: Eq + MaybeDebug, + T: Eq + MaybeDebug, +{} + pub trait KeyFunction { type Key: Send + Sync + Clone + hash::Hash + Eq; From 3867002062bed1b540f8d01f42cf63e2e317a7f2 Mon Sep 17 00:00:00 2001 From: cheme Date: Thu, 6 Jun 2019 18:10:47 +0200 Subject: [PATCH 12/12] Fix maybedebug trait absence. --- memory-db/src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/memory-db/src/lib.rs b/memory-db/src/lib.rs index 9f5ca20f..69d22e8b 100644 --- a/memory-db/src/lib.rs +++ b/memory-db/src/lib.rs @@ -62,6 +62,15 @@ use core::{ #[cfg(not(feature = "std"))] use alloc::vec::Vec; +#[cfg(feature = "std")] +pub trait MaybeDebug: std::fmt::Debug {} +#[cfg(feature = "std")] +impl MaybeDebug for T {} +#[cfg(not(feature = "std"))] +pub trait MaybeDebug {} +#[cfg(not(feature = "std"))] +impl MaybeDebug for T {} + /// Reference-counted memory-based `HashDB` implementation. /// /// Use `new()` to create a new database. Insert items with `insert()`, remove items