Skip to content

Commit 2bbffe6

Browse files
authored
Rename pallet trait Trait to Config (#7599)
* rename Trait to Config * add test asserting using Trait is still valid. * fix ui tests
1 parent da05bc8 commit 2bbffe6

File tree

9 files changed

+110
-110
lines changed

9 files changed

+110
-110
lines changed

fuzzer/src/mock.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl_outer_dispatch! {
4343
#[derive(Clone, Eq, PartialEq, Debug)]
4444
pub struct Test;
4545

46-
impl frame_system::Trait for Test {
46+
impl frame_system::Config for Test {
4747
type BaseCallFilter = ();
4848
type Origin = Origin;
4949
type DbWeight = ();
@@ -73,7 +73,7 @@ impl frame_system::Trait for Test {
7373
parameter_types! {
7474
pub const ExistentialDeposit: Balance = 10;
7575
}
76-
impl pallet_balances::Trait for Test {
76+
impl pallet_balances::Config for Test {
7777
type MaxLocks = ();
7878
type Balance = Balance;
7979
type Event = ();
@@ -82,7 +82,7 @@ impl pallet_balances::Trait for Test {
8282
type AccountStore = System;
8383
type WeightInfo = ();
8484
}
85-
impl pallet_indices::Trait for Test {
85+
impl pallet_indices::Config for Test {
8686
type AccountIndex = AccountIndex;
8787
type Event = ();
8888
type Currency = Balances;
@@ -92,13 +92,13 @@ impl pallet_indices::Trait for Test {
9292
parameter_types! {
9393
pub const MinimumPeriod: u64 = 5;
9494
}
95-
impl pallet_timestamp::Trait for Test {
95+
impl pallet_timestamp::Config for Test {
9696
type Moment = u64;
9797
type OnTimestampSet = ();
9898
type MinimumPeriod = MinimumPeriod;
9999
type WeightInfo = ();
100100
}
101-
impl pallet_session::historical::Trait for Test {
101+
impl pallet_session::historical::Config for Test {
102102
type FullIdentification = pallet_staking::Exposure<AccountId, Balance>;
103103
type FullIdentificationOf = pallet_staking::ExposureOf<Test>;
104104
}
@@ -124,7 +124,7 @@ impl pallet_session::SessionHandler<AccountId> for TestSessionHandler {
124124
fn on_disabled(_: usize) {}
125125
}
126126

127-
impl pallet_session::Trait for Test {
127+
impl pallet_session::Config for Test {
128128
type SessionManager = pallet_session::historical::NoteHistoricalRoot<Test, Staking>;
129129
type Keys = SessionKeys;
130130
type ShouldEndSession = pallet_session::PeriodicSessions<(), ()>;
@@ -161,7 +161,7 @@ impl<C> frame_system::offchain::SendTransactionTypes<C> for Test where
161161
type Extrinsic = Extrinsic;
162162
}
163163

164-
impl pallet_staking::Trait for Test {
164+
impl pallet_staking::Config for Test {
165165
type Currency = Balances;
166166
type UnixTime = pallet_timestamp::Module<Self>;
167167
type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote;

src/benchmarking.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const MAX_SLASHES: u32 = 1000;
3131

3232
// Add slashing spans to a user account. Not relevant for actual use, only to benchmark
3333
// read and write operations.
34-
fn add_slashing_spans<T: Trait>(who: &T::AccountId, spans: u32) {
34+
fn add_slashing_spans<T: Config>(who: &T::AccountId, spans: u32) {
3535
if spans == 0 { return }
3636

3737
// For the first slashing span, we initialize
@@ -48,7 +48,7 @@ fn add_slashing_spans<T: Trait>(who: &T::AccountId, spans: u32) {
4848
// This function clears all existing validators and nominators from the set, and generates one new
4949
// validator being nominated by n nominators, and returns the validator stash account and the
5050
// nominators' stash and controller. It also starts an era and creates pending payouts.
51-
pub fn create_validator_with_nominators<T: Trait>(
51+
pub fn create_validator_with_nominators<T: Config>(
5252
n: u32,
5353
upper_bound: u32,
5454
dead: bool,
@@ -729,7 +729,7 @@ mod tests {
729729

730730
let (validator_stash, nominators) = create_validator_with_nominators::<Test>(
731731
n,
732-
<Test as Trait>::MaxNominatorRewardedPerValidator::get() as u32,
732+
<Test as Config>::MaxNominatorRewardedPerValidator::get() as u32,
733733
false,
734734
RewardDestination::Staked,
735735
).unwrap();
@@ -753,7 +753,7 @@ mod tests {
753753

754754
let (validator_stash, _nominators) = create_validator_with_nominators::<Test>(
755755
n,
756-
<Test as Trait>::MaxNominatorRewardedPerValidator::get() as u32,
756+
<Test as Config>::MaxNominatorRewardedPerValidator::get() as u32,
757757
false,
758758
RewardDestination::Staked,
759759
).unwrap();

src/lib.rs

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//!
2020
//! The Staking module is used to manage funds at stake by network maintainers.
2121
//!
22-
//! - [`staking::Trait`](./trait.Trait.html)
22+
//! - [`staking::Config`](./trait.Config.html)
2323
//! - [`Call`](./enum.Call.html)
2424
//! - [`Module`](./struct.Module.html)
2525
//!
@@ -107,7 +107,7 @@
107107
//!
108108
//! Rewards must be claimed for each era before it gets too old by `$HISTORY_DEPTH` using the
109109
//! `payout_stakers` call. Any account can call `payout_stakers`, which pays the reward to the
110-
//! validator as well as its nominators. Only the [`Trait::MaxNominatorRewardedPerValidator`]
110+
//! validator as well as its nominators. Only the [`Config::MaxNominatorRewardedPerValidator`]
111111
//! biggest stakers can claim their reward. This is to limit the i/o cost to mutate storage for each
112112
//! nominator's account.
113113
//!
@@ -154,10 +154,10 @@
154154
//! use frame_system::ensure_signed;
155155
//! use pallet_staking::{self as staking};
156156
//!
157-
//! pub trait Trait: staking::Trait {}
157+
//! pub trait Config: staking::Config {}
158158
//!
159159
//! decl_module! {
160-
//! pub struct Module<T: Trait> for enum Call where origin: T::Origin {
160+
//! pub struct Module<T: Config> for enum Call where origin: T::Origin {
161161
//! /// Reward a validator.
162162
//! #[weight = 0]
163163
//! pub fn reward_myself(origin) -> dispatch::DispatchResult {
@@ -175,7 +175,7 @@
175175
//! ### Era payout
176176
//!
177177
//! The era payout is computed using yearly inflation curve defined at
178-
//! [`T::RewardCurve`](./trait.Trait.html#associatedtype.RewardCurve) as such:
178+
//! [`T::RewardCurve`](./trait.Config.html#associatedtype.RewardCurve) as such:
179179
//!
180180
//! ```nocompile
181181
//! staker_payout = yearly_inflation(npos_token_staked / total_tokens) * total_tokens / era_per_year
@@ -186,7 +186,7 @@
186186
//! remaining_payout = max_yearly_inflation * total_tokens / era_per_year - staker_payout
187187
//! ```
188188
//! The remaining reward is send to the configurable end-point
189-
//! [`T::RewardRemainder`](./trait.Trait.html#associatedtype.RewardRemainder).
189+
//! [`T::RewardRemainder`](./trait.Config.html#associatedtype.RewardRemainder).
190190
//!
191191
//! ### Reward Calculation
192192
//!
@@ -232,7 +232,7 @@
232232
//!
233233
//! The controller account can free a portion (or all) of the funds using the
234234
//! [`unbond`](enum.Call.html#variant.unbond) call. Note that the funds are not immediately
235-
//! accessible. Instead, a duration denoted by [`BondingDuration`](./trait.Trait.html#associatedtype.BondingDuration)
235+
//! accessible. Instead, a duration denoted by [`BondingDuration`](./trait.Config.html#associatedtype.BondingDuration)
236236
//! (in number of eras) must pass until the funds can actually be removed. Once the
237237
//! `BondingDuration` is over, the [`withdraw_unbonded`](./enum.Call.html#variant.withdraw_unbonded)
238238
//! call can be used to actually withdraw the funds.
@@ -385,12 +385,12 @@ pub type OffchainAccuracy = PerU16;
385385

386386
/// The balance type of this module.
387387
pub type BalanceOf<T> =
388-
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
388+
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
389389

390390
type PositiveImbalanceOf<T> =
391-
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::PositiveImbalance;
391+
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::PositiveImbalance;
392392
type NegativeImbalanceOf<T> =
393-
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::NegativeImbalance;
393+
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
394394

395395
/// Information regarding the active era (era in used in session).
396396
#[derive(Encode, Decode, RuntimeDebug)]
@@ -732,8 +732,8 @@ impl<BlockNumber> Default for ElectionStatus<BlockNumber> {
732732

733733
/// Means for interacting with a specialized version of the `session` trait.
734734
///
735-
/// This is needed because `Staking` sets the `ValidatorIdOf` of the `pallet_session::Trait`
736-
pub trait SessionInterface<AccountId>: frame_system::Trait {
735+
/// This is needed because `Staking` sets the `ValidatorIdOf` of the `pallet_session::Config`
736+
pub trait SessionInterface<AccountId>: frame_system::Config {
737737
/// Disable a given validator by stash ID.
738738
///
739739
/// 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 {
746746
fn prune_historical_up_to(up_to: SessionIndex);
747747
}
748748

749-
impl<T: Trait> SessionInterface<<T as frame_system::Trait>::AccountId> for T where
750-
T: pallet_session::Trait<ValidatorId = <T as frame_system::Trait>::AccountId>,
751-
T: pallet_session::historical::Trait<
752-
FullIdentification = Exposure<<T as frame_system::Trait>::AccountId, BalanceOf<T>>,
749+
impl<T: Config> SessionInterface<<T as frame_system::Config>::AccountId> for T where
750+
T: pallet_session::Config<ValidatorId = <T as frame_system::Config>::AccountId>,
751+
T: pallet_session::historical::Config<
752+
FullIdentification = Exposure<<T as frame_system::Config>::AccountId, BalanceOf<T>>,
753753
FullIdentificationOf = ExposureOf<T>,
754754
>,
755-
T::SessionHandler: pallet_session::SessionHandler<<T as frame_system::Trait>::AccountId>,
756-
T::SessionManager: pallet_session::SessionManager<<T as frame_system::Trait>::AccountId>,
755+
T::SessionHandler: pallet_session::SessionHandler<<T as frame_system::Config>::AccountId>,
756+
T::SessionManager: pallet_session::SessionManager<<T as frame_system::Config>::AccountId>,
757757
T::ValidatorIdOf:
758-
Convert<<T as frame_system::Trait>::AccountId, Option<<T as frame_system::Trait>::AccountId>>,
758+
Convert<<T as frame_system::Config>::AccountId, Option<<T as frame_system::Config>::AccountId>>,
759759
{
760-
fn disable_validator(validator: &<T as frame_system::Trait>::AccountId) -> Result<bool, ()> {
760+
fn disable_validator(validator: &<T as frame_system::Config>::AccountId) -> Result<bool, ()> {
761761
<pallet_session::Module<T>>::disable(validator)
762762
}
763763

764-
fn validators() -> Vec<<T as frame_system::Trait>::AccountId> {
764+
fn validators() -> Vec<<T as frame_system::Config>::AccountId> {
765765
<pallet_session::Module<T>>::validators()
766766
}
767767

@@ -770,7 +770,7 @@ impl<T: Trait> SessionInterface<<T as frame_system::Trait>::AccountId> for T whe
770770
}
771771
}
772772

773-
pub trait Trait: frame_system::Trait + SendTransactionTypes<Call<Self>> {
773+
pub trait Config: frame_system::Config + SendTransactionTypes<Call<Self>> {
774774
/// The staking balance.
775775
type Currency: LockableCurrency<Self::AccountId, Moment=Self::BlockNumber>;
776776

@@ -792,7 +792,7 @@ pub trait Trait: frame_system::Trait + SendTransactionTypes<Call<Self>> {
792792
type RewardRemainder: OnUnbalanced<NegativeImbalanceOf<Self>>;
793793

794794
/// The overarching event type.
795-
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
795+
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
796796

797797
/// Handler for the unbalanced reduction when slashing a staker.
798798
type Slash: OnUnbalanced<NegativeImbalanceOf<Self>>;
@@ -904,7 +904,7 @@ impl Default for Releases {
904904
}
905905

906906
decl_storage! {
907-
trait Store for Module<T: Trait> as Staking {
907+
trait Store for Module<T: Config> as Staking {
908908
/// Number of eras to keep in history.
909909
///
910910
/// Information is kept for eras in `[current_era - history_depth; current_era]`.
@@ -1121,7 +1121,7 @@ decl_storage! {
11211121
}
11221122

11231123
decl_event!(
1124-
pub enum Event<T> where Balance = BalanceOf<T>, <T as frame_system::Trait>::AccountId {
1124+
pub enum Event<T> where Balance = BalanceOf<T>, <T as frame_system::Config>::AccountId {
11251125
/// The era payout has been set; the first balance is the validator-payout; the second is
11261126
/// the remainder from the maximum amount of reward.
11271127
/// \[era_index, validator_payout, remainder\]
@@ -1153,7 +1153,7 @@ decl_event!(
11531153

11541154
decl_error! {
11551155
/// Error for the staking module.
1156-
pub enum Error for Module<T: Trait> {
1156+
pub enum Error for Module<T: Config> {
11571157
/// Not a controller account.
11581158
NotController,
11591159
/// Not a stash account.
@@ -1223,7 +1223,7 @@ decl_error! {
12231223
}
12241224

12251225
decl_module! {
1226-
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
1226+
pub struct Module<T: Config> for enum Call where origin: T::Origin {
12271227
/// Number of sessions per era.
12281228
const SessionsPerEra: SessionIndex = T::SessionsPerEra::get();
12291229

@@ -2159,7 +2159,7 @@ decl_module! {
21592159
}
21602160
}
21612161

2162-
impl<T: Trait> Module<T> {
2162+
impl<T: Config> Module<T> {
21632163
/// The total balance that can be slashed from a stash account as of right now.
21642164
pub fn slashable_balance_of(stash: &T::AccountId) -> BalanceOf<T> {
21652165
// Weight note: consider making the stake accessible through stash.
@@ -3083,7 +3083,7 @@ impl<T: Trait> Module<T> {
30833083
///
30843084
/// Once the first new_session is planned, all session must start and then end in order, though
30853085
/// some session can lag in between the newest session planned and the latest session started.
3086-
impl<T: Trait> pallet_session::SessionManager<T::AccountId> for Module<T> {
3086+
impl<T: Config> pallet_session::SessionManager<T::AccountId> for Module<T> {
30873087
fn new_session(new_index: SessionIndex) -> Option<Vec<T::AccountId>> {
30883088
Self::new_session(new_index)
30893089
}
@@ -3095,7 +3095,7 @@ impl<T: Trait> pallet_session::SessionManager<T::AccountId> for Module<T> {
30953095
}
30963096
}
30973097

3098-
impl<T: Trait> historical::SessionManager<T::AccountId, Exposure<T::AccountId, BalanceOf<T>>> for Module<T> {
3098+
impl<T: Config> historical::SessionManager<T::AccountId, Exposure<T::AccountId, BalanceOf<T>>> for Module<T> {
30993099
fn new_session(new_index: SessionIndex)
31003100
-> Option<Vec<(T::AccountId, Exposure<T::AccountId, BalanceOf<T>>)>>
31013101
{
@@ -3124,7 +3124,7 @@ impl<T: Trait> historical::SessionManager<T::AccountId, Exposure<T::AccountId, B
31243124
/// * 1 point to the producer of each referenced uncle block.
31253125
impl<T> pallet_authorship::EventHandler<T::AccountId, T::BlockNumber> for Module<T>
31263126
where
3127-
T: Trait + pallet_authorship::Trait + pallet_session::Trait
3127+
T: Config + pallet_authorship::Config + pallet_session::Config
31283128
{
31293129
fn note_author(author: T::AccountId) {
31303130
Self::reward_by_ids(vec![(author, 20)])
@@ -3141,7 +3141,7 @@ impl<T> pallet_authorship::EventHandler<T::AccountId, T::BlockNumber> for Module
31413141
/// if any.
31423142
pub struct StashOf<T>(sp_std::marker::PhantomData<T>);
31433143

3144-
impl<T: Trait> Convert<T::AccountId, Option<T::AccountId>> for StashOf<T> {
3144+
impl<T: Config> Convert<T::AccountId, Option<T::AccountId>> for StashOf<T> {
31453145
fn convert(controller: T::AccountId) -> Option<T::AccountId> {
31463146
<Module<T>>::ledger(&controller).map(|l| l.stash)
31473147
}
@@ -3154,7 +3154,7 @@ impl<T: Trait> Convert<T::AccountId, Option<T::AccountId>> for StashOf<T> {
31543154
/// `active_era`. It can differ from the latest planned exposure in `current_era`.
31553155
pub struct ExposureOf<T>(sp_std::marker::PhantomData<T>);
31563156

3157-
impl<T: Trait> Convert<T::AccountId, Option<Exposure<T::AccountId, BalanceOf<T>>>>
3157+
impl<T: Config> Convert<T::AccountId, Option<Exposure<T::AccountId, BalanceOf<T>>>>
31583158
for ExposureOf<T>
31593159
{
31603160
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>>
31673167
}
31683168

31693169
/// This is intended to be used with `FilterHistoricalOffences`.
3170-
impl <T: Trait>
3170+
impl <T: Config>
31713171
OnOffenceHandler<T::AccountId, pallet_session::historical::IdentificationTuple<T>, Weight>
31723172
for Module<T> where
3173-
T: pallet_session::Trait<ValidatorId = <T as frame_system::Trait>::AccountId>,
3174-
T: pallet_session::historical::Trait<
3175-
FullIdentification = Exposure<<T as frame_system::Trait>::AccountId, BalanceOf<T>>,
3173+
T: pallet_session::Config<ValidatorId = <T as frame_system::Config>::AccountId>,
3174+
T: pallet_session::historical::Config<
3175+
FullIdentification = Exposure<<T as frame_system::Config>::AccountId, BalanceOf<T>>,
31763176
FullIdentificationOf = ExposureOf<T>,
31773177
>,
3178-
T::SessionHandler: pallet_session::SessionHandler<<T as frame_system::Trait>::AccountId>,
3179-
T::SessionManager: pallet_session::SessionManager<<T as frame_system::Trait>::AccountId>,
3178+
T::SessionHandler: pallet_session::SessionHandler<<T as frame_system::Config>::AccountId>,
3179+
T::SessionManager: pallet_session::SessionManager<<T as frame_system::Config>::AccountId>,
31803180
T::ValidatorIdOf: Convert<
3181-
<T as frame_system::Trait>::AccountId,
3182-
Option<<T as frame_system::Trait>::AccountId>,
3181+
<T as frame_system::Config>::AccountId,
3182+
Option<<T as frame_system::Config>::AccountId>,
31833183
>,
31843184
{
31853185
fn on_offence(
@@ -3310,7 +3310,7 @@ pub struct FilterHistoricalOffences<T, R> {
33103310

33113311
impl<T, Reporter, Offender, R, O> ReportOffence<Reporter, Offender, O>
33123312
for FilterHistoricalOffences<Module<T>, R> where
3313-
T: Trait,
3313+
T: Config,
33143314
R: ReportOffence<Reporter, Offender, O>,
33153315
O: Offence<Offender>,
33163316
{
@@ -3335,7 +3335,7 @@ impl<T, Reporter, Offender, R, O> ReportOffence<Reporter, Offender, O>
33353335
}
33363336

33373337
#[allow(deprecated)]
3338-
impl<T: Trait> frame_support::unsigned::ValidateUnsigned for Module<T> {
3338+
impl<T: Config> frame_support::unsigned::ValidateUnsigned for Module<T> {
33393339
type Call = Call<T>;
33403340
fn validate_unsigned(source: TransactionSource, call: &Self::Call) -> TransactionValidity {
33413341
if let Call::submit_election_solution_unsigned(

0 commit comments

Comments
 (0)