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

Commit

Permalink
Add Nomination Pools to Kusama (#5447)
Browse files Browse the repository at this point in the history
* add nomination pools to kusama

* Update runtime/kusama/src/lib.rs

Co-authored-by: Mara Robin B. <mara@broda.me>

* Update runtime/kusama/src/lib.rs

* probably fix build

* really fix build

* fix benches

* cargo run --quiet --profile=production  --features=runtime-benchmarks -- benchmark pallet --chain=kusama-dev --steps=50 --repeat=20 --pallet=pallet_nomination_pools --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/kusama/src/weights/

* cargo run --quiet --profile=production  --features=runtime-benchmarks -- benchmark pallet --chain=westend-dev --steps=50 --repeat=20 --pallet=pallet_nomination_pools --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/westend/src/weights/

* whitelist transactional storage limit

* make defensive

* fix

* cargo run --quiet --profile=production  --features=runtime-benchmarks -- benchmark pallet --chain=westend-dev --steps=50 --repeat=20 --pallet=pallet_nomination_pools --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/westend/src/weights/

* update

* fix benches

* cargo run --quiet --profile=production  --features=runtime-benchmarks -- benchmark pallet --chain=kusama-dev --steps=50 --repeat=20 --pallet=pallet_nomination_pools --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/kusama/src/weights/

* change head

* fmt

Co-authored-by: Mara Robin B. <mara@broda.me>
Co-authored-by: Parity Bot <admin@parity.io>
  • Loading branch information
3 people authored May 11, 2022
1 parent 3c66d58 commit affd1eb
Show file tree
Hide file tree
Showing 9 changed files with 4,864 additions and 62 deletions.
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() {
// 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);
// 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

0 comments on commit affd1eb

Please sign in to comment.