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:
Bastian Köcher
2021-07-27 23:21:27 +02:00
committed by GitHub
parent 988c399983
commit 4fe55f0bcb
24 changed files with 550 additions and 657 deletions
@@ -18,9 +18,7 @@
use frame_support::{
dispatch::UnfilteredDispatchable,
storage::unhashed,
traits::{
GetCallName, GetPalletVersion, OnFinalize, OnGenesis, OnInitialize, OnRuntimeUpgrade,
},
traits::{GetCallName, OnFinalize, OnGenesis, OnInitialize, OnRuntimeUpgrade},
weights::{DispatchClass, DispatchInfo, GetDispatchInfo, Pays},
};
use sp_io::{
@@ -505,17 +503,7 @@ fn pallet_hooks_expand() {
assert_eq!(AllPallets::on_initialize(1), 21);
AllPallets::on_finalize(1);
assert_eq!(pallet::Pallet::<Runtime>::storage_version(), None);
assert_eq!(pallet::Pallet::<Runtime, pallet::Instance1>::storage_version(), None);
assert_eq!(AllPallets::on_runtime_upgrade(), 61);
assert_eq!(
pallet::Pallet::<Runtime>::storage_version(),
Some(pallet::Pallet::<Runtime>::current_version()),
);
assert_eq!(
pallet::Pallet::<Runtime, pallet::Instance1>::storage_version(),
Some(pallet::Pallet::<Runtime, pallet::Instance1>::current_version()),
);
// The order is indeed reversed due to https://github.com/paritytech/substrate/issues/6280
assert_eq!(
@@ -548,19 +536,9 @@ fn pallet_hooks_expand() {
#[test]
fn pallet_on_genesis() {
TestExternalities::default().execute_with(|| {
assert_eq!(pallet::Pallet::<Runtime>::storage_version(), None);
pallet::Pallet::<Runtime>::on_genesis();
assert_eq!(
pallet::Pallet::<Runtime>::storage_version(),
Some(pallet::Pallet::<Runtime>::current_version()),
);
assert_eq!(pallet::Pallet::<Runtime, pallet::Instance1>::storage_version(), None);
pallet::Pallet::<Runtime, pallet::Instance1>::on_genesis();
assert_eq!(
pallet::Pallet::<Runtime, pallet::Instance1>::storage_version(),
Some(pallet::Pallet::<Runtime, pallet::Instance1>::current_version()),
);
})
}