Make sure pallet versions are set at genesis (#7451)

* Make sure pallet versions are set at genesis

This pr ensures that pallet versions are also set at genesis. It does
this by hooking into the runtime `GenesisConfig` which means that it
will only work when the storage is setup using this genesis config. So,
the version will not be set in pallet local tests. However, I think this
isn't such a problem. The genesis config will call `on_genesis` on all
pallets. This function comes from the new trait `OnGenesis`. Currently
the user is not able to provide any custom implementation of this trait.

Besides that it also implements `Clone` and `Copy` for the pallet
version struct.

This pr also moves the macro for generating the runtime genesis config
to `frame-support` as most of the other FRAME related macros.

* Reduce line width

* Update frame/support/src/traits.rs

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
This commit is contained in:
Bastian Köcher
2020-10-29 20:20:08 +01:00
committed by GitHub
parent a5ec7e5c4e
commit e1b56f8dd3
7 changed files with 218 additions and 129 deletions
@@ -280,8 +280,8 @@ fn decl_outer_config<'a>(
)
});
quote!(
#scrate::sp_runtime::impl_outer_config! {
pub struct GenesisConfig for #runtime {
#scrate::impl_outer_config! {
pub struct GenesisConfig for #runtime where AllModulesWithSystem = AllModulesWithSystem {
#(#modules_tokens)*
}
}
@@ -462,9 +462,13 @@ fn decl_all_modules<'a>(
.filter(|n| **n != SYSTEM_MODULE_NAME)
.fold(TokenStream2::default(), |combined, name| quote!((#name, #combined)));
let all_modules_with_system = names.iter()
.fold(TokenStream2::default(), |combined, name| quote!((#name, #combined)));
quote!(
#types
type AllModules = ( #all_modules );
type AllModulesWithSystem = ( #all_modules_with_system );
)
}