Skip to content

Commit

Permalink
[MOON-2215] add pallet referenda migration (#2134)
Browse files Browse the repository at this point in the history
* add pallet referenda migration

* add migration to moonbase and moonriver only

* fix wrong file

* fix benchmarks compilation

* Update runtime/moonbeam/src/lib.rs

Co-authored-by: girazoki <gorka.irazoki@gmail.com>

---------

Co-authored-by: librelois <c@elo.tf>
Co-authored-by: girazoki <gorka.irazoki@gmail.com>
  • Loading branch information
librelois and girazoki committed Feb 27, 2023
1 parent 858ef2b commit 483f51e
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 10 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions runtime/common/Cargo.toml
Expand Up @@ -30,6 +30,7 @@ frame-system = { git = "https://github.com/purestake/substrate", branch = "moonb
pallet-collective = { git = "https://github.com/purestake/substrate", branch = "moonbeam-polkadot-v0.9.37", default-features = false }
pallet-democracy = { git = "https://github.com/purestake/substrate", branch = "moonbeam-polkadot-v0.9.37", default-features = false }
pallet-preimage = { git = "https://github.com/purestake/substrate", branch = "moonbeam-polkadot-v0.9.37", default-features = false }
pallet-referenda = { git = "https://github.com/purestake/substrate", branch = "moonbeam-polkadot-v0.9.37", default-features = false }
pallet-scheduler = { git = "https://github.com/purestake/substrate", branch = "moonbeam-polkadot-v0.9.37", default-features = false }
sp-core = { git = "https://github.com/purestake/substrate", branch = "moonbeam-polkadot-v0.9.37", default-features = false }
sp-runtime = { git = "https://github.com/purestake/substrate", branch = "moonbeam-polkadot-v0.9.37", default-features = false }
Expand Down Expand Up @@ -63,6 +64,7 @@ std = [
"pallet-migrations/std",
"pallet-parachain-staking/std",
"pallet-randomness/std",
"pallet-referenda/std",
"pallet-scheduler/std",
"pallet-xcm-transactor/std",
"precompile-utils/std",
Expand All @@ -72,6 +74,7 @@ std = [
"xcm-executor/std",
"xcm/std",
]
runtime-benchmarks = [ "pallet-referenda/runtime-benchmarks" ]
try-runtime = [
"frame-support/try-runtime",
"pallet-migrations/try-runtime",
Expand Down
47 changes: 47 additions & 0 deletions runtime/common/src/migrations.rs
Expand Up @@ -54,6 +54,53 @@ where
}
}

pub struct PalletReferendaMigrateV0ToV1<T>(pub PhantomData<T>);
impl<T> Migration for PalletReferendaMigrateV0ToV1<T>
where
T: pallet_referenda::Config<Hash = PreimageHash> + frame_system::Config,
{
fn friendly_name(&self) -> &str {
"MM_PalletReferendaMigrateV0ToV1"
}

fn migrate(&self, _available_weight: Weight) -> Weight {
pallet_referenda::migration::v1::MigrateV0ToV1::<T>::on_runtime_upgrade()
}

/// Run a standard pre-runtime test. This works the same way as in a normal runtime upgrade.
#[cfg(feature = "try-runtime")]
fn pre_upgrade(&self) -> Result<Vec<u8>, &'static str> {
pallet_referenda::migration::v1::MigrateV0ToV1::<T>::pre_upgrade()
}

/// Run a standard post-runtime test. This works the same way as in a normal runtime upgrade.
#[cfg(feature = "try-runtime")]
fn post_upgrade(&self, state: Vec<u8>) -> Result<(), &'static str> {
pallet_referenda::migration::v1::MigrateV0ToV1::<T>::post_upgrade(state)
}
}

pub struct ReferendaMigrations<Runtime, Council, Tech>(PhantomData<(Runtime, Council, Tech)>);

impl<Runtime, Council, Tech> GetMigrations for ReferendaMigrations<Runtime, Council, Tech>
where
Runtime: pallet_author_mapping::Config,
Runtime: pallet_parachain_staking::Config,
Runtime: pallet_scheduler::Config<Hash = PreimageHash>,
Runtime: AuthorSlotFilterConfig,
Council: GetStorageVersion + PalletInfoAccess + 'static,
Tech: GetStorageVersion + PalletInfoAccess + 'static,
Runtime: pallet_democracy::Config<Hash = PreimageHash>,
Runtime: pallet_preimage::Config<Hash = PreimageHash>,
Runtime: pallet_referenda::Config,
{
fn get_migrations() -> Vec<Box<dyn Migration>> {
let pallet_referenda_migrate_v0_to_v1 =
PalletReferendaMigrateV0ToV1::<Runtime>(Default::default());
vec![Box::new(pallet_referenda_migrate_v0_to_v1)]
}
}

pub struct CommonMigrations<Runtime, Council, Tech>(PhantomData<(Runtime, Council, Tech)>);

impl<Runtime, Council, Tech> GetMigrations for CommonMigrations<Runtime, Council, Tech>
Expand Down
1 change: 1 addition & 0 deletions runtime/moonbase/Cargo.toml
Expand Up @@ -295,6 +295,7 @@ runtime-benchmarks = [
"frame-system-benchmarking/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"hex-literal",
"moonbeam-runtime-common/runtime-benchmarks",
"moonbeam-xcm-benchmarks/runtime-benchmarks",
"pallet-asset-manager/runtime-benchmarks",
"pallet-author-inherent/runtime-benchmarks",
Expand Down
17 changes: 12 additions & 5 deletions runtime/moonbase/src/lib.rs
Expand Up @@ -975,11 +975,18 @@ impl pallet_migrations::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
// TODO wire up our correct list of migrations here. Maybe this shouldn't be in
// `moonbeam_runtime_common`.
type MigrationsList = moonbeam_runtime_common::migrations::CommonMigrations<
Runtime,
CouncilCollective,
TechCommitteeCollective,
>;
type MigrationsList = (
moonbeam_runtime_common::migrations::CommonMigrations<
Runtime,
CouncilCollective,
TechCommitteeCollective,
>,
moonbeam_runtime_common::migrations::ReferendaMigrations<
Runtime,
CouncilCollective,
TechCommitteeCollective,
>,
);
type XcmExecutionManager = XcmExecutionManager;
type WeightInfo = pallet_migrations::weights::SubstrateWeight<Runtime>;
}
Expand Down
1 change: 1 addition & 0 deletions runtime/moonbeam/Cargo.toml
Expand Up @@ -271,6 +271,7 @@ runtime-benchmarks = [
"frame-system-benchmarking/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"hex-literal",
"moonbeam-runtime-common/runtime-benchmarks",
"moonbeam-xcm-benchmarks/runtime-benchmarks",
"pallet-asset-manager/runtime-benchmarks",
"pallet-author-inherent/runtime-benchmarks",
Expand Down
1 change: 1 addition & 0 deletions runtime/moonriver/Cargo.toml
Expand Up @@ -289,6 +289,7 @@ runtime-benchmarks = [
"frame-system-benchmarking/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"hex-literal",
"moonbeam-runtime-common/runtime-benchmarks",
"moonbeam-xcm-benchmarks/runtime-benchmarks",
"pallet-asset-manager/runtime-benchmarks",
"pallet-author-inherent/runtime-benchmarks",
Expand Down
17 changes: 12 additions & 5 deletions runtime/moonriver/src/lib.rs
Expand Up @@ -959,11 +959,18 @@ impl pallet_proxy::Config for Runtime {

impl pallet_migrations::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type MigrationsList = moonbeam_runtime_common::migrations::CommonMigrations<
Runtime,
CouncilCollective,
TechCommitteeCollective,
>;
type MigrationsList = (
moonbeam_runtime_common::migrations::CommonMigrations<
Runtime,
CouncilCollective,
TechCommitteeCollective,
>,
moonbeam_runtime_common::migrations::ReferendaMigrations<
Runtime,
CouncilCollective,
TechCommitteeCollective,
>,
);
type XcmExecutionManager = XcmExecutionManager;
type WeightInfo = pallet_migrations::weights::SubstrateWeight<Runtime>;
}
Expand Down

0 comments on commit 483f51e

Please sign in to comment.