-
Notifications
You must be signed in to change notification settings - Fork 2.7k
trie: add ChildTrie trait to simplify future child trie types addition #3421
Conversation
The child trie fetch should start with `:default:` prefix.
|
tests fail |
cheme
left a comment
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.
looks good, maybe as small doc around the macro to make it goal explicit could be good (resolving child trie implementation from storage_key).
| use hash_db::{HashDB, HashDBRef, PlainDB, PlainDBRef}; | ||
|
|
||
| /// Definition for a child trie. | ||
| pub trait ChildTrie { |
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 wonder if we may rename ChildTrie with something a bit more generic, I would say ChildState but that is not really related to the following methods either, so here to me KeyValueState is what makes the more sense.
Similarily we can remove the 'child' info here: there is nothing related to the child nature.
Still If we add method or associated const such as
/// ChildTrie storage key defines its type. eg: the default child trie is using
/// well_known_keys:: CHILD_STORAGE_KEY_PREFIX followed by ':' then
// 'default', default being this associated const.
const TYPE_PREFIX: &'static[u8] = b"default:";
or
get_type_prefix() -> &'static[u8];
| /// Definition for a child trie. | ||
| pub trait ChildTrie { | ||
| /// Default root of the child trie. | ||
| fn default_root<L: TrieConfiguration>(&self) -> Vec<u8>; |
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.
for all those function I would consider removing type parameter L, and pushing it into the struct
struct DefaultTrie<'a, L, DB, Query>{
root: &'a[u8],
_ph: PhantomData<(L, DB, Query)>
}
instead of
struct DefaultChildTrie;
Actually this comes with some constraint (probably associated type for prover and and memorydb), so it may not be worth it at this point.
| /// Various re-exports from the `hash-db` crate. | ||
| pub use hash_db::{HashDB as HashDBT, EMPTY_PREFIX}; | ||
|
|
||
| macro_rules! with_child_trie { |
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.
Note that it will be good to have a constant reference instead of b"child_storage:default:" and if we put a function/constant in ChildTrie trait to define its type prefix, it should also be use.
core/trie/src/child_tries/default.rs
Outdated
| use trie_db::{TrieConfiguration, DBValue, Query, Trie, TrieMut}; | ||
| use hash_db::{HashDB, HashDBRef, PlainDB, PlainDBRef}; | ||
|
|
||
| /// Default child trie. |
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.
Useless docs.
core/trie/src/child_tries/mod.rs
Outdated
| use trie_db::{TrieConfiguration, DBValue, Query}; | ||
| use hash_db::{HashDB, HashDBRef, PlainDB, PlainDBRef}; | ||
|
|
||
| /// Definition for a child trie. |
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.
Useless docs.
core/trie/src/child_tries/mod.rs
Outdated
|
|
||
| /// Definition for a child trie. | ||
| pub trait ChildTrie { | ||
| /// Default root of the child trie. |
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.
Useless docs
|
is still being worked on? |
|
Sorry. Let me close this for now. |
This refactoring adds
ChildTrietrait. The aim is to simplify child trie types addition.With this PR, to add a new child trie type, one only needs to:
core/trie/src/child_tries, adds a new unit struct, and implementChildTrie.with_child_triemacro, add a new if condition defining the new prefix.