Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 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 node/service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ fn polkadot_staging_testnet_config_genesis(wasm_binary: &[u8]) -> polkadot::Gene
},
paras: Default::default(),
xcm_pallet: Default::default(),
nomination_pools: Default::default(),
}
}

Expand Down Expand Up @@ -1385,6 +1386,7 @@ pub fn polkadot_testnet_genesis(
},
paras: Default::default(),
xcm_pallet: Default::default(),
nomination_pools: Default::default(),
}
}

Expand Down
19 changes: 18 additions & 1 deletion runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use frame_support::{
weights::{constants::WEIGHT_PER_SECOND, Weight},
};
use frame_system::limits;
use primitives::v2::{AssignmentId, BlockNumber, ValidatorId};
use primitives::v2::{AssignmentId, Balance, BlockNumber, ValidatorId};
use sp_runtime::{FixedPointNumber, Perbill, Perquintill};
use static_assertions::const_assert;

Expand Down Expand Up @@ -215,6 +215,23 @@ impl pallet_staking::BenchmarkingConfig for StakingBenchmarkingConfig {
type MaxNominators = ConstU32<1000>;
}

/// Convert a balance to an unsigned 256-bit number, use in nomination pools.
pub struct BalanceToU256;
impl sp_runtime::traits::Convert<Balance, sp_core::U256> for BalanceToU256 {
fn convert(n: Balance) -> sp_core::U256 {
n.into()
}
}

/// Convert an unsigned 256-bit number to balance, use in nomination pools.
pub struct U256ToBalance;
impl sp_runtime::traits::Convert<sp_core::U256, Balance> for U256ToBalance {
fn convert(n: sp_core::U256) -> Balance {
use frame_support::traits::Defensive;
n.try_into().defensive_unwrap_or(Balance::MAX)
}
}

/// Macro to set a value (e.g. when using the `parameter_types` macro) to either a production value
/// or to an environment variable or testing value (in case the `fast-runtime` feature is selected).
/// Note that the environment variable is evaluated _at compile time_.
Expand Down
1 change: 1 addition & 0 deletions runtime/kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ try-runtime = [
"pallet-membership/try-runtime",
"pallet-multisig/try-runtime",
"pallet-nicks/try-runtime",
"pallet-nomination-pools/try-runtime",
"pallet-offences/try-runtime",
"pallet-preimage/try-runtime",
"pallet-proxy/try-runtime",
Expand Down
21 changes: 4 additions & 17 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,8 @@ impl InstanceFilter<Call> for ProxyType {
Call::Crowdloan(..) |
Call::Slots(..) |
Call::Auctions(..) | // Specifically omitting the entire XCM Pallet
Call::VoterList(..)
Call::VoterList(..) |
Call::NominationPools(..)
),
ProxyType::Governance => matches!(
c,
Expand Down Expand Up @@ -1421,20 +1422,6 @@ impl pallet_gilt::Config for Runtime {
type WeightInfo = weights::pallet_gilt::WeightInfo<Runtime>;
}

pub struct BalanceToU256;
impl sp_runtime::traits::Convert<Balance, sp_core::U256> for BalanceToU256 {
fn convert(n: Balance) -> sp_core::U256 {
n.into()
}
}
pub struct U256ToBalance;
impl sp_runtime::traits::Convert<sp_core::U256, Balance> for U256ToBalance {
fn convert(n: sp_core::U256) -> Balance {
use frame_support::traits::Defensive;
n.try_into().defensive_unwrap_or(Balance::MAX)
}
}

parameter_types! {
pub const PoolsPalletId: PalletId = PalletId(*b"py/nopls");
pub const MinPointsToBalance: u32 = 10;
Expand All @@ -1444,8 +1431,8 @@ impl pallet_nomination_pools::Config for Runtime {
type Event = Event;
type WeightInfo = weights::pallet_nomination_pools::WeightInfo<Self>;
type Currency = Balances;
type BalanceToU256 = BalanceToU256;
type U256ToBalance = U256ToBalance;
type BalanceToU256 = runtime_common::BalanceToU256;
type U256ToBalance = runtime_common::U256ToBalance;
type StakingInterface = Staking;
type PostUnbondingPoolsWindow = ConstU32<4>;
type MaxMetadataLen = ConstU32<256>;
Expand Down
5 changes: 5 additions & 0 deletions runtime/polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pallet-indices = { git = "https://github.com/paritytech/substrate", branch = "ma
pallet-membership = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-multisig = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-nicks = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-nomination-pools = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-offences = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-preimage = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-proxy = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
Expand All @@ -80,6 +81,7 @@ frame-system-benchmarking = { git = "https://github.com/paritytech/substrate", b
pallet-election-provider-support-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
pallet-offences-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
pallet-session-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
pallet-nomination-pools-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
hex-literal = { version = "0.3.4", optional = true }

runtime-common = { package = "polkadot-runtime-common", path = "../common", default-features = false }
Expand Down Expand Up @@ -142,6 +144,7 @@ std = [
"pallet-membership/std",
"pallet-multisig/std",
"pallet-nicks/std",
"pallet-nomination-pools/std",
"pallet-offences/std",
"pallet-preimage/std",
"pallet-proxy/std",
Expand Down Expand Up @@ -195,6 +198,8 @@ runtime-benchmarks = [
"pallet-indices/runtime-benchmarks",
"pallet-membership/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
"pallet-nomination-pools/runtime-benchmarks",
"pallet-nomination-pools-benchmarking",
"pallet-preimage/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
Expand Down
59 changes: 57 additions & 2 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ impl Contains<Call> for BaseFilter {
Call::Auctions(_) |
Call::Crowdloan(_) |
Call::VoterList(_) |
Call::XcmPallet(_) => true,
Call::XcmPallet(_) |
Call::NominationPools(_) => true,
// All pallets are allowed, but exhaustive match is defensive
// in the case of adding new pallets.
}
Expand Down Expand Up @@ -1177,7 +1178,8 @@ impl InstanceFilter<Call> for ProxyType {
Call::Crowdloan(..) |
Call::Slots(..) |
Call::Auctions(..) | // Specifically omitting the entire XCM Pallet
Call::VoterList(..)
Call::VoterList(..) |
Call::NominationPools(..)
),
ProxyType::Governance => matches!(
c,
Expand Down Expand Up @@ -1386,6 +1388,52 @@ impl auctions::Config for Runtime {
type WeightInfo = weights::runtime_common_auctions::WeightInfo<Runtime>;
}

parameter_types! {
pub const PoolsPalletId: PalletId = PalletId(*b"py/nopls");
pub const MinPointsToBalance: u32 = 10;
}

impl pallet_nomination_pools::Config for Runtime {
type Event = Event;
type WeightInfo = weights::pallet_nomination_pools::WeightInfo<Self>;
type Currency = Balances;
type BalanceToU256 = runtime_common::BalanceToU256;
type U256ToBalance = runtime_common::U256ToBalance;
type StakingInterface = Staking;
type PostUnbondingPoolsWindow = frame_support::traits::ConstU32<4>;
type MaxMetadataLen = frame_support::traits::ConstU32<256>;
// we use the same number of allowed unlocking chunks as with staking.
type MaxUnbonding = <Self as pallet_staking::Config>::MaxUnlockingChunks;
type PalletId = PoolsPalletId;
type MinPointsToBalance = MinPointsToBalance;
}

pub struct InitiatePoolConfigs;
impl frame_support::traits::OnRuntimeUpgrade for InitiatePoolConfigs {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
// we use one as an indicator if this has already been set.
if pallet_nomination_pools::MaxPools::<Runtime>::get().is_none() {
// 1 DOT to join a pool.
pallet_nomination_pools::MinJoinBond::<Runtime>::put(1 * UNITS);
// 100 DOT to create a pool.
pallet_nomination_pools::MinCreateBond::<Runtime>::put(100 * UNITS);

// 64 initial pools: only for initial safety: can be set to infinity when needed.
pallet_nomination_pools::MaxPools::<Runtime>::put(64);
// 4096 members per pool: only for initial safety: can be set to infinity when needed.
pallet_nomination_pools::MaxPoolMembersPerPool::<Runtime>::put(4 * 1024);
// 128k total pool members: only for initial safety: can be set to infinity when needed.
pallet_nomination_pools::MaxPoolMembers::<Runtime>::put(128 * 1024);

log::info!(target: "runtime::polkadot", "pools config initiated 🎉");
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, 5)
} else {
log::info!(target: "runtime::polkadot", "pools config already initiated 😏");
<Runtime as frame_system::Config>::DbWeight::get().reads(1)
}
}
}

construct_runtime! {
pub enum Runtime where
Block = Block,
Expand Down Expand Up @@ -1455,6 +1503,9 @@ construct_runtime! {
// Provides a semi-sorted list of nominators for staking.
VoterList: pallet_bags_list::{Pallet, Call, Storage, Event<T>} = 37,

// nomination pools: extension to staking.
NominationPools: pallet_nomination_pools::{Pallet, Call, Storage, Event<T>, Config<T>} = 39,

// Parachains pallets. Start indices at 50 to leave room.
ParachainsOrigin: parachains_origin::{Pallet, Origin} = 50,
Configuration: parachains_configuration::{Pallet, Call, Storage, Config<T>} = 51,
Expand Down Expand Up @@ -1570,6 +1621,7 @@ mod benches {
[pallet_indices, Indices]
[pallet_membership, TechnicalMembership]
[pallet_multisig, Multisig]
[pallet_nomination_pools, NominationPoolsBench::<Runtime>]
[pallet_offences, OffencesBench::<Runtime>]
[pallet_preimage, Preimage]
[pallet_proxy, Proxy]
Expand Down Expand Up @@ -1950,6 +2002,7 @@ sp_api::impl_runtime_apis! {
use pallet_session_benchmarking::Pallet as SessionBench;
use pallet_offences_benchmarking::Pallet as OffencesBench;
use pallet_election_provider_support_benchmarking::Pallet as ElectionProviderBench;
use pallet_nomination_pools_benchmarking::Pallet as NominationPoolsBench;
use frame_system_benchmarking::Pallet as SystemBench;
use frame_benchmarking::baseline::Pallet as Baseline;

Expand All @@ -1972,6 +2025,7 @@ sp_api::impl_runtime_apis! {
use pallet_session_benchmarking::Pallet as SessionBench;
use pallet_offences_benchmarking::Pallet as OffencesBench;
use pallet_election_provider_support_benchmarking::Pallet as ElectionProviderBench;
use pallet_nomination_pools_benchmarking::Pallet as NominationPoolsBench;
use frame_system_benchmarking::Pallet as SystemBench;
use frame_benchmarking::baseline::Pallet as Baseline;

Expand All @@ -1980,6 +2034,7 @@ sp_api::impl_runtime_apis! {
impl pallet_election_provider_support_benchmarking::Config for Runtime {}
impl frame_system_benchmarking::Config for Runtime {}
impl frame_benchmarking::baseline::Config for Runtime {}
impl pallet_nomination_pools_benchmarking::Config for Runtime {}

let whitelist: Vec<TrackedStorageKey> = vec![
// Block Number
Expand Down
1 change: 1 addition & 0 deletions runtime/polkadot/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub mod pallet_im_online;
pub mod pallet_indices;
pub mod pallet_membership;
pub mod pallet_multisig;
pub mod pallet_nomination_pools;
pub mod pallet_preimage;
pub mod pallet_proxy;
pub mod pallet_scheduler;
Expand Down
Loading