-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Inner hashing of value in state trie (chainspec versioning). #8931
Conversation
trie_nodes: Vec<Vec<u8>>, | ||
// TODO decode no more bytes to V0 for compatibility and remove pub(crate) | ||
pub(crate) trie_nodes: Vec<Vec<u8>>, | ||
pub(crate) state_version: StateVersion, |
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.
Changes proof format by adding state version.
Unresolve question, what is better:
- decode to V0 if state version not encoded, so previous code is guaranted unbroken.
- decode to V1 default if state version is not encoded, so it takes less size, but need coordinated update.
(for compatibility I can use a two byte header in the range of compact value encoding that does not exist by using U8_OUT_OF_RANGE_VALUE for state version)
This reverts commit b695af5, the change was generally worse (more code, more generic parameter).
An update on some design decisions after an internal discussion:
|
About point 1. I have some concern (more work than expected see #8931 (comment) last paragraph). |
I pushed a bit in the direction of using new host function in master...cheme:state-update4-host2 , still need to test, but looks promising , so part of this PR with state_versioning may be removed soon. |
Closing in favor of #9732 |
This PR brings alternate hashing of value in substrate.
It uses internally and depends on paritytech/trie#134.
Basically values in trie node got hashed a first time when they are bigger than a given threshold, such as:
hash_leaf = hash(node_header ++ key_partial ++ encoded_value)
alt hashing
value size >= thresholdhash_leaf = hash(node_header ++ key_partial ++ hash(encoded_value))
and same thing for branches with value.
To avoid migrating data, the alt hashing uses their own node header.
Note that size threshold is allowed to change and is only use when calculating trie root (triedbmut usage) in
order to possibly change type of hashing of modified and new nodes.
Node Headers for
alt_hashing
are using unused range of values of previous headers (and possibly expands to an additional byte),making this backward compatible.
The threshold is define as a value in trie state at
:trie_hashing_conf
as a compact u32 value.So if a trie state does contain this value it will not be backward compatible (no reason to be the case).
Resolution of the threshold is done against
StateVersion
defined in chain spec.Remaining TODOs
polkadot branch: https://github.com/cheme/polkadot-1/tree/state-update4
cumulus branch: https://github.com/cheme/cumulus/tree/state-update4