Skip to content

Commit

Permalink
Migration for substrate version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
ark930 committed Oct 28, 2021
1 parent 05dbd01 commit 498be58
Show file tree
Hide file tree
Showing 4 changed files with 212 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "node-cli"
version = "0.9.6"
version = "0.9.7"
authors = ["Liebi Technologies <[email protected]>"]
description = "Bifrost Parachain Node"
build = "build.rs"
Expand Down
10 changes: 7 additions & 3 deletions runtime/asgard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1826,9 +1826,13 @@ impl_runtime_apis! {

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade() -> Result<(Weight, Weight), sp_runtime::RuntimeString> {
let weight = Executive::try_runtime_upgrade()?;
Ok((weight, RuntimeBlockWeights::get().max_block))
fn on_runtime_upgrade() -> (Weight, Weight) {
log::info!("try-runtime::on_runtime_upgrade asgard.");
let weight = Executive::try_runtime_upgrade().unwrap();
(weight, RuntimeBlockWeights::get().max_block)
}
fn execute_block_no_check(block: Block) -> Weight {
Executive::execute_block_no_check(block)
}
}
}
Expand Down
208 changes: 203 additions & 5 deletions runtime/bifrost/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("bifrost"),
impl_name: create_runtime_str!("bifrost"),
authoring_version: 1,
spec_version: 906,
spec_version: 907,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down Expand Up @@ -1375,9 +1375,204 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPallets,
CustomOnRuntimeUpgrade,
(
CouncilMembershipStoragePrefixMigration,
TechnicalMembershipStoragePrefixMigration,
CouncilStoragePrefixMigration,
TechnicalCommitteeStoragePrefixMigration,
MigrateTipsPalletPrefix,
BountiesPrefixMigration,
),
>;

const COUNCIL_MEMBERSHIP_OLD_PREFIX: &str = "Instance1Membership";
/// Migrate from `Instance1Membership` to the new pallet prefix `CouncilMembership`
pub struct CouncilMembershipStoragePrefixMigration;

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

const TECHNICAL_MEMBERSHIP_OLD_PREFIX: &str = "Instance2Membership";
/// Migrate from `Instance2Membership` to the new pallet prefix `TechnicalMembership`
pub struct TechnicalMembershipStoragePrefixMigration;

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

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

impl OnRuntimeUpgrade for CouncilStoragePrefixMigration {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
pallet_collective::migrations::v4::migrate::<Runtime, Council, _>(COUNCIL_OLD_PREFIX)
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
pallet_collective::migrations::v4::pre_migrate::<Council, _>(COUNCIL_OLD_PREFIX);
Ok(())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
pallet_collective::migrations::v4::post_migrate::<Council, _>(COUNCIL_OLD_PREFIX);
Ok(())
}
}

const TECHNICAL_COMMITTEE_OLD_PREFIX: &str = "Instance2Collective";
/// Migrate from `Instance2Collective` to the new pallet prefix `TechnicalCommittee`
pub struct TechnicalCommitteeStoragePrefixMigration;

impl OnRuntimeUpgrade for TechnicalCommitteeStoragePrefixMigration {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
pallet_collective::migrations::v4::migrate::<Runtime, TechnicalCommittee, _>(
TECHNICAL_COMMITTEE_OLD_PREFIX,
)
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
pallet_collective::migrations::v4::pre_migrate::<TechnicalCommittee, _>(
TECHNICAL_COMMITTEE_OLD_PREFIX,
);
Ok(())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
pallet_collective::migrations::v4::post_migrate::<TechnicalCommittee, _>(
TECHNICAL_COMMITTEE_OLD_PREFIX,
);
Ok(())
}
}

const TIPS_OLD_PREFIX: &str = "Treasury";
/// Migrate pallet-tips from `Treasury` to the new pallet prefix `Tips`
pub struct MigrateTipsPalletPrefix;

impl OnRuntimeUpgrade for MigrateTipsPalletPrefix {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
pallet_tips::migrations::v4::migrate::<Runtime, Tips, _>(TIPS_OLD_PREFIX)
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
pallet_tips::migrations::v4::pre_migrate::<Runtime, Tips, _>(TIPS_OLD_PREFIX);
Ok(())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
pallet_tips::migrations::v4::post_migrate::<Runtime, Tips, _>(TIPS_OLD_PREFIX);
Ok(())
}
}

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(())
}
}

impl_runtime_apis! {
impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
fn validate_transaction(
Expand Down Expand Up @@ -1628,10 +1823,13 @@ impl_runtime_apis! {

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade() -> Result<(Weight, Weight), sp_runtime::RuntimeString> {
fn on_runtime_upgrade() -> (Weight, Weight) {
log::info!("try-runtime::on_runtime_upgrade bifrost.");
let weight = Executive::try_runtime_upgrade()?;
Ok((weight, RuntimeBlockWeights::get().max_block))
let weight = Executive::try_runtime_upgrade().unwrap();
(weight, RuntimeBlockWeights::get().max_block)
}
fn execute_block_no_check(block: Block) -> Weight {
Executive::execute_block_no_check(block)
}
}
}
Expand Down

0 comments on commit 498be58

Please sign in to comment.