difftreelog
fix enable scheduler v2
in: master
6 files changed
pallets/scheduler-v2/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/scheduler-v2/src/benchmarking.rs
+++ b/pallets/scheduler-v2/src/benchmarking.rs
@@ -68,7 +68,10 @@
let name = u32_to_name(i);
Scheduler::<T>::do_schedule_named(name, t, period, 0, origin.clone(), call)?;
}
- ensure!(Agenda::<T>::get(when).len() == n as usize, "didn't fill schedule");
+ ensure!(
+ Agenda::<T>::get(when).len() == n as usize,
+ "didn't fill schedule"
+ );
Ok(())
}
@@ -93,19 +96,30 @@
false => None,
};
let origin = make_origin::<T>(signed);
- Scheduled { maybe_id, priority, call, maybe_periodic, origin, _phantom: PhantomData }
+ Scheduled {
+ maybe_id,
+ priority,
+ call,
+ maybe_periodic,
+ origin,
+ _phantom: PhantomData,
+ }
}
fn bounded<T: Config>(len: u32) -> Option<ScheduledCall<T>> {
- let call =
- <<T as Config>::Call>::from(SystemCall::remark { remark: vec![0; len as usize] });
- ScheduledCall::new(call).ok()
+ let call = <<T as Config>::Call>::from(SystemCall::remark {
+ remark: vec![0; len as usize],
+ });
+ ScheduledCall::new(call).ok()
}
fn make_call<T: Config>(maybe_lookup_len: Option<u32>) -> ScheduledCall<T> {
let bound = EncodedCall::bound() as u32;
let mut len = match maybe_lookup_len {
- Some(len) => len.min(<T::Preimages as PreimageRecipient<T::Hash>>::MaxSize::get() - 2).max(bound) - 3,
+ Some(len) => {
+ len.min(<T::Preimages as PreimageRecipient<T::Hash>>::MaxSize::get() - 2)
+ .max(bound) - 3
+ }
None => bound.saturating_sub(4),
};
@@ -114,11 +128,11 @@
Some(x) => x,
None => {
len -= 1;
- continue
- },
+ continue;
+ }
};
if c.lookup_needed() == maybe_lookup_len.is_some() {
- break c
+ break c;
}
if maybe_lookup_len.is_some() {
len += 1;
@@ -126,7 +140,7 @@
if len > 0 {
len -= 1;
} else {
- break c
+ break c;
}
}
}
@@ -140,11 +154,14 @@
}
fn dummy_counter() -> WeightCounter {
- WeightCounter { used: Weight::zero(), limit: Weight::MAX }
+ WeightCounter {
+ used: Weight::zero(),
+ limit: Weight::MAX,
+ }
}
benchmarks! {
- // `service_agendas` when no work is done.
+ // `service_agendas` when no work is done.
service_agendas_base {
let now = T::BlockNumber::from(BLOCK_NUMBER);
IncompleteSince::<T>::put(now - One::one());
@@ -154,7 +171,7 @@
assert_eq!(IncompleteSince::<T>::get(), Some(now - One::one()));
}
- // `service_agenda` when no work is done.
+ // `service_agenda` when no work is done.
service_agenda_base {
let now = BLOCK_NUMBER.into();
let s in 0 .. T::MaxScheduledPerBlock::get();
@@ -166,7 +183,7 @@
assert_eq!(executed, 0);
}
- // `service_task` when the task is a non-periodic, non-named, non-fetched call which is not
+ // `service_task` when the task is a non-periodic, non-named, non-fetched call which is not
// dispatched (e.g. due to being overweight).
service_task_base {
let now = BLOCK_NUMBER.into();
@@ -179,7 +196,7 @@
//assert_eq!(result, Ok(()));
}
- // `service_task` when the task is a non-periodic, non-named, fetched call (with a known
+ // `service_task` when the task is a non-periodic, non-named, fetched call (with a known
// preimage length) and which is not dispatched (e.g. due to being overweight).
service_task_fetched {
let s in (EncodedCall::bound() as u32) .. (<T::Preimages as PreimageRecipient<T::Hash>>::MaxSize::get());
@@ -192,7 +209,7 @@
} verify {
}
- // `service_task` when the task is a non-periodic, named, non-fetched call which is not
+ // `service_task` when the task is a non-periodic, named, non-fetched call which is not
// dispatched (e.g. due to being overweight).
service_task_named {
let now = BLOCK_NUMBER.into();
@@ -204,7 +221,7 @@
} verify {
}
- // `service_task` when the task is a periodic, non-named, non-fetched call which is not
+ // `service_task` when the task is a periodic, non-named, non-fetched call which is not
// dispatched (e.g. due to being overweight).
service_task_periodic {
let now = BLOCK_NUMBER.into();
@@ -216,7 +233,7 @@
} verify {
}
- // `execute_dispatch` when the origin is `Signed`, not counting the dispatable's weight.
+ // `execute_dispatch` when the origin is `Signed`, not counting the dispatable's weight.
execute_dispatch_signed {
let mut counter = WeightCounter { used: Weight::zero(), limit: Weight::MAX };
let origin = make_origin::<T>(true);
@@ -227,7 +244,7 @@
verify {
}
- // `execute_dispatch` when the origin is not `Signed`, not counting the dispatable's weight.
+ // `execute_dispatch` when the origin is not `Signed`, not counting the dispatable's weight.
execute_dispatch_unsigned {
let mut counter = WeightCounter { used: Weight::zero(), limit: Weight::MAX };
let origin = make_origin::<T>(false);
@@ -238,7 +255,7 @@
verify {
}
- schedule {
+ schedule {
let s in 0 .. (T::MaxScheduledPerBlock::get() - 1);
let when = BLOCK_NUMBER.into();
let periodic = Some((T::BlockNumber::one(), 100));
@@ -255,7 +272,7 @@
);
}
- cancel {
+ cancel {
let s in 1 .. T::MaxScheduledPerBlock::get();
let when = BLOCK_NUMBER.into();
@@ -275,7 +292,7 @@
);
}
- schedule_named {
+ schedule_named {
let s in 0 .. (T::MaxScheduledPerBlock::get() - 1);
let id = u32_to_name(s);
let when = BLOCK_NUMBER.into();
@@ -293,7 +310,7 @@
);
}
- cancel_named {
+ cancel_named {
let s in 1 .. T::MaxScheduledPerBlock::get();
let when = BLOCK_NUMBER.into();
@@ -311,5 +328,5 @@
);
}
- // impl_benchmark_test_suite!(Scheduler, crate::mock::new_test_ext(), crate::mock::Test);
+ // impl_benchmark_test_suite!(Scheduler, crate::mock::new_test_ext(), crate::mock::Test);
}
pallets/scheduler-v2/src/lib.rsdiffbeforeafterboth78use codec::{Codec, Decode, Encode, MaxEncodedLen};78use codec::{Codec, Decode, Encode, MaxEncodedLen};79use frame_support::{79use frame_support::{80 dispatch::{80 dispatch::{DispatchError, DispatchResult, Dispatchable, GetDispatchInfo, Parameter},81 DispatchError, DispatchResult, Dispatchable, GetDispatchInfo, Parameter, RawOrigin,82 },83 ensure,84 traits::{81 traits::{85 schedule::{self, DispatchTime},82 schedule::{self, DispatchTime},86 EnsureOrigin, Get, IsType, OriginTrait,83 EnsureOrigin, Get, IsType, OriginTrait, PrivilegeCmp, StorageVersion, PreimageRecipient,87 PalletInfoAccess, PrivilegeCmp, StorageVersion,88 PreimageProvider, PreimageRecipient, ConstU32,84 ConstU32,89 },85 },90 weights::Weight,86 weights::Weight,91};87};928893use frame_system::{self as system};89use frame_system::{self as system};94use scale_info::TypeInfo;90use scale_info::TypeInfo;95use sp_io::hashing::blake2_256;96use sp_runtime::{91use sp_runtime::{97 traits::{BadOrigin, One, Saturating, Zero, Hash},92 traits::{BadOrigin, One, Saturating, Zero, Hash},98 BoundedVec, RuntimeDebug,93 BoundedVec, RuntimeDebug,132128133 Ok(Self::PreimageLookup { hash, unbounded_len: len as u32 })129 Ok(Self::PreimageLookup {130 hash,131 unbounded_len: len as u32,132 })134 }133 }135 }134 }171impl<T: Config, PP: PreimageRecipient<T::Hash>> SchedulerPreimages<T> for PP {174impl<T: Config, PP: PreimageRecipient<T::Hash>> SchedulerPreimages<T> for PP {172 fn drop(call: &ScheduledCall<T>) {175 fn drop(call: &ScheduledCall<T>) {173 match call {176 match call {174 ScheduledCall::Inline(_) => {},177 ScheduledCall::Inline(_) => {}175 ScheduledCall::PreimageLookup { hash, .. } => Self::unrequest_preimage(hash),178 ScheduledCall::PreimageLookup { hash, .. } => Self::unrequest_preimage(hash),176 }179 }177 }180 }178181179 fn peek(call: &ScheduledCall<T>) -> Result<(<T as pallet::Config>::Call, Option<u32>), DispatchError> {182 fn peek(183 call: &ScheduledCall<T>,184 ) -> Result<(<T as pallet::Config>::Call, Option<u32>), DispatchError> {180 match call {185 match call {181 ScheduledCall::Inline(data) => Ok((ScheduledCall::<T>::decode(data)?, None)),186 ScheduledCall::Inline(data) => Ok((ScheduledCall::<T>::decode(data)?, None)),182 ScheduledCall::PreimageLookup { hash, unbounded_len } => {187 ScheduledCall::PreimageLookup {188 hash,189 unbounded_len,190 } => {183 let (preimage, len) = Self::get_preimage(hash)191 let (preimage, len) = Self::get_preimage(hash)184 .ok_or(<Error<T>>::PreimageNotFound)192 .ok_or(<Error<T>>::PreimageNotFound)185 .map(|preimage| (preimage, *unbounded_len))?;193 .map(|preimage| (preimage, *unbounded_len))?;186194187 Ok((ScheduledCall::<T>::decode(preimage.as_slice())?, Some(len)))195 Ok((ScheduledCall::<T>::decode(preimage.as_slice())?, Some(len)))188 },196 }189 }197 }190 }198 }191199303 type Call: Parameter313 type Call: Parameter304 + Dispatchable<314 + Dispatchable<Origin = <Self as Config>::Origin, PostInfo = PostDispatchInfo>305 Origin = <Self as Config>::Origin,306 PostInfo = PostDispatchInfo,307 > + GetDispatchInfo315 + GetDispatchInfo308 + From<system::Call<Self>>;316 + From<system::Call<Self>>;309317402 fn on_initialize(now: T::BlockNumber) -> Weight {419 fn on_initialize(now: T::BlockNumber) -> Weight {403 let mut weight_counter =420 let mut weight_counter = WeightCounter {404 WeightCounter { used: Weight::zero(), limit: T::MaximumWeight::get() };421 used: Weight::zero(),422 limit: T::MaximumWeight::get(),423 };405 Self::service_agendas(&mut weight_counter, now, u32::max_value());424 Self::service_agendas(&mut weight_counter, now, u32::max_value());406 weight_counter.used425 weight_counter.used537 };556 };538557539 if when <= now {558 if when <= now {540 return Err(Error::<T>::TargetBlockNumberInPast.into())559 return Err(Error::<T>::TargetBlockNumberInPast.into());541 }560 }542561543 Ok(when)562 Ok(when)555 }574 }556 Self::deposit_event(Event::Scheduled { when: address.0, index: address.1 });575 Self::deposit_event(Event::Scheduled {576 when: address.0,577 index: address.1,578 });557 Ok(address)579 Ok(address)558 }580 }571 agenda[hole_index] = Some(what);593 agenda[hole_index] = Some(what);572 hole_index as u32594 hole_index as u32573 } else {595 } else {574 return Err((<Error<T>>::AgendaIsExhausted.into(), what))596 return Err((<Error<T>>::AgendaIsExhausted.into(), what));575 }597 }576 };598 };577 Agenda::<T>::insert(when, agenda);599 Agenda::<T>::insert(when, agenda);616 T::OriginPrivilegeCmp::cmp_privilege(o, &s.origin),638 T::OriginPrivilegeCmp::cmp_privilege(o, &s.origin),617 Some(Ordering::Less) | None639 Some(Ordering::Less) | None618 ) {640 ) {619 return Err(BadOrigin.into())641 return Err(BadOrigin.into());620 }642 }621 };643 };622 Ok(s.take())644 Ok(s.take())632 Self::deposit_event(Event::Canceled { when, index });654 Self::deposit_event(Event::Canceled { when, index });633 Ok(())655 Ok(())634 } else {656 } else {635 return Err(Error::<T>::NotFound.into())657 return Err(Error::<T>::NotFound.into());636 }658 }637 }659 }638660646 ) -> Result<TaskAddress<T::BlockNumber>, DispatchError> {668 ) -> Result<TaskAddress<T::BlockNumber>, DispatchError> {647 // ensure id it is unique669 // ensure id it is unique648 if Lookup::<T>::contains_key(&id) {670 if Lookup::<T>::contains_key(&id) {649 return Err(Error::<T>::FailedToSchedule.into())671 return Err(Error::<T>::FailedToSchedule.into());650 }672 }651673652 let when = Self::resolve_time(when)?;674 let when = Self::resolve_time(when)?;679 T::OriginPrivilegeCmp::cmp_privilege(o, &s.origin),701 T::OriginPrivilegeCmp::cmp_privilege(o, &s.origin),680 Some(Ordering::Less) | None702 Some(Ordering::Less) | None681 ) {703 ) {682 return Err(BadOrigin.into())704 return Err(BadOrigin.into());683 }705 }684 T::Preimages::drop(&s.call);706 T::Preimages::drop(&s.call);685 }707 }690 Self::deposit_event(Event::Canceled { when, index });712 Self::deposit_event(Event::Canceled { when, index });691 Ok(())713 Ok(())692 } else {714 } else {693 return Err(Error::<T>::NotFound.into())715 return Err(Error::<T>::NotFound.into());694 }716 }695 })717 })696 }718 }708 /// Service up to `max` agendas queue starting from earliest incompletely executed agenda.730 /// Service up to `max` agendas queue starting from earliest incompletely executed agenda.709 fn service_agendas(weight: &mut WeightCounter, now: T::BlockNumber, max: u32) {731 fn service_agendas(weight: &mut WeightCounter, now: T::BlockNumber, max: u32) {710 if !weight.check_accrue(T::WeightInfo::service_agendas_base()) {732 if !weight.check_accrue(T::WeightInfo::service_agendas_base()) {711 return733 return;712 }734 }713735714 let mut incomplete_since = now + One::one();736 let mut incomplete_since = now + One::one();770 );797 );771 if !weight.can_accrue(base_weight) {798 if !weight.can_accrue(base_weight) {772 postponed += 1;799 postponed += 1;773 break800 break;774 }801 }775 let result = Self::service_task(weight, now, when, agenda_index, *executed == 0, task);802 let result = Self::service_task(weight, now, when, agenda_index, *executed == 0, task);776 agenda[agenda_index as usize] = match result {803 agenda[agenda_index as usize] = match result {777 Err((Unavailable, slot)) => {804 Err((Unavailable, slot)) => {778 dropped += 1;805 dropped += 1;779 slot806 slot780 },807 }781 Err((Overweight, slot)) => {808 Err((Overweight, slot)) => {782 postponed += 1;809 postponed += 1;783 slot810 slot784 },811 }785 Ok(()) => {812 Ok(()) => {786 *executed += 1;813 *executed += 1;787 None814 None788 },815 }789 };816 };790 }817 }791 if postponed > 0 || dropped > 0 {818 if postponed > 0 || dropped > 0 {833 id: task.maybe_id,860 id: task.maybe_id,834 });861 });835 Err((Unavailable, Some(task)))862 Err((Unavailable, Some(task)))836 },863 }837 Err(Overweight) if is_first => {864 Err(Overweight) if is_first => {838 T::Preimages::drop(&task.call);865 T::Preimages::drop(&task.call);839 Self::deposit_event(Event::PermanentlyOverweight {866 Self::deposit_event(Event::PermanentlyOverweight {840 task: (when, agenda_index),867 task: (when, agenda_index),841 id: task.maybe_id,868 id: task.maybe_id,842 });869 });843 Err((Unavailable, Some(task)))870 Err((Unavailable, Some(task)))844 },871 }845 Err(Overweight) => Err((Overweight, Some(task))),872 Err(Overweight) => Err((Overweight, Some(task))),846 Ok(result) => {873 Ok(result) => {847 Self::deposit_event(Event::Dispatched {874 Self::deposit_event(Event::Dispatched {857 }884 }858 let wake = now.saturating_add(period);885 let wake = now.saturating_add(period);859 match Self::place_task(wake, task) {886 match Self::place_task(wake, task) {860 Ok(_) => {},887 Ok(_) => {}861 Err((_, task)) => {888 Err((_, task)) => {862 // TODO: Leave task in storage somewhere for it to be rescheduled889 // TODO: Leave task in storage somewhere for it to be rescheduled863 // manually.890 // manually.866 task: (when, agenda_index),893 task: (when, agenda_index),867 id: task.maybe_id,894 id: task.maybe_id,868 });895 });869 },896 }870 }897 }871 } else {898 } else {872 T::Preimages::drop(&task.call);899 T::Preimages::drop(&task.call);873 }900 }874 Ok(())901 Ok(())875 },902 }876 }903 }877 }904 }878905897 let max_weight = base_weight.saturating_add(call_weight);924 let max_weight = base_weight.saturating_add(call_weight);898925899 if !weight.can_accrue(max_weight) {926 if !weight.can_accrue(max_weight) {900 return Err(Overweight)927 return Err(Overweight);901 }928 }902929903 let (maybe_actual_call_weight, result) = match call.dispatch(dispatch_origin) {930 let (maybe_actual_call_weight, result) = match call.dispatch(dispatch_origin) {904 Ok(post_info) => (post_info.actual_weight, Ok(())),931 Ok(post_info) => (post_info.actual_weight, Ok(())),905 Err(error_and_info) =>932 Err(error_and_info) => (906 (error_and_info.post_info.actual_weight, Err(error_and_info.error)),933 error_and_info.post_info.actual_weight,934 Err(error_and_info.error),935 ),907 };936 };908 let call_weight = maybe_actual_call_weight.unwrap_or(call_weight);937 let call_weight = maybe_actual_call_weight.unwrap_or(call_weight);runtime/common/config/pallets/scheduler.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/scheduler.rs
+++ b/runtime/common/config/pallets/scheduler.rs
@@ -70,22 +70,22 @@
}
}
-impl pallet_unique_scheduler::Config for Runtime {
- type RuntimeEvent = RuntimeEvent;
- type RuntimeOrigin = RuntimeOrigin;
- type Currency = Balances;
- type PalletsOrigin = OriginCaller;
- type RuntimeCall = RuntimeCall;
- type MaximumWeight = MaximumSchedulerWeight;
- type ScheduleOrigin = EnsureSignedOrRoot<AccountId>;
- type PrioritySetOrigin = EnsureRoot<AccountId>;
- type MaxScheduledPerBlock = MaxScheduledPerBlock;
- type WeightInfo = ();
- type CallExecutor = SchedulerPaymentExecutor;
- type OriginPrivilegeCmp = EqualOrRootOnly;
- type PreimageProvider = ();
- type NoPreimagePostponement = NoPreimagePostponement;
-}
+// impl pallet_unique_scheduler::Config for Runtime {
+// type RuntimeEvent = RuntimeEvent;
+// type RuntimeOrigin = RuntimeOrigin;
+// type Currency = Balances;
+// type PalletsOrigin = OriginCaller;
+// type RuntimeCall = RuntimeCall;
+// type MaximumWeight = MaximumSchedulerWeight;
+// type ScheduleOrigin = EnsureSignedOrRoot<AccountId>;
+// type PrioritySetOrigin = EnsureRoot<AccountId>;
+// type MaxScheduledPerBlock = MaxScheduledPerBlock;
+// type WeightInfo = ();
+// type CallExecutor = SchedulerPaymentExecutor;
+// type OriginPrivilegeCmp = EqualOrRootOnly;
+// type PreimageProvider = ();
+// type NoPreimagePostponement = NoPreimagePostponement;
+// }
impl pallet_unique_scheduler_v2::Config for Runtime {
type Event = Event;
runtime/common/construct_runtime/mod.rsdiffbeforeafterboth--- a/runtime/common/construct_runtime/mod.rs
+++ b/runtime/common/construct_runtime/mod.rs
@@ -57,8 +57,8 @@
Inflation: pallet_inflation::{Pallet, Call, Storage} = 60,
Unique: pallet_unique::{Pallet, Call, Storage, Event<T>} = 61,
- #[runtimes(opal)]
- Scheduler: pallet_unique_scheduler::{Pallet, Call, Storage, Event<T>} = 62,
+ // #[runtimes(opal)]
+ // Scheduler: pallet_unique_scheduler::{Pallet, Call, Storage, Event<T>} = 62,
Configuration: pallet_configuration::{Pallet, Call, Storage} = 63,
@@ -97,7 +97,7 @@
Maintenance: pallet_maintenance::{Pallet, Call, Storage, Event<T>} = 154,
#[runtimes(opal)]
- SchedulerV2: pallet_unique_scheduler_v2::{Pallet, Call, Storage, Event<T>} = 154,
+ Scheduler: pallet_unique_scheduler_v2::{Pallet, Call, Storage, Event<T>} = 154,
#[runtimes(opal)]
TestUtils: pallet_test_utils = 255,
test-pallets/utils/Cargo.tomldiffbeforeafterboth--- a/test-pallets/utils/Cargo.toml
+++ b/test-pallets/utils/Cargo.toml
@@ -10,7 +10,8 @@
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
-pallet-unique-scheduler = { path = '../../pallets/scheduler', default-features = false }
+# pallet-unique-scheduler = { path = '../../pallets/scheduler', default-features = false }
+pallet-unique-scheduler-v2 = { path = '../../pallets/scheduler-v2', default-features = false }
[features]
default = ["std"]
@@ -19,6 +20,6 @@
"scale-info/std",
"frame-support/std",
"frame-system/std",
- "pallet-unique-scheduler/std",
+ "pallet-unique-scheduler-v2/std",
]
try-runtime = ["frame-support/try-runtime", "pallet-unique-scheduler/try-runtime"]
test-pallets/utils/src/lib.rsdiffbeforeafterboth--- a/test-pallets/utils/src/lib.rs
+++ b/test-pallets/utils/src/lib.rs
@@ -24,7 +24,7 @@
pub mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
- use pallet_unique_scheduler::{ScheduledId, Pallet as SchedulerPallet};
+ use pallet_unique_scheduler_v2::{TaskName, Pallet as SchedulerPallet};
#[pallet::config]
pub trait Config: frame_system::Config + pallet_unique_scheduler::Config {
@@ -94,7 +94,7 @@
#[pallet::weight(10_000)]
pub fn self_canceling_inc(
origin: OriginFor<T>,
- id: ScheduledId,
+ id: TaskName,
max_test_value: u32,
) -> DispatchResult {
Self::ensure_origin_and_enabled(origin.clone())?;