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

Add Nomination Pools to Kusama #5447

Merged
merged 25 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6b37896
add nomination pools to kusama
kianenigma May 4, 2022
67225a8
Update runtime/kusama/src/lib.rs
kianenigma May 6, 2022
029fd18
Update runtime/kusama/src/lib.rs
kianenigma May 6, 2022
ae39a62
Merge branch 'master' of github.com:paritytech/polkadot into kiz-nomp…
kianenigma May 9, 2022
a097b41
probably fix build
kianenigma May 9, 2022
96eae22
Merge branch 'kiz-nompools-ksm' of github.com:paritytech/polkadot int…
kianenigma May 9, 2022
8fd16e0
really fix build
kianenigma May 9, 2022
5ae626a
fix benches
kianenigma May 10, 2022
738b786
cargo run --quiet --profile=production --features=runtime-benchmarks…
May 10, 2022
7e9a581
Merge branch 'master' of https://github.com/paritytech/polkadot into …
May 10, 2022
0cbb475
cargo run --quiet --profile=production --features=runtime-benchmarks…
May 10, 2022
d6d040f
whitelist transactional storage limit
kianenigma May 10, 2022
2044060
Merge branch 'kiz-nompools-ksm' of github.com:paritytech/polkadot int…
kianenigma May 10, 2022
6745514
make defensive
kianenigma May 10, 2022
68c216f
fix
kianenigma May 10, 2022
3b1c8d2
Merge branch 'master' of https://github.com/paritytech/polkadot into …
May 10, 2022
95a4026
cargo run --quiet --profile=production --features=runtime-benchmarks…
May 10, 2022
c0943e2
Merge branch 'master' of github.com:paritytech/polkadot into kiz-nomp…
kianenigma May 10, 2022
dee57e7
update
kianenigma May 10, 2022
1f352f2
Merge branch 'kiz-nompools-ksm' of github.com:paritytech/polkadot int…
kianenigma May 10, 2022
394cdb8
fix benches
kianenigma May 10, 2022
4c027f3
cargo run --quiet --profile=production --features=runtime-benchmarks…
May 10, 2022
54a2cbd
change head
kianenigma May 11, 2022
0754fa2
Merge branch 'kiz-nompools-ksm' of github.com:paritytech/polkadot int…
kianenigma May 11, 2022
b3553d7
fmt
kianenigma May 11, 2022
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.

9 changes: 3 additions & 6 deletions node/service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ fn kusama_staging_testnet_config_genesis(wasm_binary: &[u8]) -> kusama::GenesisC
gilt: Default::default(),
paras: Default::default(),
xcm_pallet: Default::default(),
nomination_pools: Default::default(),
}
}

Expand Down Expand Up @@ -1471,6 +1472,7 @@ pub fn kusama_testnet_genesis(
gilt: Default::default(),
paras: Default::default(),
xcm_pallet: Default::default(),
nomination_pools: Default::default(),
}
}

Expand Down Expand Up @@ -1551,12 +1553,7 @@ pub fn westend_testnet_genesis(
next_free_para_id: polkadot_primitives::v2::LOWEST_PUBLIC_ID,
},
xcm_pallet: Default::default(),
nomination_pools: westend_runtime::NominationPoolsConfig {
max_pools: Some(128),
min_join_bond: WND,
min_create_bond: 100 * WND,
..Default::default()
},
nomination_pools: Default::default(),
}
}

Expand Down
5 changes: 5 additions & 0 deletions runtime/kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,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 @@ -83,6 +84,7 @@ frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch =
frame-try-runtime = { 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 }
frame-system-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
pallet-election-provider-support-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
hex-literal = { version = "0.3.4", optional = true }
Expand Down Expand Up @@ -147,6 +149,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 @@ -207,6 +210,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
72 changes: 70 additions & 2 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ use frame_election_provider_support::{
use frame_support::{
construct_runtime, parameter_types,
traits::{
Contains, EnsureOneOf, InstanceFilter, KeyOwnerProofSystem, LockIdentifier, PrivilegeCmp,
ConstU32, Contains, EnsureOneOf, InstanceFilter, KeyOwnerProofSystem, LockIdentifier,
OnRuntimeUpgrade, PrivilegeCmp,
},
weights::ConstantMultiplier,
PalletId, RuntimeDebug,
Expand Down Expand Up @@ -1397,6 +1398,64 @@ 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");
}

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 StakingInterface = Staking;
type PostUnbondingPoolsWindow = ConstU32<4>;
type MaxMetadataLen = 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;
}

pub struct InitiatePoolConfigs;
impl 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() {
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
// 1/600 KSM to join a pool.
pallet_nomination_pools::MinJoinBond::<Runtime>::put(50 * CENTS);
// 1 KSM to create a pool.
pallet_nomination_pools::MinCreateBond::<Runtime>::put(UNITS);

// 128 initial pools: only for initial safety: can be set to infinity when needed.
pallet_nomination_pools::MaxPools::<Runtime>::put(128);
// 64k total pool members: only for initial safety: can be set to infinity when needed.
pallet_nomination_pools::MaxPoolMembers::<Runtime>::put(64 * 1024);
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
// 1024 members per pool: only for initial safety: can be set to infinity when needed.
pallet_nomination_pools::MaxPoolMembersPerPool::<Runtime>::put(1024);

log::info!(target: "runtime::kusama", "pools config initiated 🎉");
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, 5)
} else {
log::info!(target: "runtime::kusama", "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 @@ -1481,6 +1540,9 @@ construct_runtime! {
// Provides a semi-sorted list of nominators for staking.
BagsList: pallet_bags_list::{Pallet, Call, Storage, Event<T>} = 39,

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

// 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 @@ -1537,7 +1599,7 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
(),
InitiatePoolConfigs,
>;
/// The payload being signed in the transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;
Expand Down Expand Up @@ -1582,6 +1644,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 @@ -1966,6 +2029,7 @@ sp_api::impl_runtime_apis! {
use pallet_offences_benchmarking::Pallet as OffencesBench;
use pallet_election_provider_support_benchmarking::Pallet as ElectionProviderBench;
use frame_system_benchmarking::Pallet as SystemBench;
use pallet_nomination_pools_benchmarking::Pallet as NominationPoolsBench;
use frame_benchmarking::baseline::Pallet as Baseline;

let mut list = Vec::<BenchmarkList>::new();
Expand All @@ -1988,6 +2052,7 @@ sp_api::impl_runtime_apis! {
use pallet_offences_benchmarking::Pallet as OffencesBench;
use pallet_election_provider_support_benchmarking::Pallet as ElectionProviderBench;
use frame_system_benchmarking::Pallet as SystemBench;
use pallet_nomination_pools_benchmarking::Pallet as NominationPoolsBench;
use frame_benchmarking::baseline::Pallet as Baseline;
use xcm::latest::prelude::*;
use xcm_config::{CheckAccount, KsmLocation, SovereignAccountOf, Statemine, XcmConfig};
Expand All @@ -1997,6 +2062,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 {}

impl pallet_xcm_benchmarks::Config for Runtime {
type XcmConfig = XcmConfig;
Expand Down Expand Up @@ -2077,6 +2143,8 @@ sp_api::impl_runtime_apis! {
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da95ecffd7b6c0f78751baa9d281e0bfa3a6d6f646c70792f74727372790000000000000000000000000000000000000000").to_vec().into(),
// Configuration ActiveConfig
hex_literal::hex!("06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385").to_vec().into(),
// The transactional storage limit.
hex_literal::hex!("3a7472616e73616374696f6e5f6c6576656c3a").to_vec().into(),
];

let mut batches = Vec::<BenchmarkBatch>::new();
Expand Down
1 change: 1 addition & 0 deletions runtime/kusama/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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