OpenGov in Westend and Rococo (#1177)

Migrating [PR from the archived polkadot
repo](https://github.com/paritytech/polkadot/pull/7272)

As per
https://github.com/paritytech/polkadot/pull/7272#issuecomment-1559240466,
the changes in this MR include the following pallets into [x] Rococo and
[x] Westend runtimes:

    pallet_conviction_voting
    pallet_referenda
    pallet_ranked_collective
    pallet_custom_origins
    pallet_whitelist

And only for westend-runtime:

    pallet_treasury

Following [Kusama runtime
config](https://github.com/paritytech/polkadot/tree/dbae30efe080a1d41fe54ef4da8af47614c9ca93/runtime/kusama/src)
as a baseline.

Benchmarking of the following pallets done for both Rococo and Westend:

    pallet_conviction_voting
    pallet_referenda
    pallet_ranked_collective (only on Rococo)
    pallet_whitelist

And only for Westend:

    pallet_treasury

Removed Gov1 from Rococo as in
https://github.com/paritytech/polkadot/pull/6701

Rococo Gov1 storage will be cleaned in a different PR - [issue ](https://github.com/paritytech/polkadot-sdk/issues/1618)

---------

Co-authored-by: Giles Cope <gilescope@gmail.com>
This commit is contained in:
Alejandro Martinez Andres
2023-09-27 16:37:00 +02:00
committed by GitHub
parent 8b061a5c5d
commit 69ed3087e1
35 changed files with 4964 additions and 2385 deletions
+86 -21
View File
@@ -17,7 +17,7 @@
//! The Westend runtime. This can be compiled with `#[no_std]`, ready for Wasm.
#![cfg_attr(not(feature = "std"), no_std)]
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 512.
// `construct_runtime!` does a lot of recursion and requires us to increase the limit.
#![recursion_limit = "512"]
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
@@ -31,9 +31,9 @@ use frame_support::{
genesis_builder_helper::{build_config, create_default_config},
parameter_types,
traits::{
fungible::HoldConsideration, ConstU32, Contains, EverythingBut, InstanceFilter,
KeyOwnerProofSystem, LinearStoragePrice, ProcessMessage, ProcessMessageError,
WithdrawReasons,
fungible::HoldConsideration, ConstU32, Contains, EitherOf, EitherOfDiverse, EverythingBut,
InstanceFilter, KeyOwnerProofSystem, LinearStoragePrice, ProcessMessage,
ProcessMessageError, WithdrawReasons,
},
weights::{ConstantMultiplier, WeightMeter},
PalletId,
@@ -80,7 +80,7 @@ use sp_runtime::{
Keccak256, OpaqueKeys, SaturatedConversion, Verify,
},
transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity},
ApplyExtrinsicResult, FixedU128, KeyTypeId, Perbill, Percent,
ApplyExtrinsicResult, FixedU128, KeyTypeId, Perbill, Percent, Permill,
};
use sp_staking::SessionIndex;
use sp_std::{collections::btree_map::BTreeMap, prelude::*};
@@ -107,6 +107,13 @@ mod bag_thresholds;
mod weights;
pub mod xcm_config;
// Governance and configurations.
pub mod governance;
use governance::{
pallet_custom_origins, AuctionAdmin, FellowshipAdmin, GeneralAdmin, LeaseAdmin, StakingAdmin,
Treasurer, TreasurySpender,
};
#[cfg(test)]
mod tests;
@@ -122,7 +129,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("westend"),
impl_name: create_runtime_str!("parity-westend"),
authoring_version: 2,
spec_version: 9430,
spec_version: 10020,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 22,
@@ -197,7 +204,9 @@ impl pallet_scheduler::Config for Runtime {
type PalletsOrigin = OriginCaller;
type RuntimeCall = RuntimeCall;
type MaximumWeight = MaximumSchedulerWeight;
type ScheduleOrigin = EnsureRoot<AccountId>;
// The goal of having ScheduleOrigin include AuctionAdmin is to allow the auctions track of
// OpenGov to schedule periodic auctions.
type ScheduleOrigin = EitherOf<EnsureRoot<AccountId>, AuctionAdmin>;
type MaxScheduledPerBlock = MaxScheduledPerBlock;
type WeightInfo = weights::pallet_scheduler::WeightInfo<Runtime>;
type OriginPrivilegeCmp = frame_support::traits::EqualPrivilegeOnly;
@@ -683,7 +692,40 @@ impl pallet_fast_unstake::Config for Runtime {
}
parameter_types! {
pub const ProposalBond: Permill = Permill::from_percent(5);
pub const ProposalBondMinimum: Balance = 2000 * CENTS;
pub const ProposalBondMaximum: Balance = 1 * GRAND;
pub const SpendPeriod: BlockNumber = 6 * DAYS;
pub const Burn: Permill = Permill::from_perthousand(2);
pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
pub const TipCountdown: BlockNumber = 1 * DAYS;
pub const TipFindersFee: Percent = Percent::from_percent(20);
pub const TipReportDepositBase: Balance = 100 * CENTS;
pub const DataDepositPerByte: Balance = 1 * CENTS;
pub const MaxApprovals: u32 = 100;
pub const MaxAuthorities: u32 = 100_000;
pub const MaxKeys: u32 = 10_000;
pub const MaxPeerInHeartbeats: u32 = 10_000;
}
impl pallet_treasury::Config for Runtime {
type PalletId = TreasuryPalletId;
type Currency = Balances;
type ApproveOrigin = EitherOfDiverse<EnsureRoot<AccountId>, Treasurer>;
type RejectOrigin = EitherOfDiverse<EnsureRoot<AccountId>, Treasurer>;
type RuntimeEvent = RuntimeEvent;
type OnSlash = Treasury;
type ProposalBond = ProposalBond;
type ProposalBondMinimum = ProposalBondMinimum;
type ProposalBondMaximum = ProposalBondMaximum;
type SpendPeriod = SpendPeriod;
type Burn = Burn;
type BurnDestination = ();
type MaxApprovals = MaxApprovals;
type WeightInfo = weights::pallet_treasury::WeightInfo<Runtime>;
type SpendFunds = ();
type SpendOrigin = TreasurySpender;
}
impl pallet_offences::Config for Runtime {
@@ -699,8 +741,6 @@ impl pallet_authority_discovery::Config for Runtime {
parameter_types! {
pub const NposSolutionPriority: TransactionPriority = TransactionPriority::max_value() / 2;
pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value();
pub const MaxKeys: u32 = 10_000;
pub const MaxPeerInHeartbeats: u32 = 10_000;
}
impl pallet_im_online::Config for Runtime {
@@ -814,8 +854,8 @@ impl pallet_identity::Config for Runtime {
type MaxSubAccounts = MaxSubAccounts;
type MaxAdditionalFields = MaxAdditionalFields;
type MaxRegistrars = MaxRegistrars;
type RegistrarOrigin = frame_system::EnsureRoot<AccountId>;
type ForceOrigin = frame_system::EnsureRoot<AccountId>;
type ForceOrigin = EitherOf<EnsureRoot<Self::AccountId>, GeneralAdmin>;
type RegistrarOrigin = EitherOf<EnsureRoot<Self::AccountId>, GeneralAdmin>;
type WeightInfo = weights::pallet_identity::WeightInfo<Runtime>;
}
@@ -912,6 +952,7 @@ parameter_types! {
pub enum ProxyType {
Any,
NonTransfer,
Governance,
Staking,
SudoBalances,
IdentityJudgement,
@@ -944,6 +985,9 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
RuntimeCall::ImOnline(..) |
RuntimeCall::Utility(..) |
RuntimeCall::Identity(..) |
RuntimeCall::ConvictionVoting(..) |
RuntimeCall::Referenda(..) |
RuntimeCall::Whitelist(..) |
RuntimeCall::Recovery(pallet_recovery::Call::as_recovered{..}) |
RuntimeCall::Recovery(pallet_recovery::Call::vouch_recovery{..}) |
RuntimeCall::Recovery(pallet_recovery::Call::claim_recovery{..}) |
@@ -989,6 +1033,13 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
RuntimeCall::Utility(..) => true,
_ => false,
},
ProxyType::Governance => matches!(
c,
// OpenGov calls
RuntimeCall::ConvictionVoting(..) |
RuntimeCall::Referenda(..) |
RuntimeCall::Whitelist(..)
),
ProxyType::IdentityJudgement => matches!(
c,
RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) |
@@ -1184,7 +1235,7 @@ impl parachains_slashing::Config for Runtime {
parameter_types! {
pub const ParaDeposit: Balance = 2000 * CENTS;
pub const DataDepositPerByte: Balance = deposit(0, 1);
pub const RegistrarDataDepositPerByte: Balance = deposit(0, 1);
}
impl paras_registrar::Config for Runtime {
@@ -1193,7 +1244,7 @@ impl paras_registrar::Config for Runtime {
type Currency = Balances;
type OnSwap = (Crowdloan, Slots);
type ParaDeposit = ParaDeposit;
type DataDepositPerByte = DataDepositPerByte;
type DataDepositPerByte = RegistrarDataDepositPerByte;
type WeightInfo = weights::runtime_common_paras_registrar::WeightInfo<Runtime>;
}
@@ -1207,7 +1258,7 @@ impl slots::Config for Runtime {
type Registrar = Registrar;
type LeasePeriod = LeasePeriod;
type LeaseOffset = ();
type ForceOrigin = EnsureRoot<AccountId>;
type ForceOrigin = EitherOf<EnsureRoot<Self::AccountId>, LeaseAdmin>;
type WeightInfo = weights::runtime_common_slots::WeightInfo<Runtime>;
}
@@ -1247,7 +1298,7 @@ impl auctions::Config for Runtime {
type EndingPeriod = EndingPeriod;
type SampleLength = SampleLength;
type Randomness = pallet_babe::RandomnessFromOneEpochAgo<Runtime>;
type InitiateOrigin = EnsureRoot<AccountId>;
type InitiateOrigin = EitherOf<EnsureRoot<Self::AccountId>, AuctionAdmin>;
type WeightInfo = weights::runtime_common_auctions::WeightInfo<Runtime>;
}
@@ -1352,6 +1403,15 @@ construct_runtime! {
// Fast unstake pallet: extension to staking.
FastUnstake: pallet_fast_unstake = 30,
// OpenGov
ConvictionVoting: pallet_conviction_voting::{Pallet, Call, Storage, Event<T>} = 31,
Referenda: pallet_referenda::{Pallet, Call, Storage, Event<T>} = 32,
Origins: pallet_custom_origins::{Origin} = 35,
Whitelist: pallet_whitelist::{Pallet, Call, Storage, Event<T>} = 36,
// Treasury
Treasury: pallet_treasury::{Pallet, Call, Storage, Config<T>, Event<T>} = 37,
// Parachains pallets. Start indices at 40 to leave room.
ParachainsOrigin: parachains_origin::{Pallet, Origin} = 41,
Configuration: parachains_configuration::{Pallet, Call, Storage, Config<T>} = 42,
@@ -1445,6 +1505,7 @@ pub mod migrations {
UpgradeSessionKeys,
parachains_configuration::migration::v9::MigrateToV9<Runtime>,
paras_registrar::migration::VersionCheckedMigrateToV1<Runtime, ()>,
pallet_referenda::migration::v1::MigrateV0ToV1<Runtime, ()>,
);
}
@@ -1485,6 +1546,7 @@ mod benches {
// Substrate
[pallet_bags_list, VoterList]
[pallet_balances, Balances]
[pallet_conviction_voting, ConvictionVoting]
[pallet_election_provider_multi_phase, ElectionProviderMultiPhase]
[frame_election_provider_support, ElectionProviderBench::<Runtime>]
[pallet_fast_unstake, FastUnstake]
@@ -1498,14 +1560,17 @@ mod benches {
[pallet_preimage, Preimage]
[pallet_proxy, Proxy]
[pallet_recovery, Recovery]
[pallet_referenda, Referenda]
[pallet_scheduler, Scheduler]
[pallet_session, SessionBench::<Runtime>]
[pallet_staking, Staking]
[pallet_sudo, Sudo]
[frame_system, SystemBench::<Runtime>]
[pallet_timestamp, Timestamp]
[pallet_treasury, Treasury]
[pallet_utility, Utility]
[pallet_vesting, Vesting]
[pallet_whitelist, Whitelist]
// XCM
[pallet_xcm, XcmPallet]
// NOTE: Make sure you point to the individual modules below.
@@ -2059,13 +2124,13 @@ sp_api::impl_runtime_apis! {
AssetId::*, Fungibility::*, InteriorMultiLocation, Junction, Junctions::*,
MultiAsset, MultiAssets, MultiLocation, NetworkId, Response,
};
use xcm_config::{Westmint, TokenLocation};
use xcm_config::{AssetHub, TokenLocation};
impl pallet_xcm_benchmarks::Config for Runtime {
type XcmConfig = xcm_config::XcmConfig;
type AccountIdConverter = xcm_config::LocationConverter;
fn valid_destination() -> Result<MultiLocation, BenchmarkError> {
Ok(Westmint::get())
Ok(AssetHub::get())
}
fn worst_case_holding(_depositable_count: u32) -> MultiAssets {
// Westend only knows about WND.
@@ -2078,7 +2143,7 @@ sp_api::impl_runtime_apis! {
parameter_types! {
pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some((
Westmint::get(),
AssetHub::get(),
MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(TokenLocation::get()) },
));
pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = None;
@@ -2117,15 +2182,15 @@ sp_api::impl_runtime_apis! {
}
fn transact_origin_and_runtime_call() -> Result<(MultiLocation, RuntimeCall), BenchmarkError> {
Ok((Westmint::get(), frame_system::Call::remark_with_event { remark: vec![] }.into()))
Ok((AssetHub::get(), frame_system::Call::remark_with_event { remark: vec![] }.into()))
}
fn subscribe_origin() -> Result<MultiLocation, BenchmarkError> {
Ok(Westmint::get())
Ok(AssetHub::get())
}
fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> {
let origin = Westmint::get();
let origin = AssetHub::get();
let assets: MultiAssets = (Concrete(TokenLocation::get()), 1_000 * UNITS).into();
let ticket = MultiLocation { parents: 0, interior: Here };
Ok((origin, ticket, assets))