Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Bound pallet-scheduler #11589

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,11 @@ impl pallet_scheduler::Config for Runtime {
type MaximumWeight = MaximumSchedulerWeight;
type ScheduleOrigin = EnsureRoot<AccountId>;
type MaxScheduledPerBlock = ConstU32<50>;
type MaxAgendas = ConstU32<100>;
type MaxSchedules = ConstU32<250>;
type MaxScheduleIdLen = ConstU32<8>;
type MaxCallLen = ConstU32<300_000>; // TODO
type MaxPalletsOriginLen = ConstU32<16>; // TODO
type WeightInfo = pallet_scheduler::weights::SubstrateWeight<Runtime>;
type OriginPrivilegeCmp = EqualPrivilegeOnly;
type PreimageProvider = Preimage;
Expand Down
37 changes: 21 additions & 16 deletions frame/scheduler/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@ fn fill_schedule<T: Config>(
let t = DispatchTime::At(when);
let origin = frame_system::RawOrigin::Root.into();
if named {
Scheduler::<T>::do_schedule_named(i.encode(), t, period, 0, origin, call_or_hash)?;
Scheduler::<T>::do_schedule_named(
i.encode().try_into().unwrap(),
t,
period,
0,
origin,
call_or_hash,
)?;
} else {
Scheduler::<T>::do_schedule(t, period, 0, origin, call_or_hash)?;
}
Expand Down Expand Up @@ -201,7 +208,7 @@ benchmarks! {
}

schedule {
let s in 0 .. T::MaxScheduledPerBlock::get();
let s in 0 .. (T::MaxScheduledPerBlock::get() - 1);
let when = BLOCK_NUMBER.into();
let periodic = Some((T::BlockNumber::one(), 100));
let priority = 0;
Expand All @@ -223,22 +230,21 @@ benchmarks! {
let when = BLOCK_NUMBER.into();

fill_schedule::<T>(when, s, true, true, Some(false))?;
assert_eq!(Agenda::<T>::get(when).len(), s as usize);
assert_eq!(Agenda::<T>::get(when).len() as u32, s);
}: _(RawOrigin::Root, when, 0)
verify {
let id: ScheduleIdOf<T> = 0.encode().try_into().unwrap();
ensure!(
Lookup::<T>::get(0.encode()).is_none(),
Lookup::<T>::get(id).is_none(),
"didn't remove from lookup"
);
// Removed schedule is NONE
ensure!(
Agenda::<T>::get(when)[0].is_none(),
"didn't remove from schedule"
);
// Removed schedule and its agenda are gone.
// Removed schedule is gone.
assert_eq!(Agenda::<T>::get(when).len() as u32, s-1, "didn't remove the agenda");
}

schedule_named {
let s in 0 .. T::MaxScheduledPerBlock::get();
let s in 0 .. (T::MaxScheduledPerBlock::get() - 1);
let id = s.encode();
let when = BLOCK_NUMBER.into();
let periodic = Some((T::BlockNumber::one(), 100));
Expand All @@ -261,17 +267,16 @@ benchmarks! {
let when = BLOCK_NUMBER.into();

fill_schedule::<T>(when, s, true, true, Some(false))?;
assert_eq!(Agenda::<T>::get(when).len() as u32, s);
}: _(RawOrigin::Root, 0.encode())
verify {
let id: ScheduleIdOf<T> = 0.encode().try_into().unwrap();
ensure!(
Lookup::<T>::get(0.encode()).is_none(),
Lookup::<T>::get(id).is_none(),
"didn't remove from lookup"
);
// Removed schedule is NONE
ensure!(
Agenda::<T>::get(when)[0].is_none(),
"didn't remove from schedule"
);
// Removed schedule is gone.
assert_eq!(Agenda::<T>::get(when).len() as u32, s-1, "didn't remove the agenda");
}

impl_benchmark_test_suite!(Scheduler, crate::mock::new_test_ext(), crate::mock::Test);
Expand Down
Loading