Implements pallet versioning (#7208)

* Start

* Make macro work

* Rename `ModuleToIndex` to `PalletRuntimeSetup`

Besides the renaming it also adds support getting the name of a pallet
as configured in the runtime.

* Rename it to `PalletInfo`

* Remove accidentally added files

* Some work

* Make everything compile

* Adds a test and fixes some bugs

* Implement ordering for `PalletVersion`

* Apply suggestions from code review

* Review feedback

* Update frame/support/src/dispatch.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Update frame/support/src/dispatch.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Fix compilation

* Fix test

* Fix doc test

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
Bastian Köcher
2020-10-21 19:05:52 +02:00
committed by GitHub
parent 8cebbd142d
commit ed1d0fa815
30 changed files with 640 additions and 161 deletions
+21 -2
View File
@@ -375,6 +375,21 @@ pub use frame_support_procedural::DebugNoBound;
/// ```
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)`.
@@ -485,9 +500,11 @@ mod tests {
use sp_std::{marker::PhantomData, result};
use sp_io::TestExternalities;
pub trait Trait {
pub trait Trait: 'static {
type BlockNumber: Codec + EncodeLike + Default;
type Origin;
type PalletInfo: crate::traits::PalletInfo;
type DbWeight: crate::traits::Get<crate::weights::RuntimeDbWeight>;
}
mod module {
@@ -496,7 +513,7 @@ mod tests {
use super::Trait;
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {}
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system=self {}
}
}
use self::module::Module;
@@ -527,6 +544,8 @@ mod tests {
impl Trait for Test {
type BlockNumber = u32;
type Origin = u32;
type PalletInfo = ();
type DbWeight = ();
}
fn new_test_ext() -> TestExternalities {