Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NPoS] Paging reward payouts in order to scale rewardable nominators #1189

Merged
merged 23 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

20 changes: 12 additions & 8 deletions polkadot/runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl pallet_babe::Config for Runtime {
type WeightInfo = ();

type MaxAuthorities = MaxAuthorities;
type MaxNominators = MaxNominatorRewardedPerValidator;
type MaxNominators = MaxExposurePageSize;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a pretty bad name? I belive what pallet_babe wants to convey here is MaxNominatorsPerValidator?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, indeed, the correct value for this should be something like max_pages * page_size, but I trust that this will come in a follow-up.

Copy link
Contributor Author

@Ank4n Ank4n Sep 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its terrible but its just more apparent now :(. MaxNominatorRewardedPerValidator was also wrong and exactly same thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add a comment about this in the code. Not sure what else I can do in the scope of current PR.

}

parameter_types! {
Expand Down Expand Up @@ -322,7 +322,7 @@ parameter_types! {
impl pallet_beefy::Config for Runtime {
type BeefyId = BeefyId;
type MaxAuthorities = MaxAuthorities;
type MaxNominators = MaxNominatorRewardedPerValidator;
type MaxNominators = MaxExposurePageSize;
type MaxSetIdSessionEntries = BeefySetIdSessionEntries;
type OnNewValidatorSet = BeefyMmrLeaf;
type WeightInfo = ();
Expand Down Expand Up @@ -670,7 +670,8 @@ parameter_types! {
27,
"DOT_SLASH_DEFER_DURATION"
);
pub const MaxNominatorRewardedPerValidator: u32 = 512;
pub const MaxExposurePageSize: u32 = 512;

pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17);
// 24
pub const MaxNominations: u32 = <NposCompactSolution24 as NposSolution>::LIMIT as u32;
Expand All @@ -694,7 +695,7 @@ impl pallet_staking::Config for Runtime {
type SessionInterface = Self;
type EraPayout = EraPayout;
type NextNewSession = Session;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type MaxExposurePageSize = MaxExposurePageSize;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type VoterList = VoterList;
type TargetList = UseValidatorsMap<Self>;
Expand All @@ -714,8 +715,6 @@ impl pallet_fast_unstake::Config for Runtime {
type ControlOrigin = EnsureRoot<AccountId>;
type Staking = Staking;
type MaxErasToCheckPerBlock = ConstU32<1>;
#[cfg(feature = "runtime-benchmarks")]
type MaxBackersPerValidator = MaxNominatorRewardedPerValidator;
type WeightInfo = weights::pallet_fast_unstake::WeightInfo<Runtime>;
}

Expand Down Expand Up @@ -829,7 +828,7 @@ impl pallet_grandpa::Config for Runtime {

type WeightInfo = ();
type MaxAuthorities = MaxAuthorities;
type MaxNominators = MaxNominatorRewardedPerValidator;
type MaxNominators = MaxExposurePageSize;
type MaxSetIdSessionEntries = MaxSetIdSessionEntries;

type KeyOwnerProof = <Historical as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;
Expand Down Expand Up @@ -1719,6 +1718,7 @@ pub mod migrations {
>,
pallet_im_online::migration::v1::Migration<Runtime>,
parachains_configuration::migration::v7::MigrateToV7<Runtime>,
pallet_staking::migrations::v14::MigrateToV14<Runtime>,
parachains_scheduler::migration::v1::MigrateToV1<Runtime>,
parachains_configuration::migration::v8::MigrateToV8<Runtime>,

Expand Down Expand Up @@ -2272,10 +2272,14 @@ sp_api::impl_runtime_apis! {
}
}

impl pallet_staking_runtime_api::StakingApi<Block, Balance> for Runtime {
impl pallet_staking_runtime_api::StakingApi<Block, Balance, AccountId> for Runtime {
fn nominations_quota(balance: Balance) -> u32 {
Staking::api_nominations_quota(balance)
}

fn eras_stakers_page_count(era: sp_staking::EraIndex, account: AccountId) -> sp_staking::PageIndex {
Staking::api_eras_stakers_page_count(era, account)
}
}

#[cfg(feature = "try-runtime")]
Expand Down
2 changes: 1 addition & 1 deletion polkadot/runtime/kusama/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn payout_weight_portion() {
use pallet_staking::WeightInfo;
let payout_weight =
<Runtime as pallet_staking::Config>::WeightInfo::payout_stakers_alive_staked(
MaxNominatorRewardedPerValidator::get(),
MaxExposurePageSize::get().into(),
)
.ref_time() as f64;
let block_weight = BlockWeights::get().max_block.ref_time() as f64;
Expand Down
19 changes: 11 additions & 8 deletions polkadot/runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ impl pallet_babe::Config for Runtime {
type WeightInfo = ();

type MaxAuthorities = MaxAuthorities;
type MaxNominators = MaxNominatorRewardedPerValidator;
type MaxNominators = MaxExposurePageSize;

type KeyOwnerProof =
<Historical as KeyOwnerProofSystem<(KeyTypeId, pallet_babe::AuthorityId)>>::Proof;
Expand Down Expand Up @@ -530,7 +530,7 @@ parameter_types! {
"DOT_SLASH_DEFER_DURATION"
);
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const MaxNominatorRewardedPerValidator: u32 = 512;
pub const MaxExposurePageSize: u32 = 512;
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17);
// 16
pub const MaxNominations: u32 = <NposCompactSolution16 as frame_election_provider_support::NposSolution>::LIMIT as u32;
Expand Down Expand Up @@ -579,7 +579,7 @@ impl pallet_staking::Config for Runtime {
type AdminOrigin = EitherOf<EnsureRoot<Self::AccountId>, StakingAdmin>;
type SessionInterface = Self;
type EraPayout = EraPayout;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type MaxExposurePageSize = MaxExposurePageSize;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type NextNewSession = Session;
type ElectionProvider = ElectionProviderMultiPhase;
Expand All @@ -602,8 +602,6 @@ impl pallet_fast_unstake::Config for Runtime {
type ControlOrigin = EnsureRoot<AccountId>;
type Staking = Staking;
type MaxErasToCheckPerBlock = ConstU32<1>;
#[cfg(feature = "runtime-benchmarks")]
type MaxBackersPerValidator = MaxNominatorRewardedPerValidator;
type WeightInfo = weights::pallet_fast_unstake::WeightInfo<Runtime>;
}

Expand Down Expand Up @@ -746,7 +744,7 @@ impl pallet_grandpa::Config for Runtime {

type WeightInfo = ();
type MaxAuthorities = MaxAuthorities;
type MaxNominators = MaxNominatorRewardedPerValidator;
type MaxNominators = MaxExposurePageSize;
type MaxSetIdSessionEntries = MaxSetIdSessionEntries;

type KeyOwnerProof = <Historical as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;
Expand Down Expand Up @@ -1506,6 +1504,7 @@ pub mod migrations {
pub type Unreleased = (
pallet_im_online::migration::v1::Migration<Runtime>,
parachains_configuration::migration::v7::MigrateToV7<Runtime>,
pallet_staking::migrations::v14::MigrateToV14<Runtime>,
parachains_scheduler::migration::v1::MigrateToV1<Runtime>,
parachains_configuration::migration::v8::MigrateToV8<Runtime>,

Expand Down Expand Up @@ -1666,10 +1665,14 @@ sp_api::impl_runtime_apis! {
}
}

impl pallet_staking_runtime_api::StakingApi<Block, Balance> for Runtime {
impl pallet_staking_runtime_api::StakingApi<Block, Balance, AccountId> for Runtime {
fn nominations_quota(balance: Balance) -> u32 {
Staking::api_nominations_quota(balance)
}

fn eras_stakers_page_count(era: sp_staking::EraIndex, account: AccountId) -> sp_staking::PageIndex {
Staking::api_eras_stakers_page_count(era, account)
}
}

impl tx_pool_api::runtime_api::TaggedTransactionQueue<Block> for Runtime {
Expand Down Expand Up @@ -2209,7 +2212,7 @@ mod test_fees {
use pallet_staking::WeightInfo;
let payout_weight =
<Runtime as pallet_staking::Config>::WeightInfo::payout_stakers_alive_staked(
MaxNominatorRewardedPerValidator::get(),
MaxExposurePageSize::get().into(),
)
.ref_time() as f64;
let block_weight = BlockWeights::get().max_block.ref_time() as f64;
Expand Down
8 changes: 4 additions & 4 deletions polkadot/runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl pallet_babe::Config for Runtime {
type WeightInfo = ();

type MaxAuthorities = MaxAuthorities;
type MaxNominators = MaxNominatorRewardedPerValidator;
type MaxNominators = MaxExposurePageSize;

type KeyOwnerProof =
<Historical as KeyOwnerProofSystem<(KeyTypeId, pallet_babe::AuthorityId)>>::Proof;
Expand Down Expand Up @@ -315,7 +315,7 @@ parameter_types! {
// 27 eras in which slashes can be cancelled (a bit less than 7 days).
pub storage SlashDeferDuration: sp_staking::EraIndex = 27;
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub storage MaxNominatorRewardedPerValidator: u32 = 64;
pub const MaxExposurePageSize: u32 = 64;
pub storage OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17);
pub const MaxAuthorities: u32 = 100_000;
pub const OnChainMaxWinners: u32 = u32::MAX;
Expand Down Expand Up @@ -351,7 +351,7 @@ impl pallet_staking::Config for Runtime {
type AdminOrigin = frame_system::EnsureNever<()>;
type SessionInterface = Self;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type MaxExposurePageSize = MaxExposurePageSize;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type NextNewSession = Session;
type ElectionProvider = onchain::OnChainExecution<OnChainSeqPhragmen>;
Expand All @@ -377,7 +377,7 @@ impl pallet_grandpa::Config for Runtime {

type WeightInfo = ();
type MaxAuthorities = MaxAuthorities;
type MaxNominators = MaxNominatorRewardedPerValidator;
type MaxNominators = MaxExposurePageSize;
type MaxSetIdSessionEntries = MaxSetIdSessionEntries;

type KeyOwnerProof = sp_core::Void;
Expand Down
19 changes: 11 additions & 8 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl pallet_babe::Config for Runtime {
type WeightInfo = ();

type MaxAuthorities = MaxAuthorities;
type MaxNominators = MaxNominatorRewardedPerValidator;
type MaxNominators = MaxExposurePageSize;

type KeyOwnerProof =
<Historical as KeyOwnerProofSystem<(KeyTypeId, pallet_babe::AuthorityId)>>::Proof;
Expand Down Expand Up @@ -279,7 +279,7 @@ parameter_types! {
impl pallet_beefy::Config for Runtime {
type BeefyId = BeefyId;
type MaxAuthorities = MaxAuthorities;
type MaxNominators = MaxNominatorRewardedPerValidator;
type MaxNominators = MaxExposurePageSize;
type MaxSetIdSessionEntries = BeefySetIdSessionEntries;
type OnNewValidatorSet = BeefyMmrLeaf;
type WeightInfo = ();
Expand Down Expand Up @@ -616,7 +616,7 @@ parameter_types! {
// 1 era in which slashes can be cancelled (6 hours).
pub const SlashDeferDuration: sp_staking::EraIndex = 1;
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const MaxNominatorRewardedPerValidator: u32 = 64;
pub const MaxExposurePageSize: u32 = 64;
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17);
pub const MaxNominations: u32 = <NposCompactSolution16 as frame_election_provider_support::NposSolution>::LIMIT as u32;
}
Expand All @@ -636,7 +636,7 @@ impl pallet_staking::Config for Runtime {
type AdminOrigin = EnsureRoot<AccountId>;
type SessionInterface = Self;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type MaxExposurePageSize = MaxExposurePageSize;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type NextNewSession = Session;
type ElectionProvider = ElectionProviderMultiPhase;
Expand All @@ -659,8 +659,6 @@ impl pallet_fast_unstake::Config for Runtime {
type ControlOrigin = EnsureRoot<AccountId>;
type Staking = Staking;
type MaxErasToCheckPerBlock = ConstU32<1>;
#[cfg(feature = "runtime-benchmarks")]
type MaxBackersPerValidator = MaxNominatorRewardedPerValidator;
type WeightInfo = weights::pallet_fast_unstake::WeightInfo<Runtime>;
}

Expand Down Expand Up @@ -706,7 +704,7 @@ impl pallet_grandpa::Config for Runtime {

type WeightInfo = ();
type MaxAuthorities = MaxAuthorities;
type MaxNominators = MaxNominatorRewardedPerValidator;
type MaxNominators = MaxExposurePageSize;
type MaxSetIdSessionEntries = MaxSetIdSessionEntries;

type KeyOwnerProof = <Historical as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;
Expand Down Expand Up @@ -1420,6 +1418,7 @@ pub mod migrations {
pub type Unreleased = (
pallet_im_online::migration::v1::Migration<Runtime>,
parachains_configuration::migration::v7::MigrateToV7<Runtime>,
pallet_staking::migrations::v14::MigrateToV14<Runtime>,
assigned_slots::migration::v1::VersionCheckedMigrateToV1<Runtime>,
parachains_scheduler::migration::v1::MigrateToV1<Runtime>,
parachains_configuration::migration::v8::MigrateToV8<Runtime>,
Expand Down Expand Up @@ -1952,10 +1951,14 @@ sp_api::impl_runtime_apis! {
}
}

impl pallet_staking_runtime_api::StakingApi<Block, Balance> for Runtime {
impl pallet_staking_runtime_api::StakingApi<Block, Balance, AccountId> for Runtime {
fn nominations_quota(balance: Balance) -> u32 {
Staking::api_nominations_quota(balance)
}

fn eras_stakers_page_count(era: sp_staking::EraIndex, account: AccountId) -> sp_staking::PageIndex {
Staking::api_eras_stakers_page_count(era, account)
}
}

#[cfg(feature = "try-runtime")]
Expand Down
16 changes: 9 additions & 7 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ impl pallet_babe::Config for Runtime {
type DisabledValidators = Session;
type WeightInfo = ();
type MaxAuthorities = MaxAuthorities;
type MaxNominators = MaxNominatorRewardedPerValidator;
type MaxNominators = MaxExposurePageSize;
type KeyOwnerProof =
<Historical as KeyOwnerProofSystem<(KeyTypeId, pallet_babe::AuthorityId)>>::Proof;
type EquivocationReportSystem =
Expand Down Expand Up @@ -619,7 +619,7 @@ parameter_types! {
pub const BondingDuration: sp_staking::EraIndex = 24 * 28;
pub const SlashDeferDuration: sp_staking::EraIndex = 24 * 7; // 1/4 the bonding duration.
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const MaxNominatorRewardedPerValidator: u32 = 256;
pub const MaxExposurePageSize: u32 = 256;
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17);
pub OffchainRepeat: BlockNumber = 5;
pub HistoryDepth: u32 = 84;
Expand Down Expand Up @@ -654,7 +654,7 @@ impl pallet_staking::Config for Runtime {
type SessionInterface = Self;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type NextNewSession = Session;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type MaxExposurePageSize = ConstU32<256>;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type ElectionProvider = ElectionProviderMultiPhase;
type GenesisElectionProvider = onchain::OnChainExecution<OnChainSeqPhragmen>;
Expand All @@ -677,8 +677,6 @@ impl pallet_fast_unstake::Config for Runtime {
type Currency = Balances;
type Staking = Staking;
type MaxErasToCheckPerBlock = ConstU32<1>;
#[cfg(feature = "runtime-benchmarks")]
type MaxBackersPerValidator = MaxNominatorRewardedPerValidator;
type WeightInfo = ();
}

Expand Down Expand Up @@ -1429,7 +1427,7 @@ impl pallet_grandpa::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type MaxAuthorities = MaxAuthorities;
type MaxNominators = MaxNominatorRewardedPerValidator;
type MaxNominators = MaxExposurePageSize;
type MaxSetIdSessionEntries = MaxSetIdSessionEntries;
type KeyOwnerProof = <Historical as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;
type EquivocationReportSystem =
Expand Down Expand Up @@ -2342,10 +2340,14 @@ impl_runtime_apis! {
}
}

impl pallet_staking_runtime_api::StakingApi<Block, Balance> for Runtime {
impl pallet_staking_runtime_api::StakingApi<Block, Balance, AccountId> for Runtime {
fn nominations_quota(balance: Balance) -> u32 {
Staking::api_nominations_quota(balance)
}

fn eras_stakers_page_count(era: sp_staking::EraIndex, account: AccountId) -> sp_staking::PageIndex {
Staking::api_eras_stakers_page_count(era, account)
}
}

impl sp_consensus_babe::BabeApi<Block> for Runtime {
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl pallet_staking::Config for Test {
type SessionInterface = Self;
type UnixTime = pallet_timestamp::Pallet<Test>;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type MaxNominatorRewardedPerValidator = ConstU32<64>;
type MaxExposurePageSize = ConstU32<64>;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type NextNewSession = Session;
type ElectionProvider = onchain::OnChainExecution<OnChainSeqPhragmen>;
Expand Down
8 changes: 4 additions & 4 deletions substrate/frame/babe/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ fn report_equivocation_current_session_works() {
assert_eq!(Staking::slashable_balance_of(validator), 10_000);

assert_eq!(
Staking::eras_stakers(1, validator),
Staking::eras_stakers(1, &validator),
pallet_staking::Exposure { total: 10_000, own: 10_000, others: vec![] },
);
}
Expand Down Expand Up @@ -481,7 +481,7 @@ fn report_equivocation_current_session_works() {
assert_eq!(Balances::total_balance(&offending_validator_id), 10_000_000 - 10_000);
assert_eq!(Staking::slashable_balance_of(&offending_validator_id), 0);
assert_eq!(
Staking::eras_stakers(2, offending_validator_id),
Staking::eras_stakers(2, &offending_validator_id),
pallet_staking::Exposure { total: 0, own: 0, others: vec![] },
);

Expand All @@ -494,7 +494,7 @@ fn report_equivocation_current_session_works() {
assert_eq!(Balances::total_balance(validator), 10_000_000);
assert_eq!(Staking::slashable_balance_of(validator), 10_000);
assert_eq!(
Staking::eras_stakers(2, validator),
Staking::eras_stakers(2, &validator),
pallet_staking::Exposure { total: 10_000, own: 10_000, others: vec![] },
);
}
Expand Down Expand Up @@ -553,7 +553,7 @@ fn report_equivocation_old_session_works() {
assert_eq!(Balances::total_balance(&offending_validator_id), 10_000_000 - 10_000);
assert_eq!(Staking::slashable_balance_of(&offending_validator_id), 0);
assert_eq!(
Staking::eras_stakers(3, offending_validator_id),
Staking::eras_stakers(3, &offending_validator_id),
pallet_staking::Exposure { total: 0, own: 0, others: vec![] },
);
})
Expand Down