Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Prev Previous commit
Next Next commit
add pre_upgrade to pallet rename
  • Loading branch information
shawntabrizi committed May 18, 2022
commit 6e0b10704b20a4f456f0ca246e9684ab6faf054b
8 changes: 7 additions & 1 deletion runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1626,7 +1626,7 @@ pub type Executive = frame_executive::Executive<
AllPalletsWithSystem,
(
RenameBagsListToVoterList,
pallet_bags_list::migrations::AddScore<Runtime, ()>,
pallet_bags_list::migrations::AddScore<Runtime>,
InitiatePoolConfigs,
),
>;
Expand All @@ -1636,6 +1636,12 @@ pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;
/// A migration which renames the pallet `BagsList` to `VoterList`
pub struct RenameBagsListToVoterList;
impl frame_support::traits::OnRuntimeUpgrade for RenameBagsListToVoterList {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
// For other pre-upgrade checks, we need the storage to already be migrated.
frame_support::storage::migration::move_pallet(b"BagsList", b"VoterList");
Comment on lines +1641 to +1642
Copy link
Member

Choose a reason for hiding this comment

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

I don't get why we need this in the pre upgrade check?

Copy link
Contributor

Choose a reason for hiding this comment

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

this is just a hack because we have two migrations around the same pallet. All pre-migrations are ran first, then all migrations, then all post migrations.

We need to mimic the old migrations happening to make it work.

Perhaps we can change the logic here to run the pre-post hooks per migration, not all at once.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I was thinking the same thing, but not sure how easily implementable that is given the "tuple" trait stuff.

Ok(())
}
fn on_runtime_upgrade() -> frame_support::weights::Weight {
frame_support::storage::migration::move_pallet(b"BagsList", b"VoterList");
frame_support::weights::Weight::MAX
Expand Down
8 changes: 7 additions & 1 deletion runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1512,14 +1512,20 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
(RenameBagsListToVoterList, pallet_bags_list::migrations::AddScore<Runtime, ()>),
(RenameBagsListToVoterList, pallet_bags_list::migrations::AddScore<Runtime>),
>;
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;

/// A migration which renames the pallet `BagsList` to `VoterList`
pub struct RenameBagsListToVoterList;
impl frame_support::traits::OnRuntimeUpgrade for RenameBagsListToVoterList {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
// For other pre-upgrade checks, we need the storage to already be migrated.
frame_support::storage::migration::move_pallet(b"BagsList", b"VoterList");
Ok(())
}
fn on_runtime_upgrade() -> frame_support::weights::Weight {
frame_support::storage::migration::move_pallet(b"BagsList", b"VoterList");
frame_support::weights::Weight::MAX
Expand Down
8 changes: 7 additions & 1 deletion runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1161,14 +1161,20 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
(RenameBagsListToVoterList, pallet_bags_list::migrations::AddScore<Runtime, ()>),
(RenameBagsListToVoterList, pallet_bags_list::migrations::AddScore<Runtime>),
>;
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;

/// A migration which renames the pallet `BagsList` to `VoterList`
pub struct RenameBagsListToVoterList;
impl frame_support::traits::OnRuntimeUpgrade for RenameBagsListToVoterList {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
// For other pre-upgrade checks, we need the storage to already be migrated.
frame_support::storage::migration::move_pallet(b"BagsList", b"VoterList");
Ok(())
}
fn on_runtime_upgrade() -> frame_support::weights::Weight {
frame_support::storage::migration::move_pallet(b"BagsList", b"VoterList");
frame_support::weights::Weight::MAX
Expand Down