From ea5938333c03ecb123b60bda35d49f864bf20957 Mon Sep 17 00:00:00 2001 From: giuseppere Date: Mon, 2 Dec 2024 19:07:02 +0100 Subject: [PATCH] Use `MaxValidatorsCount` to bound `ErasRewardPoints` `BoundedVec` --- substrate/frame/staking/src/benchmarking.rs | 10 ++-------- substrate/frame/staking/src/lib.rs | 10 ++++++---- substrate/frame/staking/src/migrations.rs | 2 +- substrate/frame/staking/src/mock.rs | 4 ++-- substrate/frame/staking/src/pallet/mod.rs | 4 ++-- substrate/frame/staking/src/tests.rs | 2 -- 6 files changed, 13 insertions(+), 19 deletions(-) diff --git a/substrate/frame/staking/src/benchmarking.rs b/substrate/frame/staking/src/benchmarking.rs index 100ae5965a72..509037f16740 100644 --- a/substrate/frame/staking/src/benchmarking.rs +++ b/substrate/frame/staking/src/benchmarking.rs @@ -130,10 +130,7 @@ pub fn create_validator_with_nominators( assert_ok!(reward_map.try_insert(validator, reward)); } // Give Era Points - let reward = EraRewardPoints::< - T::AccountId, - ::MaxWinners, - > { + let reward = EraRewardPoints:: { total: points_total, individual: reward_map, }; @@ -880,10 +877,7 @@ mod benchmarks { assert_ok!(reward_map.try_insert(validator, reward)); } // Give Era Points - let reward = EraRewardPoints::< - T::AccountId, - ::MaxWinners, - > { + let reward = EraRewardPoints:: { total: points_total, individual: reward_map, }; diff --git a/substrate/frame/staking/src/lib.rs b/substrate/frame/staking/src/lib.rs index 33f269eea93a..4fb494d6b079 100644 --- a/substrate/frame/staking/src/lib.rs +++ b/substrate/frame/staking/src/lib.rs @@ -386,15 +386,17 @@ pub struct ActiveEraInfo { /// /// This points will be used to reward validators and their respective nominators. #[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] -#[scale_info(skip_type_params(MaxWinners))] -pub struct EraRewardPoints> { +#[scale_info(skip_type_params(MaxValidatorsCount))] +pub struct EraRewardPoints> { /// Total number of points. Equals the sum of reward points for each validator. pub total: RewardPoint, /// The reward points earned by a given validator. - pub individual: BoundedBTreeMap, + pub individual: BoundedBTreeMap, } -impl> Default for EraRewardPoints { +impl> Default + for EraRewardPoints +{ fn default() -> Self { EraRewardPoints { total: Default::default(), individual: BoundedBTreeMap::new() } } diff --git a/substrate/frame/staking/src/migrations.rs b/substrate/frame/staking/src/migrations.rs index 76cd46a91167..7f999a22233e 100644 --- a/substrate/frame/staking/src/migrations.rs +++ b/substrate/frame/staking/src/migrations.rs @@ -111,7 +111,7 @@ pub mod v17 { Ok(individual_rewards) => { let bounded_era_rewards = EraRewardPoints::< ::AccountId, - <::ElectionProvider as ElectionProviderBase>::MaxWinners, + ::MaxValidatorsCount, > { individual: individual_rewards, total: era_rewards.total, diff --git a/substrate/frame/staking/src/mock.rs b/substrate/frame/staking/src/mock.rs index 4cdf60204295..eacc316c0227 100644 --- a/substrate/frame/staking/src/mock.rs +++ b/substrate/frame/staking/src/mock.rs @@ -342,7 +342,7 @@ impl Default for ExtBuilder { validator_count: 2, minimum_validator_count: 0, balance_factor: 1, - invulnerables: vec![], + invulnerables: BoundedVec::new(), has_stakers: true, initialize_first_session: true, min_nominator_bond: ExistentialDeposit::get(), @@ -376,7 +376,7 @@ impl ExtBuilder { self } pub fn invulnerables(mut self, invulnerables: Vec) -> Self { - self.invulnerables = invulnerables; + self.invulnerables = BoundedVec::force_from(invulnerables).unwrap(); self } pub fn session_per_era(self, length: SessionIndex) -> Self { diff --git a/substrate/frame/staking/src/pallet/mod.rs b/substrate/frame/staking/src/pallet/mod.rs index a09b07018a73..6a0257544fe4 100644 --- a/substrate/frame/staking/src/pallet/mod.rs +++ b/substrate/frame/staking/src/pallet/mod.rs @@ -582,7 +582,7 @@ pub mod pallet { _, Twox64Concat, EraIndex, - EraRewardPoints::MaxWinners>, + EraRewardPoints, ValueQuery, >; @@ -1050,7 +1050,7 @@ pub mod pallet { /// Get the rewards for the last [`Config::HistoryDepth`] eras. pub fn eras_reward_points( era_index: EncodeLikeEraIndex, - ) -> EraRewardPoints::MaxWinners> + ) -> EraRewardPoints where EncodeLikeEraIndex: codec::EncodeLike, { diff --git a/substrate/frame/staking/src/tests.rs b/substrate/frame/staking/src/tests.rs index 8f9cb2917294..61a80460f493 100644 --- a/substrate/frame/staking/src/tests.rs +++ b/substrate/frame/staking/src/tests.rs @@ -72,7 +72,6 @@ fn set_staking_configs_works() { ConfigOp::Noop, ConfigOp::Noop, ConfigOp::Noop, - ConfigOp::Noop, ConfigOp::Noop ))); @@ -84,7 +83,6 @@ fn set_staking_configs_works() { ConfigOp::Remove, ConfigOp::Remove, ConfigOp::Remove, - ConfigOp::Remove, ConfigOp::Remove )); assert_eq!(MinNominatorBond::::get(), 0);