From 5ad5847aefa05be59d5f20f186d87e5c77cc67b9 Mon Sep 17 00:00:00 2001 From: Erick Casanova Date: Wed, 13 Dec 2023 10:55:49 -0600 Subject: [PATCH 01/12] =?UTF-8?q?=F0=9F=94=A5=20refactor(benchmarking.rs):?= =?UTF-8?q?=20Update=20benchmarking=20setup=20for=20pallet-template=20?= =?UTF-8?q?=F0=9F=94=A5=20refactor(lib.rs):=20Remove=20migrations=20module?= =?UTF-8?q?=20and=20v2=20migration=20file=20The=20benchmarking=20setup=20f?= =?UTF-8?q?or=20the=20pallet-template=20has=20been=20updated=20to=20use=20?= =?UTF-8?q?the=20`frame=5Fbenchmarking::v2`=20module=20instead=20of=20`fra?= =?UTF-8?q?me=5Fbenchmarking::{benchmarks,=20whitelisted=5Fcaller}`.=20Thi?= =?UTF-8?q?s=20change=20improves=20compatibility=20with=20the=20latest=20v?= =?UTF-8?q?ersion=20of=20the=20frame=5Fbenchmarking=20crate.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The migrations module and v2 migration file have been removed as they are no longer needed. The v2 migration logic has been integrated into the main pallet module, eliminating the need for a separate migrations module. This simplifies the codebase and improves maintainability. --- pallets/template/src/benchmarking.rs | 3 +- pallets/template/src/lib.rs | 4 +- pallets/template/src/migrations/mod.rs | 5 -- pallets/template/src/migrations/v2.rs | 75 -------------------------- 4 files changed, 3 insertions(+), 84 deletions(-) delete mode 100644 pallets/template/src/migrations/mod.rs delete mode 100644 pallets/template/src/migrations/v2.rs diff --git a/pallets/template/src/benchmarking.rs b/pallets/template/src/benchmarking.rs index d496a9fc..fe1a51c0 100644 --- a/pallets/template/src/benchmarking.rs +++ b/pallets/template/src/benchmarking.rs @@ -1,10 +1,11 @@ //! Benchmarking setup for pallet-template +#![cfg(feature = "runtime-benchmarks")] use super::*; #[allow(unused)] use crate::Pallet as Template; -use frame_benchmarking::{benchmarks, whitelisted_caller}; +use frame_benchmarking::v2::*; use frame_system::RawOrigin; benchmarks! { diff --git a/pallets/template/src/lib.rs b/pallets/template/src/lib.rs index c5f778a2..1bb78e4c 100644 --- a/pallets/template/src/lib.rs +++ b/pallets/template/src/lib.rs @@ -15,8 +15,6 @@ mod tests; mod benchmarking; /// All migrations. -pub mod migrations; - #[frame_support::pallet] pub mod pallet { @@ -34,7 +32,7 @@ pub mod pallet { #[pallet::pallet] #[pallet::storage_version(STORAGE_VERSION)] - + pub struct Pallet(_); // The pallet's runtime storage items. diff --git a/pallets/template/src/migrations/mod.rs b/pallets/template/src/migrations/mod.rs deleted file mode 100644 index add68f67..00000000 --- a/pallets/template/src/migrations/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ - -//! All migrations of this pallet. - -/// Version 2. -pub mod v2; diff --git a/pallets/template/src/migrations/v2.rs b/pallets/template/src/migrations/v2.rs deleted file mode 100644 index 10c0874a..00000000 --- a/pallets/template/src/migrations/v2.rs +++ /dev/null @@ -1,75 +0,0 @@ -//! Migrations to version [`2.0.0`], as denoted by the changelog. - -use frame_support::{ - traits::{Get, StorageVersion}, - weights::Weight, -}; -use frame_support::sp_runtime::traits::Zero; - -/// The old prefix. -pub const OLD_PREFIX: &[u8] = b"Template"; - -/// Some checks prior to migration. This can be linked to -/// [`frame_support::traits::OnRuntimeUpgrade::pre_upgrade`] for further testing. -/// -/// Panics if anything goes wrong. -pub fn pre_migration>(new: N) { - let new = new.as_ref(); - log::info!("pre-migration for the template pallet v2 = {}", new); - - // ensure storage version is 3. - assert_eq!(StorageVersion::get::>(), 1); -} - -/// Migrate the entire storage of this pallet to a new prefix. -/// -/// This new prefix must be the same as the one set in construct_runtime. For safety, use -/// `PalletInfo` to get it, as: -/// `::PalletInfo::name::