Skip to content
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

Allow constant associated empty root value. #77

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cheme
Copy link
Contributor

@cheme cheme commented Feb 6, 2020

This PR adds new trait HasherNullEmptyRoot that keep trace of an associated null value for an empty type.
A new trait is used because this only makes sense if we assumes that the codec use in the trie will encode node to [0] (this is a bit fishy but rather straightforward solution).
Another memory db is implemented that uses this trait to avoid having to calculate the empty trie root (this happens a lot in substrate).
The implementation is generated from a macro and I am not very happy with the result, but again did not find any good and simple way to implement that, suggestions are very welcome.
Not that in the macro I did ommit an indentation on purpose to keep the diff readable, it should be added before merging, also did not do crate versioning update.

@burdges
Copy link

burdges commented Feb 6, 2020

Is this for domain separation in the hash?

@cheme
Copy link
Contributor Author

cheme commented Feb 6, 2020

I am not sure about what you mean by "domain separation in the hash", but I it is probably not, it is just to avoid this kind of code https://github.com/paritytech/substrate/blob/faf608eeeda0031629f7608321c7ab41fac6024f/primitives/trie/src/lib.rs#L217 in substrate.
Edit: This is currently use to initialize the memorydb for child trie, so this allows to skip the calculation of the empty root which happen on new child trie but also one first editing of all child trie content (the overlay that store delta is a memory db. Thinking twice the overlay could switch to a type that does not implement the null node optimisation, that would be another option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants