-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Conversation
@KiChjang I see this is a draft. If there are outstanding things that need to be done, make a checklist of those things? |
@shawntabrizi There are some really tough problems with regards to supporting iteration of prefixes in the Other than that, what's mostly left to do is trying to get it to actually work in pallets, so that people can start using it. |
It feels to me without the ability to do iteration and the lingering @bkchr are there better ways to approach this? |
@shawntabrizi Just to clarify, iteration itself is supported, the only problem is supporting the iteration of prefixes. EDIT: That means there is a very crude way of supporting the iteration of prefixes using I'm pausing development for now until there's a consensus on what to do next. |
If you use tuples as keys, you should be able to remove this extra What is the exact problem with prefix iteration? That it is hard to declare a prefix of |
@bkchr With the current design, this is how a fn iter_prefix<KG, KArg>(key: (KArg, KG::NextKey)) -> ??? // what should even go in here? The problem I see here is two-fold:
|
for prefix iterator maybe we can create a new trait which enforce the correctness of the prefix. an example can be: trait KeyPrefix<T>: KeyGenerator {}
// To be implemented with macro
impl<A: KeyGenerator, B: KeyGenerator, C: KeyGenerator> KeyPrefix<(A, B, C)> for (A, B) {}
impl<A: KeyGenerator, B: KeyGenerator, C: KeyGenerator, D: KeyGenerator> KeyPrefix<(A, B, C, D)> for (A, B) {}
impl<A: KeyGenerator, B: KeyGenerator, C: KeyGenerator, D: KeyGenerator, E: KeyGenerator> KeyPrefix<(A, B, C, D, E)> for (A, B) {}
impl<A: KeyGenerator, B: KeyGenerator, C: KeyGenerator, D: KeyGenerator> KeyPrefix<(A, B, C, D)> for (A, B, C) {}
impl<A: KeyGenerator, B: KeyGenerator, C: KeyGenerator, D: KeyGenerator, E: KeyGenerator> KeyPrefix<(A, B, C, D, E)> for (A, B, C) {} |
Yeah nice! I had the same idea, basically it should be done in a similar way as it is done with So,
|
So, I would actually do it the other way around:
And we will probably require some methods on |
So the suggestions above would only solve (1), but I suppose I can easily extend it to contain an associated type fn iter_prefix<P>(prefix: P) -> PrefixIterator<(<Key as KeyPrefix<P>>::KeySuffix, V)> where Key: KeyPrefix<P> Now here comes the fun part: what do I do about |
Meaning you take the old hashers as tuple as you take them for the struct itself. The user would need to make sure that they pass the same number of arguments of hashers as the struct itself. |
I thought about this before, but I of course could add a |
If migrate keys is a problem, you could obmit it for now and make the rest working for now. |
f3d539f
to
ad8f391
Compare
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 to me, polkadot js seems to support it polkadot-js/api#3465
but I don't know how much we should advertise the metadata change.
But at some point as long as we don't use any storage n map in polkadot the metadata are entirely compatible, except the version has bump to v13.
note the metadata will also change in #8615, I don't know if worth doing both at the same time.
maybe @joepetrowski can say more ?
Will not affect tx-version. |
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 see some leftover discussions, but probably all can be done separately.
As sanity, I'd be interested in seeing a a test that demonstrates a double map and an NMap(2) which same key types and hashers, generate exactly identical keys, and are thus exactly identical.
And for all the rest looks broadly good to me! Welcome :)
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.
Some nitpicks.
I also did not review anything, but I also don't want to block anything here.
it seems follow up pieces are:
|
bot merge |
Trying merge. |
* Implement StorageNMap * Change copyright date to 2021 * Rewrite keys to use impl_for_tuples instead of recursion * Implement prefix iteration on StorageNMap * Implement EncodeLike for key arguments * Rename KeyGenerator::Arg to KeyGenerator::KArg * Support StorageNMap in decl_storage and #[pallet::storage] macros * Use StorageNMap in assets pallet * Support migrate_keys in StorageNMap * Reduce line characters on select files * Refactor crate imports in decl_storage macros * Some more line char reductions and doc comment update * Update UI test expectations * Revert whitespace changes to untouched files * Generate Key struct instead of a 1-tuple when only 1 pair of key and hasher is provided * Revert formatting changes to unrelated files * Introduce KeyGeneratorInner * Add tests for StorageNMap in FRAMEv2 pallet macro * Small fixes to unit tests for StorageNMap * Bump runtime metadata version * Remove unused import * Update tests to use runtime metadata v13 * Introduce and use EncodeLikeTuple as a trait bound for KArg * Add some rustdocs * Revert usage of StorageNMap in assets pallet * Make use of ext::PunctuatedTrailing * Add rustdoc for final_hash * Fix StorageNMap proc macro expansions for single key cases * Create associated const in KeyGenerator for hasher metadata * Refactor code according to comments from Basti * Add module docs for generator/nmap.rs * Re-export storage::Key as NMapKey in pallet prelude * Seal the EncodeLikeTuple trait * Extract sealing code out of key.rs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Partial #8291.
Things left to be done:
StorageNMap
in#[pallet::storage]
anddecl_storage!
macrosStorageTripleMap
StorageMap
andStorageDoubleMap
and make them useStorageNMap
underneath