-
Notifications
You must be signed in to change notification settings - Fork 140
chore(trie): refactor existing header encoding #2530
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2a49ed7
WIP
qdm12 082db17
Update documentation
qdm12 ae1d476
More understandable test cases
qdm12 49bd044
Add copyright notice
qdm12 99b871c
Set all child nodes as dirty when decoding
qdm12 cf7107a
Fix typo in error wrapping
qdm12 a7d7c14
Use `ChildrenCapacity` instead of `16`
qdm12 fd15b16
Review error wrappings
qdm12 374a29b
Add performance note on local scoped variants slice
qdm12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Trie node | ||
|
||
Package node defines the `Node` structure with methods to be used in the modified Merkle-Patricia Radix-16 trie. | ||
|
||
## Codec | ||
|
||
The following sub-sections precise the encoding of a node. | ||
This encoding is formally described in [the Polkadot specification](https://spec.polkadot.network/#sect-state-storage). | ||
|
||
### Header | ||
|
||
Each node encoding has a header of one or more bytes. | ||
The first byte contains the node variant and some or all of the partial key length of the node. | ||
If the partial key length cannot fit in the first byte, additional bytes are added to the header to represent the total partial key length. | ||
|
||
### Partial key | ||
|
||
The header is then concatenated with the partial key of the node, encoded as Little Endian bytes. | ||
|
||
### Remaining bytes | ||
|
||
The remaining bytes appended depend on the node variant. | ||
|
||
- For leaves, the SCALE-encoded leaf value is appended. | ||
- For branches, the following elements are concatenated in this order and appended to the previous header+partial key: | ||
- Children bitmap (2 bytes) | ||
- SCALE-encoded node value | ||
- Hash(Encoding(Child[0])) | ||
- Hash(Encoding(Child[1])) | ||
- ... | ||
- Hash(Encoding(Child[15])) |
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.