Skip to content

Commit

Permalink
Substrate Companion for #9566 (#3704)
Browse files Browse the repository at this point in the history
* runtime migrations

* clean up

* cargo fmt

* companion

* add _ to satisfy trait

* fix try-runtime

* update substrate

Co-authored-by: thiolliere <gui.thiolliere@gmail.com>
  • Loading branch information
ferrell-code and gui1117 authored Sep 21, 2021
1 parent ad34ee1 commit 72121eb
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
38 changes: 38 additions & 0 deletions polkadot/runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1555,12 +1555,50 @@ pub type Executive = frame_executive::Executive<
TechnicalCommitteeStoragePrefixMigration,
TechnicalMembershipStoragePrefixMigration,
MigrateTipsPalletPrefix,
BountiesPrefixMigration,
StakingBagsListMigrationV8,
),
>;
/// The payload being signed in the transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;

const BOUNTIES_OLD_PREFIX: &str = "Treasury";

/// Migrate from 'Treasury' to the new prefix 'Bounties'
pub struct BountiesPrefixMigration;

impl OnRuntimeUpgrade for BountiesPrefixMigration {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
use frame_support::traits::PalletInfo;
let name = <Runtime as frame_system::Config>::PalletInfo::name::<Bounties>()
.expect("Bounties is part of runtime, so it has a name; qed");
pallet_bounties::migrations::v4::migrate::<Runtime, Bounties, _>(BOUNTIES_OLD_PREFIX, 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::<Bounties>()
.expect("Bounties is part of runtime, so it has a name; qed");
pallet_bounties::migrations::v4::pre_migration::<Runtime, Bounties, _>(
BOUNTIES_OLD_PREFIX,
name,
);
Ok(())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
use frame_support::traits::PalletInfo;
let name = <Runtime as frame_system::Config>::PalletInfo::name::<Bounties>()
.expect("Bounties is part of runtime, so it has a name; qed");
pallet_bounties::migrations::v4::post_migration::<Runtime, Bounties, _>(
BOUNTIES_OLD_PREFIX,
name,
);
Ok(())
}
}

const COUNCIL_OLD_PREFIX: &str = "Instance1Collective";
/// Migrate from `Instance1Collective` to the new pallet prefix `Council`
pub struct CouncilStoragePrefixMigration;
Expand Down
39 changes: 39 additions & 0 deletions polkadot/runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,7 @@ pub type Executive = frame_executive::Executive<
Runtime,
AllPallets,
(
BountiesPrefixMigration,
CouncilStoragePrefixMigration,
TechnicalCommitteeStoragePrefixMigration,
TechnicalMembershipStoragePrefixMigration,
Expand All @@ -1165,6 +1166,44 @@ pub type Executive = frame_executive::Executive<
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;

const BOUNTIES_OLD_PREFIX: &str = "Treasury";

/// Migrate from 'Treasury' to the new prefix 'Bounties'
pub struct BountiesPrefixMigration;

impl OnRuntimeUpgrade for BountiesPrefixMigration {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
use frame_support::traits::PalletInfo;
let name = <Runtime as frame_system::Config>::PalletInfo::name::<Bounties>()
.expect("Bounties is part of runtime, so it has a name; qed");
pallet_bounties::migrations::v4::migrate::<Runtime, Bounties, _>(BOUNTIES_OLD_PREFIX, 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::<Bounties>()
.expect("Bounties is part of runtime, so it has a name; qed");
pallet_bounties::migrations::v4::pre_migration::<Runtime, Bounties, _>(
BOUNTIES_OLD_PREFIX,
name,
);
Ok(())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
use frame_support::traits::PalletInfo;
let name = <Runtime as frame_system::Config>::PalletInfo::name::<Bounties>()
.expect("Bounties is part of runtime, so it has a name; qed");
pallet_bounties::migrations::v4::post_migration::<Runtime, Bounties, _>(
BOUNTIES_OLD_PREFIX,
name,
);
Ok(())
}
}

const COUNCIL_OLD_PREFIX: &str = "Instance1Collective";
/// Migrate from `Instance1Collective` to the new pallet prefix `Council`
pub struct CouncilStoragePrefixMigration;
Expand Down

0 comments on commit 72121eb

Please sign in to comment.