Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
use democracy standalone migration
Browse files Browse the repository at this point in the history
  • Loading branch information
liamaharon committed Aug 16, 2023
1 parent 45ba24f commit 5e440c1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 67 deletions.
59 changes: 1 addition & 58 deletions runtime/kusama/src/governance/old.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
//! See https://github.com/paritytech/polkadot/issues/6749

use crate::*;
use frame_support::{
parameter_types,
traits::{EitherOfDiverse, LockIdentifier},
};
use frame_support::{parameter_types, traits::LockIdentifier};
use frame_system::EnsureNever;
use static_assertions::const_assert;

Expand All @@ -41,60 +38,6 @@ parameter_types! {
pub MaxProposalWeight: Weight = Perbill::from_percent(50) * BlockWeights::get().max_block;
}

impl pallet_democracy::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type EnactmentPeriod = EnactmentPeriod;
type VoteLockingPeriod = EnactmentPeriod;
type LaunchPeriod = LaunchPeriod;
type VotingPeriod = VotingPeriod;
type MinimumDeposit = MinimumDeposit;
type SubmitOrigin = frame_system::EnsureSigned<AccountId>;
/// A straight majority of the council can decide what their next motion is.
type ExternalOrigin =
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 1, 2>;
/// A majority can have the next scheduled referendum be a straight majority-carries vote.
type ExternalMajorityOrigin =
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 1, 2>;
/// A unanimous council can have the next scheduled referendum be a straight default-carries
/// (NTB) vote.
type ExternalDefaultOrigin =
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 1, 1>;
/// Two thirds of the technical committee can have an `ExternalMajority/ExternalDefault` vote
/// be tabled immediately and with a shorter voting/enactment period.
type FastTrackOrigin =
pallet_collective::EnsureProportionAtLeast<AccountId, TechnicalCollective, 2, 3>;
type InstantOrigin =
pallet_collective::EnsureProportionAtLeast<AccountId, TechnicalCollective, 1, 1>;
type InstantAllowed = InstantAllowed;
type FastTrackVotingPeriod = FastTrackVotingPeriod;
// To cancel a proposal which has been passed, 2/3 of the council must agree to it.
type CancellationOrigin = EitherOfDiverse<
EnsureNever<AccountId>,
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 2, 3>,
>;
type BlacklistOrigin = EnsureNever<AccountId>;
// To cancel a proposal before it has been passed, the technical committee must be unanimous or
// Root must agree.
type CancelProposalOrigin = EitherOfDiverse<
EnsureNever<AccountId>,
pallet_collective::EnsureProportionAtLeast<AccountId, TechnicalCollective, 1, 1>,
>;
// Any single technical committee member may veto a coming council proposal, however they can
// only do it once and it lasts only for the cooloff period.
type VetoOrigin = pallet_collective::EnsureMember<AccountId, TechnicalCollective>;
type CooloffPeriod = CooloffPeriod;
type Slash = Treasury;
type Scheduler = Scheduler;
type PalletsOrigin = OriginCaller;
type MaxVotes = MaxVotes;
type WeightInfo = weights::pallet_democracy::WeightInfo<Runtime>;
type MaxProposals = MaxProposals;
type Preimages = Preimage;
type MaxDeposits = ConstU32<100>;
type MaxBlacklisted = ConstU32<100>;
}

parameter_types! {
pub CouncilMotionDuration: BlockNumber = prod_or_fast!(3 * DAYS, 2 * MINUTES, "KSM_MOTION_DURATION");
pub const CouncilMaxProposals: u32 = 100;
Expand Down
33 changes: 24 additions & 9 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,6 @@ construct_runtime! {

// Old, deprecated governance pallets. Here purely so storage can be migrated.
// See https://github.com/paritytech/polkadot/issues/6749
Democracy: pallet_democracy exclude_parts {Call} = 13,
Council: pallet_collective::<Instance1> exclude_parts {Call} = 14,
TechnicalCommittee: pallet_collective::<Instance2> exclude_parts {Call} = 15,
PhragmenElection: pallet_elections_phragmen exclude_parts {Call} = 16,
Expand Down Expand Up @@ -1543,12 +1542,12 @@ impl Get<Perbill> for NominationPoolsMigrationV4OldPallet {
// Gov V1 pallets pending storage removal using the frame_support RemovePallet migration.
// See https://github.com/paritytech/polkadot/issues/6749
parameter_types! {
pub const DemocracyStr: &'static str = "Democracy";
pub const CouncilStr: &'static str = "Council";
pub const TechnicalCommitteeStr: &'static str = "TechnicalCommittee";
pub const PhragmenElectionStr: &'static str = "PhragmenElection";
pub const TechnicalMembershipStr: &'static str = "TechnicalMembership";
pub const TipsStr: &'static str = "Tips";
pub const DemocracyPalletName: &'static str = "Democracy";
pub const CouncilPalletName: &'static str = "Council";
pub const TechnicalCommitteePalletName: &'static str = "TechnicalCommittee";
pub const PhragmenElectionPalletName: &'static str = "PhragmenElection";
pub const TechnicalMembershipPalletName: &'static str = "TechnicalMembership";
pub const TipsPalletName: &'static str = "Tips";
}

/// All migrations that will run on the next runtime upgrade.
Expand All @@ -1561,6 +1560,22 @@ pub type Migrations = (migrations::Unreleased,);
#[allow(deprecated, missing_docs)]
pub mod migrations {
use super::*;
use frame_system::pallet_prelude::BlockNumberFor;

// Stand-in configuration for the Democracy pallet to pass to its migration.
// Allows us to run the migration for the pallet without it existing in the runtime.
pub struct DemocracyUnlockConfig;
impl pallet_democracy::migrations::unlock_and_unreserve_all_funds::UnlockConfig
for DemocracyUnlockConfig
{
type Currency = Balances;
type MaxVotes = ConstU32<100>;
type MaxDeposits = ConstU32<100>;
type AccountId = AccountId;
type BlockNumber = BlockNumberFor<Runtime>;
type DbWeight = <Runtime as frame_system::Config>::DbWeight;
type PalletName = DemocracyPalletName;
}

/// Unreleased migrations. Add new ones here:
pub type Unreleased = (
Expand All @@ -1576,15 +1591,15 @@ pub mod migrations {
// Gov v1 storage migrations
// https://github.com/paritytech/polkadot/issues/6749
pallet_elections_phragmen::migrations::unlock_and_unreserve_all_funds::UnlockAndUnreserveAllFunds<Runtime>,
pallet_democracy::migrations::unlock_and_unreserve_all_funds::UnlockAndUnreserveAllFunds<Runtime>,
pallet_democracy::migrations::unlock_and_unreserve_all_funds::UnlockAndUnreserveAllFunds<DemocracyUnlockConfig>,
pallet_tips::migrations::unreserve_deposits::UnreserveDeposits<Runtime, ()>,

// RemovePallets only after they have been removed from the runtime. Otherwise, the on-chain
// storage version is removed for active pallets causing try-runtime to fail. The below code
// should be uncommented to fully remove the storage at the same time as the pallets are
// removed from the runtime, probably in 1.1.
// See https://github.com/paritytech/polkadot/issues/6749
// frame_support::migrations::RemovePallet<DemocracyStr, RocksDbWeight>,
frame_support::migrations::RemovePallet<DemocracyPalletName, <Runtime as frame_system::Config>::DbWeight>,
// frame_support::migrations::RemovePallet<CouncilStr, RocksDbWeight>,
// frame_support::migrations::RemovePallet<TechnicalCommitteeStr, RocksDbWeight>,
// frame_support::migrations::RemovePallet<PhragmenElectionStr, RocksDbWeight>,
Expand Down

0 comments on commit 5e440c1

Please sign in to comment.