Skip to content

Commit

Permalink
Switch to using Delegation Staking for pools (#5)
Browse files Browse the repository at this point in the history
* add delegated staking to kusama

* delegate stake in polkadot

* fmt

* comment

* update delegated staking pallet

* fix comment

* make slashes go to the treasury

* update changelog

* fmt
  • Loading branch information
Ank4n authored Nov 9, 2024
1 parent f54a026 commit cf05416
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- \[Assets\] Call implementation for `transfer_all` ([SDK `stable2409` #4527](https://github.com/paritytech/polkadot-sdk/pull/4527))
- Tx Payment: drop ED requirements for tx payments with exchangeable asset ([SDK `stable2409` #4488](https://github.com/paritytech/polkadot-sdk/pull/4488))
- Coretime auto-renew ([SDK `stable2409` #4424](https://github.com/paritytech/polkadot-sdk/pull/4424))
- Initialises pallet-delegated-staking ([SDK `v1.12.0` #3904](https://github.com/paritytech/polkadot-sdk/pull/3904))

### Changed

Expand All @@ -26,6 +27,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Bridges V2 refactoring backport and `pallet_bridge_messages` simplifications ([SDK `stable2407` #4935](https://github.com/paritytech/polkadot-sdk/pull/4935))
- Renamed `assigner_on_demand` to `on_demand` ([SDK `stable2409` #4706](https://github.com/paritytech/polkadot-sdk/pull/4706)).
- \[BEEFY\] Add runtime support for reporting fork voting ([SDK `stable2407` #4522](https://github.com/paritytech/polkadot-sdk/pull/4522)).
- Migrates Nomination Pool to use delegated staking: i.e. allowing delegated funds to be held in member's own account
instead of the pool account. This would enable pool member funds to be used for voting in opengov.
([SDK `v1.13.0` #3905](https://github.com/paritytech/polkadot-sdk/pull/3905))

## [1.3.4] 01.11.2024

Expand Down
4 changes: 3 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ pallet-session = { version = "38.0.0", default-features = false }
pallet-session-benchmarking = { version = "38.0.0", default-features = false }
pallet-society = { version = "38.0.0", default-features = false }
pallet-staking = { version = "38.0.0", default-features = false }
pallet-delegated-staking = { version = "5.0.0", default-features = false }
pallet-staking-reward-curve = { version = "12.0.0" }
pallet-staking-reward-fn = { version = "22.0.0", default-features = false }
pallet-staking-runtime-api = { version = "24.0.0", default-features = false }
Expand Down
4 changes: 4 additions & 0 deletions relay/kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pallet-transaction-payment = { workspace = true }
pallet-transaction-payment-rpc-runtime-api = { workspace = true }
pallet-nomination-pools-runtime-api = { workspace = true }
pallet-conviction-voting = { workspace = true }
pallet-delegated-staking = { workspace = true }
pallet-election-provider-multi-phase = { workspace = true }
pallet-fast-unstake = { workspace = true }
frame-executive = { workspace = true }
Expand Down Expand Up @@ -151,6 +152,7 @@ std = [
"pallet-bounties/std",
"pallet-child-bounties/std",
"pallet-conviction-voting/std",
"pallet-delegated-staking/std",
"pallet-election-provider-multi-phase/std",
"pallet-election-provider-support-benchmarking?/std",
"pallet-fast-unstake/std",
Expand Down Expand Up @@ -231,6 +233,7 @@ runtime-benchmarks = [
"pallet-bounties/runtime-benchmarks",
"pallet-child-bounties/runtime-benchmarks",
"pallet-conviction-voting/runtime-benchmarks",
"pallet-delegated-staking/runtime-benchmarks",
"pallet-election-provider-multi-phase/runtime-benchmarks",
"pallet-election-provider-support-benchmarking/runtime-benchmarks",
"pallet-fast-unstake/runtime-benchmarks",
Expand Down Expand Up @@ -288,6 +291,7 @@ try-runtime = [
"pallet-bounties/try-runtime",
"pallet-child-bounties/try-runtime",
"pallet-conviction-voting/try-runtime",
"pallet-delegated-staking/try-runtime",
"pallet-election-provider-multi-phase/try-runtime",
"pallet-fast-unstake/try-runtime",
"pallet-grandpa/try-runtime",
Expand Down
46 changes: 40 additions & 6 deletions relay/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ use frame_support::{
genesis_builder_helper::{build_state, get_preset},
parameter_types,
traits::{
fungible::HoldConsideration, tokens::UnityOrOuterConversion, ConstU32, ConstU8, EitherOf,
EitherOfDiverse, Everything, FromContains, InstanceFilter, KeyOwnerProofSystem,
LinearStoragePrice, PrivilegeCmp, ProcessMessage, ProcessMessageError, StorageMapShim,
WithdrawReasons,
fungible::HoldConsideration,
tokens::{imbalance::ResolveTo, UnityOrOuterConversion},
ConstU32, ConstU8, EitherOf, EitherOfDiverse, Everything, FromContains, InstanceFilter,
KeyOwnerProofSystem, LinearStoragePrice, PrivilegeCmp, ProcessMessage, ProcessMessageError,
StorageMapShim, WithdrawReasons,
},
weights::{ConstantMultiplier, WeightMeter, WeightToFee as _},
PalletId,
Expand Down Expand Up @@ -127,6 +128,7 @@ pub use frame_system::Call as SystemCall;
pub use pallet_balances::Call as BalancesCall;
pub use pallet_election_provider_multi_phase::{Call as EPMCall, GeometricDepositBase};
use pallet_staking::UseValidatorsMap;
use pallet_treasury::TreasuryAccountId;
use sp_runtime::traits::Get;
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
Expand Down Expand Up @@ -805,7 +807,7 @@ impl pallet_staking::Config for Runtime {
type HistoryDepth = frame_support::traits::ConstU32<84>;
type MaxControllersInDeprecationBatch = ConstU32<5169>;
type BenchmarkingConfig = polkadot_runtime_common::StakingBenchmarkingConfig;
type EventListeners = NominationPools;
type EventListeners = (NominationPools, DelegatedStaking);
type DisablingStrategy = pallet_staking::UpToLimitDisablingStrategy;
type WeightInfo = weights::pallet_staking::WeightInfo<Runtime>;
}
Expand Down Expand Up @@ -1613,7 +1615,8 @@ impl pallet_nomination_pools::Config for Runtime {
type RewardCounter = FixedU128;
type BalanceToU256 = BalanceToU256;
type U256ToBalance = U256ToBalance;
type StakeAdapter = pallet_nomination_pools::adapter::TransferStake<Self, Staking>;
type StakeAdapter =
pallet_nomination_pools::adapter::DelegateStake<Self, Staking, DelegatedStaking>;
type PostUnbondingPoolsWindow = ConstU32<4>;
type MaxMetadataLen = ConstU32<256>;
// we use the same number of allowed unlocking chunks as with staking.
Expand All @@ -1623,6 +1626,22 @@ impl pallet_nomination_pools::Config for Runtime {
type AdminOrigin = EitherOf<EnsureRoot<AccountId>, StakingAdmin>;
}

parameter_types! {
pub const DelegatedStakingPalletId: PalletId = PalletId(*b"py/dlstk");
pub const SlashRewardFraction: Perbill = Perbill::from_percent(1);
}

impl pallet_delegated_staking::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type PalletId = DelegatedStakingPalletId;
type Currency = Balances;
// slashes are sent to the treasury.
type OnSlash = ResolveTo<TreasuryAccountId<Self>, Balances>;
type SlashRewardFraction = SlashRewardFraction;
type RuntimeHoldReason = RuntimeHoldReason;
type CoreStaking = Staking;
}

/// The [frame_support::traits::tokens::ConversionFromAssetBalance] implementation provided by the
/// `AssetRate` pallet instance.
///
Expand Down Expand Up @@ -1737,6 +1756,9 @@ construct_runtime! {
// Fast unstake pallet: extension to staking.
FastUnstake: pallet_fast_unstake = 42,

// Staking extension for delegation
DelegatedStaking: pallet_delegated_staking = 47,

// Parachains pallets. Start indices at 50 to leave room.
ParachainsOrigin: parachains_origin = 50,
Configuration: parachains_configuration = 51,
Expand Down Expand Up @@ -1809,6 +1831,13 @@ impl Get<Perbill> for NominationPoolsMigrationV4OldPallet {
}
}

parameter_types! {
// This is used to limit max pools that migrates in the runtime upgrade. This is set to
// existing_pool_count plus ~15 to also account for any new pools getting created before the
// migration is actually executed.
pub const MaxPoolsToMigrate: u32 = 200;
}

/// All migrations that will run on the next runtime upgrade.
///
/// This contains the combined migrations of the last 10 releases. It allows to skip runtime
Expand All @@ -1827,6 +1856,11 @@ pub mod migrations {
parachains_inclusion::migration::MigrateToV1<Runtime>,
parachains_on_demand::migration::MigrateV0ToV1<Runtime>,
restore_corrupted_ledgers::Migrate<Runtime>,
// Migrate NominationPools to `DelegateStake` adapter. This is an unversioned upgrade.
pallet_nomination_pools::migration::unversioned::DelegationStakeMigration<
Runtime,
MaxPoolsToMigrate,
>,
);

/// Migrations/checks that do not need to be versioned and can run on every update.
Expand Down
4 changes: 4 additions & 0 deletions relay/polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pallet-beefy-mmr = { workspace = true }
pallet-bounties = { workspace = true }
pallet-broker = { workspace = true }
pallet-child-bounties = { workspace = true }
pallet-delegated-staking = { workspace = true }
pallet-transaction-payment = { workspace = true }
pallet-transaction-payment-rpc-runtime-api = { workspace = true }
pallet-conviction-voting = { workspace = true }
Expand Down Expand Up @@ -155,6 +156,7 @@ std = [
"pallet-broker/std",
"pallet-child-bounties/std",
"pallet-conviction-voting/std",
"pallet-delegated-staking/std",
"pallet-election-provider-multi-phase/std",
"pallet-election-provider-support-benchmarking?/std",
"pallet-fast-unstake/std",
Expand Down Expand Up @@ -236,6 +238,7 @@ runtime-benchmarks = [
"pallet-broker/runtime-benchmarks",
"pallet-child-bounties/runtime-benchmarks",
"pallet-conviction-voting/runtime-benchmarks",
"pallet-delegated-staking/runtime-benchmarks",
"pallet-election-provider-multi-phase/runtime-benchmarks",
"pallet-election-provider-support-benchmarking/runtime-benchmarks",
"pallet-fast-unstake/runtime-benchmarks",
Expand Down Expand Up @@ -292,6 +295,7 @@ try-runtime = [
"pallet-broker/try-runtime",
"pallet-child-bounties/try-runtime",
"pallet-conviction-voting/try-runtime",
"pallet-delegated-staking/try-runtime",
"pallet-election-provider-multi-phase/try-runtime",
"pallet-fast-unstake/try-runtime",
"pallet-grandpa/try-runtime",
Expand Down
46 changes: 40 additions & 6 deletions relay/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ use frame_support::{
genesis_builder_helper::{build_state, get_preset},
parameter_types,
traits::{
fungible::HoldConsideration, tokens::UnityOrOuterConversion, ConstU32, ConstU8, EitherOf,
EitherOfDiverse, Everything, FromContains, Get, InstanceFilter, KeyOwnerProofSystem,
LinearStoragePrice, OnRuntimeUpgrade, PrivilegeCmp, ProcessMessage, ProcessMessageError,
WithdrawReasons,
fungible::HoldConsideration,
tokens::{imbalance::ResolveTo, UnityOrOuterConversion},
ConstU32, ConstU8, EitherOf, EitherOfDiverse, Everything, FromContains, Get,
InstanceFilter, KeyOwnerProofSystem, LinearStoragePrice, OnRuntimeUpgrade, PrivilegeCmp,
ProcessMessage, ProcessMessageError, WithdrawReasons,
},
weights::{
constants::{WEIGHT_PROOF_SIZE_PER_KB, WEIGHT_REF_TIME_PER_MICROS},
Expand Down Expand Up @@ -121,6 +122,7 @@ pub use pallet_balances::Call as BalancesCall;
pub use pallet_election_provider_multi_phase::{Call as EPMCall, GeometricDepositBase};
use pallet_staking::UseValidatorsMap;
pub use pallet_timestamp::Call as TimestampCall;
use pallet_treasury::TreasuryAccountId;
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;

Expand Down Expand Up @@ -785,7 +787,7 @@ impl pallet_staking::Config for Runtime {
type HistoryDepth = frame_support::traits::ConstU32<84>;
type MaxControllersInDeprecationBatch = ConstU32<5314>;
type BenchmarkingConfig = polkadot_runtime_common::StakingBenchmarkingConfig;
type EventListeners = NominationPools;
type EventListeners = (NominationPools, DelegatedStaking);
type DisablingStrategy = pallet_staking::UpToLimitDisablingStrategy;
type WeightInfo = weights::pallet_staking::WeightInfo<Runtime>;
}
Expand Down Expand Up @@ -1523,7 +1525,8 @@ impl pallet_nomination_pools::Config for Runtime {
type RewardCounter = FixedU128;
type BalanceToU256 = polkadot_runtime_common::BalanceToU256;
type U256ToBalance = polkadot_runtime_common::U256ToBalance;
type StakeAdapter = pallet_nomination_pools::adapter::TransferStake<Self, Staking>;
type StakeAdapter =
pallet_nomination_pools::adapter::DelegateStake<Self, Staking, DelegatedStaking>;
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.
Expand All @@ -1534,6 +1537,22 @@ impl pallet_nomination_pools::Config for Runtime {
type AdminOrigin = EitherOf<EnsureRoot<AccountId>, StakingAdmin>;
}

parameter_types! {
pub const DelegatedStakingPalletId: PalletId = PalletId(*b"py/dlstk");
pub const SlashRewardFraction: Perbill = Perbill::from_percent(1);
}

impl pallet_delegated_staking::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type PalletId = DelegatedStakingPalletId;
type Currency = Balances;
// slashes are sent to the treasury.
type OnSlash = ResolveTo<TreasuryAccountId<Self>, Balances>;
type SlashRewardFraction = SlashRewardFraction;
type RuntimeHoldReason = RuntimeHoldReason;
type CoreStaking = Staking;
}

pub struct InitiateNominationPools;
impl frame_support::traits::OnRuntimeUpgrade for InitiateNominationPools {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
Expand Down Expand Up @@ -1680,6 +1699,9 @@ construct_runtime! {
// Fast unstake pallet: extension to staking.
FastUnstake: pallet_fast_unstake = 40,

// Staking extension for delegation
DelegatedStaking: pallet_delegated_staking = 41,

// Parachains pallets. Start indices at 50 to leave room.
ParachainsOrigin: parachains_origin = 50,
Configuration: parachains_configuration = 51,
Expand Down Expand Up @@ -2036,6 +2058,13 @@ pub mod migrations {
}
}

parameter_types! {
// This is used to limit max pools that migrates in the runtime upgrade. This is set to
// existing_pool_count plus ~15 to also account for any new pools getting created before the
// migration is actually executed.
pub const MaxPoolsToMigrate: u32 = 250;
}

/// Unreleased migrations. Add new ones here:
pub type Unreleased = (
parachains_configuration::migration::v12::MigrateToV12<Runtime>,
Expand All @@ -2058,6 +2087,11 @@ pub mod migrations {
>,
CancelAuctions,
restore_corrupted_ledgers::Migrate<Runtime>,
// Migrate NominationPools to `DelegateStake` adapter.
pallet_nomination_pools::migration::unversioned::DelegationStakeMigration<
Runtime,
MaxPoolsToMigrate,
>,
);

/// Migrations/checks that do not need to be versioned and can run on every update.
Expand Down

0 comments on commit cf05416

Please sign in to comment.