-
Notifications
You must be signed in to change notification settings - Fork 70
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
Fixup merkle-value #698
Fixup merkle-value #698
Conversation
I assume the merkle value follows how we declare an inline node in the trie crate? If yes, then the size of the node value can be up to 32 bytes.
Where is this defined in the source? I only found this, which would suggest that it's only inline if |
And |
As far as I can tell, the code you linked relates to whether or not a node has a hashed subvalue (see this, which links the usage of that threshold constant to the state version, and this, which shows that the The section of the spec edited in this PR does not relate to the hashed subvalue, but rather the merkle value of a trie node. (The format of the hashed subvalue is, except for how it changes the header, almost entirely undocumented in the spec; there is no mention of the threshold you link, nor even how the format of the subvalue changes.) |
I honestly have no idea what the "merkle value" is used for. Our trie crate doesn't use this term nor does it cares. However, I would be surprised why the threshold that decides on inline child nodes should be different to the value that decides if the merkle value is a hash or the node value. Maybe @cheme can shine some light here on what merkle value is used for. I can not recall on anything outside of the encoding that should care if something is a hash or a value. |
Yes I am not really using "merkle value" wording usually, but it is used in the rpc spec paritytech/json-rpc-interface-spec#37. Actually for inline node the limit would have been better at 31 (since for 32 byte we encode the size and use 33 bytes in the end). |
If one has only partial information about the trie (i.e. only has the preimages of some of the node hashes, as in the case of a light client), when attempting to read from the trie, one must determine if a child is inlined or hashed. The only way to do so is to check the length – if it's (For values, on the other hand, whether it's inline or hashed is explicitly stored in the node header.) If nodes are in fact inlined when |
It is when node < 33 (<= 32). I was just mentioning < 32 would have been better. |
yes you're right, I got bad memory. Inline node are actually from 0 to 31 encoded len, then one byte is used to encode the len in the node encoding which result to 32 byte so good. (you can see more in triedbmut and lookup (same thing look for comparison againt |
W00t.... Why do we have done this..? |
tbh partially an overlook, but at the same time I cannot say if putting cursor for using a value node at 32 or 33 or even 40 is the better choice. So unless we do some smarter proof encoding, this is not really impacting at the time (only impacting in a good way). |
IMO it would just have been easier to consume if inline node and inline value use the same threshold. Deciding what exactly this threshold should be, would be some extra step. Just for understanding the entire structure it would have been easier. But yeah, we are now too late :P |
I assume the merkle value follows how we declare an inline node in the trie crate? If yes, then the size of the node value can be up to 32 bytes.