-
Notifications
You must be signed in to change notification settings - Fork 648
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
Improve APIs for Tries in Runtime #5756
base: master
Are you sure you want to change the base?
Conversation
This reverts commit 1cfb29f.
Co-authored-by: Ankan <10196091+Ank4n@users.noreply.github.com>
…abrizi/polkadot-sdk into shawntabrizi-proving-trie
…tech/polkadot-sdk into shawntabrizi-binary-trie2
} | ||
|
||
#[test] | ||
fn proof_size_to_hashes() { |
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.
Overall, the assumption here is that the bytes of the proof are mostly hashes.
Based on how many hashes are there, and the structure of the trie, we can then know how deep the trie is.
For example, if we have a base 2 trie, there should be 1 hash at for every level of the trie. For a base 16 trie, there should be 15 hashes.
Funny enough, for worst case scenario, we need minimum_encoded_len
of the types to get a more accurate result.
To get the most accurate result, we also want to remove the key and value bytes and any other extraneous information from the proof size.
If we use MaxEncodedLen
, we may overestimate how many bytes are actually being used for the values, and then underestimate the number of hashes we will actually do.
In this case, I assume an even worst case scenario that all bytes are hashes.
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.
In this case, I assume an even worst case scenario that all bytes are hashes.
I only read the code and figured that's what's going on. It is a pragmatic solution and i think it should be fine =)
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.
I made the trait more general, just ProofToHashes
.
For Base2 trie, we can look at the number of items directly to get the depth. For Base16, we can still use this length trick.
This is a refactor and improvement from: #3881
sp_runtime::proving_trie
now exposes aBasicProvingTrie
for bothbase2
andbase16
.base16
are more focused on single value proofs, also aligning their APIs with thebase2
trieProvingTrie
trait is included which wraps both thebase2
andbase16
trie, and exposes all APIs needed for an end to end scenario.