mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 15:51:12 +00:00
Move PalletVersion away from the crate version (#9165)
* Move `PalletVersion` away from the crate version Before this pr, `PalletVersion` was referring to the crate version that hosted the pallet. This pr introduces a custom `package.metadata.frame` section in the `Cargo.toml` that can contain a `pallet-version` key value pair. While the value is expected to be a valid u16. If this key/value pair isn't given, the version is set to 1. It also changes the `PalletVersion` declaration. We now only have one `u16` that represents the version. Not a major/minor/patch version. As the old `PalletVersion` was starting with the `u16` major, decoding the old values will work. * Overhaul the entire implementation - Drop PalletVersion - Introduce StorageVersion - StorageVersion needs to be set in the crate and set for the macros - Added migration * Fix migrations * Review feedback * Remove unneeded dep * remove pub consts * Brings back logging and implements `GetStorageVersion` * Return weight from migration * Fmt and remove unused import * Update frame/support/src/dispatch.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Update frame/support/src/traits/metadata.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
@@ -111,7 +111,7 @@ use crate::{
|
||||
};
|
||||
use frame_support::{
|
||||
dispatch::Dispatchable,
|
||||
traits::{Currency, Filter, Get, OnUnbalanced, Randomness, Time},
|
||||
traits::{Currency, Filter, Get, OnUnbalanced, Randomness, StorageVersion, Time},
|
||||
weights::{GetDispatchInfo, PostDispatchInfo, Weight, WithPostDispatchInfo},
|
||||
};
|
||||
use frame_system::Pallet as System;
|
||||
@@ -134,6 +134,9 @@ type NegativeImbalanceOf<T> = <<T as Config>::Currency as Currency<
|
||||
<T as frame_system::Config>::AccountId,
|
||||
>>::NegativeImbalance;
|
||||
|
||||
/// The current storage version.
|
||||
const STORAGE_VERSION: StorageVersion = StorageVersion::new(4);
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
@@ -273,6 +276,7 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::storage_version(STORAGE_VERSION)]
|
||||
pub struct Pallet<T>(PhantomData<T>);
|
||||
|
||||
#[pallet::hooks]
|
||||
|
||||
@@ -18,22 +18,17 @@
|
||||
use crate::{Config, Pallet, Weight};
|
||||
use frame_support::{
|
||||
storage::migration,
|
||||
traits::{Get, GetPalletVersion, PalletInfoAccess, PalletVersion},
|
||||
traits::{Get, PalletInfoAccess, StorageVersion},
|
||||
};
|
||||
|
||||
pub fn migrate<T: Config>() -> Weight {
|
||||
let mut weight: Weight = 0;
|
||||
|
||||
match <Pallet<T>>::storage_version() {
|
||||
Some(version) if version == PalletVersion::new(3, 0, 0) => {
|
||||
weight = weight.saturating_add(T::DbWeight::get().writes(1));
|
||||
migration::remove_storage_prefix(
|
||||
<Pallet<T>>::name().as_bytes(),
|
||||
b"CurrentSchedule",
|
||||
b"",
|
||||
);
|
||||
},
|
||||
_ => (),
|
||||
if StorageVersion::get::<Pallet<T>>() == 3 {
|
||||
weight = weight.saturating_add(T::DbWeight::get().writes(1));
|
||||
migration::remove_storage_prefix(<Pallet<T>>::name().as_bytes(), b"CurrentSchedule", b"");
|
||||
|
||||
StorageVersion::new(4).put::<Pallet<T>>();
|
||||
}
|
||||
|
||||
weight
|
||||
|
||||
Reference in New Issue
Block a user