mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 14:37:57 +00:00
Improve handling of unset StorageVersion (#13417)
* Improve handling of unset `StorageVersion` When a user is forgetting to set the storage version in a pallet and calls `current_storage_version` to compare it against the `on_chain_storage_version` it will now fail to compile the code. Before the pallet macro just returned `StorageVersion::default()` for `current_storage_version` leading to potential issues with migrations. Besides that it also checks in `post_upgrade` that the pallet storage version was upgraded and thus, no migration was missed. * Use correct `Cargo.lock` * Fixes * Fix test * Update frame/support/test/tests/pallet.rs * Ensure we don't set a storage version when the pallet is missing the attribute * Fix merge conflict * Update frame/support/procedural/src/pallet/expand/hooks.rs Co-authored-by: Roman Useinov <roman.useinov@gmail.com> * Update frame/support/procedural/src/pallet/expand/hooks.rs Co-authored-by: Roman Useinov <roman.useinov@gmail.com> * Fix compilation * Do not run everything with `try-runtime` * Fix test * Apply suggestions from code review Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix `no-metadata-docs` --------- Co-authored-by: Roman Useinov <roman.useinov@gmail.com> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: parity-processbot <>
This commit is contained in:
@@ -2500,7 +2500,9 @@ macro_rules! decl_module {
|
||||
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $crate::traits::GetStorageVersion
|
||||
for $module<$trait_instance $(, $instance)?> where $( $other_where_bounds )*
|
||||
{
|
||||
fn current_storage_version() -> $crate::traits::StorageVersion {
|
||||
type CurrentStorageVersion = $crate::traits::StorageVersion;
|
||||
|
||||
fn current_storage_version() -> Self::CurrentStorageVersion {
|
||||
$( $storage_version )*
|
||||
}
|
||||
|
||||
@@ -2508,6 +2510,16 @@ macro_rules! decl_module {
|
||||
$crate::traits::StorageVersion::get::<Self>()
|
||||
}
|
||||
}
|
||||
|
||||
// Implement `OnGenesis` for `Module`
|
||||
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $crate::traits::OnGenesis
|
||||
for $module<$trait_instance $(, $instance)?> where $( $other_where_bounds )*
|
||||
{
|
||||
fn on_genesis() {
|
||||
let storage_version = <Self as $crate::traits::GetStorageVersion>::current_storage_version();
|
||||
storage_version.put::<Self>();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Implementation for `GetStorageVersion` when no storage version is passed.
|
||||
@@ -2519,7 +2531,9 @@ macro_rules! decl_module {
|
||||
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $crate::traits::GetStorageVersion
|
||||
for $module<$trait_instance $(, $instance)?> where $( $other_where_bounds )*
|
||||
{
|
||||
fn current_storage_version() -> $crate::traits::StorageVersion {
|
||||
type CurrentStorageVersion = $crate::traits::NoStorageVersionSet;
|
||||
|
||||
fn current_storage_version() -> Self::CurrentStorageVersion {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
@@ -2527,6 +2541,16 @@ macro_rules! decl_module {
|
||||
$crate::traits::StorageVersion::get::<Self>()
|
||||
}
|
||||
}
|
||||
|
||||
// Implement `OnGenesis` for `Module`
|
||||
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $crate::traits::OnGenesis
|
||||
for $module<$trait_instance $(, $instance)?> where $( $other_where_bounds )*
|
||||
{
|
||||
fn on_genesis() {
|
||||
let storage_version = $crate::traits::StorageVersion::default();
|
||||
storage_version.put::<Self>();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// The main macro expansion that actually renders the module code.
|
||||
@@ -2814,16 +2838,6 @@ macro_rules! decl_module {
|
||||
}
|
||||
}
|
||||
|
||||
// Implement `OnGenesis` for `Module`
|
||||
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $crate::traits::OnGenesis
|
||||
for $mod_type<$trait_instance $(, $instance)?> where $( $other_where_bounds )*
|
||||
{
|
||||
fn on_genesis() {
|
||||
let storage_version = <Self as $crate::traits::GetStorageVersion>::current_storage_version();
|
||||
storage_version.put::<Self>();
|
||||
}
|
||||
}
|
||||
|
||||
// manual implementation of clone/eq/partialeq because using derive erroneously requires
|
||||
// clone/eq/partialeq from T.
|
||||
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $crate::dispatch::Clone
|
||||
|
||||
Reference in New Issue
Block a user