-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Support multi-hash in multi-trie via PlainDB #1106
Conversation
Rust does not support super-trait upcasting
I: IntoIterator<Item = (A, Option<B>)>, | ||
A: AsRef<[u8]> + Ord, | ||
B: AsRef<[u8]>, | ||
DB: hash_db::HashDB<H, trie_db::DBValue> + hash_db::PlainDB<H::Out, trie_db::DBValue>, |
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.
This looks like can't use the HashDB
type alias defined above because Rust treats type alias and traits differently.
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 has been an RFC for trait aliases for ages but not happening anytime soon sadly. type aliases of traits are actually for the unsized values with the type of the trait.
We always check overlay first for a storage fetch, which already checked null data. Using PlainDB here makes it work nicer with other PlainDB overlays.
Added two new traits in |
would be great to get some more eyes on this as it may become relevant for a smart-contract chain with storage-rent. @svyatonik will this present a big issue for light client and/or change trie? |
For light client, imo, that wouldn't be a problem iff there'll be some strict correspondence (known to light client) between child storage (identified by Changes trie is a separate trie, which could use its own hashing algorithm (i.e. Blake2 for all child storages). But there's another issue - we need to emit separate |
* Temporarily pin trie to #2 * Use generic and delay trait object casting Rust does not support super-trait upcasting * Add PlainDB impl for Ephemeral * Add PlainDB trait alias for completeness * Use PlainDB for test TrieBackendStorage fetch We always check overlay first for a storage fetch, which already checked null data. Using PlainDB here makes it work nicer with other PlainDB overlays. * Update trie reference * Use HashDBRef in places when approriate * Use PlainDBRef in places when approriate * Update trie crate reference * Remove unused HashDB::keys * Patch dependencies * Fix cargolock * Update cargo lock again
Requires paritytech/trie#2, solves #872 (comment)
This adds multiple hash algorithm support for multi-trie. See paritytech/trie#2 description for how this will work.
Ephemeral
implementsPlainDB
traits.PlainDB
isHashDB
with hashing stripped. UnlikeHashDB
,PlainDB
will not check for null node, and it's expected that wrapper ofPlainDB
handles that.substrate-trie
,hash_db::HashDB/PlainDB
are taken into function as generic (instead of trait objects). This change is because Rust does not support super-trait upcasting, but for functions likechild_delta_trie_root
, we needDB
to beHashDB + PlainDB
.