Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
776f324
fuse commit of no extension branch.
cheme Feb 15, 2019
4eae594
Tabify.
cheme Feb 19, 2019
5d79a12
Implementation for trie_root.
cheme Feb 22, 2019
fe603e8
Merge branch '12' into n_ext_trie_key, try to complete for no_ext, tests
cheme Mar 21, 2019
e7b299c
Fix test
cheme Mar 22, 2019
2ca4542
Fuzz of prefix seems ok for pr 12, no_ext things are totally broken.
cheme Mar 22, 2019
cfeb96a
Fix iter_build key indexes.
cheme Mar 22, 2019
e38532c
Merge branch 'master' into n_ext_trie_key, tests are broken again
cheme Apr 1, 2019
1d9be11
Fix merge regression
cheme Apr 2, 2019
f1fdcbd
No error found : need more tests (after evos).
cheme Apr 2, 2019
bd5b735
Put a no_ext header specific scheme (with second bit as in substrate).
cheme Apr 2, 2019
e727fbd
Fix decoding issue of iter
cheme Apr 2, 2019
b3c988c
Reset fuzzer to right no_ext impl, found a failing test (in comment).
cheme Apr 2, 2019
bdd99c0
Find and fix fuzzing error (a missing branch child ix).
cheme Apr 3, 2019
ac36fc9
Removing bench blobs.
cheme Apr 3, 2019
42c2eba
Minor change (remove dead branch, and useless encoding, also panic on
cheme Apr 8, 2019
84ff90d
Use a unique trait for spec (layout) : hasher, nodecodec and alogorithm
cheme Apr 9, 2019
e092a0c
Fuse triedbmut code, before remove NoExt variant
cheme Apr 9, 2019
3bd3127
Fix merge and remove triedbmutnoext variant.
cheme Apr 9, 2019
a8b73f6
No instance for Layout (NodeCodec should have one at some point), to
cheme Apr 9, 2019
1c34745
Apply layout trait to non mut trie too.
cheme Apr 9, 2019
12842a6
Nibbleslice using inner trait to define multiple encoding: this is
cheme Apr 10, 2019
4478ece
NibbleVec move size arelated methods.
cheme Apr 10, 2019
318e7c8
Reverse padding in nibble
cheme Apr 11, 2019
b30698a
start testing, first broken part see triedbmut advance println
cheme Apr 11, 2019
097fec5
Fix offset issue of nodecodec
cheme Apr 12, 2019
f892c76
Switch remaining tests to use postfix for no ext
cheme Apr 12, 2019
57a86c5
Switch header encoding scheme. Failing test is related to the
cheme Apr 12, 2019
0cab2eb
TrieStream implementation : warning it is not parameterized.
cheme Apr 16, 2019
f21398b
Back to prefix padded nibble (TODO see if removal of all previous change
cheme Apr 17, 2019
d36ba7d
Simplification of nibleslice, not stabilized yet (many unused and some
cheme Apr 18, 2019
bc1ae2b
fix stack of prefix on commit
cheme Apr 18, 2019
4ddb1eb
fix into_part method
cheme Apr 19, 2019
da335d4
fix fuzz1
cheme Apr 19, 2019
f276ace
bad work on fixing fix: buf is needed only for terminal and recursive is
cheme Apr 19, 2019
c5d907d
small cleaning
cheme Apr 19, 2019
71e8fab
Fix remove issue, will need more test (playpen on noext and check
cheme Apr 20, 2019
0c7efd1
clean up prefixkeymut before merge with keyvec
cheme Apr 22, 2019
8ee9798
implement, still 2 failing test (note on remove I did change prefix a…
cheme Apr 22, 2019
241eb4a
nightly debug format
cheme Apr 20, 2019
107027b
Use keyvec instead of keymut.
cheme Apr 22, 2019
ca950b9
ref padding constant
cheme Apr 23, 2019
ba7de31
remove PartialKey (same as NibbleSlice in this state).
cheme Apr 23, 2019
5de3fbe
no ext error from playpen
cheme Apr 23, 2019
cf2b5e3
Fix playpen error.
cheme Apr 23, 2019
2e8cd6a
fix some warnings
cheme Apr 24, 2019
6c69177
use nibblevec instead of vec in iter, TODO still need remove a useless
cheme Apr 24, 2019
fbe84fb
end of switch Vec<u8> to NibbleVec, this will need a bench.
cheme Apr 24, 2019
50fec85
make a nibble module to share field between vec and slice
cheme Apr 25, 2019
275f5b8
push_pop on quarter
cheme Apr 25, 2019
6fd7531
in progress - append_partial
cheme Apr 28, 2019
959da6c
partial & prefix cannot be simply option but (nb_nibble, aligned_val)…
cheme Apr 30, 2019
dd93050
switch partial to (u8, u8)
cheme Apr 30, 2019
b756248
Replace prefix option by index bytes
cheme May 1, 2019
9e45eda
clean code from padding_bitmask a bit
cheme May 2, 2019
9657a15
Fix regression
cheme May 2, 2019
3bfe451
fuzz1 and 2 passing
cheme May 3, 2019
757f630
a few fix, next needed are combine_key and shifted_key
cheme May 3, 2019
2704459
fix a few test
cheme May 4, 2019
d844cd2
fix range iter
cheme May 5, 2019
8f428f1
remove a few todos and fix bench (except memdb).
cheme May 6, 2019
e88dbc2
cleaning
cheme May 6, 2019
8a4f75e
Abstract buff size of iter_build
cheme May 6, 2019
398c915
plug iter_build on TrieLayout
cheme May 6, 2019
38c4899
Make children slice variable length depending on trait.
cheme May 7, 2019
45009f8
Clone and debug for kf function
cheme May 8, 2019
1c40a98
nibble vec append fix
cheme May 8, 2019
c4ace9a
right vec append fix
cheme May 9, 2019
530f5f1
Add debug assertion to help implementation of codec.
cheme May 9, 2019
a8bcdf5
fix
cheme May 9, 2019
28271c2
lookup advance branch for other than 16
cheme May 9, 2019
57bb429
no_std update
cheme May 10, 2019
bce5c66
Fix no ext key lookup
cheme May 13, 2019
f9430e0
smaller empty prefix result
cheme May 13, 2019
0ada0af
Fix wasm code (rust std doc for usize is unaccurate).
cheme May 13, 2019
1a09044
bench len/size factor 2
cheme May 14, 2019
7cec6af
Add test with values on encode_size, fix debug output (previous change
cheme May 23, 2019
b13bb9a
indent
cheme May 23, 2019
06f5360
do not allow decoding of longer length node (encoding still truncate)
cheme May 30, 2019
ed68da6
format
cheme May 31, 2019
feb0660
Legacy prefix tools.
cheme Jun 4, 2019
776a1f3
Fix legacy prefix
cheme Jun 4, 2019
43b3225
Some documentation, and switch `masked_right` semantic to be similar to
cheme Jun 5, 2019
727837d
Documentation improvement and breaking long lines.
cheme Jun 5, 2019
8d1b2ae
some additional formatting
cheme Jun 5, 2019
a5a95bd
Remove BM from NodeCodec (specific to some implementation only).
cheme Jun 5, 2019
be66ce2
Invalid asumption about prefix ordering of key, fix doc and implement
cheme Jun 6, 2019
ddd24d2
OrderedPrefix instance.
cheme Jun 7, 2019
fec4a79
inprogress
cheme Jun 9, 2019
b45762d
No exessive buffer len, simplify flush_branch.
cheme Jun 9, 2019
0218331
fix quarter error
cheme Jun 10, 2019
82c920a
Merge branch 'master' into n_ext_trie
cheme Jun 22, 2019
a2f31c5
iter_build instance with print trace.
cheme Jun 22, 2019
65b748a
gen impl over H.
cheme Jun 22, 2019
56b1398
no_std
cheme Jun 25, 2019
4c381d7
Merge branch 'n_ext_trie' of github.com:cheme/trie into n_ext_trie
cheme Jun 25, 2019
2efca9b
fix no_std bis
cheme Jun 25, 2019
fcb70e2
no_std tierce
cheme Jun 25, 2019
116978f
quick bench trie mut against trie root.
cheme Jul 3, 2019
af7f2bb
memory db building iter_build benches
cheme Jul 3, 2019
6d38133
Merge branch 'master' into n_ext_trie
cheme Jul 8, 2019
5eb9b99
update versioning
cheme Jul 8, 2019
0a29389
Small doc changes and formatting fixes.
cheme Jul 22, 2019
5e1126a
ChildBitmap renamed to more generic BitMap.
cheme Jul 22, 2019
c8e66cd
Renaming of LayOut to Layout.
cheme Jul 22, 2019
bb2588e
replace _ix with _index, bm with bitmap, and Ix with Index.
cheme Jul 22, 2019
202bc74
Removing padding length from prefix.
cheme Jul 24, 2019
0de2f85
Renamings.
cheme Jul 24, 2019
93e9c13
Remove substrate from comment.
cheme Jul 24, 2019
699cdc0
First pass of renamaings.
cheme Jul 26, 2019
68e3832
Line length bellow 100.
cheme Jul 26, 2019
19f92fb
add after comma space and after closure paramater space.
cheme Jul 26, 2019
4f3bb58
Renaming of variables and methods.
cheme Jul 26, 2019
a65724d
Some line length.
cheme Jul 26, 2019
502740b
Rename subtrait of TrieLayout to full names.
cheme Jul 29, 2019
b6e8f9c
Replace 'masked_' by 'pad_'.
cheme Jul 29, 2019
5ada0fe
documentation small fixes.
cheme Jul 29, 2019
2fe240c
Restore new line at end.
cheme Jul 29, 2019
5a81906
Remove old feature.
cheme Jul 29, 2019
fb0e822
Merge branch 'master' into n_ext_trie
cheme Jul 31, 2019
8a9cc47
Remove multiple trie radix support.
cheme Jul 31, 2019
d9a12d0
Comment.
cheme Jul 31, 2019
869b4ce
formatting, and remove unused BitMap trait.
cheme Aug 1, 2019
9b94482
Removing: radix related cache struct from iter_build.
cheme Aug 1, 2019
5b9b022
No assumption on biggest_depth.
cheme Aug 1, 2019
79d71b6
fixing biggest depth correctly.
cheme Aug 1, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hash-db/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hash-db"
version = "0.14.0"
version = "0.15.0"
authors = ["Parity Technologies <[email protected]>"]
description = "Trait for hash-keyed databases."
license = "Apache-2.0"
Expand Down
76 changes: 47 additions & 29 deletions hash-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,47 @@
use std::fmt::Debug;
#[cfg(feature = "std")]
use std::hash;
#[cfg(not(feature = "std"))]
use core::hash;

#[cfg(feature = "std")]
pub trait MaybeDebug: Debug {}
#[cfg(feature = "std")]
impl<T: Debug> MaybeDebug for T {}

#[cfg(not(feature = "std"))]
use core::hash;
#[cfg(not(feature = "std"))]
pub trait MaybeDebug {}
#[cfg(not(feature = "std"))]
impl<T> MaybeDebug for T {}


/// Empty prefix constant.
pub static EMPTY_PREFIX: Prefix<'static> = &[];
/// A trie node prefix, it is the nibble path from the trie root
/// to the trie node.
/// For a node containing no partial key value it is the full key.
/// For a value node or node containing a partial key, it is the full key minus its node partial
/// nibbles (the node key can be split into prefix and node partial).
/// Therefore it is always the leftmost portion of the node key, so its internal representation
/// is a non expanded byte slice followed by a last padded byte representation.
/// The padded byte is an optional padded value.
pub type Prefix<'a> = (&'a[u8], Option<u8>);

/// Prefix byte information for avoding rc.
pub type Prefix<'a> = &'a[u8];
/// An empty prefix constant.
/// Can be use when the prefix is not use internally
/// or for root nodes.
pub static EMPTY_PREFIX: Prefix<'static> = (&[], None);

/// 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.
pub trait Hasher: Sync + Send {
/// The output type of the `Hasher`
type Out: AsRef<[u8]> + AsMut<[u8]> + Default + MaybeDebug + PartialEq + Eq + hash::Hash + Send + Sync + Clone + Copy;
/// What to use to build `HashMap`s with this `Hasher`
type Out: AsRef<[u8]> + AsMut<[u8]> + Default + MaybeDebug + PartialEq + Eq
+ hash::Hash + Send + Sync + Clone + Copy;
/// What to use to build `HashMap`s with this `Hasher`.
type StdHasher: Sync + Send + Default + hash::Hasher;
/// The length in bytes of the `Hasher` output
/// The length in bytes of the `Hasher` output.
const LENGTH: usize;

/// Compute the hash of the provided slice of bytes returning the `Out` type of the `Hasher`
/// Compute the hash of the provided slice of bytes returning the `Out` type of the `Hasher`.
fn hash(x: &[u8]) -> Self::Out;
}

Expand Down Expand Up @@ -101,42 +111,47 @@ impl<'a, K, V> PlainDBRef<K, V> for &'a mut dyn PlainDB<K, V> {
pub trait HashDB<H: Hasher, T>: Send + Sync + AsHashDB<H, T> {
/// Look up a given hash into the bytes that hash to it, returning None if the
/// hash is not known.
fn get(&self, key: &H::Out, prefix: &[u8]) -> Option<T>;
fn get(&self, key: &H::Out, prefix: Prefix) -> Option<T>;

/// Check for the existance of a hash-key.
fn contains(&self, key: &H::Out, prefix: &[u8]) -> bool;
fn contains(&self, key: &H::Out, prefix: Prefix) -> bool;

/// Insert a datum item into the DB and return the datum's hash for a later lookup. Insertions
/// are counted and the equivalent number of `remove()`s must be performed before the data
/// is considered dead.
fn insert(&mut self, prefix: &[u8], value: &[u8]) -> H::Out;
fn insert(&mut self, prefix: Prefix, value: &[u8]) -> H::Out;

/// Like `insert()`, except you provide the key and the data is all moved.
fn emplace(&mut self, key: H::Out, prefix: &[u8], value: T);
fn emplace(&mut self, key: H::Out, prefix: Prefix, value: T);

/// Remove a datum previously inserted. Insertions can be "owed" such that the same number of `insert()`s may
/// happen without the data being eventually being inserted into the DB. It can be "owed" more than once.
fn remove(&mut self, key: &H::Out, prefix: &[u8]);
/// Remove a datum previously inserted. Insertions can be "owed" such that the same number of
/// `insert()`s may happen without the data being eventually being inserted into the DB.
/// It can be "owed" more than once.
fn remove(&mut self, key: &H::Out, prefix: Prefix);
}

/// Trait for immutable reference of HashDB.
pub trait HashDBRef<H: Hasher, T> {
/// Look up a given hash into the bytes that hash to it, returning None if the
/// hash is not known.
fn get(&self, key: &H::Out, prefix: &[u8]) -> Option<T>;
fn get(&self, key: &H::Out, prefix: Prefix) -> Option<T>;

/// Check for the existance of a hash-key.
fn contains(&self, key: &H::Out, prefix: &[u8]) -> bool;
fn contains(&self, key: &H::Out, prefix: Prefix) -> bool;
}

impl<'a, H: Hasher, T> HashDBRef<H, T> for &'a dyn HashDB<H, T> {
fn get(&self, key: &H::Out, prefix: &[u8]) -> Option<T> { HashDB::get(*self, key, prefix) }
fn contains(&self, key: &H::Out, prefix: &[u8]) -> bool { HashDB::contains(*self, key, prefix) }
fn get(&self, key: &H::Out, prefix: Prefix) -> Option<T> { HashDB::get(*self, key, prefix) }
fn contains(&self, key: &H::Out, prefix: Prefix) -> bool {
HashDB::contains(*self, key, prefix)
}
}

impl<'a, H: Hasher, T> HashDBRef<H, T> for &'a mut dyn HashDB<H, T> {
fn get(&self, key: &H::Out, prefix: &[u8]) -> Option<T> { HashDB::get(*self, key, prefix) }
fn contains(&self, key: &H::Out, prefix: &[u8]) -> bool { HashDB::contains(*self, key, prefix) }
fn get(&self, key: &H::Out, prefix: Prefix) -> Option<T> { HashDB::get(*self, key, prefix) }
fn contains(&self, key: &H::Out, prefix: Prefix) -> bool {
HashDB::contains(*self, key, prefix)
}
}

/// Upcast trait for HashDB.
Expand All @@ -155,15 +170,18 @@ pub trait AsPlainDB<K, V> {
fn as_plain_db_mut<'a>(&'a mut self) -> &'a mut (dyn PlainDB<K, V> + 'a);
}

// NOTE: There used to be a `impl<T> AsHashDB for T` but that does not work with generics. See https://stackoverflow.com/questions/48432842/implementing-a-trait-for-reference-and-non-reference-types-causes-conflicting-im
// This means we need concrete impls of AsHashDB in several places, which somewhat defeats the point of the trait.
// NOTE: There used to be a `impl<T> AsHashDB for T` but that does not work with generics.
// See https://stackoverflow.com/questions/48432842/
// implementing-a-trait-for-reference-and-non-reference-types-causes-conflicting-im
// This means we need concrete impls of AsHashDB in several places, which somewhat defeats
// the point of the trait.
impl<'a, H: Hasher, T> AsHashDB<H, T> for &'a mut dyn HashDB<H, T> {
fn as_hash_db(&self) -> &dyn HashDB<H, T> { &**self }
fn as_hash_db_mut<'b>(&'b mut self) -> &'b mut (dyn HashDB<H, T> + 'b) { &mut **self }
}

#[cfg(feature = "std")]
impl<'a, K, V> AsPlainDB<K, V> for &'a mut PlainDB<K, V> {
fn as_plain_db(&self) -> &PlainDB<K, V> { &**self }
fn as_plain_db_mut<'b>(&'b mut self) -> &'b mut (PlainDB<K, V> + 'b) { &mut **self }
impl<'a, K, V> AsPlainDB<K, V> for &'a mut dyn PlainDB<K, V> {
fn as_plain_db(&self) -> &dyn PlainDB<K, V> { &**self }
fn as_plain_db_mut<'b>(&'b mut self) -> &'b mut (dyn PlainDB<K, V> + 'b) { &mut **self }
}
2 changes: 1 addition & 1 deletion hash256-std-hasher/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "hash256-std-hasher"
description = "Standard library hasher for 256-bit prehashed keys."
version = "0.14.0"
version = "0.15.0"
authors = ["Parity Technologies <[email protected]>"]
license = "Apache-2.0"
homepage = "https://github.com/paritytech/trie"
Expand Down
1 change: 0 additions & 1 deletion hash256-std-hasher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(core_intrinsics))]

#[macro_use]
extern crate crunchy;
Expand Down
6 changes: 3 additions & 3 deletions memory-db/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "memory-db"
version = "0.14.0"
version = "0.15.0"
authors = ["Parity Technologies <[email protected]>"]
description = "In-memory implementation of hash-db, useful for tests"
repository = "https://github.com/paritytech/trie"
Expand All @@ -9,11 +9,11 @@ license = "Apache-2.0"
[dependencies]
heapsize = { version = "0.4", optional = true }
parity-util-mem = { version = "0.2", default-features = false }
hash-db = { path = "../hash-db", default-features = false, version = "0.14.0"}
hash-db = { path = "../hash-db", default-features = false, version = "0.15.0"}
hashmap_core = { version = "0.1" }

[dev-dependencies]
keccak-hasher = { path = "../test-support/keccak-hasher", version = "0.14.0"}
keccak-hasher = { path = "../test-support/keccak-hasher", version = "0.15.0"}
criterion = "0.2.8"

[features]
Expand Down
17 changes: 9 additions & 8 deletions memory-db/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ extern crate memory_db;
extern crate keccak_hasher;

use memory_db::MemoryDB;
use memory_db::HashKey;
use keccak_hasher::KeccakHasher;
use hash_db::{HashDB, Hasher};
use hash_db::{HashDB, Hasher, EMPTY_PREFIX};

fn instantiation(b: &mut Criterion) {
b.bench_function("instantiation", |b| b.iter(|| {
MemoryDB::<KeccakHasher, Vec<u8>>::default();
MemoryDB::<KeccakHasher, HashKey<KeccakHasher>, Vec<u8>>::default();
}));
}

Expand All @@ -52,19 +53,19 @@ fn compare_to_null_in_const(b: &mut Criterion) {
}

fn contains_with_non_null_key(b: &mut Criterion) {
let mut m = MemoryDB::<KeccakHasher, Vec<u8>>::default();
let mut m = MemoryDB::<KeccakHasher, HashKey<KeccakHasher>, Vec<u8>>::default();
let key = KeccakHasher::hash(b"abc");
m.insert(b"abcefghijklmnopqrstuvxyz");
m.insert(EMPTY_PREFIX, b"abcefghijklmnopqrstuvxyz");
b.bench_function("contains_with_non_null_key", |b| b.iter(|| {
m.contains(&key);
m.contains(&key, EMPTY_PREFIX);
}));
}

fn contains_with_null_key(b: &mut Criterion) {
let mut m = MemoryDB::<KeccakHasher, Vec<u8>>::default();
let mut m = MemoryDB::<KeccakHasher, HashKey<KeccakHasher>, Vec<u8>>::default();
let null_key = KeccakHasher::hash(&[0u8][..]);
m.insert(b"abcefghijklmnopqrstuvxyz");
m.insert(EMPTY_PREFIX, b"abcefghijklmnopqrstuvxyz");
b.bench_function("contains_with_null_key", |b| b.iter(|| {
m.contains(&null_key);
m.contains(&null_key, EMPTY_PREFIX);
}));
}
Loading