Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Make storage give the expected maximum number of values (for PoV) #8729

@gui1117

Description

@gui1117

related #8719, paritytech/polkadot-sdk#398

We want storages to give the maximum number of values.

One idea is to have user giving it to the macro for each storages and the macro would make use of it to generate the storage description needed for PoV computation.
it can look like this:

#[pallet::storage(max_values = 300)]
type MyStorage = StorageMap<_, Twox128Concat, u32, u32>;

But actually we could modify storage types so they implement the bound themself. (the idea is that the macro generate less stuff, and instead it is just regular rust code).
For this we would modify StorageMap and add a const generic in 2nd position.

pub struct StorageMap<Prefix, MaxValues, Hasher, Key, Value, QueryKind=OptionQuery, OnEmpty=GetDefault>(
	core::marker::PhantomData<(Prefix, MaxValues, Hasher, Key, Value, QueryKind, OnEmpty)>
);
// NOTE: we use a generic here for MaxValue and not a const generic because we might want to make it 
// configurable.
// But at some point using `const MaxValue: u32` could be enough.

pub struct ConstU32<const T: u32>;
impl<const T: u32> Get<u32> for ConstU32<T> {
	fn get() -> u32 {
		T
	}
}

#[pallet::storage]
type MyStorage = StorageMap<_, ConstU32<300>, Twox128Concat, u32, u32>;

I'm not sure what is best yet another generic which is not named and make the list quite long. Or an attribute but this bring more macro magic.

For now I'll go for the new attribute

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions