Rename pallet trait Trait to Config (#7599)

* rename Trait to Config

* add test asserting using Trait is still valid.

* fix ui tests
This commit is contained in:
Guillaume Thiolliere
2020-11-30 15:34:54 +01:00
committed by GitHub
parent dd3c84c362
commit 1cbfc9257f
200 changed files with 1767 additions and 1607 deletions
+4 -4
View File
@@ -31,7 +31,7 @@ const MAX_SLASHES: u32 = 1000;
// Add slashing spans to a user account. Not relevant for actual use, only to benchmark
// read and write operations.
fn add_slashing_spans<T: Trait>(who: &T::AccountId, spans: u32) {
fn add_slashing_spans<T: Config>(who: &T::AccountId, spans: u32) {
if spans == 0 { return }
// For the first slashing span, we initialize
@@ -48,7 +48,7 @@ fn add_slashing_spans<T: Trait>(who: &T::AccountId, spans: u32) {
// This function clears all existing validators and nominators from the set, and generates one new
// validator being nominated by n nominators, and returns the validator stash account and the
// nominators' stash and controller. It also starts an era and creates pending payouts.
pub fn create_validator_with_nominators<T: Trait>(
pub fn create_validator_with_nominators<T: Config>(
n: u32,
upper_bound: u32,
dead: bool,
@@ -729,7 +729,7 @@ mod tests {
let (validator_stash, nominators) = create_validator_with_nominators::<Test>(
n,
<Test as Trait>::MaxNominatorRewardedPerValidator::get() as u32,
<Test as Config>::MaxNominatorRewardedPerValidator::get() as u32,
false,
RewardDestination::Staked,
).unwrap();
@@ -753,7 +753,7 @@ mod tests {
let (validator_stash, _nominators) = create_validator_with_nominators::<Test>(
n,
<Test as Trait>::MaxNominatorRewardedPerValidator::get() as u32,
<Test as Config>::MaxNominatorRewardedPerValidator::get() as u32,
false,
RewardDestination::Staked,
).unwrap();
+43 -43
View File
@@ -19,7 +19,7 @@
//!
//! The Staking module is used to manage funds at stake by network maintainers.
//!
//! - [`staking::Trait`](./trait.Trait.html)
//! - [`staking::Config`](./trait.Config.html)
//! - [`Call`](./enum.Call.html)
//! - [`Module`](./struct.Module.html)
//!
@@ -107,7 +107,7 @@
//!
//! Rewards must be claimed for each era before it gets too old by `$HISTORY_DEPTH` using the
//! `payout_stakers` call. Any account can call `payout_stakers`, which pays the reward to the
//! validator as well as its nominators. Only the [`Trait::MaxNominatorRewardedPerValidator`]
//! validator as well as its nominators. Only the [`Config::MaxNominatorRewardedPerValidator`]
//! biggest stakers can claim their reward. This is to limit the i/o cost to mutate storage for each
//! nominator's account.
//!
@@ -154,10 +154,10 @@
//! use frame_system::ensure_signed;
//! use pallet_staking::{self as staking};
//!
//! pub trait Trait: staking::Trait {}
//! pub trait Config: staking::Config {}
//!
//! decl_module! {
//! pub struct Module<T: Trait> for enum Call where origin: T::Origin {
//! pub struct Module<T: Config> for enum Call where origin: T::Origin {
//! /// Reward a validator.
//! #[weight = 0]
//! pub fn reward_myself(origin) -> dispatch::DispatchResult {
@@ -175,7 +175,7 @@
//! ### Era payout
//!
//! The era payout is computed using yearly inflation curve defined at
//! [`T::RewardCurve`](./trait.Trait.html#associatedtype.RewardCurve) as such:
//! [`T::RewardCurve`](./trait.Config.html#associatedtype.RewardCurve) as such:
//!
//! ```nocompile
//! staker_payout = yearly_inflation(npos_token_staked / total_tokens) * total_tokens / era_per_year
@@ -186,7 +186,7 @@
//! remaining_payout = max_yearly_inflation * total_tokens / era_per_year - staker_payout
//! ```
//! The remaining reward is send to the configurable end-point
//! [`T::RewardRemainder`](./trait.Trait.html#associatedtype.RewardRemainder).
//! [`T::RewardRemainder`](./trait.Config.html#associatedtype.RewardRemainder).
//!
//! ### Reward Calculation
//!
@@ -232,7 +232,7 @@
//!
//! The controller account can free a portion (or all) of the funds using the
//! [`unbond`](enum.Call.html#variant.unbond) call. Note that the funds are not immediately
//! accessible. Instead, a duration denoted by [`BondingDuration`](./trait.Trait.html#associatedtype.BondingDuration)
//! accessible. Instead, a duration denoted by [`BondingDuration`](./trait.Config.html#associatedtype.BondingDuration)
//! (in number of eras) must pass until the funds can actually be removed. Once the
//! `BondingDuration` is over, the [`withdraw_unbonded`](./enum.Call.html#variant.withdraw_unbonded)
//! call can be used to actually withdraw the funds.
@@ -385,12 +385,12 @@ pub type OffchainAccuracy = PerU16;
/// The balance type of this module.
pub type BalanceOf<T> =
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
type PositiveImbalanceOf<T> =
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::PositiveImbalance;
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::PositiveImbalance;
type NegativeImbalanceOf<T> =
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::NegativeImbalance;
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
/// Information regarding the active era (era in used in session).
#[derive(Encode, Decode, RuntimeDebug)]
@@ -732,8 +732,8 @@ impl<BlockNumber> Default for ElectionStatus<BlockNumber> {
/// Means for interacting with a specialized version of the `session` trait.
///
/// This is needed because `Staking` sets the `ValidatorIdOf` of the `pallet_session::Trait`
pub trait SessionInterface<AccountId>: frame_system::Trait {
/// This is needed because `Staking` sets the `ValidatorIdOf` of the `pallet_session::Config`
pub trait SessionInterface<AccountId>: frame_system::Config {
/// Disable a given validator by stash ID.
///
/// Returns `true` if new era should be forced at the end of this session.
@@ -746,22 +746,22 @@ pub trait SessionInterface<AccountId>: frame_system::Trait {
fn prune_historical_up_to(up_to: SessionIndex);
}
impl<T: Trait> SessionInterface<<T as frame_system::Trait>::AccountId> for T where
T: pallet_session::Trait<ValidatorId = <T as frame_system::Trait>::AccountId>,
T: pallet_session::historical::Trait<
FullIdentification = Exposure<<T as frame_system::Trait>::AccountId, BalanceOf<T>>,
impl<T: Config> SessionInterface<<T as frame_system::Config>::AccountId> for T where
T: pallet_session::Config<ValidatorId = <T as frame_system::Config>::AccountId>,
T: pallet_session::historical::Config<
FullIdentification = Exposure<<T as frame_system::Config>::AccountId, BalanceOf<T>>,
FullIdentificationOf = ExposureOf<T>,
>,
T::SessionHandler: pallet_session::SessionHandler<<T as frame_system::Trait>::AccountId>,
T::SessionManager: pallet_session::SessionManager<<T as frame_system::Trait>::AccountId>,
T::SessionHandler: pallet_session::SessionHandler<<T as frame_system::Config>::AccountId>,
T::SessionManager: pallet_session::SessionManager<<T as frame_system::Config>::AccountId>,
T::ValidatorIdOf:
Convert<<T as frame_system::Trait>::AccountId, Option<<T as frame_system::Trait>::AccountId>>,
Convert<<T as frame_system::Config>::AccountId, Option<<T as frame_system::Config>::AccountId>>,
{
fn disable_validator(validator: &<T as frame_system::Trait>::AccountId) -> Result<bool, ()> {
fn disable_validator(validator: &<T as frame_system::Config>::AccountId) -> Result<bool, ()> {
<pallet_session::Module<T>>::disable(validator)
}
fn validators() -> Vec<<T as frame_system::Trait>::AccountId> {
fn validators() -> Vec<<T as frame_system::Config>::AccountId> {
<pallet_session::Module<T>>::validators()
}
@@ -770,7 +770,7 @@ impl<T: Trait> SessionInterface<<T as frame_system::Trait>::AccountId> for T whe
}
}
pub trait Trait: frame_system::Trait + SendTransactionTypes<Call<Self>> {
pub trait Config: frame_system::Config + SendTransactionTypes<Call<Self>> {
/// The staking balance.
type Currency: LockableCurrency<Self::AccountId, Moment=Self::BlockNumber>;
@@ -792,7 +792,7 @@ pub trait Trait: frame_system::Trait + SendTransactionTypes<Call<Self>> {
type RewardRemainder: OnUnbalanced<NegativeImbalanceOf<Self>>;
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
/// Handler for the unbalanced reduction when slashing a staker.
type Slash: OnUnbalanced<NegativeImbalanceOf<Self>>;
@@ -904,7 +904,7 @@ impl Default for Releases {
}
decl_storage! {
trait Store for Module<T: Trait> as Staking {
trait Store for Module<T: Config> as Staking {
/// Number of eras to keep in history.
///
/// Information is kept for eras in `[current_era - history_depth; current_era]`.
@@ -1121,7 +1121,7 @@ decl_storage! {
}
decl_event!(
pub enum Event<T> where Balance = BalanceOf<T>, <T as frame_system::Trait>::AccountId {
pub enum Event<T> where Balance = BalanceOf<T>, <T as frame_system::Config>::AccountId {
/// The era payout has been set; the first balance is the validator-payout; the second is
/// the remainder from the maximum amount of reward.
/// \[era_index, validator_payout, remainder\]
@@ -1153,7 +1153,7 @@ decl_event!(
decl_error! {
/// Error for the staking module.
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// Not a controller account.
NotController,
/// Not a stash account.
@@ -1223,7 +1223,7 @@ decl_error! {
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
/// Number of sessions per era.
const SessionsPerEra: SessionIndex = T::SessionsPerEra::get();
@@ -2159,7 +2159,7 @@ decl_module! {
}
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
/// The total balance that can be slashed from a stash account as of right now.
pub fn slashable_balance_of(stash: &T::AccountId) -> BalanceOf<T> {
// Weight note: consider making the stake accessible through stash.
@@ -3083,7 +3083,7 @@ impl<T: Trait> Module<T> {
///
/// Once the first new_session is planned, all session must start and then end in order, though
/// some session can lag in between the newest session planned and the latest session started.
impl<T: Trait> pallet_session::SessionManager<T::AccountId> for Module<T> {
impl<T: Config> pallet_session::SessionManager<T::AccountId> for Module<T> {
fn new_session(new_index: SessionIndex) -> Option<Vec<T::AccountId>> {
Self::new_session(new_index)
}
@@ -3095,7 +3095,7 @@ impl<T: Trait> pallet_session::SessionManager<T::AccountId> for Module<T> {
}
}
impl<T: Trait> historical::SessionManager<T::AccountId, Exposure<T::AccountId, BalanceOf<T>>> for Module<T> {
impl<T: Config> historical::SessionManager<T::AccountId, Exposure<T::AccountId, BalanceOf<T>>> for Module<T> {
fn new_session(new_index: SessionIndex)
-> Option<Vec<(T::AccountId, Exposure<T::AccountId, BalanceOf<T>>)>>
{
@@ -3124,7 +3124,7 @@ impl<T: Trait> historical::SessionManager<T::AccountId, Exposure<T::AccountId, B
/// * 1 point to the producer of each referenced uncle block.
impl<T> pallet_authorship::EventHandler<T::AccountId, T::BlockNumber> for Module<T>
where
T: Trait + pallet_authorship::Trait + pallet_session::Trait
T: Config + pallet_authorship::Config + pallet_session::Config
{
fn note_author(author: T::AccountId) {
Self::reward_by_ids(vec![(author, 20)])
@@ -3141,7 +3141,7 @@ impl<T> pallet_authorship::EventHandler<T::AccountId, T::BlockNumber> for Module
/// if any.
pub struct StashOf<T>(sp_std::marker::PhantomData<T>);
impl<T: Trait> Convert<T::AccountId, Option<T::AccountId>> for StashOf<T> {
impl<T: Config> Convert<T::AccountId, Option<T::AccountId>> for StashOf<T> {
fn convert(controller: T::AccountId) -> Option<T::AccountId> {
<Module<T>>::ledger(&controller).map(|l| l.stash)
}
@@ -3154,7 +3154,7 @@ impl<T: Trait> Convert<T::AccountId, Option<T::AccountId>> for StashOf<T> {
/// `active_era`. It can differ from the latest planned exposure in `current_era`.
pub struct ExposureOf<T>(sp_std::marker::PhantomData<T>);
impl<T: Trait> Convert<T::AccountId, Option<Exposure<T::AccountId, BalanceOf<T>>>>
impl<T: Config> Convert<T::AccountId, Option<Exposure<T::AccountId, BalanceOf<T>>>>
for ExposureOf<T>
{
fn convert(validator: T::AccountId) -> Option<Exposure<T::AccountId, BalanceOf<T>>> {
@@ -3167,19 +3167,19 @@ impl<T: Trait> Convert<T::AccountId, Option<Exposure<T::AccountId, BalanceOf<T>>
}
/// This is intended to be used with `FilterHistoricalOffences`.
impl <T: Trait>
impl <T: Config>
OnOffenceHandler<T::AccountId, pallet_session::historical::IdentificationTuple<T>, Weight>
for Module<T> where
T: pallet_session::Trait<ValidatorId = <T as frame_system::Trait>::AccountId>,
T: pallet_session::historical::Trait<
FullIdentification = Exposure<<T as frame_system::Trait>::AccountId, BalanceOf<T>>,
T: pallet_session::Config<ValidatorId = <T as frame_system::Config>::AccountId>,
T: pallet_session::historical::Config<
FullIdentification = Exposure<<T as frame_system::Config>::AccountId, BalanceOf<T>>,
FullIdentificationOf = ExposureOf<T>,
>,
T::SessionHandler: pallet_session::SessionHandler<<T as frame_system::Trait>::AccountId>,
T::SessionManager: pallet_session::SessionManager<<T as frame_system::Trait>::AccountId>,
T::SessionHandler: pallet_session::SessionHandler<<T as frame_system::Config>::AccountId>,
T::SessionManager: pallet_session::SessionManager<<T as frame_system::Config>::AccountId>,
T::ValidatorIdOf: Convert<
<T as frame_system::Trait>::AccountId,
Option<<T as frame_system::Trait>::AccountId>,
<T as frame_system::Config>::AccountId,
Option<<T as frame_system::Config>::AccountId>,
>,
{
fn on_offence(
@@ -3310,7 +3310,7 @@ pub struct FilterHistoricalOffences<T, R> {
impl<T, Reporter, Offender, R, O> ReportOffence<Reporter, Offender, O>
for FilterHistoricalOffences<Module<T>, R> where
T: Trait,
T: Config,
R: ReportOffence<Reporter, Offender, O>,
O: Offence<Offender>,
{
@@ -3335,7 +3335,7 @@ impl<T, Reporter, Offender, R, O> ReportOffence<Reporter, Offender, O>
}
#[allow(deprecated)]
impl<T: Trait> frame_support::unsigned::ValidateUnsigned for Module<T> {
impl<T: Config> frame_support::unsigned::ValidateUnsigned for Module<T> {
type Call = Call<T>;
fn validate_unsigned(source: TransactionSource, call: &Self::Call) -> TransactionValidity {
if let Call::submit_election_solution_unsigned(
+9 -9
View File
@@ -141,7 +141,7 @@ parameter_types! {
pub static MaxIterations: u32 = 0;
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = AccountIndex;
@@ -168,7 +168,7 @@ impl frame_system::Trait for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
}
impl pallet_balances::Trait for Test {
impl pallet_balances::Config for Test {
type MaxLocks = MaxLocks;
type Balance = Balance;
type Event = MetaEvent;
@@ -187,7 +187,7 @@ sp_runtime::impl_opaque_keys! {
pub other: OtherSessionHandler,
}
}
impl pallet_session::Trait for Test {
impl pallet_session::Config for Test {
type SessionManager = pallet_session::historical::NoteHistoricalRoot<Test, Staking>;
type Keys = SessionKeys;
type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
@@ -200,11 +200,11 @@ impl pallet_session::Trait for Test {
type WeightInfo = ();
}
impl pallet_session::historical::Trait for Test {
impl pallet_session::historical::Config for Test {
type FullIdentification = crate::Exposure<AccountId, Balance>;
type FullIdentificationOf = crate::ExposureOf<Test>;
}
impl pallet_authorship::Trait for Test {
impl pallet_authorship::Config for Test {
type FindAuthor = Author11;
type UncleGenerations = UncleGenerations;
type FilterUncle = ();
@@ -213,7 +213,7 @@ impl pallet_authorship::Trait for Test {
parameter_types! {
pub const MinimumPeriod: u64 = 5;
}
impl pallet_timestamp::Trait for Test {
impl pallet_timestamp::Config for Test {
type Moment = u64;
type OnTimestampSet = ();
type MinimumPeriod = MinimumPeriod;
@@ -253,7 +253,7 @@ impl OnUnbalanced<NegativeImbalanceOf<Test>> for RewardRemainderMock {
}
}
impl Trait for Test {
impl Config for Test {
type Currency = Balances;
type UnixTime = Timestamp;
type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote;
@@ -659,7 +659,7 @@ pub(crate) fn start_era(era_index: EraIndex) {
pub(crate) fn current_total_payout_for_duration(duration: u64) -> Balance {
inflation::compute_total_payout(
<Test as Trait>::RewardCurve::get(),
<Test as Config>::RewardCurve::get(),
Staking::eras_total_stake(Staking::active_era().unwrap().index),
Balances::total_issuance(),
duration,
@@ -667,7 +667,7 @@ pub(crate) fn current_total_payout_for_duration(duration: u64) -> Balance {
}
pub(crate) fn reward_all_elected() {
let rewards = <Test as Trait>::SessionInterface::validators()
let rewards = <Test as Config>::SessionInterface::validators()
.into_iter()
.map(|v| (v, 1));
@@ -19,7 +19,7 @@
use crate::{
Call, CompactAssignments, ElectionSize, Module, NominatorIndex, Nominators, OffchainAccuracy,
Trait, ValidatorIndex, WeightInfo,
Config, ValidatorIndex, WeightInfo,
};
use codec::Decode;
use frame_support::{traits::Get, weights::Weight, IterableStorageMap};
@@ -71,7 +71,7 @@ pub(crate) const DEFAULT_LONGEVITY: u64 = 25;
/// don't run twice within a window of length [`OFFCHAIN_REPEAT`].
///
/// Returns `Ok(())` if offchain worker should happen, `Err(reason)` otherwise.
pub(crate) fn set_check_offchain_execution_status<T: Trait>(
pub(crate) fn set_check_offchain_execution_status<T: Config>(
now: T::BlockNumber,
) -> Result<(), &'static str> {
let storage = StorageValueRef::persistent(&OFFCHAIN_HEAD_DB);
@@ -108,7 +108,7 @@ pub(crate) fn set_check_offchain_execution_status<T: Trait>(
/// The internal logic of the offchain worker of this module. This runs the phragmen election,
/// compacts and reduces the solution, computes the score and submits it back to the chain as an
/// unsigned transaction, without any signature.
pub(crate) fn compute_offchain_election<T: Trait>() -> Result<(), OffchainElectionError> {
pub(crate) fn compute_offchain_election<T: Config>() -> Result<(), OffchainElectionError> {
let iters = get_balancing_iters::<T>();
// compute raw solution. Note that we use `OffchainAccuracy`.
let ElectionResult {
@@ -151,7 +151,7 @@ pub(crate) fn compute_offchain_election<T: Trait>() -> Result<(), OffchainElecti
/// Get a random number of iterations to run the balancing.
///
/// Uses the offchain seed to generate a random number.
pub fn get_balancing_iters<T: Trait>() -> usize {
pub fn get_balancing_iters<T: Config>() -> usize {
match T::MaxIterations::get() {
0 => 0,
max @ _ => {
@@ -257,7 +257,7 @@ pub fn maximum_compact_len<W: crate::WeightInfo>(
///
/// Indeed, the score must be computed **after** this step. If this step reduces the score too much,
/// then the solution will be discarded.
pub fn trim_to_weight<T: Trait, FN>(
pub fn trim_to_weight<T: Config, FN>(
maximum_allowed_voters: u32,
mut compact: CompactAssignments,
nominator_index: FN,
@@ -318,7 +318,7 @@ where
/// Takes an election result and spits out some data that can be submitted to the chain.
///
/// This does a lot of stuff; read the inline comments.
pub fn prepare_submission<T: Trait>(
pub fn prepare_submission<T: Config>(
assignments: Vec<Assignment<T::AccountId, OffchainAccuracy>>,
winners: Vec<(T::AccountId, ExtendedBalance)>,
do_reduce: bool,
+14 -14
View File
@@ -50,7 +50,7 @@
//! Based on research at https://research.web3.foundation/en/latest/polkadot/slashing/npos/
use super::{
EraIndex, Trait, Module, Store, BalanceOf, Exposure, Perbill, SessionInterface,
EraIndex, Config, Module, Store, BalanceOf, Exposure, Perbill, SessionInterface,
NegativeImbalanceOf, UnappliedSlash, Error,
};
use sp_runtime::{traits::{Zero, Saturating}, RuntimeDebug, DispatchResult};
@@ -190,7 +190,7 @@ impl<Balance> SpanRecord<Balance> {
/// Parameters for performing a slash.
#[derive(Clone)]
pub(crate) struct SlashParams<'a, T: 'a + Trait> {
pub(crate) struct SlashParams<'a, T: 'a + Config> {
/// The stash account being slashed.
pub(crate) stash: &'a T::AccountId,
/// The proportion of the slash.
@@ -214,7 +214,7 @@ pub(crate) struct SlashParams<'a, T: 'a + Trait> {
///
/// The pending slash record returned does not have initialized reporters. Those have
/// to be set at a higher level, if any.
pub(crate) fn compute_slash<T: Trait>(params: SlashParams<T>)
pub(crate) fn compute_slash<T: Config>(params: SlashParams<T>)
-> Option<UnappliedSlash<T::AccountId, BalanceOf<T>>>
{
let SlashParams {
@@ -309,7 +309,7 @@ pub(crate) fn compute_slash<T: Trait>(params: SlashParams<T>)
// doesn't apply any slash, but kicks out the validator if the misbehavior is from
// the most recent slashing span.
fn kick_out_if_recent<T: Trait>(
fn kick_out_if_recent<T: Config>(
params: SlashParams<T>,
) {
// these are not updated by era-span or end-span.
@@ -338,7 +338,7 @@ fn kick_out_if_recent<T: Trait>(
/// Slash nominators. Accepts general parameters and the prior slash percentage of the validator.
///
/// Returns the amount of reward to pay out.
fn slash_nominators<T: Trait>(
fn slash_nominators<T: Config>(
params: SlashParams<T>,
prior_slash_p: Perbill,
nominators_slashed: &mut Vec<(T::AccountId, BalanceOf<T>)>,
@@ -418,7 +418,7 @@ fn slash_nominators<T: Trait>(
// dropping this struct applies any necessary slashes, which can lead to free balance
// being 0, and the account being garbage-collected -- a dead account should get no new
// metadata.
struct InspectingSpans<'a, T: Trait + 'a> {
struct InspectingSpans<'a, T: Config + 'a> {
dirty: bool,
window_start: EraIndex,
stash: &'a T::AccountId,
@@ -430,7 +430,7 @@ struct InspectingSpans<'a, T: Trait + 'a> {
}
// fetches the slashing spans record for a stash account, initializing it if necessary.
fn fetch_spans<'a, T: Trait + 'a>(
fn fetch_spans<'a, T: Config + 'a>(
stash: &'a T::AccountId,
window_start: EraIndex,
paid_out: &'a mut BalanceOf<T>,
@@ -455,7 +455,7 @@ fn fetch_spans<'a, T: Trait + 'a>(
}
}
impl<'a, T: 'a + Trait> InspectingSpans<'a, T> {
impl<'a, T: 'a + Config> InspectingSpans<'a, T> {
fn span_index(&self) -> SpanIndex {
self.spans.span_index
}
@@ -526,7 +526,7 @@ impl<'a, T: 'a + Trait> InspectingSpans<'a, T> {
}
}
impl<'a, T: 'a + Trait> Drop for InspectingSpans<'a, T> {
impl<'a, T: 'a + Config> Drop for InspectingSpans<'a, T> {
fn drop(&mut self) {
// only update on disk if we slashed this account.
if !self.dirty { return }
@@ -542,13 +542,13 @@ impl<'a, T: 'a + Trait> Drop for InspectingSpans<'a, T> {
}
/// Clear slashing metadata for an obsolete era.
pub(crate) fn clear_era_metadata<T: Trait>(obsolete_era: EraIndex) {
pub(crate) fn clear_era_metadata<T: Config>(obsolete_era: EraIndex) {
<Module<T> as Store>::ValidatorSlashInEra::remove_prefix(&obsolete_era);
<Module<T> as Store>::NominatorSlashInEra::remove_prefix(&obsolete_era);
}
/// Clear slashing metadata for a dead account.
pub(crate) fn clear_stash_metadata<T: Trait>(
pub(crate) fn clear_stash_metadata<T: Config>(
stash: &T::AccountId,
num_slashing_spans: u32,
) -> DispatchResult {
@@ -576,7 +576,7 @@ pub(crate) fn clear_stash_metadata<T: Trait>(
// apply the slash to a stash account, deducting any missing funds from the reward
// payout, saturating at 0. this is mildly unfair but also an edge-case that
// can only occur when overlapping locked funds have been slashed.
pub fn do_slash<T: Trait>(
pub fn do_slash<T: Config>(
stash: &T::AccountId,
value: BalanceOf<T>,
reward_payout: &mut BalanceOf<T>,
@@ -613,7 +613,7 @@ pub fn do_slash<T: Trait>(
}
/// Apply a previously-unapplied slash.
pub(crate) fn apply_slash<T: Trait>(unapplied_slash: UnappliedSlash<T::AccountId, BalanceOf<T>>) {
pub(crate) fn apply_slash<T: Config>(unapplied_slash: UnappliedSlash<T::AccountId, BalanceOf<T>>) {
let mut slashed_imbalance = NegativeImbalanceOf::<T>::zero();
let mut reward_payout = unapplied_slash.payout;
@@ -638,7 +638,7 @@ pub(crate) fn apply_slash<T: Trait>(unapplied_slash: UnappliedSlash<T::AccountId
/// Apply a reward payout to some reporters, paying the rewards out of the slashed imbalance.
fn pay_reporters<T: Trait>(
fn pay_reporters<T: Config>(
reward_payout: BalanceOf<T>,
slashed_imbalance: NegativeImbalanceOf<T>,
reporters: &[T::AccountId],
+11 -11
View File
@@ -29,13 +29,13 @@ use sp_npos_elections::*;
const SEED: u32 = 0;
/// This function removes all validators and nominators from storage.
pub fn clear_validators_and_nominators<T: Trait>() {
pub fn clear_validators_and_nominators<T: Config>() {
Validators::<T>::remove_all();
Nominators::<T>::remove_all();
}
/// Grab a funded user.
pub fn create_funded_user<T: Trait>(
pub fn create_funded_user<T: Config>(
string: &'static str,
n: u32,
balance_factor: u32,
@@ -49,7 +49,7 @@ pub fn create_funded_user<T: Trait>(
}
/// Create a stash and controller pair.
pub fn create_stash_controller<T: Trait>(
pub fn create_stash_controller<T: Config>(
n: u32,
balance_factor: u32,
destination: RewardDestination<T::AccountId>,
@@ -66,7 +66,7 @@ pub fn create_stash_controller<T: Trait>(
/// Create a stash and controller pair, where the controller is dead, and payouts go to controller.
/// This is used to test worst case payout scenarios.
pub fn create_stash_and_dead_controller<T: Trait>(
pub fn create_stash_and_dead_controller<T: Config>(
n: u32,
balance_factor: u32,
destination: RewardDestination<T::AccountId>,
@@ -83,7 +83,7 @@ pub fn create_stash_and_dead_controller<T: Trait>(
}
/// create `max` validators.
pub fn create_validators<T: Trait>(
pub fn create_validators<T: Config>(
max: u32,
balance_factor: u32,
) -> Result<Vec<<T::Lookup as StaticLookup>::Source>, &'static str> {
@@ -115,7 +115,7 @@ pub fn create_validators<T: Trait>(
/// Else, all of them are considered and `edge_per_nominator` random validators are voted for.
///
/// Return the validators choosen to be nominated.
pub fn create_validators_with_nominators_for_era<T: Trait>(
pub fn create_validators_with_nominators_for_era<T: Config>(
validators: u32,
nominators: u32,
edge_per_nominator: usize,
@@ -173,7 +173,7 @@ pub fn create_validators_with_nominators_for_era<T: Trait>(
/// Build a _really bad_ but acceptable solution for election. This should always yield a solution
/// which has a less score than the seq-phragmen.
pub fn get_weak_solution<T: Trait>(
pub fn get_weak_solution<T: Config>(
do_reduce: bool,
) -> (Vec<ValidatorIndex>, CompactAssignments, ElectionScore, ElectionSize) {
let mut backing_stake_of: BTreeMap<T::AccountId, BalanceOf<T>> = BTreeMap::new();
@@ -282,7 +282,7 @@ pub fn get_weak_solution<T: Trait>(
/// Create a solution for seq-phragmen. This uses the same internal function as used by the offchain
/// worker code.
pub fn get_seq_phragmen_solution<T: Trait>(
pub fn get_seq_phragmen_solution<T: Config>(
do_reduce: bool,
) -> (
Vec<ValidatorIndex>,
@@ -307,7 +307,7 @@ pub fn get_seq_phragmen_solution<T: Trait>(
}
/// Returns a solution in which only one winner is elected with just a self vote.
pub fn get_single_winner_solution<T: Trait>(
pub fn get_single_winner_solution<T: Config>(
winner: T::AccountId,
) -> Result<
(
@@ -352,7 +352,7 @@ pub fn get_single_winner_solution<T: Trait>(
}
/// get the active era.
pub fn current_era<T: Trait>() -> EraIndex {
pub fn current_era<T: Config>() -> EraIndex {
<Module<T>>::current_era().unwrap_or(0)
}
@@ -366,7 +366,7 @@ pub fn init_active_era() {
/// Create random assignments for the given list of winners. Each assignment will have
/// MAX_NOMINATIONS edges.
pub fn create_assignments_for_offchain<T: Trait>(
pub fn create_assignments_for_offchain<T: Config>(
num_assignments: u32,
winners: Vec<<T::Lookup as StaticLookup>::Source>,
) -> Result<
+15 -15
View File
@@ -3267,7 +3267,7 @@ mod offchain_election {
ElectionSize::default(),
),
Error::<Test>::OffchainElectionEarlySubmission,
Some(<Test as frame_system::Trait>::DbWeight::get().reads(1)),
Some(<Test as frame_system::Config>::DbWeight::get().reads(1)),
);
})
}
@@ -3303,7 +3303,7 @@ mod offchain_election {
score,
),
Error::<Test>::OffchainElectionWeakSubmission,
Some(<Test as frame_system::Trait>::DbWeight::get().reads(3))
Some(<Test as frame_system::Config>::DbWeight::get().reads(3))
);
})
}
@@ -4340,7 +4340,7 @@ fn test_max_nominator_rewarded_per_validator_and_cant_steal_someone_else_reward(
// then the nominator can't claim its reward
// * A nominator can't claim another nominator reward
ExtBuilder::default().build_and_execute(|| {
for i in 0..=<Test as Trait>::MaxNominatorRewardedPerValidator::get() {
for i in 0..=<Test as Config>::MaxNominatorRewardedPerValidator::get() {
let stash = 10_000 + i as AccountId;
let controller = 20_000 + i as AccountId;
let balance = 10_000 + i as Balance;
@@ -4366,7 +4366,7 @@ fn test_max_nominator_rewarded_per_validator_and_cant_steal_someone_else_reward(
mock::make_all_reward_payment(1);
// Assert only nominators from 1 to Max are rewarded
for i in 0..=<Test as Trait>::MaxNominatorRewardedPerValidator::get() {
for i in 0..=<Test as Config>::MaxNominatorRewardedPerValidator::get() {
let stash = 10_000 + i as AccountId;
let balance = 10_000 + i as Balance;
if stash == 10_000 {
@@ -4569,14 +4569,14 @@ fn bond_during_era_correctly_populates_claimed_rewards() {
fn offences_weight_calculated_correctly() {
ExtBuilder::default().nominate(true).build_and_execute(|| {
// On offence with zero offenders: 4 Reads, 1 Write
let zero_offence_weight = <Test as frame_system::Trait>::DbWeight::get().reads_writes(4, 1);
let zero_offence_weight = <Test as frame_system::Config>::DbWeight::get().reads_writes(4, 1);
assert_eq!(Staking::on_offence(&[], &[Perbill::from_percent(50)], 0), Ok(zero_offence_weight));
// On Offence with N offenders, Unapplied: 4 Reads, 1 Write + 4 Reads, 5 Writes
let n_offence_unapplied_weight = <Test as frame_system::Trait>::DbWeight::get().reads_writes(4, 1)
+ <Test as frame_system::Trait>::DbWeight::get().reads_writes(4, 5);
let n_offence_unapplied_weight = <Test as frame_system::Config>::DbWeight::get().reads_writes(4, 1)
+ <Test as frame_system::Config>::DbWeight::get().reads_writes(4, 5);
let offenders: Vec<OffenceDetails<<Test as frame_system::Trait>::AccountId, pallet_session::historical::IdentificationTuple<Test>>>
let offenders: Vec<OffenceDetails<<Test as frame_system::Config>::AccountId, pallet_session::historical::IdentificationTuple<Test>>>
= (1..10).map(|i|
OffenceDetails {
offender: (i, Staking::eras_stakers(Staking::active_era().unwrap().index, i)),
@@ -4595,14 +4595,14 @@ fn offences_weight_calculated_correctly() {
let n = 1; // Number of offenders
let rw = 3 + 3 * n; // rw reads and writes
let one_offence_unapplied_weight = <Test as frame_system::Trait>::DbWeight::get().reads_writes(4, 1)
+ <Test as frame_system::Trait>::DbWeight::get().reads_writes(rw, rw)
let one_offence_unapplied_weight = <Test as frame_system::Config>::DbWeight::get().reads_writes(4, 1)
+ <Test as frame_system::Config>::DbWeight::get().reads_writes(rw, rw)
// One `slash_cost`
+ <Test as frame_system::Trait>::DbWeight::get().reads_writes(6, 5)
+ <Test as frame_system::Config>::DbWeight::get().reads_writes(6, 5)
// `slash_cost` * nominators (1)
+ <Test as frame_system::Trait>::DbWeight::get().reads_writes(6, 5)
+ <Test as frame_system::Config>::DbWeight::get().reads_writes(6, 5)
// `reward_cost` * reporters (1)
+ <Test as frame_system::Trait>::DbWeight::get().reads_writes(2, 2);
+ <Test as frame_system::Config>::DbWeight::get().reads_writes(2, 2);
assert_eq!(Staking::on_offence(&one_offender, &[Perbill::from_percent(50)], 0), Ok(one_offence_unapplied_weight));
});
@@ -4614,7 +4614,7 @@ fn on_initialize_weight_is_correct() {
assert_eq!(Validators::<Test>::iter().count(), 0);
assert_eq!(Nominators::<Test>::iter().count(), 0);
// When this pallet has nothing, we do 4 reads each block
let base_weight = <Test as frame_system::Trait>::DbWeight::get().reads(4);
let base_weight = <Test as frame_system::Config>::DbWeight::get().reads(4);
assert_eq!(base_weight, Staking::on_initialize(0));
});
@@ -4636,7 +4636,7 @@ fn on_initialize_weight_is_correct() {
// With 4 validators and 5 nominator, we should increase weight by:
// - (4 + 5) reads
// - 3 Writes
let final_weight = <Test as frame_system::Trait>::DbWeight::get().reads_writes(4 + 9, 3);
let final_weight = <Test as frame_system::Config>::DbWeight::get().reads_writes(4 + 9, 3);
assert_eq!(final_weight, Staking::on_initialize(System::block_number()));
});
}
+1 -1
View File
@@ -72,7 +72,7 @@ pub trait WeightInfo {
/// Weights for pallet_staking using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Trait> WeightInfo for SubstrateWeight<T> {
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn bond() -> Weight {
(99_659_000 as Weight)
.saturating_add(T::DbWeight::get().reads(5 as Weight))