Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
No instance for Layout (NodeCodec should have one at some point), to
benefit from constant.
  • Loading branch information
cheme committed Apr 9, 2019
commit a8b73f665a0f808557094598488ca2ffa74405df
54 changes: 24 additions & 30 deletions test-support/reference-trie/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,22 @@ use keccak_hasher::KeccakHasher;
pub use trie_db::{Trie, TrieMut, NibbleSlice, NodeCodec, Recorder, Record, TrieLayOut};
pub use trie_root::TrieStream;

#[derive(Clone,Default)]
/// trie layout similar to parity-ethereum
pub struct LayoutOri;
Copy link
Member

@arkpar arkpar Jul 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LayoutOriginal? Full name would be more readable. OriginalLayout would be even better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I am also removing the idea of new and origin, I will use 'ExtensionLayout' and 'NoExtensionLayout'. The fact that reference trie uses same scheme as substrate should not be something strict (code will diverge at some point).


impl TrieLayOut for LayoutOri {
type H = keccak_hasher::KeccakHasher;
type C = ReferenceNodeCodec;

fn uses_extension(&self) -> bool { true }
fn new_codec(&self) -> Self::C { ReferenceNodeCodec }
const USE_EXTENSION: bool = true;
type H = keccak_hasher::KeccakHasher;
type C = ReferenceNodeCodec;
}

#[derive(Clone,Default)]
/// trie layout similar to substrate one
pub struct LayoutNew;
Copy link
Member

@arkpar arkpar Jul 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"New" used here and further in this PR is not descriptive. If we move to a different scheme this naming will get out of hand. Better come up with proper name now.


impl TrieLayOut for LayoutNew {
type H = keccak_hasher::KeccakHasher;
type C = ReferenceNodeCodecNoExt;

fn uses_extension(&self) -> bool { false }
fn new_codec(&self) -> Self::C { ReferenceNodeCodecNoExt }
const USE_EXTENSION: bool = false;
type H = keccak_hasher::KeccakHasher;
type C = ReferenceNodeCodecNoExt;
}

pub type RefTrieDB<'a> = trie_db::TrieDB<'a, keccak_hasher::KeccakHasher, ReferenceNodeCodec>;
Expand Down Expand Up @@ -700,7 +694,7 @@ pub fn compare_impl<X : hash_db::HashDB<KeccakHasher,DBValue> + Eq> (
};
let root = {
let mut root = Default::default();
let mut t = RefTrieDBMut::new(&mut memdb, &mut root, LayoutOri);
let mut t = RefTrieDBMut::new(&mut memdb, &mut root);
for i in 0..data.len() {
t.insert(&data[i].0[..],&data[i].1[..]).unwrap();
}
Expand Down Expand Up @@ -742,7 +736,7 @@ pub fn compare_root(
};
let root = {
let mut root = Default::default();
let mut t = RefTrieDBMut::new(&mut memdb, &mut root, LayoutOri);
let mut t = RefTrieDBMut::new(&mut memdb, &mut root);
for i in 0..data.len() {
t.insert(&data[i].0[..],&data[i].1[..]).unwrap();
}
Expand Down Expand Up @@ -818,17 +812,17 @@ pub fn compare_impl_no_ext(
};
let root = {
let mut root = Default::default();
let mut t = RefTrieDBMutNoExt::new(&mut memdb, &mut root, LayoutNew);
let mut t = RefTrieDBMutNoExt::new(&mut memdb, &mut root);
for i in 0..data.len() {
t.insert(&data[i].0[..],&data[i].1[..]).unwrap();
}
t.root().clone()
};
/* {
/* {
let db : &dyn hash_db::HashDB<_,_> = &memdb;
let t = RefTrieDBNoExt::new(&db, &root).unwrap();
println!("{:?}", t);
}*/
}*/

if root != root_new {
{
Expand Down Expand Up @@ -860,7 +854,7 @@ pub fn compare_impl_no_ext_unordered(
let mut b_map = std::collections::btree_map::BTreeMap::new();
let root = {
let mut root = Default::default();
let mut t = RefTrieDBMutNoExt::new(&mut memdb, &mut root, LayoutNew);
let mut t = RefTrieDBMutNoExt::new(&mut memdb, &mut root);
for i in 0..data.len() {
t.insert(&data[i].0[..],&data[i].1[..]).unwrap();
b_map.insert(data[i].0.clone(),data[i].1.clone());
Expand Down Expand Up @@ -903,13 +897,13 @@ pub fn compare_no_ext_insert_remove(
let mut root = Default::default();
let mut a = 0;
{
let mut t = RefTrieDBMutNoExt::new(&mut memdb, &mut root, LayoutNew);
let mut t = RefTrieDBMutNoExt::new(&mut memdb, &mut root);
t.commit();
}
while a < data.len() {
// new triemut every 3 element
root = {
let mut t = RefTrieDBMutNoExt::from_existing(&mut memdb, &mut root, LayoutNew).unwrap();
let mut t = RefTrieDBMutNoExt::from_existing(&mut memdb, &mut root).unwrap();
for _ in 0..3 {
if data[a].0 {
// remove
Expand All @@ -930,7 +924,7 @@ pub fn compare_no_ext_insert_remove(
*t.root()
};
}
let mut t = RefTrieDBMutNoExt::from_existing(&mut memdb, &mut root, LayoutNew).unwrap();
let mut t = RefTrieDBMutNoExt::from_existing(&mut memdb, &mut root).unwrap();
// we are testing the RefTrie code here so we do not sort or check uniqueness
// before.
assert_eq!(*t.root(), calc_root_no_ext(data2));
Expand All @@ -944,13 +938,13 @@ pub fn compare_no_ext_insert_remove(
#[should_panic]
#[test]
fn too_big_nibble_len () {
// + 1 for 0 added byte of nibble encode
let input = vec![0u8; (noext_cst::LEAF_NODE_OVER as usize + 256) / 2 + 1];
let enc = ReferenceNodeCodecNoExt::leaf_node(&input, &[1]);
let dec = ReferenceNodeCodecNoExt::decode(&enc).unwrap();
let o_sl = if let Node::Leaf(sl,_) = dec {
//assert_eq!(&input[..], &sl.encoded(false)[..]);
Some(sl)
} else { None };
//assert!(o_sl.is_some());
// + 1 for 0 added byte of nibble encode
let input = vec![0u8; (noext_cst::LEAF_NODE_OVER as usize + 256) / 2 + 1];
let enc = ReferenceNodeCodecNoExt::leaf_node(&input, &[1]);
let dec = ReferenceNodeCodecNoExt::decode(&enc).unwrap();
let o_sl = if let Node::Leaf(sl,_) = dec {
//assert_eq!(&input[..], &sl.encoded(false)[..]);
Some(sl)
} else { None };
//assert!(o_sl.is_some());
}
6 changes: 3 additions & 3 deletions test-support/trie-bench/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ where
trie_root::<L::H, S, _, _, _>(d.0.clone())
})),
Fun::new("Fill", |b, d: &TrieInsertionList| b.iter(&mut ||{
let mut memdb = MemoryDB::<_, HashKey<_>, _>::new(&L::C::empty_node()[..]);
let mut memdb = MemoryDB::<_, HashKey<L::H>, _>::new(&L::C::empty_node()[..]);
let mut root = <TrieHash<L>>::default();
let mut t = TrieDBMut::new(&mut memdb, &mut root, L::default());
let mut t = TrieDBMut::<L>::new(&mut memdb, &mut root);
for i in d.0.iter() {
t.insert(&i.0, &i.1).unwrap();
}
Expand All @@ -66,7 +66,7 @@ where
let mut memdb = MemoryDB::<_, HashKey<_>, _>::new(&L::C::empty_node()[..]);
let mut root = <TrieHash<L>>::default();
{
let mut t = TrieDBMut::new(&mut memdb, &mut root, L::default());
let mut t = TrieDBMut::<L>::new(&mut memdb, &mut root);
for i in d.0.iter() {
t.insert(&i.0, &i.1).unwrap();
}
Expand Down
2 changes: 1 addition & 1 deletion trie-db/src/fatdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ mod test {
let mut memdb = MemoryDB::<KeccakHasher, HashKey<_>, DBValue>::default();
let mut root = Default::default();
{
let mut t = RefFatDBMut::new(&mut memdb, &mut root, Default::default());
let mut t = RefFatDBMut::new(&mut memdb, &mut root);
t.insert(&[0x01u8, 0x23], &[0x01u8, 0x23]).unwrap();
}
let t = RefFatDB::new(&memdb, &root).unwrap();
Expand Down
12 changes: 6 additions & 6 deletions trie-db/src/fatdbmut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ where
/// Create a new trie with the backing database `db` and empty `root`
/// Initialise to the state entailed by the genesis block.
/// This guarantees the trie is built correctly.
pub fn new(db: &'db mut HashDB<L::H, DBValue>, root: &'db mut TrieHash<L>, layout: L) -> Self {
FatDBMut { raw: TrieDBMut::new(db, root, layout) }
pub fn new(db: &'db mut HashDB<L::H, DBValue>, root: &'db mut TrieHash<L>) -> Self {
FatDBMut { raw: TrieDBMut::new(db, root) }
}

/// Create a new trie with the backing database `db` and `root`.
///
/// Returns an error if root does not exist.
pub fn from_existing(db: &'db mut HashDB<L::H, DBValue>, root: &'db mut TrieHash<L>, layout: L) -> Result<Self, TrieHash<L>, CError<L>> {
Ok(FatDBMut { raw: TrieDBMut::from_existing(db, root, layout)? })
pub fn from_existing(db: &'db mut HashDB<L::H, DBValue>, root: &'db mut TrieHash<L>) -> Result<Self, TrieHash<L>, CError<L>> {
Ok(FatDBMut { raw: TrieDBMut::from_existing(db, root)? })
}

/// Get the backing database.
Expand Down Expand Up @@ -114,7 +114,7 @@ mod test {
let mut memdb = MemoryDB::<KeccakHasher, HashKey<_>, _>::default();
let mut root = Default::default();
{
let mut t = RefFatDBMut::new(&mut memdb, &mut root, Default::default());
let mut t = RefFatDBMut::new(&mut memdb, &mut root);
t.insert(&[0x01u8, 0x23], &[0x01u8, 0x23]).unwrap();
}
let t = RefTrieDB::new(&memdb, &root).unwrap();
Expand All @@ -129,7 +129,7 @@ mod test {
let val = [0x01u8, 0x24];
let key_hash = KeccakHasher::hash(&key);
let aux_hash = KeccakHasher::hash(&key_hash);
let mut t = RefFatDBMut::new(&mut memdb, &mut root, Default::default());
let mut t = RefFatDBMut::new(&mut memdb, &mut root);
t.insert(&key, &val).unwrap();
assert_eq!(t.get(&key), Ok(Some(DBValue::from_slice(&val))));
assert_eq!(t.db().get(&aux_hash, &[]), Some(DBValue::from_slice(&key)));
Expand Down
2 changes: 1 addition & 1 deletion trie-db/src/iter_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ where
self.0[branch_d].0.iter(), v.as_ref().map(|v|v.as_ref()));
self.reset_depth(branch_d);
let ext_len = nkey.as_ref().map(|nkeyix|nkeyix.0).unwrap_or(0);
let encoded_key = NibbleSlice::new(&key_branch.as_ref()[..]).encoded_leftmost(branch_d - ext_len, false); // TODO EMCH !!!!!!!!!!! debug that it may be shifted from a unit!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
let encoded_key = NibbleSlice::new(&key_branch.as_ref()[..]).encoded_leftmost(branch_d - ext_len, false);
cb_ext.process(&encoded_key[..], encoded, is_root)
}

Expand Down
27 changes: 12 additions & 15 deletions trie-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,11 @@ where
}

/// Create new mutable instance of Trie.
pub fn create(&self, db: &'db mut HashDB<L::H, DBValue>, root: &'db mut TrieHash<L>, layout: L) -> Box<TrieMut<L::H, L::C> + 'db> {
pub fn create(&self, db: &'db mut HashDB<L::H, DBValue>, root: &'db mut TrieHash<L>) -> Box<TrieMut<L::H, L::C> + 'db> {
match self.spec {
TrieSpec::Generic => Box::new(TrieDBMut::new(db, root, layout)),
TrieSpec::Secure => Box::new(SecTrieDBMut::new(db, root, layout)),
TrieSpec::Fat => Box::new(FatDBMut::new(db, root, layout)),
TrieSpec::Generic => Box::new(TrieDBMut::<L>::new(db, root)),
TrieSpec::Secure => Box::new(SecTrieDBMut::<L>::new(db, root)),
TrieSpec::Fat => Box::new(FatDBMut::<L>::new(db, root)),
}
}

Expand All @@ -355,12 +355,11 @@ where
&self,
db: &'db mut HashDB<L::H, DBValue>,
root: &'db mut TrieHash<L>,
layout: L,
) -> Result<Box<TrieMut<L::H,L::C> + 'db>, TrieHash<L>, CError<L>> {
match self.spec {
TrieSpec::Generic => Ok(Box::new(TrieDBMut::from_existing(db, root, layout)?)),
TrieSpec::Secure => Ok(Box::new(SecTrieDBMut::from_existing(db, root, layout)?)),
TrieSpec::Fat => Ok(Box::new(FatDBMut::from_existing(db, root, layout)?)),
TrieSpec::Generic => Ok(Box::new(TrieDBMut::<L>::from_existing(db, root)?)),
TrieSpec::Secure => Ok(Box::new(SecTrieDBMut::<L>::from_existing(db, root)?)),
TrieSpec::Fat => Ok(Box::new(FatDBMut::<L>::from_existing(db, root)?)),
}
}

Expand All @@ -370,17 +369,15 @@ where


/// trait with definition of trie layout
pub trait TrieLayOut: Clone + Send + Sync + Default {
pub trait TrieLayOut {
/// does the trie use extension before its branch
const USE_EXTENSION: bool;
type H: Hasher;
type C: NodeCodec<Self::H>;

/// does the trie use extension before its branch
fn uses_extension(&self) -> bool;
fn new_codec(&self) -> Self::C;
}

/// alias to acces hasher hash output type from a `TrieLayout`
pub type TrieHash<L: TrieLayOut> = <L::H as Hasher>::Out;
pub type TrieHash<L> = <<L as TrieLayOut>::H as Hasher>::Out;
/// alias to acces `NodeCodec` `Error` type from a `TrieLayout`
pub type CError<L: TrieLayOut> = <L::C as NodeCodec<L::H>>::Error;
pub type CError<L> = <<L as TrieLayOut>::C as NodeCodec<<L as TrieLayOut>::H>>::Error;

2 changes: 1 addition & 1 deletion trie-db/src/recorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ mod tests {
let mut db = MemoryDB::<KeccakHasher, HashKey<_>, _>::default();
let mut root = Default::default();
{
let mut x = RefTrieDBMut::new(&mut db, &mut root, Default::default());
let mut x = RefTrieDBMut::new(&mut db, &mut root);

x.insert(b"dog", b"cat").unwrap();
x.insert(b"lunch", b"time").unwrap();
Expand Down
2 changes: 1 addition & 1 deletion trie-db/src/sectriedb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ mod test {
let mut db = MemoryDB::<KeccakHasher, HashKey<_>, DBValue>::default();
let mut root = Default::default();
{
let mut t = RefTrieDBMut::new(&mut db, &mut root, Default::default());
let mut t = RefTrieDBMut::new(&mut db, &mut root);
t.insert(&KeccakHasher::hash(&[0x01u8, 0x23]), &[0x01u8, 0x23]).unwrap();
}
let t = RefSecTrieDB::new(&db, &root).unwrap();
Expand Down
10 changes: 5 additions & 5 deletions trie-db/src/sectriedbmut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ where
/// Create a new trie with the backing database `db` and empty `root`
/// Initialise to the state entailed by the genesis block.
/// This guarantees the trie is built correctly.
pub fn new(db: &'db mut HashDB<L::H, DBValue>, root: &'db mut TrieHash<L>, layout: L) -> Self {
SecTrieDBMut { raw: TrieDBMut::new(db, root, layout) }
pub fn new(db: &'db mut HashDB<L::H, DBValue>, root: &'db mut TrieHash<L>) -> Self {
SecTrieDBMut { raw: TrieDBMut::new(db, root) }
}

/// Create a new trie with the backing database `db` and `root`.
///
/// Returns an error if root does not exist.
pub fn from_existing(db: &'db mut HashDB<L::H, DBValue>, root: &'db mut TrieHash<L>, layout: L) -> Result<Self, TrieHash<L>, CError<L>> {
Ok(SecTrieDBMut { raw: TrieDBMut::from_existing(db, root, layout)? })
pub fn from_existing(db: &'db mut HashDB<L::H, DBValue>, root: &'db mut TrieHash<L>) -> Result<Self, TrieHash<L>, CError<L>> {
Ok(SecTrieDBMut { raw: TrieDBMut::from_existing(db, root)? })
}

/// Get the backing database.
Expand Down Expand Up @@ -94,7 +94,7 @@ mod test {
let mut memdb = MemoryDB::<KeccakHasher, HashKey<_>, DBValue>::default();
let mut root = Default::default();
{
let mut t = RefSecTrieDBMut::new(&mut memdb, &mut root, Default::default());
let mut t = RefSecTrieDBMut::new(&mut memdb, &mut root);
t.insert(&[0x01u8, 0x23], &[0x01u8, 0x23]).unwrap();
}
let t = RefTrieDB::new(&memdb, &root).unwrap();
Expand Down
Loading