Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Port of paritytech/substrate#14747
This MR implements
StorageList
andStoragePagedNMap
. Only the latter contains code, the former is an adapter type of it. Alike it should be possible to use it asStoragePagedDoubleMap
andStoragePagedMap
. All variants are counted, so the Counted prefix is omitted.API
The core API of a
StoragePagedNMap
is given by the traitStorageKeyedList<K, V>
and very similar to a paged list - just with an additional key argument.It does currently not support partial key iterations, but i think it should be possible to add it.
Storage Layout
The
StoragePagedNMap
accepts a tuple of key generators in its type signature and a tuple of matching keys in every of its functions. TheKeyGenerator
then allows to encode that tuple of keys to a proper storage key. We use this here, denoted asKEY
. Note that since aStoragePagedList
is just a special instance of a NMap, theKEY
can be constructed by passing()
into theKeyGenerator
.The
Metadata
is located attwox128(PALLET_PREFIX) ++ twox128(STORAGE_PREFIX) ++ KEY ++ "meta"
.Each page with index
INDEX
is located at:twox128(PALLET_PREFIX) ++ twox128(STORAGE_PREFIX) ++ KEY ++ "page" ++ INDEX
.It looks a bit like this, because a "Paged NMap" basically maps a key to a "Paged List":
Metadata
The metadata of a
StoragePagedList<Value>
is currently set to the metadata of aStorageMap<u32, Vec<Value>>
. This is correct on the storage level, since it maps the page-index (u32
) to a page (Vec<Value>
). But when reading the page, it is unclear to the reader what offset to use within the page to avoid reading removed values.FRAME metadata V17 would be needed to fix this properly so that the reader is aware of the metadata field in storage.