Contracts: Ensure latest migration match pallet_version (#14676)

* Add version check

* fix format

* simplify

* restructure imports

* add version check

* Fix benchmarking

* Rename migrations -> BenchMigrations

* doc

* add more docs

* fix format string

* Update frame/contracts/build.rs

* fix

* add cargo:rerun-if-changed

---------

Co-authored-by: parity-processbot <>
This commit is contained in:
PG Herveou
2023-07-31 16:48:53 +02:00
committed by GitHub
parent fb39893bb3
commit 49816ff4d9
7 changed files with 139 additions and 46 deletions
@@ -30,7 +30,7 @@ use self::{
};
use crate::{
exec::{AccountIdOf, Key},
migration::{v09, v10, v11, v12, v13, MigrationStep},
migration::{codegen::LATEST_MIGRATION_VERSION, v09, v10, v11, v12, v13, MigrationStep},
wasm::CallFlags,
Pallet as Contracts, *,
};
@@ -273,29 +273,32 @@ benchmarks! {
// This benchmarks the weight of executing Migration::migrate to execute a noop migration.
#[pov_mode = Measured]
migration_noop {
assert_eq!(StorageVersion::get::<Pallet<T>>(), 2);
let version = LATEST_MIGRATION_VERSION;
assert_eq!(StorageVersion::get::<Pallet<T>>(), version);
}: {
Migration::<T>::migrate(Weight::MAX)
} verify {
assert_eq!(StorageVersion::get::<Pallet<T>>(), 2);
assert_eq!(StorageVersion::get::<Pallet<T>>(), version);
}
// This benchmarks the weight of dispatching migrate to execute 1 `NoopMigraton`
#[pov_mode = Measured]
migrate {
StorageVersion::new(0).put::<Pallet<T>>();
let latest_version = LATEST_MIGRATION_VERSION;
StorageVersion::new(latest_version - 2).put::<Pallet<T>>();
<Migration::<T, false> as frame_support::traits::OnRuntimeUpgrade>::on_runtime_upgrade();
let caller: T::AccountId = whitelisted_caller();
let origin = RawOrigin::Signed(caller.clone());
}: _(origin, Weight::MAX)
verify {
assert_eq!(StorageVersion::get::<Pallet<T>>(), 1);
assert_eq!(StorageVersion::get::<Pallet<T>>(), latest_version - 1);
}
// This benchmarks the weight of running on_runtime_upgrade when there are no migration in progress.
#[pov_mode = Measured]
on_runtime_upgrade_noop {
assert_eq!(StorageVersion::get::<Pallet<T>>(), 2);
let latest_version = LATEST_MIGRATION_VERSION;
assert_eq!(StorageVersion::get::<Pallet<T>>(), latest_version);
}: {
<Migration::<T, false> as frame_support::traits::OnRuntimeUpgrade>::on_runtime_upgrade()
} verify {
@@ -305,7 +308,8 @@ benchmarks! {
// This benchmarks the weight of running on_runtime_upgrade when there is a migration in progress.
#[pov_mode = Measured]
on_runtime_upgrade_in_progress {
StorageVersion::new(0).put::<Pallet<T>>();
let latest_version = LATEST_MIGRATION_VERSION;
StorageVersion::new(latest_version - 2).put::<Pallet<T>>();
let v = vec![42u8].try_into().ok();
MigrationInProgress::<T>::set(v.clone());
}: {
@@ -318,7 +322,8 @@ benchmarks! {
// This benchmarks the weight of running on_runtime_upgrade when there is a migration to process.
#[pov_mode = Measured]
on_runtime_upgrade {
StorageVersion::new(0).put::<Pallet<T>>();
let latest_version = LATEST_MIGRATION_VERSION;
StorageVersion::new(latest_version - 2).put::<Pallet<T>>();
}: {
<Migration::<T, false> as frame_support::traits::OnRuntimeUpgrade>::on_runtime_upgrade()
} verify {