Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pallet referenda migration for referendumInfo #2134

Merged
merged 5 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
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.

2 changes: 2 additions & 0 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ frame-system = { workspace = true }
pallet-collective = { workspace = true }
pallet-democracy = { workspace = true }
pallet-preimage = { workspace = true }
pallet-referenda = { workspace = true }
pallet-scheduler = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
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 Down
47 changes: 47 additions & 0 deletions runtime/common/src/migrations.rs
Original file line number Diff line number Diff line change
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
17 changes: 12 additions & 5 deletions runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
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/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,7 @@ impl pallet_migrations::Config for Runtime {
CouncilCollective,
TechCommitteeCollective,
>;

nbaztec marked this conversation as resolved.
Show resolved Hide resolved
type XcmExecutionManager = XcmExecutionManager;
type WeightInfo = pallet_migrations::weights::SubstrateWeight<Runtime>;
}
Expand Down
17 changes: 12 additions & 5 deletions runtime/moonriver/src/lib.rs
Original file line number Diff line number Diff line change
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