4

In the various frame pallets in substrate there are two ways of declaring storage.

For example some pallet storage is declared with <T: Config> while others are declared <T: Config<I>, I: 'static = ()>

frame/whitelist/src/lib.rs

pub type WhitelistedCall<T: Config> = StorageMap<_, Twox64Concat, T::Hash, (), OptionQuery>; 

frame/balances/src/lib.rs

pub type TotalIssuance<T: Config<I>, I: 'static = ()> = StorageValue<_, T::Balance, ValueQuery>;

It is not clear what the advantage of using the 'static (long-lived) type is in this context. What is it?

1 Answer 1

1

These are not really two ways of declaring storage. These are exactly the same. The only difference is that one pallet is instantiable, which means that you can add it multiple times to your runtime and the other is not instantiable, which means that you can only add it once to the runtime.

The I is here the generic parameter to represent the instance. You will never instantiate this type, it only exists as a marker to make the pallet type "unique". Internally FRAME uses the type system to identify pallets to generate stuff like the unique prefix per pallet used by the storage items. The 'static bound is there just a requirement by the type system for stuff we are using. BTW, T is also bound to be ' static because the super trait of your Config trait is the frame_system::Config which is bound to 'static.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.