-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make triehash generic over encoding scheme #61
Conversation
…oding * master: Simple test case for the pr Update README.md Fix for removal of a fatdb value.
…oding * master: (22 commits) fix rebase and bump rlp in trie-standardmap remove elastic-array in triehash fix indentations fix retab bug with pretty-print use Vec in memorydb benches rebased and retab update patricia-trie to use generic hashdb elements bump hasdb and memorydb v0.3.0 and fix tests have memorydb be generic over the value type have hashdb be generic over DBValue have NodeCodec using Vec bump rlp v0.3.0 and make all workspace test pass fix doc test remove elastic-array and use Vec instead publish kvdb-rocksdb v0.1.4 Update fs-swap version Patricia tree version 0.2.2 with fatdb changes Better error messages Use debug instead of warn for atomic swap failure log document public functions and use expect instead of unwrap ...
triestream/src/lib.rs
Outdated
fn out(self) -> Vec<u8>; | ||
fn as_raw(&self) -> &[u8]; | ||
|
||
fn encode(k: &usize) -> Vec<u8>; // Arrgh – `ordered_trie_root` enumerates and rlp-encodes items with `rlp::encode()` so need something similar here. :/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errant spaces
/// assert_eq!(ordered_trie_root::<KeccakHasher, _>(v), root.into()); | ||
/// } | ||
/// ``` | ||
pub fn ordered_trie_root<H, I>(input: I) -> H::Out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is moved to triehash-ethereum
to avoid depending on rlp::encode
. Need to implement enumerated_trie_root
in substrate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's fair enough - it's pretty trivial.
triehash/src/lib.rs
Outdated
H::hash(&stream.out()) | ||
} | ||
|
||
#[cfg(test)] | ||
pub fn unhashed_trie<H, S, I, A, B>(input: I) -> Vec<u8> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same as trie_root
but skips the final hashing. Useful for debugging (probably should be removed before merging).
triestream/src/lib.rs
Outdated
fn append_extension(&mut self, key: &[u8]); | ||
fn append_substream<H: Hasher>(&mut self, other: Self); | ||
fn out(self) -> Vec<u8>; | ||
fn as_raw(&self) -> &[u8]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is useful for debugging but not needed otherwise.
Remove as_raw() from trait (impl on concrete type for now – may be removed before merge)
triestream/src/codec_triestream.rs
Outdated
println!("[begin_branch] pushing BRANCH_NODE: {}, {:#x?}, {:#010b}", BRANCH_NODE, BRANCH_NODE, BRANCH_NODE); | ||
self.buffer.push(BRANCH_NODE); | ||
println!("[begin_branch] buffer so far: {:#x?}", self.buffer); | ||
// TODO: I think this is wrong. I need to know how long the full branch node is I think and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why would you? it's always 17-length tuple.
triestream/src/codec_triestream.rs
Outdated
|
||
fn append_leaf(&mut self, key: &[u8], value: &[u8]) { | ||
let mut hpe = hex_prefix_encode_substrate(key, true); | ||
self.buffer.push(hpe.next().expect("key is not empty; qed")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this shouldn't be here.
triestream/src/codec_triestream.rs
Outdated
} | ||
fn append_extension(&mut self, key: &[u8]) { | ||
let mut hpe = hex_prefix_encode_substrate(key, false); | ||
self.buffer.push(hpe.next().expect("key is not empty; qed")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't be here.
@@ -99,6 +100,19 @@ fn take(input: &mut &[u8], count: usize) -> Option<&[u8]> { | |||
Some(r) | |||
} | |||
|
|||
fn partial_to_key(partial: &[u8], offset: u8, big: u8) -> Vec<u8> { | |||
let nibble_count = partial.len() * 2 + if data[0] & 16 == 16 { 1 } else { 0 }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is data
? Missing param?
Part of paritytech/substrate#664
Introduces a TrieStream trait (in a triestream crate) that lets us compute trie roots without depending on RLP. Refactors the trie building using the new trait.
I'm quite unhappy with how the new trait is essentially modeled on RlpStream. In particular having to have an encode method seems awkward and out of place. Ideas for improving this are most welcome.