mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-01 03:07:56 +00:00
Bound staking storage items (#12230)
* replace pallet level unboundedness to individual storage items * bound structs * bounding history depth * defensive error * use the era history depth from config * clean up history depth from storage in v11 * keep the name HistoryDepth for the new configuration value * use u32 for history depth in node runtime * improve doc comments * add HistoryDepth to mock runtimes with pallet-staking * rustfmt * refactor and doc improve * apply re-benchmarked weight for staking * pr feedback improvements * test for claimed rewards following the expected bounds * refactor test to calculate first and last reward era programmatically * verify previous eras cannot be claimed * add migration v12 * ".git/.scripts/bench-bot.sh" pallet dev pallet_staking * fix compiler error * corrupting history depth does not lead to catastrophic issue * fix new line * remove unused import * fmt * add test to document scenario where history depth is reduced without migration * fmt * Update frame/staking/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update frame/staking/src/migrations.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * doc for all storage items bounded by HistoryDepth * Update frame/staking/src/pallet/mod.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update frame/staking/src/tests.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * pr feedback fixes * Update frame/staking/src/tests.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * remove extra checks * fix merge * fmt Co-authored-by: command-bot <> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: kianenigma <kian@parity.io>
This commit is contained in:
@@ -299,12 +299,12 @@ pub mod weights;
|
||||
|
||||
mod pallet;
|
||||
|
||||
use codec::{Decode, Encode, HasCompact};
|
||||
use codec::{Decode, Encode, HasCompact, MaxEncodedLen};
|
||||
use frame_support::{
|
||||
parameter_types,
|
||||
traits::{Currency, Defensive, Get},
|
||||
weights::Weight,
|
||||
BoundedVec, EqNoBound, PartialEqNoBound, RuntimeDebugNoBound,
|
||||
BoundedVec, CloneNoBound, EqNoBound, PartialEqNoBound, RuntimeDebugNoBound,
|
||||
};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_runtime::{
|
||||
@@ -354,7 +354,7 @@ parameter_types! {
|
||||
}
|
||||
|
||||
/// Information regarding the active era (era in used in session).
|
||||
#[derive(Encode, Decode, RuntimeDebug, TypeInfo)]
|
||||
#[derive(Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)]
|
||||
pub struct ActiveEraInfo {
|
||||
/// Index of era.
|
||||
pub index: EraIndex,
|
||||
@@ -395,7 +395,7 @@ pub enum StakerStatus<AccountId> {
|
||||
}
|
||||
|
||||
/// A destination account for payment.
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)]
|
||||
pub enum RewardDestination<AccountId> {
|
||||
/// Pay into the stash account, increasing the amount at stake accordingly.
|
||||
Staked,
|
||||
@@ -416,7 +416,7 @@ impl<AccountId> Default for RewardDestination<AccountId> {
|
||||
}
|
||||
|
||||
/// Preference of what happens regarding validation.
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, Default)]
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, Default, MaxEncodedLen)]
|
||||
pub struct ValidatorPrefs {
|
||||
/// Reward that validator takes up-front; only the rest is split between themselves and
|
||||
/// nominators.
|
||||
@@ -429,8 +429,8 @@ pub struct ValidatorPrefs {
|
||||
}
|
||||
|
||||
/// Just a Balance/BlockNumber tuple to encode when a chunk of funds will be unlocked.
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
|
||||
pub struct UnlockChunk<Balance: HasCompact> {
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)]
|
||||
pub struct UnlockChunk<Balance: HasCompact + MaxEncodedLen> {
|
||||
/// Amount of funds to be unlocked.
|
||||
#[codec(compact)]
|
||||
value: Balance,
|
||||
@@ -440,7 +440,16 @@ pub struct UnlockChunk<Balance: HasCompact> {
|
||||
}
|
||||
|
||||
/// The ledger of a (bonded) stash.
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebugNoBound, TypeInfo)]
|
||||
#[derive(
|
||||
PartialEqNoBound,
|
||||
EqNoBound,
|
||||
CloneNoBound,
|
||||
Encode,
|
||||
Decode,
|
||||
RuntimeDebugNoBound,
|
||||
TypeInfo,
|
||||
MaxEncodedLen,
|
||||
)]
|
||||
#[scale_info(skip_type_params(T))]
|
||||
pub struct StakingLedger<T: Config> {
|
||||
/// The stash account whose balance is actually locked and at stake.
|
||||
@@ -459,7 +468,7 @@ pub struct StakingLedger<T: Config> {
|
||||
pub unlocking: BoundedVec<UnlockChunk<BalanceOf<T>>, MaxUnlockingChunks>,
|
||||
/// List of eras for which the stakers behind a validator have claimed rewards. Only updated
|
||||
/// for validators.
|
||||
pub claimed_rewards: Vec<EraIndex>,
|
||||
pub claimed_rewards: BoundedVec<EraIndex, T::HistoryDepth>,
|
||||
}
|
||||
|
||||
impl<T: Config> StakingLedger<T> {
|
||||
@@ -470,7 +479,7 @@ impl<T: Config> StakingLedger<T> {
|
||||
total: Zero::zero(),
|
||||
active: Zero::zero(),
|
||||
unlocking: Default::default(),
|
||||
claimed_rewards: vec![],
|
||||
claimed_rewards: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -676,7 +685,9 @@ impl<T: Config> StakingLedger<T> {
|
||||
}
|
||||
|
||||
/// A record of the nominations made by a specific account.
|
||||
#[derive(PartialEqNoBound, EqNoBound, Clone, Encode, Decode, RuntimeDebugNoBound, TypeInfo)]
|
||||
#[derive(
|
||||
PartialEqNoBound, EqNoBound, Clone, Encode, Decode, RuntimeDebugNoBound, TypeInfo, MaxEncodedLen,
|
||||
)]
|
||||
#[codec(mel_bound())]
|
||||
#[scale_info(skip_type_params(T))]
|
||||
pub struct Nominations<T: Config> {
|
||||
@@ -850,7 +861,7 @@ impl<Balance: AtLeast32BitUnsigned + Clone, T: Get<&'static PiecewiseLinear<'sta
|
||||
}
|
||||
|
||||
/// Mode of era-forcing.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)]
|
||||
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum Forcing {
|
||||
/// Not forcing anything - just let whatever happen.
|
||||
@@ -874,7 +885,7 @@ impl Default for Forcing {
|
||||
// A value placed in storage that represents the current version of the Staking storage. This value
|
||||
// is used by the `on_runtime_upgrade` logic to determine whether we run storage migration logic.
|
||||
// This should match directly with the semantic versions of the Rust crate.
|
||||
#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, RuntimeDebug, TypeInfo)]
|
||||
#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
|
||||
enum Releases {
|
||||
V1_0_0Ancient,
|
||||
V2_0_0,
|
||||
@@ -887,6 +898,7 @@ enum Releases {
|
||||
V9_0_0, // inject validators into `VoterList` as well.
|
||||
V10_0_0, // remove `EarliestUnappliedSlash`.
|
||||
V11_0_0, // Move pallet storage prefix, e.g. BagsList -> VoterBagsList
|
||||
V12_0_0, // remove `HistoryDepth`.
|
||||
}
|
||||
|
||||
impl Default for Releases {
|
||||
|
||||
Reference in New Issue
Block a user