-
Notifications
You must be signed in to change notification settings - Fork 74
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
Implement trie version 1 #2277
Implement trie version 1 #2277
Conversation
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.
Automatically approving tomaka's pull requests. This auto-approval will be removed once more maintainers are active.
twiggy diff reportDifference in .wasm size before and after this pull request.
|
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.
👍
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.
💪 🏋 🥇
@tomaka once completely switched to V1 , is it possible to go back by setting state_version to 0? |
Any thoughts on this? |
cc #1967
The first version of trie is called version 0. In version 1 of the trie, values that are longer than 32 bytes are hashed. Additionally, the header of each trie element has some additional bit patterns that indicate whether the value is hashed or not.
In order to know whether to use v0 or v1 of the trie, the runtime spec (found in the runtime) has an additional field called
state_version
(which was already parsed by smoldot since #1971 but ignored) indicating the version.For this reason, it is no longer appropriate to have a standalone
calculate_genesis_block_header
function. Calculating the genesis block header requires knowing information from the genesis runtime, and building the genesis runtime is a very expensive operation. Instead, the genesis block header can now be obtained by higher-level code by building the genesisChainInformation
.Note that technically each individual item of the trie is either v0 or v1. In other words, a trie can be in "hybrid" mode with some items in v0 and some items in v1. This happens if the chain was using v0 in the past and has switched to v1. When a chain switches to v1 (by modifying the
state_version
field), the updates are done lazily when items are written to the storage.This means that Merkle proofs can also contain a hybrid of v0 and v1 items.
I have not implemented the full-node-related changes, as they are not straight forward and require some changes to the database. At the moment, the full node will error if you use it on a chain with a v1 trie or try to switch to v1. The places that need an update have been appropriately marked with
TODO
s.