Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Companion for Substrate#9165
  • Loading branch information
bkchr committed Jul 27, 2021
commit fbe5628c65263cca6ba61e6f80f5e225145ad930
15 changes: 13 additions & 2 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ use sp_core::OpaqueMetadata;
use sp_staking::SessionIndex;
use frame_support::{
parameter_types, construct_runtime, RuntimeDebug, PalletId,
traits::{KeyOwnerProofSystem, LockIdentifier, Filter, InstanceFilter, All},
traits::{KeyOwnerProofSystem, LockIdentifier, Filter, InstanceFilter, All, OnRuntimeUpgrade},
weights::Weight,
};
use frame_system::{EnsureRoot, EnsureOneOf};
Expand Down Expand Up @@ -1525,11 +1525,22 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPallets,
RemoveCollectiveFlip,
(RemoveCollectiveFlip, MigratePalletVersionToStorageVersion),
>;
/// The payload being signed in the transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;

/// Migrate from `PalletVersion` to the new `StorageVersion`
pub struct MigratePalletVersionToStorageVersion;

impl OnRuntimeUpgrade for MigratePalletVersionToStorageVersion {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
frame_support::migrations::migrate_from_pallet_version_to_storage_version::<AllPalletsWithSystem>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will write the new version to the storage before executing the pallet specific hooks,
If some hooks rely on the stored version, this upgrade can break them.
I'll double check now, but I guess we should double check before the next releases as well.

&RocksDbWeight::get()
)
}
}

pub struct RemoveCollectiveFlip;
impl frame_support::traits::OnRuntimeUpgrade for RemoveCollectiveFlip {
fn on_runtime_upgrade() -> Weight {
Expand Down
15 changes: 13 additions & 2 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ use sp_core::OpaqueMetadata;
use sp_staking::SessionIndex;
use frame_support::{
parameter_types, construct_runtime, RuntimeDebug, PalletId,
traits::{KeyOwnerProofSystem, LockIdentifier, Filter},
traits::{KeyOwnerProofSystem, LockIdentifier, Filter, OnRuntimeUpgrade},
weights::Weight,
};
use frame_system::{EnsureRoot, EnsureOneOf};
Expand Down Expand Up @@ -1088,11 +1088,22 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPallets,
RemoveCollectiveFlip,
(RemoveCollectiveFlip, MigratePalletVersionToStorageVersion),
>;
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;

/// Migrate from `PalletVersion` to the new `StorageVersion`
pub struct MigratePalletVersionToStorageVersion;

impl OnRuntimeUpgrade for MigratePalletVersionToStorageVersion {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
frame_support::migrations::migrate_from_pallet_version_to_storage_version::<AllPalletsWithSystem>(
&RocksDbWeight::get()
)
}
}

pub struct RemoveCollectiveFlip;
impl frame_support::traits::OnRuntimeUpgrade for RemoveCollectiveFlip {
fn on_runtime_upgrade() -> Weight {
Expand Down
43 changes: 14 additions & 29 deletions runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ use runtime_parachains::{
runtime_api_impl::v1 as runtime_api_impl,
};
use frame_support::{
construct_runtime, parameter_types,
traits::{Filter, KeyOwnerProofSystem, Randomness, All, IsInVec},
PalletId, construct_runtime, parameter_types,
traits::{All, Filter, IsInVec, KeyOwnerProofSystem, OnRuntimeUpgrade, Randomness},
weights::Weight,
PalletId
};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
Expand Down Expand Up @@ -159,6 +158,17 @@ pub type SignedExtra = (
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
);

/// Migrate from `PalletVersion` to the new `StorageVersion`
pub struct MigratePalletVersionToStorageVersion;

impl OnRuntimeUpgrade for MigratePalletVersionToStorageVersion {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
frame_support::migrations::migrate_from_pallet_version_to_storage_version::<AllPalletsWithSystem>(
&RocksDbWeight::get()
)
}
}

/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;
/// Executive: handles dispatch to the various modules.
Expand All @@ -168,7 +178,7 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPallets,
GrandpaStoragePrefixMigration,
MigratePalletVersionToStorageVersion,
>;
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;
Expand Down Expand Up @@ -267,31 +277,6 @@ construct_runtime! {
}
}

pub struct GrandpaStoragePrefixMigration;
impl frame_support::traits::OnRuntimeUpgrade for GrandpaStoragePrefixMigration {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
use frame_support::traits::PalletInfo;
let name = <Runtime as frame_system::Config>::PalletInfo::name::<Grandpa>()
.expect("grandpa is part of pallets in construct_runtime, so it has a name; qed");
pallet_grandpa::migrations::v3_1::migrate::<Runtime, Grandpa, _>(name)
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
use frame_support::traits::PalletInfo;
let name = <Runtime as frame_system::Config>::PalletInfo::name::<Grandpa>()
.expect("grandpa is part of pallets in construct_runtime, so it has a name; qed");
pallet_grandpa::migrations::v3_1::pre_migration::<Runtime, Grandpa, _>(name);
Ok(())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
pallet_grandpa::migrations::v3_1::post_migration::<Grandpa>();
Ok(())
}
}

pub struct BaseFilter;
impl Filter<Call> for BaseFilter {
fn filter(_call: &Call) -> bool {
Expand Down
15 changes: 13 additions & 2 deletions runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ use sp_core::OpaqueMetadata;
use sp_staking::SessionIndex;
use frame_support::{
parameter_types, construct_runtime, RuntimeDebug, PalletId,
traits::{KeyOwnerProofSystem, Filter, InstanceFilter, All},
traits::{KeyOwnerProofSystem, Filter, InstanceFilter, All, OnRuntimeUpgrade},
weights::Weight,
};
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
Expand Down Expand Up @@ -1116,11 +1116,22 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPallets,
RemoveCollectiveFlip,
(RemoveCollectiveFlip, MigratePalletVersionToStorageVersion),
>;
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;

/// Migrate from `PalletVersion` to the new `StorageVersion`
pub struct MigratePalletVersionToStorageVersion;

impl OnRuntimeUpgrade for MigratePalletVersionToStorageVersion {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
frame_support::migrations::migrate_from_pallet_version_to_storage_version::<AllPalletsWithSystem>(
&RocksDbWeight::get()
)
}
}

pub struct RemoveCollectiveFlip;
impl frame_support::traits::OnRuntimeUpgrade for RemoveCollectiveFlip {
fn on_runtime_upgrade() -> Weight {
Expand Down