-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Switch to shiny new fast, RLP-less trie #795
Conversation
assert_eq!(changes_trie_nodes, Some(vec![ | ||
InputPair::ExtrinsicIndex(ExtrinsicIndex { block: 4, key: vec![100] }, vec![0, 2, 3]), | ||
InputPair::ExtrinsicIndex(ExtrinsicIndex { block: 4, key: vec![101] }, vec![1]), | ||
InputPair::ExtrinsicIndex(ExtrinsicIndex { block: 4, key: vec![103] }, vec![0, 1]), | ||
|
||
InputPair::DigestIndex(DigestIndex { block: 4, key: vec![100] }, vec![1, 3]), |
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.
@svyatonik I had to change this to make the tests work. any idea why?
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.
@gavofyork I'm getting an error "Error while iterating by prefix: Database missing expected key: 0x9500103000000000000000464cfe10021c011404000000001c01140401000000" here. So:
- too bad that this error is discarded - will note this && prepare PR when other is done;
- this seems like a similar issue when we have moved from
KeccakHasher
toBlake2Hasher
, but this time I'm not sure where this constant cames from (probably it is in )
That said, this change ([1, 3]
-> [1]
+ similar) is wrong.
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.
ok if it's an issue with the iterator, then it would be good to have a test where i can reproduce it...
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.
here's the test: 93e13a8
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.
thanks. that's fixed now, but the fix didn't invalidate the changes 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.
nm false alarm. tests confirm fix.
InputPair::DigestIndex(DigestIndex { block: 4, key: vec![101] }, vec![1]), | ||
InputPair::DigestIndex(DigestIndex { block: 4, key: vec![102] }, vec![2]), | ||
InputPair::DigestIndex(DigestIndex { block: 4, key: vec![105] }, vec![1, 3]), |
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.
@svyatonik here, too
assert_eq!(changes_trie_nodes, Some(vec![ | ||
InputPair::ExtrinsicIndex(ExtrinsicIndex { block: 4, key: vec![100] }, vec![0, 2, 3]), | ||
InputPair::ExtrinsicIndex(ExtrinsicIndex { block: 4, key: vec![101] }, vec![1]), | ||
InputPair::ExtrinsicIndex(ExtrinsicIndex { block: 4, key: vec![103] }, vec![0, 1]), | ||
|
||
InputPair::DigestIndex(DigestIndex { block: 4, key: vec![100] }, vec![1, 3]), | ||
InputPair::DigestIndex(DigestIndex { block: 4, key: vec![100] }, vec![1]), |
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.
@svyatonik ...and here...
InputPair::DigestIndex(DigestIndex { block: 4, key: vec![101] }, vec![1]), | ||
InputPair::DigestIndex(DigestIndex { block: 4, key: vec![102] }, vec![2]), | ||
InputPair::DigestIndex(DigestIndex { block: 4, key: vec![105] }, vec![1, 3]), |
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.
@svyatonik ...and here
@svyatonik quite a few of the change-trie tests include raw roots. there's little i can do except to replace with the expected root. i don't know how to ensure these trie changes haven't broken their logic. |
@gavofyork The same is true for |
@svyatonik yeah the hashes i'm less bothered about (though it is rather tedious). however, those four changes i pointed to above are switching out some of the structure's values, which is concerning. |
@@ -0,0 +1,635 @@ | |||
// Copyright 2015-2018 Parity Technologies (UK) Ltd. |
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.
docs are missing in this file/crate
core/trie/src/lib.rs
Outdated
} | ||
|
||
/* | ||
// TODO: Remove |
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.
committing commented code
core/trie/src/lib.rs
Outdated
use trie_standardmap::{Alphabet, ValueMode, StandardMap}; | ||
|
||
fn check_equivalent(input: &Vec<(&[u8], &[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.
here too
twox-hash = "1.1.0" | ||
lazy_static = "1.0" | ||
parking_lot = "*" | ||
log = "0.3" | ||
hashdb = "0.2.1" | ||
hash-db = { git = "https://github.com/paritytech/trie" } |
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.
kind of unfortunate that we are moving back off of crates.io deps and into GitHub land
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.
once it stablises (i.e. sometime between now and 1.0 final), i'm happy to publish and move back.
core/trie/src/node_codec.rs
Outdated
fn leaf_node(partial: &[u8], value: &[u8]) -> Vec<u8> { | ||
let mut output = partial_to_key(partial, LEAF_NODE_OFFSET, LEAF_NODE_BIG); | ||
value.encode_to(&mut output); | ||
// println!("leaf_node: {:#x?}", output); |
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.
stray println commented here
core/trie/src/node_codec.rs
Outdated
ChildReference::Inline(inline_data, len) => | ||
(&AsRef::<[u8]>::as_ref(&inline_data)[..len]).encode_to(&mut output), | ||
}; | ||
// println!("ext_node: {:#x?}", output); |
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.
and here
core/trie/src/node_codec.rs
Outdated
None => false, | ||
})); | ||
output[0..3].copy_from_slice(&prefix[..]); | ||
// println!("branch_node: {:#x?}", output); |
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.
and here
core/trie/src/node_codec_alt.rs
Outdated
// You should have received a copy of the GNU General Public License | ||
// along with Parity. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
//! `NodeCodec` implementation for Rlp |
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.
is this "alt" implementation for RLP for Parity Codec?
core/trie/README.md
Outdated
@@ -0,0 +1,2 @@ | |||
This crate provides utility functions to validate and initialize tries using flexible input. | |||
It is used extensively in `parity-ethereum` to validate blocks (mostly transactions and receipt roots). |
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 looks irrelevant.
Null, | ||
Branch(bool), | ||
Extension(usize), | ||
Leaf(usize), |
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.
usize? Is it supposed to be platform-dependent? u32
should probably enough
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 mostly being assigned/compared to sizes of Vec
s and has a custom Decode
/Encode
. switching to u32
would necessitate most casting but wouldn't provide any material benefit.
core/trie/src/lib.rs
Outdated
@@ -0,0 +1,421 @@ | |||
// Copyright 2015-2018 Parity Technologies (UK) Ltd. | |||
// This file is part of Parity. |
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.
Needs updating?
core/trie/README.md
Outdated
@@ -0,0 +1,2 @@ | |||
This crate provides utility functions to validate and initialize tries using flexible input. | |||
It is used extensively in `parity-ethereum` to validate blocks (mostly transactions and receipt roots). |
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.
Might want to remove this line.
} | ||
|
||
/// Determine a trie root node's data given its ordered contents, closed form. | ||
pub fn unhashed_trie<H: Hasher, I, A, B>(input: I) -> Vec<u8> where |
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.
Is this method used for anything outside tests?
// NOTE: what we'd really like here is: | ||
// `impl<H: Hasher> NodeCodec<H> for RlpNodeCodec<H> where H::Out: Decodable` | ||
// but due to the current limitations of Rust const evaluation we can't | ||
// do `const HASHED_NULL_NODE: H::Out = H::Out( … … )`. Perhaps one day soon? |
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 comment is probably not helpful anymore.
_ => { | ||
// println!("[append_substream] would have hashed, because data.len() = {}", data.len()); | ||
// data.encode_to(&mut self.buffer) | ||
// TODO: re-enable hashing before merging |
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.
Some cleanup to do in this file.
* Remove Cargo.lock from gitignore Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * cargo: Add `Cargo.lock` Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Update the releasing process Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Closes #664
Also expunges RLP from the codebase. There's not really any new logic outside of the
substrate-trie
crate.The codebase is no longer generic over
NodeCodec
; the reason for this twofold: firstly, trie node format allows for much less opinionated selection than the hashing algorithm. Formats do not significantly change in terms of security. Performance tweaks are non-controversial and are easily folded in over time. Secondly, it would require a two generic parameters, not one as before.