Skip to content

Commit aef83c9

Browse files
committed
[pallet_staking] adapt paritytech/polkadot-sdk#1189
1 parent 41fd521 commit aef83c9

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

relay/kusama/src/lib.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ impl pallet_babe::Config for Runtime {
299299
type WeightInfo = ();
300300

301301
type MaxAuthorities = MaxAuthorities;
302-
type MaxNominators = MaxNominatorRewardedPerValidator;
302+
type MaxNominators = MaxNominators;
303303
}
304304

305305
parameter_types! {
@@ -344,7 +344,7 @@ parameter_types! {
344344
impl pallet_beefy::Config for Runtime {
345345
type BeefyId = BeefyId;
346346
type MaxAuthorities = MaxAuthorities;
347-
type MaxNominators = MaxNominatorRewardedPerValidator;
347+
type MaxNominators = MaxNominators;
348348
type MaxSetIdSessionEntries = BeefySetIdSessionEntries;
349349
type OnNewValidatorSet = BeefyMmrLeaf;
350350
type WeightInfo = ();
@@ -657,7 +657,12 @@ parameter_types! {
657657
27,
658658
"DOT_SLASH_DEFER_DURATION"
659659
);
660-
pub const MaxNominatorRewardedPerValidator: u32 = 512;
660+
// TODO:(PR#137) - check MaxExposurePageSize/MaxNominators 512?
661+
pub const MaxExposurePageSize: u32 = 512;
662+
// Note: this is not really correct as Max Nominators is (MaxExposurePageSize * page_count) but
663+
// this is an unbounded number. We just set it to a reasonably high value, 1 full page
664+
// of nominators.
665+
pub const MaxNominators: u32 = 512;
661666
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17);
662667
// 24
663668
pub const MaxNominations: u32 = <NposCompactSolution24 as NposSolution>::LIMIT as u32;
@@ -681,7 +686,7 @@ impl pallet_staking::Config for Runtime {
681686
type SessionInterface = Self;
682687
type EraPayout = EraPayout;
683688
type NextNewSession = Session;
684-
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
689+
type MaxExposurePageSize = MaxExposurePageSize;
685690
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
686691
type VoterList = VoterList;
687692
type TargetList = UseValidatorsMap<Self>;
@@ -701,8 +706,6 @@ impl pallet_fast_unstake::Config for Runtime {
701706
type ControlOrigin = EnsureRoot<AccountId>;
702707
type Staking = Staking;
703708
type MaxErasToCheckPerBlock = ConstU32<1>;
704-
#[cfg(feature = "runtime-benchmarks")]
705-
type MaxBackersPerValidator = MaxNominatorRewardedPerValidator;
706709
type WeightInfo = weights::pallet_fast_unstake::WeightInfo<Runtime>;
707710
}
708711

@@ -837,7 +840,7 @@ impl pallet_grandpa::Config for Runtime {
837840

838841
type WeightInfo = ();
839842
type MaxAuthorities = MaxAuthorities;
840-
type MaxNominators = MaxNominatorRewardedPerValidator;
843+
type MaxNominators = MaxNominators;
841844
type MaxSetIdSessionEntries = MaxSetIdSessionEntries;
842845

843846
type KeyOwnerProof = <Historical as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;
@@ -1684,6 +1687,7 @@ pub mod migrations {
16841687
pub type Unreleased = (
16851688
pallet_nomination_pools::migration::versioned::V5toV6<Runtime>,
16861689
pallet_nomination_pools::migration::versioned::V6ToV7<Runtime>,
1690+
pallet_staking::migrations::v14::MigrateToV14<Runtime>,
16871691
);
16881692
}
16891693

@@ -2234,10 +2238,14 @@ sp_api::impl_runtime_apis! {
22342238
}
22352239
}
22362240

2237-
impl pallet_staking_runtime_api::StakingApi<Block, Balance> for Runtime {
2241+
impl pallet_staking_runtime_api::StakingApi<Block, Balance, AccountId> for Runtime {
22382242
fn nominations_quota(balance: Balance) -> u32 {
22392243
Staking::api_nominations_quota(balance)
22402244
}
2245+
2246+
fn eras_stakers_page_count(era: sp_staking::EraIndex, account: AccountId) -> sp_staking::Page {
2247+
Staking::api_eras_stakers_page_count(era, account)
2248+
}
22412249
}
22422250

22432251
impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {

relay/kusama/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn payout_weight_portion() {
5959
use pallet_staking::WeightInfo;
6060
let payout_weight =
6161
<Runtime as pallet_staking::Config>::WeightInfo::payout_stakers_alive_staked(
62-
MaxNominatorRewardedPerValidator::get(),
62+
MaxNominators::get(),
6363
)
6464
.ref_time() as f64;
6565
let block_weight = BlockWeights::get().max_block.ref_time() as f64;

relay/polkadot/src/lib.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ impl pallet_babe::Config for Runtime {
279279
type WeightInfo = ();
280280

281281
type MaxAuthorities = MaxAuthorities;
282-
type MaxNominators = MaxNominatorRewardedPerValidator;
282+
type MaxNominators = MaxNominators;
283283

284284
type KeyOwnerProof =
285285
<Historical as KeyOwnerProofSystem<(KeyTypeId, pallet_babe::AuthorityId)>>::Proof;
@@ -330,7 +330,7 @@ parameter_types! {
330330
impl pallet_beefy::Config for Runtime {
331331
type BeefyId = BeefyId;
332332
type MaxAuthorities = MaxAuthorities;
333-
type MaxNominators = MaxNominatorRewardedPerValidator;
333+
type MaxNominators = MaxNominators;
334334
type MaxSetIdSessionEntries = BeefySetIdSessionEntries;
335335
type OnNewValidatorSet = BeefyMmrLeaf;
336336
type WeightInfo = ();
@@ -667,7 +667,12 @@ parameter_types! {
667667
"DOT_SLASH_DEFER_DURATION"
668668
);
669669
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
670-
pub const MaxNominatorRewardedPerValidator: u32 = 512;
670+
// TODO:(PR#137) - check MaxExposurePageSize/MaxNominators 512?
671+
pub const MaxExposurePageSize: u32 = 512;
672+
// Note: this is not really correct as Max Nominators is (MaxExposurePageSize * page_count) but
673+
// this is an unbounded number. We just set it to a reasonably high value, 1 full page
674+
// of nominators.
675+
pub const MaxNominators: u32 = 512;
671676
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17);
672677
// 16
673678
pub const MaxNominations: u32 = <NposCompactSolution16 as frame_election_provider_support::NposSolution>::LIMIT as u32;
@@ -764,7 +769,7 @@ impl pallet_staking::Config for Runtime {
764769
type AdminOrigin = EitherOf<EnsureRoot<Self::AccountId>, StakingAdmin>;
765770
type SessionInterface = Self;
766771
type EraPayout = EraPayout;
767-
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
772+
type MaxExposurePageSize = MaxExposurePageSize;
768773
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
769774
type NextNewSession = Session;
770775
type ElectionProvider = ElectionProviderMultiPhase;
@@ -787,8 +792,6 @@ impl pallet_fast_unstake::Config for Runtime {
787792
type ControlOrigin = EnsureRoot<AccountId>;
788793
type Staking = Staking;
789794
type MaxErasToCheckPerBlock = ConstU32<1>;
790-
#[cfg(feature = "runtime-benchmarks")]
791-
type MaxBackersPerValidator = MaxNominatorRewardedPerValidator;
792795
type WeightInfo = weights::pallet_fast_unstake::WeightInfo<Runtime>;
793796
}
794797

@@ -953,7 +956,7 @@ impl pallet_grandpa::Config for Runtime {
953956

954957
type WeightInfo = ();
955958
type MaxAuthorities = MaxAuthorities;
956-
type MaxNominators = MaxNominatorRewardedPerValidator;
959+
type MaxNominators = MaxNominators;
957960
type MaxSetIdSessionEntries = MaxSetIdSessionEntries;
958961

959962
type KeyOwnerProof = <Historical as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;
@@ -1705,6 +1708,7 @@ pub mod migrations {
17051708
UpgradeSessionKeys,
17061709
pallet_nomination_pools::migration::versioned::V5toV6<Runtime>,
17071710
pallet_nomination_pools::migration::versioned::V6ToV7<Runtime>,
1711+
pallet_staking::migrations::v14::MigrateToV14<Runtime>,
17081712
);
17091713
}
17101714

@@ -1848,10 +1852,14 @@ sp_api::impl_runtime_apis! {
18481852
}
18491853
}
18501854

1851-
impl pallet_staking_runtime_api::StakingApi<Block, Balance> for Runtime {
1855+
impl pallet_staking_runtime_api::StakingApi<Block, Balance, AccountId> for Runtime {
18521856
fn nominations_quota(balance: Balance) -> u32 {
18531857
Staking::api_nominations_quota(balance)
18541858
}
1859+
1860+
fn eras_stakers_page_count(era: sp_staking::EraIndex, account: AccountId) -> sp_staking::Page {
1861+
Staking::api_eras_stakers_page_count(era, account)
1862+
}
18551863
}
18561864

18571865
impl tx_pool_api::runtime_api::TaggedTransactionQueue<Block> for Runtime {
@@ -2449,7 +2457,7 @@ mod test_fees {
24492457
use pallet_staking::WeightInfo;
24502458
let payout_weight =
24512459
<Runtime as pallet_staking::Config>::WeightInfo::payout_stakers_alive_staked(
2452-
MaxNominatorRewardedPerValidator::get(),
2460+
MaxNominators::get(),
24532461
)
24542462
.ref_time() as f64;
24552463
let block_weight = BlockWeights::get().max_block.ref_time() as f64;

0 commit comments

Comments
 (0)