Skip to content

Commit

Permalink
Remove democracy pallet (#2685)
Browse files Browse the repository at this point in the history
* add migration to remove democracy
* remove democracy lazy migration
* remove democracy pallet and precompile
* check that there is no data for Democracy.VotingOf key prefix
  • Loading branch information
noandrea authored Mar 1, 2024
1 parent c0246d8 commit 85b81ca
Show file tree
Hide file tree
Showing 46 changed files with 1,528 additions and 6,232 deletions.
36 changes: 1 addition & 35 deletions Cargo.lock

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

719 changes: 358 additions & 361 deletions Cargo.toml

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions node/service/src/chain_spec/moonbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use cumulus_primitives_core::ParaId;
use hex_literal::hex;
use moonbase_runtime::{
currency::UNIT, AccountId, AuthorFilterConfig, AuthorMappingConfig, Balance, BalancesConfig,
CrowdloanRewardsConfig, DemocracyConfig, EVMConfig, EligibilityValue, EthereumChainIdConfig,
EthereumConfig, GenesisAccount, InflationInfo, MaintenanceModeConfig, MoonbeamOrbitersConfig,
CrowdloanRewardsConfig, EVMConfig, EligibilityValue, EthereumChainIdConfig, EthereumConfig,
GenesisAccount, InflationInfo, MaintenanceModeConfig, MoonbeamOrbitersConfig,
OpenTechCommitteeCollectiveConfig, ParachainInfoConfig, ParachainStakingConfig,
PolkadotXcmConfig, Precompiles, Range, RuntimeGenesisConfig, SudoConfig, SystemConfig,
TransactionPaymentConfig, TreasuryCouncilCollectiveConfig, XcmTransactorConfig, HOURS,
Expand Down Expand Up @@ -285,7 +285,6 @@ pub fn testnet_genesis(
ethereum: EthereumConfig {
..Default::default()
},
democracy: DemocracyConfig::default(),
parachain_staking: ParachainStakingConfig {
candidates: candidates
.iter()
Expand Down
5 changes: 2 additions & 3 deletions node/service/src/chain_spec/moonbeam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use hex_literal::hex;
use moonbase_runtime::EligibilityValue;
use moonbeam_runtime::{
currency::GLMR, currency::SUPPLY_FACTOR, AccountId, AuthorFilterConfig, AuthorMappingConfig,
Balance, BalancesConfig, CrowdloanRewardsConfig, DemocracyConfig, EVMConfig,
EthereumChainIdConfig, EthereumConfig, GenesisAccount, InflationInfo, MaintenanceModeConfig,
Balance, BalancesConfig, CrowdloanRewardsConfig, EVMConfig, EthereumChainIdConfig,
EthereumConfig, GenesisAccount, InflationInfo, MaintenanceModeConfig,
OpenTechCommitteeCollectiveConfig, ParachainInfoConfig, ParachainStakingConfig,
PolkadotXcmConfig, Precompiles, Range, RuntimeGenesisConfig, SystemConfig,
TransactionPaymentConfig, TreasuryCouncilCollectiveConfig, HOURS, WASM_BINARY,
Expand Down Expand Up @@ -270,7 +270,6 @@ pub fn testnet_genesis(
ethereum: EthereumConfig {
..Default::default()
},
democracy: DemocracyConfig::default(),
parachain_staking: ParachainStakingConfig {
candidates: candidates
.iter()
Expand Down
10 changes: 4 additions & 6 deletions node/service/src/chain_spec/moonriver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ use hex_literal::hex;
use moonbase_runtime::EligibilityValue;
use moonriver_runtime::{
currency::MOVR, AccountId, AuthorFilterConfig, AuthorMappingConfig, Balance, BalancesConfig,
CrowdloanRewardsConfig, DemocracyConfig, EVMConfig, EthereumChainIdConfig, EthereumConfig,
GenesisAccount, InflationInfo, MaintenanceModeConfig, OpenTechCommitteeCollectiveConfig,
ParachainInfoConfig, ParachainStakingConfig, PolkadotXcmConfig, Precompiles, Range,
RuntimeGenesisConfig, SystemConfig, TransactionPaymentConfig, TreasuryCouncilCollectiveConfig,
HOURS, WASM_BINARY,
CrowdloanRewardsConfig, EVMConfig, EthereumChainIdConfig, EthereumConfig, GenesisAccount,
InflationInfo, MaintenanceModeConfig, OpenTechCommitteeCollectiveConfig, ParachainInfoConfig,
ParachainStakingConfig, PolkadotXcmConfig, Precompiles, Range, RuntimeGenesisConfig,
SystemConfig, TransactionPaymentConfig, TreasuryCouncilCollectiveConfig, HOURS, WASM_BINARY,
};
use nimbus_primitives::NimbusId;
use pallet_transaction_payment::Multiplier;
Expand Down Expand Up @@ -270,7 +269,6 @@ pub fn testnet_genesis(
ethereum: EthereumConfig {
..Default::default()
},
democracy: DemocracyConfig::default(),
parachain_staking: ParachainStakingConfig {
candidates: candidates
.iter()
Expand Down
63 changes: 31 additions & 32 deletions pallets/moonbeam-lazy-migrations/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,52 +1,51 @@
[package]
name = "pallet-moonbeam-lazy-migrations"
authors = { workspace = true }
authors = {workspace = true}
description = "A pallet for performing migrations from extrinsics"
edition = "2021"
name = "pallet-moonbeam-lazy-migrations"
version = "0.1.0"

[dependencies]
log = { workspace = true }
log = {workspace = true}

# Substrate
frame-support = { workspace = true }
frame-system = { workspace = true }
parity-scale-codec = { workspace = true }
scale-info = { workspace = true, features = ["derive"] }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
pallet-democracy = { workspace = true }
pallet-scheduler = { workspace = true }
sp-std = { workspace = true }
frame-support = {workspace = true}
frame-system = {workspace = true}
pallet-scheduler = {workspace = true}
parity-scale-codec = {workspace = true}
scale-info = {workspace = true, features = ["derive"]}
sp-core = {workspace = true}
sp-io = {workspace = true}
sp-runtime = {workspace = true}
sp-std = {workspace = true}

# Frontier
pallet-evm = { workspace = true, features = ["forbid-evm-reentrancy"] }
pallet-evm = {workspace = true, features = ["forbid-evm-reentrancy"]}

# Benchmarks
frame-benchmarking = { workspace = true, optional = true }
frame-benchmarking = {workspace = true, optional = true}

[dev-dependencies]
pallet-balances = { workspace = true, features = ["std"] }
pallet-timestamp = { workspace = true, features = ["std"] }
frame-benchmarking = { workspace = true, features = ["std"] }
sp-io = { workspace = true, features = ["std"] }
rlp = { workspace = true, features = ["std"] }
frame-benchmarking = {workspace = true, features = ["std"]}
pallet-balances = {workspace = true, features = ["std"]}
pallet-timestamp = {workspace = true, features = ["std"]}
rlp = {workspace = true, features = ["std"]}
sp-io = {workspace = true, features = ["std"]}

[features]
default = ["std"]
runtime-benchmarks = ["frame-benchmarking"]
std = [
"pallet-balances/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
"pallet-evm/std",
"pallet-timestamp/std",
"rlp/std",
"pallet-balances/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
"pallet-evm/std",
"pallet-timestamp/std",
"rlp/std",
]
runtime-benchmarks = ["frame-benchmarking"]
try-runtime = ["frame-support/try-runtime"]
58 changes: 1 addition & 57 deletions pallets/moonbeam-lazy-migrations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ pub use pallet::*;
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_support::traits::{LockIdentifier, LockableCurrency};
use frame_system::pallet_prelude::*;
use pallet_democracy::VotingOf;
use sp_core::H160;

pub const ARRAY_LIMIT: u32 = 1000;
Expand All @@ -49,15 +47,6 @@ pub mod pallet {
const MAX_LOCAL_ASSETS_STORAGE_ENTRY_SIZE: u64 =
(/* biggest key on moonbeam */136) + (/* biggest value on moonbeam */142);

/// Copied from pallet-democracy
const DEMOCRACY_ID: LockIdentifier = *b"democrac";
const MAX_DEMOCRACY_VOTINGOF_STORAGE_ENTRY_SIZE: u64 =
(/* biggest key on moonbeam */60) + (/* biggest value on moonbeam */1440);
const MAX_BALANCES_LOCKS_STORAGE_ENTRY_SIZE: u64 =
(/* biggest key on moonbeam */60) + (/* biggest value on moonbeam */26 * 3);
const MAX_UNLOCK_PROOF_PER_ACCOUNT: u64 =
MAX_BALANCES_LOCKS_STORAGE_ENTRY_SIZE + MAX_DEMOCRACY_VOTINGOF_STORAGE_ENTRY_SIZE;

/// Pallet for multi block migrations
#[pallet::pallet]
pub struct Pallet<T>(PhantomData<T>);
Expand All @@ -66,17 +55,13 @@ pub mod pallet {
/// If true, it means that LocalAssets storage has been removed.
pub(crate) type LocalAssetsMigrationCompleted<T: Config> = StorageValue<_, bool, ValueQuery>;

#[pallet::storage]
/// If true, it means that Democracy funds have been unlocked.
pub(crate) type DemocracyLocksMigrationCompleted<T: Config> = StorageValue<_, bool, ValueQuery>;

#[pallet::storage]
/// The total number of suicided contracts that were removed
pub(crate) type SuicidedContractsRemoved<T: Config> = StorageValue<_, u32, ValueQuery>;

/// Configuration trait of this pallet.
#[pallet::config]
pub trait Config: frame_system::Config + pallet_evm::Config + pallet_democracy::Config {
pub trait Config: frame_system::Config + pallet_evm::Config {
type WeightInfo: WeightInfo;
}

Expand Down Expand Up @@ -202,46 +187,5 @@ pub mod pallet {
}
Ok(Pays::No.into())
}

// TODO(alexandru): This extrinsic should be removed once Gov V1 is removed.
// Note: We don't need to unreserve any funds, as they are assumed to be already
// unreserved prior to this operation and the proposal submission disabled.
#[pallet::call_index(2)]
#[pallet::weight(
Weight::from_parts(0,
INTERMEDIATES_NODES_SIZE + MAX_UNLOCK_PROOF_PER_ACCOUNT * <u64>::from(*limit))
.saturating_add(<T as frame_system::Config>::DbWeight::get()
.reads_writes((*limit + 1).into(), (*limit + 1).into()).saturating_mul(2))
)]
pub fn unlock_democracy_funds(
origin: OriginFor<T>,
limit: u32,
) -> DispatchResultWithPostInfo {
ensure_signed(origin)?;
ensure!(limit != 0, Error::<T>::LimitCannotBeZero);
ensure!(limit <= 50, Error::<T>::UnlockLimitTooHigh);

ensure!(
!DemocracyLocksMigrationCompleted::<T>::get(),
Error::<T>::AllDemocracyFundsUnlocked
);

// Unlock staked funds and remove the voting entry. This way we can keep track of what
// is left without extra cost.
let unlocked_accounts = VotingOf::<T>::iter()
.drain()
.take(limit as usize)
.map(|(account, _)| {
<T as pallet_democracy::Config>::Currency::remove_lock(DEMOCRACY_ID, &account)
})
.count() as u32;

if unlocked_accounts < limit {
DemocracyLocksMigrationCompleted::<T>::set(true);
}

log::info!("Unlocked {} accounts 🧹", unlocked_accounts);
Ok(Pays::No.into())
}
}
}
34 changes: 1 addition & 33 deletions pallets/moonbeam-lazy-migrations/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use frame_support::{
traits::{EqualPrivilegeOnly, Everything, SortedMembers},
weights::{constants::RocksDbWeight, Weight},
};
use frame_system::{EnsureRoot, EnsureSigned};
use frame_system::EnsureRoot;
use pallet_evm::{AddressMapping, EnsureAddressTruncated};
use sp_core::{ConstU32, H160, H256, U256};
use sp_runtime::{
Expand All @@ -43,7 +43,6 @@ construct_runtime!(
Timestamp: pallet_timestamp,
EVM: pallet_evm,
LazyMigrations: pallet_moonbeam_lazy_migrations::{Pallet, Call},
Democracy: pallet_democracy::{Pallet, Call, Storage, Config<T>, Event<T>},
Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>},
}
);
Expand Down Expand Up @@ -130,37 +129,6 @@ impl SortedMembers<u64> for OneToFive {
#[cfg(feature = "runtime-benchmarks")]
fn add(_m: &u64) {}
}
impl pallet_democracy::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = pallet_balances::Pallet<Self>;
type EnactmentPeriod = ();
type LaunchPeriod = ();
type VotingPeriod = ();
type VoteLockingPeriod = ();
type FastTrackVotingPeriod = ();
type MinimumDeposit = ();
type MaxDeposits = ();
type MaxBlacklisted = ();
type SubmitOrigin = EnsureSigned<AccountId32>;
type ExternalOrigin = EnsureRoot<AccountId32>;
type ExternalMajorityOrigin = EnsureRoot<AccountId32>;
type ExternalDefaultOrigin = EnsureRoot<AccountId32>;
type FastTrackOrigin = EnsureRoot<AccountId32>;
type CancellationOrigin = EnsureRoot<AccountId32>;
type BlacklistOrigin = EnsureRoot<AccountId32>;
type CancelProposalOrigin = EnsureRoot<AccountId32>;
type VetoOrigin = EnsureSigned<AccountId32>;
type CooloffPeriod = ();
type Slash = ();
type InstantOrigin = EnsureRoot<AccountId32>;
type InstantAllowed = ();
type Scheduler = Scheduler;
type MaxVotes = ();
type PalletsOrigin = OriginCaller;
type WeightInfo = ();
type MaxProposals = ();
type Preimages = ();
}

parameter_types! {
pub const MinimumPeriod: u64 = 6000 / 2;
Expand Down
Loading

0 comments on commit 85b81ca

Please sign in to comment.