Skip to content

Commit f8bfc89

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 cc561ef commit f8bfc89

File tree

3 files changed

+52
-52
lines changed

3 files changed

+52
-52
lines changed

src/benchmarking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use frame_system::Module as System;
3131
const BLOCK_NUMBER: u32 = 2;
3232

3333
// Add `n` named items to the schedule
34-
fn fill_schedule<T: Trait> (when: T::BlockNumber, n: u32) -> Result<(), &'static str> {
34+
fn fill_schedule<T: Config> (when: T::BlockNumber, n: u32) -> Result<(), &'static str> {
3535
// Essentially a no-op call.
3636
let call = frame_system::Call::set_storage(vec![]);
3737
for i in 0..n {

src/lib.rs

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//! # Scheduler
1919
//! A module for scheduling dispatches.
2020
//!
21-
//! - [`scheduler::Trait`](./trait.Trait.html)
21+
//! - [`scheduler::Config`](./trait.Config.html)
2222
//! - [`Call`](./enum.Call.html)
2323
//! - [`Module`](./struct.Module.html)
2424
//!
@@ -29,7 +29,7 @@
2929
//! may be named or anonymous and may be canceled.
3030
//!
3131
//! **NOTE:** The scheduled calls will be dispatched with the default filter
32-
//! for the origin: namely `frame_system::Trait::BaseCallFilter` for all origin
32+
//! for the origin: namely `frame_system::Config::BaseCallFilter` for all origin
3333
//! except root which will get no filter. And not the filter contained in origin
3434
//! use to call `fn schedule`.
3535
//!
@@ -70,27 +70,27 @@ pub use weights::WeightInfo;
7070
/// pallet is dependent on specific other pallets, then their configuration traits
7171
/// should be added to our implied traits list.
7272
///
73-
/// `system::Trait` should always be included in our implied traits.
74-
pub trait Trait: system::Trait {
73+
/// `system::Config` should always be included in our implied traits.
74+
pub trait Config: system::Config {
7575
/// The overarching event type.
76-
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
76+
type Event: From<Event<Self>> + Into<<Self as system::Config>::Event>;
7777

7878
/// The aggregated origin which the dispatch will take.
7979
type Origin: OriginTrait<PalletsOrigin =
80-
Self::PalletsOrigin> + From<Self::PalletsOrigin> + IsType<<Self as system::Trait>::Origin>;
80+
Self::PalletsOrigin> + From<Self::PalletsOrigin> + IsType<<Self as system::Config>::Origin>;
8181

8282
/// The caller origin, overarching type of all pallets origins.
8383
type PalletsOrigin: From<system::RawOrigin<Self::AccountId>> + Codec + Clone + Eq;
8484

8585
/// The aggregated call type.
86-
type Call: Parameter + Dispatchable<Origin=<Self as Trait>::Origin> + GetDispatchInfo + From<system::Call<Self>>;
86+
type Call: Parameter + Dispatchable<Origin=<Self as Config>::Origin> + GetDispatchInfo + From<system::Call<Self>>;
8787

8888
/// The maximum weight that may be scheduled per block for any dispatchables of less priority
8989
/// than `schedule::HARD_DEADLINE`.
9090
type MaximumWeight: Get<Weight>;
9191

9292
/// Required origin to schedule or cancel calls.
93-
type ScheduleOrigin: EnsureOrigin<<Self as system::Trait>::Origin>;
93+
type ScheduleOrigin: EnsureOrigin<<Self as system::Config>::Origin>;
9494

9595
/// The maximum number of scheduled calls in the queue for a single block.
9696
/// Not strictly enforced, but used for weight estimation.
@@ -150,10 +150,10 @@ impl Default for Releases {
150150
}
151151

152152
decl_storage! {
153-
trait Store for Module<T: Trait> as Scheduler {
153+
trait Store for Module<T: Config> as Scheduler {
154154
/// Items to be executed, indexed by the block number that they should be executed on.
155155
pub Agenda: map hasher(twox_64_concat) T::BlockNumber
156-
=> Vec<Option<Scheduled<<T as Trait>::Call, T::BlockNumber, T::PalletsOrigin, T::AccountId>>>;
156+
=> Vec<Option<Scheduled<<T as Config>::Call, T::BlockNumber, T::PalletsOrigin, T::AccountId>>>;
157157

158158
/// Lookup from identity to the block number and index of the task.
159159
Lookup: map hasher(twox_64_concat) Vec<u8> => Option<TaskAddress<T::BlockNumber>>;
@@ -166,7 +166,7 @@ decl_storage! {
166166
}
167167

168168
decl_event!(
169-
pub enum Event<T> where <T as system::Trait>::BlockNumber {
169+
pub enum Event<T> where <T as system::Config>::BlockNumber {
170170
/// Scheduled some task. \[when, index\]
171171
Scheduled(BlockNumber, u32),
172172
/// Canceled some task. \[when, index\]
@@ -177,7 +177,7 @@ decl_event!(
177177
);
178178

179179
decl_error! {
180-
pub enum Error for Module<T: Trait> {
180+
pub enum Error for Module<T: Config> {
181181
/// Failed to schedule a call
182182
FailedToSchedule,
183183
/// Cannot find the scheduled call.
@@ -191,7 +191,7 @@ decl_error! {
191191

192192
decl_module! {
193193
/// Scheduler module declaration.
194-
pub struct Module<T: Trait> for enum Call where origin: <T as system::Trait>::Origin {
194+
pub struct Module<T: Config> for enum Call where origin: <T as system::Config>::Origin {
195195
type Error = Error<T>;
196196
fn deposit_event() = default;
197197

@@ -210,10 +210,10 @@ decl_module! {
210210
when: T::BlockNumber,
211211
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
212212
priority: schedule::Priority,
213-
call: Box<<T as Trait>::Call>,
213+
call: Box<<T as Config>::Call>,
214214
) {
215215
T::ScheduleOrigin::ensure_origin(origin.clone())?;
216-
let origin = <T as Trait>::Origin::from(origin);
216+
let origin = <T as Config>::Origin::from(origin);
217217
Self::do_schedule(DispatchTime::At(when), maybe_periodic, priority, origin.caller().clone(), *call)?;
218218
}
219219

@@ -230,7 +230,7 @@ decl_module! {
230230
#[weight = T::WeightInfo::cancel(T::MaxScheduledPerBlock::get())]
231231
fn cancel(origin, when: T::BlockNumber, index: u32) {
232232
T::ScheduleOrigin::ensure_origin(origin.clone())?;
233-
let origin = <T as Trait>::Origin::from(origin);
233+
let origin = <T as Config>::Origin::from(origin);
234234
Self::do_cancel(Some(origin.caller().clone()), (when, index))?;
235235
}
236236

@@ -250,10 +250,10 @@ decl_module! {
250250
when: T::BlockNumber,
251251
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
252252
priority: schedule::Priority,
253-
call: Box<<T as Trait>::Call>,
253+
call: Box<<T as Config>::Call>,
254254
) {
255255
T::ScheduleOrigin::ensure_origin(origin.clone())?;
256-
let origin = <T as Trait>::Origin::from(origin);
256+
let origin = <T as Config>::Origin::from(origin);
257257
Self::do_schedule_named(
258258
id, DispatchTime::At(when), maybe_periodic, priority, origin.caller().clone(), *call
259259
)?;
@@ -272,7 +272,7 @@ decl_module! {
272272
#[weight = T::WeightInfo::cancel_named(T::MaxScheduledPerBlock::get())]
273273
fn cancel_named(origin, id: Vec<u8>) {
274274
T::ScheduleOrigin::ensure_origin(origin.clone())?;
275-
let origin = <T as Trait>::Origin::from(origin);
275+
let origin = <T as Config>::Origin::from(origin);
276276
Self::do_cancel_named(Some(origin.caller().clone()), id)?;
277277
}
278278

@@ -286,10 +286,10 @@ decl_module! {
286286
after: T::BlockNumber,
287287
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
288288
priority: schedule::Priority,
289-
call: Box<<T as Trait>::Call>,
289+
call: Box<<T as Config>::Call>,
290290
) {
291291
T::ScheduleOrigin::ensure_origin(origin.clone())?;
292-
let origin = <T as Trait>::Origin::from(origin);
292+
let origin = <T as Config>::Origin::from(origin);
293293
Self::do_schedule(
294294
DispatchTime::After(after), maybe_periodic, priority, origin.caller().clone(), *call
295295
)?;
@@ -306,10 +306,10 @@ decl_module! {
306306
after: T::BlockNumber,
307307
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
308308
priority: schedule::Priority,
309-
call: Box<<T as Trait>::Call>,
309+
call: Box<<T as Config>::Call>,
310310
) {
311311
T::ScheduleOrigin::ensure_origin(origin.clone())?;
312-
let origin = <T as Trait>::Origin::from(origin);
312+
let origin = <T as Config>::Origin::from(origin);
313313
Self::do_schedule_named(
314314
id, DispatchTime::After(after), maybe_periodic, priority, origin.caller().clone(), *call
315315
)?;
@@ -347,7 +347,7 @@ decl_module! {
347347
*cumulative_weight = cumulative_weight
348348
.saturating_add(s.call.get_dispatch_info().weight);
349349

350-
let origin = <<T as Trait>::Origin as From<T::PalletsOrigin>>::from(
350+
let origin = <<T as Config>::Origin as From<T::PalletsOrigin>>::from(
351351
s.origin.clone()
352352
).into();
353353

@@ -415,15 +415,15 @@ decl_module! {
415415
}
416416
}
417417

418-
impl<T: Trait> Module<T> {
418+
impl<T: Config> Module<T> {
419419
/// Migrate storage format from V1 to V2.
420420
/// Return true if migration is performed.
421421
pub fn migrate_v1_to_t2() -> bool {
422422
if StorageVersion::get() == Releases::V1 {
423423
StorageVersion::put(Releases::V2);
424424

425425
Agenda::<T>::translate::<
426-
Vec<Option<ScheduledV1<<T as Trait>::Call, T::BlockNumber>>>, _
426+
Vec<Option<ScheduledV1<<T as Config>::Call, T::BlockNumber>>>, _
427427
>(|_, agenda| Some(
428428
agenda
429429
.into_iter()
@@ -447,7 +447,7 @@ impl<T: Trait> Module<T> {
447447
/// Helper to migrate scheduler when the pallet origin type has changed.
448448
pub fn migrate_origin<OldOrigin: Into<T::PalletsOrigin> + codec::Decode>() {
449449
Agenda::<T>::translate::<
450-
Vec<Option<Scheduled<<T as Trait>::Call, T::BlockNumber, OldOrigin, T::AccountId>>>, _
450+
Vec<Option<Scheduled<<T as Config>::Call, T::BlockNumber, OldOrigin, T::AccountId>>>, _
451451
>(|_, agenda| Some(
452452
agenda
453453
.into_iter()
@@ -485,7 +485,7 @@ impl<T: Trait> Module<T> {
485485
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
486486
priority: schedule::Priority,
487487
origin: T::PalletsOrigin,
488-
call: <T as Trait>::Call
488+
call: <T as Config>::Call
489489
) -> Result<TaskAddress<T::BlockNumber>, DispatchError> {
490490
let when = Self::resolve_time(when)?;
491491

@@ -569,7 +569,7 @@ impl<T: Trait> Module<T> {
569569
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
570570
priority: schedule::Priority,
571571
origin: T::PalletsOrigin,
572-
call: <T as Trait>::Call,
572+
call: <T as Config>::Call,
573573
) -> Result<TaskAddress<T::BlockNumber>, DispatchError> {
574574
// ensure id it is unique
575575
if Lookup::<T>::contains_key(&id) {
@@ -657,15 +657,15 @@ impl<T: Trait> Module<T> {
657657
}
658658
}
659659

660-
impl<T: Trait> schedule::Anon<T::BlockNumber, <T as Trait>::Call, T::PalletsOrigin> for Module<T> {
660+
impl<T: Config> schedule::Anon<T::BlockNumber, <T as Config>::Call, T::PalletsOrigin> for Module<T> {
661661
type Address = TaskAddress<T::BlockNumber>;
662662

663663
fn schedule(
664664
when: DispatchTime<T::BlockNumber>,
665665
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
666666
priority: schedule::Priority,
667667
origin: T::PalletsOrigin,
668-
call: <T as Trait>::Call
668+
call: <T as Config>::Call
669669
) -> Result<Self::Address, DispatchError> {
670670
Self::do_schedule(when, maybe_periodic, priority, origin, call)
671671
}
@@ -686,7 +686,7 @@ impl<T: Trait> schedule::Anon<T::BlockNumber, <T as Trait>::Call, T::PalletsOrig
686686
}
687687
}
688688

689-
impl<T: Trait> schedule::Named<T::BlockNumber, <T as Trait>::Call, T::PalletsOrigin> for Module<T> {
689+
impl<T: Config> schedule::Named<T::BlockNumber, <T as Config>::Call, T::PalletsOrigin> for Module<T> {
690690
type Address = TaskAddress<T::BlockNumber>;
691691

692692
fn schedule_named(
@@ -695,7 +695,7 @@ impl<T: Trait> schedule::Named<T::BlockNumber, <T as Trait>::Call, T::PalletsOri
695695
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
696696
priority: schedule::Priority,
697697
origin: T::PalletsOrigin,
698-
call: <T as Trait>::Call,
698+
call: <T as Config>::Call,
699699
) -> Result<Self::Address, ()> {
700700
Self::do_schedule_named(id, when, maybe_periodic, priority, origin, call).map_err(|_| ())
701701
}
@@ -746,19 +746,19 @@ mod tests {
746746
pub fn log() -> Vec<(OriginCaller, u32)> {
747747
LOG.with(|log| log.borrow().clone())
748748
}
749-
pub trait Trait: system::Trait {
750-
type Event: From<Event> + Into<<Self as system::Trait>::Event>;
749+
pub trait Config: system::Config {
750+
type Event: From<Event> + Into<<Self as system::Config>::Event>;
751751
}
752752
decl_event! {
753753
pub enum Event {
754754
Logged(u32, Weight),
755755
}
756756
}
757757
decl_module! {
758-
pub struct Module<T: Trait> for enum Call
758+
pub struct Module<T: Config> for enum Call
759759
where
760-
origin: <T as system::Trait>::Origin,
761-
<T as system::Trait>::Origin: OriginTrait<PalletsOrigin = OriginCaller>
760+
origin: <T as system::Config>::Origin,
761+
<T as system::Config>::Origin: OriginTrait<PalletsOrigin = OriginCaller>
762762
{
763763
fn deposit_event() = default;
764764

@@ -816,7 +816,7 @@ mod tests {
816816
pub const MaximumBlockLength: u32 = 2 * 1024;
817817
pub const AvailableBlockRatio: Perbill = Perbill::one();
818818
}
819-
impl system::Trait for Test {
819+
impl system::Config for Test {
820820
type BaseCallFilter = BaseFilter;
821821
type Origin = Origin;
822822
type Call = Call;
@@ -843,7 +843,7 @@ mod tests {
843843
type OnKilledAccount = ();
844844
type SystemWeightInfo = ();
845845
}
846-
impl logger::Trait for Test {
846+
impl logger::Config for Test {
847847
type Event = ();
848848
}
849849
parameter_types! {
@@ -854,7 +854,7 @@ mod tests {
854854
pub const One: u64 = 1;
855855
}
856856

857-
impl Trait for Test {
857+
impl Config for Test {
858858
type Event = ();
859859
type Origin = Origin;
860860
type PalletsOrigin = OriginCaller;
@@ -889,7 +889,7 @@ mod tests {
889889
fn basic_scheduling_works() {
890890
new_test_ext().execute_with(|| {
891891
let call = Call::Logger(logger::Call::log(42, 1000));
892-
assert!(!<Test as frame_system::Trait>::BaseCallFilter::filter(&call));
892+
assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(&call));
893893
assert_ok!(Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call));
894894
run_to_block(3);
895895
assert!(logger::log().is_empty());
@@ -905,7 +905,7 @@ mod tests {
905905
new_test_ext().execute_with(|| {
906906
run_to_block(2);
907907
let call = Call::Logger(logger::Call::log(42, 1000));
908-
assert!(!<Test as frame_system::Trait>::BaseCallFilter::filter(&call));
908+
assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(&call));
909909
// This will schedule the call 3 blocks after the next block... so block 3 + 3 = 6
910910
assert_ok!(Scheduler::do_schedule(DispatchTime::After(3), None, 127, root(), call));
911911
run_to_block(5);
@@ -922,7 +922,7 @@ mod tests {
922922
new_test_ext().execute_with(|| {
923923
run_to_block(2);
924924
let call = Call::Logger(logger::Call::log(42, 1000));
925-
assert!(!<Test as frame_system::Trait>::BaseCallFilter::filter(&call));
925+
assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(&call));
926926
assert_ok!(Scheduler::do_schedule(DispatchTime::After(0), None, 127, root(), call));
927927
// Will trigger on the next block.
928928
run_to_block(3);
@@ -960,7 +960,7 @@ mod tests {
960960
fn reschedule_works() {
961961
new_test_ext().execute_with(|| {
962962
let call = Call::Logger(logger::Call::log(42, 1000));
963-
assert!(!<Test as frame_system::Trait>::BaseCallFilter::filter(&call));
963+
assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(&call));
964964
assert_eq!(Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call).unwrap(), (4, 0));
965965

966966
run_to_block(3);
@@ -985,7 +985,7 @@ mod tests {
985985
fn reschedule_named_works() {
986986
new_test_ext().execute_with(|| {
987987
let call = Call::Logger(logger::Call::log(42, 1000));
988-
assert!(!<Test as frame_system::Trait>::BaseCallFilter::filter(&call));
988+
assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(&call));
989989
assert_eq!(Scheduler::do_schedule_named(
990990
1u32.encode(), DispatchTime::At(4), None, 127, root(), call
991991
).unwrap(), (4, 0));
@@ -1012,7 +1012,7 @@ mod tests {
10121012
fn reschedule_named_perodic_works() {
10131013
new_test_ext().execute_with(|| {
10141014
let call = Call::Logger(logger::Call::log(42, 1000));
1015-
assert!(!<Test as frame_system::Trait>::BaseCallFilter::filter(&call));
1015+
assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(&call));
10161016
assert_eq!(Scheduler::do_schedule_named(
10171017
1u32.encode(), DispatchTime::At(4), Some((3, 3)), 127, root(), call
10181018
).unwrap(), (4, 0));
@@ -1203,10 +1203,10 @@ mod tests {
12031203
#[test]
12041204
fn on_initialize_weight_is_correct() {
12051205
new_test_ext().execute_with(|| {
1206-
let base_weight: Weight = <Test as frame_system::Trait>::DbWeight::get().reads_writes(1, 2);
1206+
let base_weight: Weight = <Test as frame_system::Config>::DbWeight::get().reads_writes(1, 2);
12071207
let base_multiplier = 0;
1208-
let named_multiplier = <Test as frame_system::Trait>::DbWeight::get().writes(1);
1209-
let periodic_multiplier = <Test as frame_system::Trait>::DbWeight::get().reads_writes(1, 1);
1208+
let named_multiplier = <Test as frame_system::Config>::DbWeight::get().writes(1);
1209+
let periodic_multiplier = <Test as frame_system::Config>::DbWeight::get().reads_writes(1, 1);
12101210

12111211
// Named
12121212
assert_ok!(

src/weights.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub trait WeightInfo {
5252

5353
/// Weights for pallet_scheduler using the Substrate node and recommended hardware.
5454
pub struct SubstrateWeight<T>(PhantomData<T>);
55-
impl<T: frame_system::Trait> WeightInfo for SubstrateWeight<T> {
55+
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
5656
fn schedule(s: u32, ) -> Weight {
5757
(35_029_000 as Weight)
5858
.saturating_add((77_000 as Weight).saturating_mul(s as Weight))

0 commit comments

Comments
 (0)