Skip to content
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

PlainDB for multi-trie multi-hash #2

Merged
merged 6 commits into from
Feb 6, 2019
Merged

PlainDB for multi-trie multi-hash #2

merged 6 commits into from
Feb 6, 2019

Conversation

sorpaas
Copy link
Member

@sorpaas sorpaas commented Nov 12, 2018

This lays out the traits needed to solve paritytech/substrate#872 (comment), to support multiple hashing algorithms in multi-trie.

Because we can't know how many children tries are created, multi-trie needs to write all hashdb values into a single storage. To support multiple hash algorithms, the length of the hash might also be different, while the underlying data store might expect a fixed length hash. With traits in this PR, we can fix both of the issues:

  • Pass PlainDB reference in children delta trie root generation. The generation function wraps PlainDB into another HashDB of the targeted hash algorithm to continue the operation.
  • If the generation function is really sure that targeted hash and original hash have the same length (and hashes won't collide), then the wrapper can directly use targeted hash as original hash and pass it back to PlainDB.
  • Otherwise, the wrapper can use original hash algorithm to do H::hash(key) before passing it back to PlainDB.

This PR should be backward-compatible. The only case where it breaks is if a file tries to do use hash_db::*.

@sorpaas
Copy link
Member Author

sorpaas commented Nov 14, 2018

Figured out that HashDB::keys won't work with the above design. However, this function doesn't seem to be used anywhere. So I moved it to impl MemoryDB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants