mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 04:37:57 +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:
@@ -59,6 +59,7 @@ pub mod inherent;
|
||||
#[macro_use]
|
||||
pub mod error;
|
||||
pub mod instances;
|
||||
pub mod migrations;
|
||||
pub mod traits;
|
||||
pub mod weights;
|
||||
|
||||
@@ -667,21 +668,6 @@ pub use frame_support_procedural::DefaultNoBound;
|
||||
/// ```
|
||||
pub use frame_support_procedural::require_transactional;
|
||||
|
||||
/// Convert the current crate version into a [`PalletVersion`](crate::traits::PalletVersion).
|
||||
///
|
||||
/// It uses the `CARGO_PKG_VERSION_MAJOR`, `CARGO_PKG_VERSION_MINOR` and
|
||||
/// `CARGO_PKG_VERSION_PATCH` environment variables to fetch the crate version.
|
||||
/// This means that the [`PalletVersion`](crate::traits::PalletVersion)
|
||||
/// object will correspond to the version of the crate the macro is called in!
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// # use frame_support::{traits::PalletVersion, crate_to_pallet_version};
|
||||
/// const Version: PalletVersion = crate_to_pallet_version!();
|
||||
/// ```
|
||||
pub use frame_support_procedural::crate_to_pallet_version;
|
||||
|
||||
/// Return Err of the expression: `return Err($expression);`.
|
||||
///
|
||||
/// Used as `fail!(expression)`.
|
||||
@@ -1301,7 +1287,7 @@ pub mod pallet_prelude {
|
||||
},
|
||||
},
|
||||
traits::{
|
||||
ConstU32, EnsureOrigin, Get, GetDefault, GetPalletVersion, Hooks, IsType,
|
||||
ConstU32, EnsureOrigin, Get, GetDefault, GetStorageVersion, Hooks, IsType,
|
||||
PalletInfoAccess, StorageInfoTrait,
|
||||
},
|
||||
weights::{DispatchClass, Pays, Weight},
|
||||
@@ -1422,6 +1408,19 @@ pub mod pallet_prelude {
|
||||
/// This require all storage to implement the trait [`traits::StorageInfoTrait`], thus all keys
|
||||
/// and value types must bound [`pallet_prelude::MaxEncodedLen`].
|
||||
///
|
||||
/// As the macro implements [`traits::GetStorageVersion`], the current storage version needs to be
|
||||
/// communicated to the macro. This can be done by using the `storage_version` attribute:
|
||||
///
|
||||
/// ```ignore
|
||||
/// const STORAGE_VERSION: StorageVersion = StorageVersion::new(5);
|
||||
///
|
||||
/// #[pallet::pallet]
|
||||
/// #[pallet::storage_version(STORAGE_VERSION)]
|
||||
/// pub struct Pallet<T>(_);
|
||||
/// ```
|
||||
///
|
||||
/// If not present, the current storage version is set to the default value.
|
||||
///
|
||||
/// ### Macro expansion:
|
||||
///
|
||||
/// The macro add this attribute to the struct definition:
|
||||
@@ -1436,7 +1435,7 @@ pub mod pallet_prelude {
|
||||
/// and replace the type `_` by `PhantomData<T>`.
|
||||
///
|
||||
/// It implements on pallet:
|
||||
/// * [`traits::GetPalletVersion`]
|
||||
/// * [`traits::GetStorageVersion`]
|
||||
/// * [`traits::OnGenesis`]: contains some logic to write pallet version into storage.
|
||||
/// * `ModuleErrorMetadata`: using error declared or no metadata.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user