-
Notifications
You must be signed in to change notification settings - Fork 69
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
complex proof (binary tree hash). #81
Open
cheme
wants to merge
77
commits into
paritytech:master
Choose a base branch
from
cheme:complex_proof
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ahead logic is based on the first one which makes thing a bit hard to read).
cheme
added a commit
to cheme/trie
that referenced
this pull request
May 18, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This draft PR tracks some experiments with binary tree hash replacing the hash of children for
a binary tree hash of childrens in branch nodes.
Current state is tests passing (but not tested in depth, just existing test minus 2 that acts differently).
All test runs on this new proof (see COMPLEX_HASH associated constant definition in test-support/reference-trie/src/lib.rs).
Code and interface change needs rework (lots of TODOs and duplicated code but initial purpose of writing this was to pass tests in order to check limitations and possibly unexpected blockers).
Performance was not really checked thoroughly (binary hasher trait is incredibly awkward at this point and is instantiated for every binary hash, and there is some skippable memcopy), on iter_build it looked like a ~40% perf dropdown.
Proof build from Recorder are not trimmed (recorder record all stored data and cannot really skip some child hash).
Proof compacted with trie_codec and 'generate_proof' do skip child hash not needed for binary tree hash. The format is (inline node are never skipped for simplicity):
'standard encoded branch without children' ++ '2 byte bitmap in proof elements' ++ 'inline nodes' ++ 'additional hashes'
The bitmap is needed to know which children are defined as input for the proof (it is the skipped hash from compact proof ++ inline children).
Inline nodes are here even when not needed in the proof, this could be optimized but would change the proof compaction to go into inline node (that is the case for 'generate_proof' but I do not think it is worth it to have something different from the general case).
Additional hashes are the hashes needed to check proof in order (on a 4 size tree with one node in the proof it will be two elements: the sibling input hash and the hash of the other two siblings).
The binary hash applied is running over a sized binary tree with size defined as consecutive existing children of a branch (since we got a bitmap of their position in the header we can calculate the binary proof on a contiguous sequence).
So for a branch with one child the binary hash is the hash of the child, for two hash it is hash(hash1 ++ hash2) for three hash it is hash(hash(hash1 ++ hash2) ++ hash3) and so on.