Skip to content

Commit 63c61a4

Browse files
committed
[pallet_staking] adapt paritytech/polkadot-sdk#1189
1 parent 0b27e9d commit 63c61a4

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
@@ -297,7 +297,7 @@ impl pallet_babe::Config for Runtime {
297297
type WeightInfo = ();
298298

299299
type MaxAuthorities = MaxAuthorities;
300-
type MaxNominators = MaxNominatorRewardedPerValidator;
300+
type MaxNominators = MaxNominators;
301301
}
302302

303303
parameter_types! {
@@ -342,7 +342,7 @@ parameter_types! {
342342
impl pallet_beefy::Config for Runtime {
343343
type BeefyId = BeefyId;
344344
type MaxAuthorities = MaxAuthorities;
345-
type MaxNominators = MaxNominatorRewardedPerValidator;
345+
type MaxNominators = MaxNominators;
346346
type MaxSetIdSessionEntries = BeefySetIdSessionEntries;
347347
type OnNewValidatorSet = BeefyMmrLeaf;
348348
type WeightInfo = ();
@@ -655,7 +655,12 @@ parameter_types! {
655655
27,
656656
"DOT_SLASH_DEFER_DURATION"
657657
);
658-
pub const MaxNominatorRewardedPerValidator: u32 = 512;
658+
// TODO:(PR#137) - check MaxExposurePageSize/MaxNominators 512?
659+
pub const MaxExposurePageSize: u32 = 512;
660+
// Note: this is not really correct as Max Nominators is (MaxExposurePageSize * page_count) but
661+
// this is an unbounded number. We just set it to a reasonably high value, 1 full page
662+
// of nominators.
663+
pub const MaxNominators: u32 = 512;
659664
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17);
660665
// 24
661666
pub const MaxNominations: u32 = <NposCompactSolution24 as NposSolution>::LIMIT as u32;
@@ -679,7 +684,7 @@ impl pallet_staking::Config for Runtime {
679684
type SessionInterface = Self;
680685
type EraPayout = EraPayout;
681686
type NextNewSession = Session;
682-
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
687+
type MaxExposurePageSize = MaxExposurePageSize;
683688
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
684689
type VoterList = VoterList;
685690
type TargetList = UseValidatorsMap<Self>;
@@ -699,8 +704,6 @@ impl pallet_fast_unstake::Config for Runtime {
699704
type ControlOrigin = EnsureRoot<AccountId>;
700705
type Staking = Staking;
701706
type MaxErasToCheckPerBlock = ConstU32<1>;
702-
#[cfg(feature = "runtime-benchmarks")]
703-
type MaxBackersPerValidator = MaxNominatorRewardedPerValidator;
704707
type WeightInfo = weights::pallet_fast_unstake::WeightInfo<Runtime>;
705708
}
706709

@@ -835,7 +838,7 @@ impl pallet_grandpa::Config for Runtime {
835838

836839
type WeightInfo = ();
837840
type MaxAuthorities = MaxAuthorities;
838-
type MaxNominators = MaxNominatorRewardedPerValidator;
841+
type MaxNominators = MaxNominators;
839842
type MaxSetIdSessionEntries = MaxSetIdSessionEntries;
840843

841844
type KeyOwnerProof = <Historical as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;
@@ -1682,6 +1685,7 @@ pub mod migrations {
16821685
pub type Unreleased = (
16831686
pallet_nomination_pools::migration::versioned::V5toV6<Runtime>,
16841687
pallet_nomination_pools::migration::versioned::V6ToV7<Runtime>,
1688+
pallet_staking::migrations::v14::MigrateToV14<Runtime>,
16851689
);
16861690
}
16871691

@@ -2228,10 +2232,14 @@ sp_api::impl_runtime_apis! {
22282232
}
22292233
}
22302234

2231-
impl pallet_staking_runtime_api::StakingApi<Block, Balance> for Runtime {
2235+
impl pallet_staking_runtime_api::StakingApi<Block, Balance, AccountId> for Runtime {
22322236
fn nominations_quota(balance: Balance) -> u32 {
22332237
Staking::api_nominations_quota(balance)
22342238
}
2239+
2240+
fn eras_stakers_page_count(era: sp_staking::EraIndex, account: AccountId) -> sp_staking::Page {
2241+
Staking::api_eras_stakers_page_count(era, account)
2242+
}
22352243
}
22362244

22372245
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)