git.delta.rocks / unique-network / refs/commits / d1cb9dcf372b

difftreelog

fix enable scheduler v2

Daniel Shiposha2022-10-20parent: #6930406.patch.diff
in: master

6 files changed

modifiedpallets/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);
 }
modifiedpallets/scheduler-v2/src/lib.rsdiffbeforeafterboth
--- a/pallets/scheduler-v2/src/lib.rs
+++ b/pallets/scheduler-v2/src/lib.rs
@@ -77,22 +77,17 @@
 
 use codec::{Codec, Decode, Encode, MaxEncodedLen};
 use frame_support::{
-	dispatch::{
-		DispatchError, DispatchResult, Dispatchable, GetDispatchInfo, Parameter, RawOrigin,
-	},
-	ensure,
+	dispatch::{DispatchError, DispatchResult, Dispatchable, GetDispatchInfo, Parameter},
 	traits::{
 		schedule::{self, DispatchTime},
-		EnsureOrigin, Get, IsType, OriginTrait,
-		PalletInfoAccess, PrivilegeCmp, StorageVersion,
-        PreimageProvider, PreimageRecipient, ConstU32,
+		EnsureOrigin, Get, IsType, OriginTrait, PrivilegeCmp, StorageVersion, PreimageRecipient,
+		ConstU32,
 	},
 	weights::Weight,
 };
 
 use frame_system::{self as system};
 use scale_info::TypeInfo;
-use sp_io::hashing::blake2_256;
 use sp_runtime::{
 	traits::{BadOrigin, One, Saturating, Zero, Hash},
 	BoundedVec, RuntimeDebug,
@@ -112,11 +107,8 @@
 #[derive(Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)]
 #[scale_info(skip_type_params(T))]
 pub enum ScheduledCall<T: Config> {
-    Inline(EncodedCall),
-    PreimageLookup {
-        hash: T::Hash,
-        unbounded_len: u32,
-    },
+	Inline(EncodedCall),
+	PreimageLookup { hash: T::Hash, unbounded_len: u32 },
 }
 
 impl<T: Config> ScheduledCall<T> {
@@ -128,9 +120,16 @@
 			Ok(bounded) => Ok(Self::Inline(bounded)),
 			Err(_) => {
 				let hash = <T as system::Config>::Hashing::hash_of(&encoded);
-				<T as Config>::Preimages::note_preimage(encoded.try_into().map_err(|_| <Error<T>>::TooBigScheduledCall)?);
+				<T as Config>::Preimages::note_preimage(
+					encoded
+						.try_into()
+						.map_err(|_| <Error<T>>::TooBigScheduledCall)?,
+				);
 
-				Ok(Self::PreimageLookup { hash, unbounded_len: len as u32 })
+				Ok(Self::PreimageLookup {
+					hash,
+					unbounded_len: len as u32,
+				})
 			}
 		}
 	}
@@ -153,43 +152,54 @@
 
 	fn decode(mut data: &[u8]) -> Result<<T as Config>::Call, DispatchError> {
 		<T as Config>::Call::decode(&mut data)
-				.map_err(|_| <Error<T>>::ScheduledCallCorrupted.into())
+			.map_err(|_| <Error<T>>::ScheduledCallCorrupted.into())
 	}
 }
 
 pub trait SchedulerPreimages<T: Config>: PreimageRecipient<T::Hash> {
-    fn drop(call: &ScheduledCall<T>);
+	fn drop(call: &ScheduledCall<T>);
 
-	fn peek(call: &ScheduledCall<T>) -> Result<(<T as pallet::Config>::Call, Option<u32>), DispatchError>;
+	fn peek(
+		call: &ScheduledCall<T>,
+	) -> Result<(<T as pallet::Config>::Call, Option<u32>), DispatchError>;
 
 	/// Convert the given scheduled `call` value back into its original instance. If successful,
 	/// `drop` any data backing it. This will not break the realisability of independently
 	/// created instances of `ScheduledCall` which happen to have identical data.
-	fn realize(call: &ScheduledCall<T>) -> Result<(<T as pallet::Config>::Call, Option<u32>), DispatchError>;
+	fn realize(
+		call: &ScheduledCall<T>,
+	) -> Result<(<T as pallet::Config>::Call, Option<u32>), DispatchError>;
 }
 
 impl<T: Config, PP: PreimageRecipient<T::Hash>> SchedulerPreimages<T> for PP {
-    fn drop(call: &ScheduledCall<T>) {
-        match call {
-            ScheduledCall::Inline(_) => {},
-            ScheduledCall::PreimageLookup { hash, .. } => Self::unrequest_preimage(hash),
-        }
-    }
+	fn drop(call: &ScheduledCall<T>) {
+		match call {
+			ScheduledCall::Inline(_) => {}
+			ScheduledCall::PreimageLookup { hash, .. } => Self::unrequest_preimage(hash),
+		}
+	}
 
-	fn peek(call: &ScheduledCall<T>) -> Result<(<T as pallet::Config>::Call, Option<u32>), DispatchError> {
+	fn peek(
+		call: &ScheduledCall<T>,
+	) -> Result<(<T as pallet::Config>::Call, Option<u32>), DispatchError> {
 		match call {
 			ScheduledCall::Inline(data) => Ok((ScheduledCall::<T>::decode(data)?, None)),
-			ScheduledCall::PreimageLookup { hash, unbounded_len } => {
+			ScheduledCall::PreimageLookup {
+				hash,
+				unbounded_len,
+			} => {
 				let (preimage, len) = Self::get_preimage(hash)
 					.ok_or(<Error<T>>::PreimageNotFound)
 					.map(|preimage| (preimage, *unbounded_len))?;
 
 				Ok((ScheduledCall::<T>::decode(preimage.as_slice())?, Some(len)))
-			},
+			}
 		}
 	}
 
-	fn realize(call: &ScheduledCall<T>) -> Result<(<T as pallet::Config>::Call, Option<u32>), DispatchError> {
+	fn realize(
+		call: &ScheduledCall<T>,
+	) -> Result<(<T as pallet::Config>::Call, Option<u32>), DispatchError> {
 		let r = Self::peek(call)?;
 		Self::drop(call);
 		Ok(r)
@@ -205,16 +215,16 @@
 	/// The unique identity for this task, if there is one.
 	maybe_id: Option<Name>,
 
-    /// This task's priority.
+	/// This task's priority.
 	priority: schedule::Priority,
 
-    /// The call to be dispatched.
+	/// The call to be dispatched.
 	call: Call,
 
-    /// If the call is periodic, then this points to the information concerning that.
+	/// If the call is periodic, then this points to the information concerning that.
 	maybe_periodic: Option<schedule::Period<BlockNumber>>,
 
-    /// The origin with which to dispatch the call.
+	/// The origin with which to dispatch the call.
 	origin: PalletsOrigin,
 	_phantom: PhantomData<AccountId>,
 }
@@ -276,68 +286,66 @@
 	/// The current storage version.
 	const STORAGE_VERSION: StorageVersion = StorageVersion::new(0);
 
-    #[pallet::pallet]
+	#[pallet::pallet]
 	#[pallet::generate_store(pub(super) trait Store)]
 	#[pallet::storage_version(STORAGE_VERSION)]
 	pub struct Pallet<T>(_);
 
 	#[pallet::config]
 	pub trait Config: frame_system::Config {
-        type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
+		type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
 
-        /// The aggregated origin which the dispatch will take.
+		/// The aggregated origin which the dispatch will take.
 		type Origin: OriginTrait<PalletsOrigin = Self::PalletsOrigin>
-            + From<Self::PalletsOrigin>
-            + IsType<<Self as system::Config>::Origin>
+			+ From<Self::PalletsOrigin>
+			+ IsType<<Self as system::Config>::Origin>
 			+ Clone;
 
-        /// The caller origin, overarching type of all pallets origins.
-        type PalletsOrigin: From<system::RawOrigin<Self::AccountId>>
-            + Codec
-            + Clone
-            + Eq
-            + TypeInfo
-            + MaxEncodedLen;
+		/// The caller origin, overarching type of all pallets origins.
+		type PalletsOrigin: From<system::RawOrigin<Self::AccountId>>
+			+ Codec
+			+ Clone
+			+ Eq
+			+ TypeInfo
+			+ MaxEncodedLen;
 
-        /// The aggregated call type.
-        type Call: Parameter
-            + Dispatchable<
-                Origin = <Self as Config>::Origin,
-                PostInfo = PostDispatchInfo,
-            > + GetDispatchInfo
-            + From<system::Call<Self>>;
+		/// The aggregated call type.
+		type Call: Parameter
+			+ Dispatchable<Origin = <Self as Config>::Origin, PostInfo = PostDispatchInfo>
+			+ GetDispatchInfo
+			+ From<system::Call<Self>>;
 
-        /// The maximum weight that may be scheduled per block for any dispatchables.
-        #[pallet::constant]
-        type MaximumWeight: Get<Weight>;
+		/// The maximum weight that may be scheduled per block for any dispatchables.
+		#[pallet::constant]
+		type MaximumWeight: Get<Weight>;
 
-        /// Required origin to schedule or cancel calls.
-        type ScheduleOrigin: EnsureOrigin<<Self as system::Config>::Origin>;
+		/// Required origin to schedule or cancel calls.
+		type ScheduleOrigin: EnsureOrigin<<Self as system::Config>::Origin>;
 
-        /// Compare the privileges of origins.
-        ///
-        /// This will be used when canceling a task, to ensure that the origin that tries
-        /// to cancel has greater or equal privileges as the origin that created the scheduled task.
-        ///
-        /// For simplicity the [`EqualPrivilegeOnly`](frame_support::traits::EqualPrivilegeOnly) can
-        /// be used. This will only check if two given origins are equal.
-        type OriginPrivilegeCmp: PrivilegeCmp<Self::PalletsOrigin>;
+		/// Compare the privileges of origins.
+		///
+		/// This will be used when canceling a task, to ensure that the origin that tries
+		/// to cancel has greater or equal privileges as the origin that created the scheduled task.
+		///
+		/// For simplicity the [`EqualPrivilegeOnly`](frame_support::traits::EqualPrivilegeOnly) can
+		/// be used. This will only check if two given origins are equal.
+		type OriginPrivilegeCmp: PrivilegeCmp<Self::PalletsOrigin>;
 
-        /// The maximum number of scheduled calls in the queue for a single block.
-        #[pallet::constant]
-        type MaxScheduledPerBlock: Get<u32>;
+		/// The maximum number of scheduled calls in the queue for a single block.
+		#[pallet::constant]
+		type MaxScheduledPerBlock: Get<u32>;
 
-        /// Weight information for extrinsics in this pallet.
-        type WeightInfo: WeightInfo;
+		/// Weight information for extrinsics in this pallet.
+		type WeightInfo: WeightInfo;
 
-        /// The preimage provider with which we look up call hashes to get the call.
+		/// The preimage provider with which we look up call hashes to get the call.
 		type Preimages: SchedulerPreimages<Self>;
-    }
+	}
 
-    #[pallet::storage]
+	#[pallet::storage]
 	pub type IncompleteSince<T: Config> = StorageValue<_, T::BlockNumber>;
 
-    /// Items to be executed, indexed by the block number that they should be executed on.
+	/// Items to be executed, indexed by the block number that they should be executed on.
 	#[pallet::storage]
 	pub type Agenda<T: Config> = StorageMap<
 		_,
@@ -347,12 +355,12 @@
 		ValueQuery,
 	>;
 
-    /// Lookup from a name to the block number and index of the task.
+	/// Lookup from a name to the block number and index of the task.
 	#[pallet::storage]
 	pub(crate) type Lookup<T: Config> =
 		StorageMap<_, Twox64Concat, TaskName, TaskAddress<T::BlockNumber>>;
 
-    /// Events type.
+	/// Events type.
 	#[pallet::event]
 	#[pallet::generate_deposit(pub(super) fn deposit_event)]
 	pub enum Event<T: Config> {
@@ -367,19 +375,28 @@
 			result: DispatchResult,
 		},
 		/// The call for the provided hash was not found so the task has been aborted.
-		CallUnavailable { task: TaskAddress<T::BlockNumber>, id: Option<[u8; 32]> },
+		CallUnavailable {
+			task: TaskAddress<T::BlockNumber>,
+			id: Option<[u8; 32]>,
+		},
 		/// The given task was unable to be renewed since the agenda is full at that block.
-		PeriodicFailed { task: TaskAddress<T::BlockNumber>, id: Option<[u8; 32]> },
+		PeriodicFailed {
+			task: TaskAddress<T::BlockNumber>,
+			id: Option<[u8; 32]>,
+		},
 		/// The given task can never be executed since it is overweight.
-		PermanentlyOverweight { task: TaskAddress<T::BlockNumber>, id: Option<[u8; 32]> },
+		PermanentlyOverweight {
+			task: TaskAddress<T::BlockNumber>,
+			id: Option<[u8; 32]>,
+		},
 	}
 
-    #[pallet::error]
+	#[pallet::error]
 	pub enum Error<T> {
 		/// Failed to schedule a call
 		FailedToSchedule,
-        /// There is no place for a new task in the agenda
-        AgendaIsExhausted,
+		/// There is no place for a new task in the agenda
+		AgendaIsExhausted,
 		/// Scheduled call is corrupted
 		ScheduledCallCorrupted,
 		/// Scheduled call preimage is not found
@@ -396,20 +413,22 @@
 		Named,
 	}
 
-    #[pallet::hooks]
+	#[pallet::hooks]
 	impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
 		/// Execute the scheduled calls
 		fn on_initialize(now: T::BlockNumber) -> Weight {
-			let mut weight_counter =
-				WeightCounter { used: Weight::zero(), limit: T::MaximumWeight::get() };
+			let mut weight_counter = WeightCounter {
+				used: Weight::zero(),
+				limit: T::MaximumWeight::get(),
+			};
 			Self::service_agendas(&mut weight_counter, now, u32::max_value());
 			weight_counter.used
 		}
 	}
 
-    #[pallet::call]
+	#[pallet::call]
 	impl<T: Config> Pallet<T> {
-        /// Anonymously schedule a task.
+		/// Anonymously schedule a task.
 		#[pallet::weight(<T as Config>::WeightInfo::schedule(T::MaxScheduledPerBlock::get()))]
 		pub fn schedule(
 			origin: OriginFor<T>,
@@ -522,11 +541,11 @@
 			)?;
 			Ok(())
 		}
-    }
+	}
 }
 
 impl<T: Config> Pallet<T> {
-    fn resolve_time(when: DispatchTime<T::BlockNumber>) -> Result<T::BlockNumber, DispatchError> {
+	fn resolve_time(when: DispatchTime<T::BlockNumber>) -> Result<T::BlockNumber, DispatchError> {
 		let now = frame_system::Pallet::<T>::block_number();
 
 		let when = match when {
@@ -537,13 +556,13 @@
 		};
 
 		if when <= now {
-			return Err(Error::<T>::TargetBlockNumberInPast.into())
+			return Err(Error::<T>::TargetBlockNumberInPast.into());
 		}
 
 		Ok(when)
 	}
 
-    fn place_task(
+	fn place_task(
 		when: T::BlockNumber,
 		what: ScheduledOf<T>,
 	) -> Result<TaskAddress<T::BlockNumber>, (DispatchError, ScheduledOf<T>)> {
@@ -553,11 +572,14 @@
 		if let Some(name) = maybe_name {
 			Lookup::<T>::insert(name, address)
 		}
-		Self::deposit_event(Event::Scheduled { when: address.0, index: address.1 });
+		Self::deposit_event(Event::Scheduled {
+			when: address.0,
+			index: address.1,
+		});
 		Ok(address)
 	}
 
-    fn push_to_agenda(
+	fn push_to_agenda(
 		when: T::BlockNumber,
 		what: ScheduledOf<T>,
 	) -> Result<u32, (DispatchError, ScheduledOf<T>)> {
@@ -571,14 +593,14 @@
 				agenda[hole_index] = Some(what);
 				hole_index as u32
 			} else {
-				return Err((<Error<T>>::AgendaIsExhausted.into(), what))
+				return Err((<Error<T>>::AgendaIsExhausted.into(), what));
 			}
 		};
 		Agenda::<T>::insert(when, agenda);
 		Ok(index)
 	}
 
-    fn do_schedule(
+	fn do_schedule(
 		when: DispatchTime<T::BlockNumber>,
 		maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
 		priority: schedule::Priority,
@@ -603,7 +625,7 @@
 		Self::place_task(when, task).map_err(|x| x.0)
 	}
 
-    fn do_cancel(
+	fn do_cancel(
 		origin: Option<T::PalletsOrigin>,
 		(when, index): TaskAddress<T::BlockNumber>,
 	) -> Result<(), DispatchError> {
@@ -616,7 +638,7 @@
 							T::OriginPrivilegeCmp::cmp_privilege(o, &s.origin),
 							Some(Ordering::Less) | None
 						) {
-							return Err(BadOrigin.into())
+							return Err(BadOrigin.into());
 						}
 					};
 					Ok(s.take())
@@ -624,7 +646,7 @@
 			)
 		})?;
 		if let Some(s) = scheduled {
-            T::Preimages::drop(&s.call);
+			T::Preimages::drop(&s.call);
 
 			if let Some(id) = s.maybe_id {
 				Lookup::<T>::remove(id);
@@ -632,11 +654,11 @@
 			Self::deposit_event(Event::Canceled { when, index });
 			Ok(())
 		} else {
-			return Err(Error::<T>::NotFound.into())
+			return Err(Error::<T>::NotFound.into());
 		}
 	}
 
-    fn do_schedule_named(
+	fn do_schedule_named(
 		id: TaskName,
 		when: DispatchTime<T::BlockNumber>,
 		maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
@@ -646,7 +668,7 @@
 	) -> Result<TaskAddress<T::BlockNumber>, DispatchError> {
 		// ensure id it is unique
 		if Lookup::<T>::contains_key(&id) {
-			return Err(Error::<T>::FailedToSchedule.into())
+			return Err(Error::<T>::FailedToSchedule.into());
 		}
 
 		let when = Self::resolve_time(when)?;
@@ -668,7 +690,7 @@
 		Self::place_task(when, task).map_err(|x| x.0)
 	}
 
-    fn do_cancel_named(origin: Option<T::PalletsOrigin>, id: TaskName) -> DispatchResult {
+	fn do_cancel_named(origin: Option<T::PalletsOrigin>, id: TaskName) -> DispatchResult {
 		Lookup::<T>::try_mutate_exists(id, |lookup| -> DispatchResult {
 			if let Some((when, index)) = lookup.take() {
 				let i = index as usize;
@@ -679,7 +701,7 @@
 								T::OriginPrivilegeCmp::cmp_privilege(o, &s.origin),
 								Some(Ordering::Less) | None
 							) {
-								return Err(BadOrigin.into())
+								return Err(BadOrigin.into());
 							}
 							T::Preimages::drop(&s.call);
 						}
@@ -690,7 +712,7 @@
 				Self::deposit_event(Event::Canceled { when, index });
 				Ok(())
 			} else {
-				return Err(Error::<T>::NotFound.into())
+				return Err(Error::<T>::NotFound.into());
 			}
 		})
 	}
@@ -708,7 +730,7 @@
 	/// Service up to `max` agendas queue starting from earliest incompletely executed agenda.
 	fn service_agendas(weight: &mut WeightCounter, now: T::BlockNumber, max: u32) {
 		if !weight.check_accrue(T::WeightInfo::service_agendas_base()) {
-			return
+			return;
 		}
 
 		let mut incomplete_since = now + One::one();
@@ -745,13 +767,18 @@
 			.iter()
 			.enumerate()
 			.filter_map(|(index, maybe_item)| {
-				maybe_item.as_ref().map(|item| (index as u32, item.priority))
+				maybe_item
+					.as_ref()
+					.map(|item| (index as u32, item.priority))
 			})
 			.collect::<Vec<_>>();
 		ordered.sort_by_key(|k| k.1);
 		let within_limit =
 			weight.check_accrue(T::WeightInfo::service_agenda_base(ordered.len() as u32));
-		debug_assert!(within_limit, "weight limit should have been checked in advance");
+		debug_assert!(
+			within_limit,
+			"weight limit should have been checked in advance"
+		);
 
 		// Items which we know can be executed and have postponed for execution in a later block.
 		let mut postponed = (ordered.len() as u32).saturating_sub(max);
@@ -770,22 +797,22 @@
 			);
 			if !weight.can_accrue(base_weight) {
 				postponed += 1;
-				break
+				break;
 			}
 			let result = Self::service_task(weight, now, when, agenda_index, *executed == 0, task);
 			agenda[agenda_index as usize] = match result {
 				Err((Unavailable, slot)) => {
 					dropped += 1;
 					slot
-				},
+				}
 				Err((Overweight, slot)) => {
 					postponed += 1;
 					slot
-				},
+				}
 				Ok(()) => {
 					*executed += 1;
 					None
-				},
+				}
 			};
 		}
 		if postponed > 0 || dropped > 0 {
@@ -833,7 +860,7 @@
 					id: task.maybe_id,
 				});
 				Err((Unavailable, Some(task)))
-			},
+			}
 			Err(Overweight) if is_first => {
 				T::Preimages::drop(&task.call);
 				Self::deposit_event(Event::PermanentlyOverweight {
@@ -841,7 +868,7 @@
 					id: task.maybe_id,
 				});
 				Err((Unavailable, Some(task)))
-			},
+			}
 			Err(Overweight) => Err((Overweight, Some(task))),
 			Ok(result) => {
 				Self::deposit_event(Event::Dispatched {
@@ -857,7 +884,7 @@
 					}
 					let wake = now.saturating_add(period);
 					match Self::place_task(wake, task) {
-						Ok(_) => {},
+						Ok(_) => {}
 						Err((_, task)) => {
 							// TODO: Leave task in storage somewhere for it to be rescheduled
 							// manually.
@@ -866,13 +893,13 @@
 								task: (when, agenda_index),
 								id: task.maybe_id,
 							});
-						},
+						}
 					}
 				} else {
 					T::Preimages::drop(&task.call);
 				}
 				Ok(())
-			},
+			}
 		}
 	}
 
@@ -897,13 +924,15 @@
 		let max_weight = base_weight.saturating_add(call_weight);
 
 		if !weight.can_accrue(max_weight) {
-			return Err(Overweight)
+			return Err(Overweight);
 		}
 
 		let (maybe_actual_call_weight, result) = match call.dispatch(dispatch_origin) {
 			Ok(post_info) => (post_info.actual_weight, Ok(())),
-			Err(error_and_info) =>
-				(error_and_info.post_info.actual_weight, Err(error_and_info.error)),
+			Err(error_and_info) => (
+				error_and_info.post_info.actual_weight,
+				Err(error_and_info.error),
+			),
 		};
 		let call_weight = maybe_actual_call_weight.unwrap_or(call_weight);
 		weight.check_accrue(base_weight);
modifiedruntime/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;
modifiedruntime/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,
modifiedtest-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"]
modifiedtest-pallets/utils/src/lib.rsdiffbeforeafterboth
before · test-pallets/utils/src/lib.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819pub use pallet::*;20use frame_support::pallet_prelude::*;21use frame_system::pallet_prelude::*;2223#[frame_support::pallet]24pub mod pallet {25	use frame_support::pallet_prelude::*;26	use frame_system::pallet_prelude::*;27	use pallet_unique_scheduler::{ScheduledId, Pallet as SchedulerPallet};2829	#[pallet::config]30	pub trait Config: frame_system::Config + pallet_unique_scheduler::Config {31		type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;32	}3334	#[pallet::event]35	#[pallet::generate_deposit(pub(super) fn deposit_event)]36	pub enum Event<T: Config> {37		ValueIsSet,38		ShouldRollback,39	}4041	#[pallet::pallet]42	#[pallet::generate_store(pub(super) trait Store)]43	pub struct Pallet<T>(_);4445	#[pallet::storage]46	#[pallet::getter(fn is_enabled)]47	pub type Enabled<T> = StorageValue<_, bool, ValueQuery>;4849	#[pallet::storage]50	#[pallet::getter(fn test_value)]51	pub type TestValue<T> = StorageValue<_, u32, ValueQuery>;5253	#[pallet::error]54	pub enum Error<T> {55		TestPalletDisabled,56		TriggerRollback,57	}5859	#[pallet::call]60	impl<T: Config> Pallet<T> {61		#[pallet::weight(10_000)]62		pub fn enable(origin: OriginFor<T>) -> DispatchResult {63			ensure_root(origin)?;64			<Enabled<T>>::set(true);6566			Ok(())67		}6869		#[pallet::weight(10_000)]70		pub fn set_test_value(origin: OriginFor<T>, value: u32) -> DispatchResult {71			Self::ensure_origin_and_enabled(origin)?;7273			<TestValue<T>>::put(value);7475			Self::deposit_event(Event::ValueIsSet);7677			Ok(())78		}7980		#[pallet::weight(10_000)]81		pub fn set_test_value_and_rollback(origin: OriginFor<T>, value: u32) -> DispatchResult {82			Self::set_test_value(origin, value)?;8384			Self::deposit_event(Event::ShouldRollback);8586			Err(<Error<T>>::TriggerRollback.into())87		}8889		#[pallet::weight(10_000)]90		pub fn inc_test_value(origin: OriginFor<T>) -> DispatchResult {91			Self::set_test_value(origin, <TestValue<T>>::get() + 1)92		}9394		#[pallet::weight(10_000)]95		pub fn self_canceling_inc(96			origin: OriginFor<T>,97			id: ScheduledId,98			max_test_value: u32,99		) -> DispatchResult {100			Self::ensure_origin_and_enabled(origin.clone())?;101102			if <TestValue<T>>::get() < max_test_value {103				Self::inc_test_value(origin)?;104			} else {105				SchedulerPallet::<T>::cancel_named(origin, id)?;106			}107108			Ok(())109		}110111		#[pallet::weight(100_000_000)]112		pub fn just_take_fee(origin: OriginFor<T>) -> DispatchResult {113			Self::ensure_origin_and_enabled(origin)?;114			Ok(())115		}116	}117}118119impl<T: Config> Pallet<T> {120	fn ensure_origin_and_enabled(origin: OriginFor<T>) -> DispatchResult {121		ensure_signed(origin)?;122		<Enabled<T>>::get()123			.then(|| ())124			.ok_or(<Error<T>>::TestPalletDisabled.into())125	}126}
after · test-pallets/utils/src/lib.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819pub use pallet::*;20use frame_support::pallet_prelude::*;21use frame_system::pallet_prelude::*;2223#[frame_support::pallet]24pub mod pallet {25	use frame_support::pallet_prelude::*;26	use frame_system::pallet_prelude::*;27	use pallet_unique_scheduler_v2::{TaskName, Pallet as SchedulerPallet};2829	#[pallet::config]30	pub trait Config: frame_system::Config + pallet_unique_scheduler::Config {31		type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;32	}3334	#[pallet::event]35	#[pallet::generate_deposit(pub(super) fn deposit_event)]36	pub enum Event<T: Config> {37		ValueIsSet,38		ShouldRollback,39	}4041	#[pallet::pallet]42	#[pallet::generate_store(pub(super) trait Store)]43	pub struct Pallet<T>(_);4445	#[pallet::storage]46	#[pallet::getter(fn is_enabled)]47	pub type Enabled<T> = StorageValue<_, bool, ValueQuery>;4849	#[pallet::storage]50	#[pallet::getter(fn test_value)]51	pub type TestValue<T> = StorageValue<_, u32, ValueQuery>;5253	#[pallet::error]54	pub enum Error<T> {55		TestPalletDisabled,56		TriggerRollback,57	}5859	#[pallet::call]60	impl<T: Config> Pallet<T> {61		#[pallet::weight(10_000)]62		pub fn enable(origin: OriginFor<T>) -> DispatchResult {63			ensure_root(origin)?;64			<Enabled<T>>::set(true);6566			Ok(())67		}6869		#[pallet::weight(10_000)]70		pub fn set_test_value(origin: OriginFor<T>, value: u32) -> DispatchResult {71			Self::ensure_origin_and_enabled(origin)?;7273			<TestValue<T>>::put(value);7475			Self::deposit_event(Event::ValueIsSet);7677			Ok(())78		}7980		#[pallet::weight(10_000)]81		pub fn set_test_value_and_rollback(origin: OriginFor<T>, value: u32) -> DispatchResult {82			Self::set_test_value(origin, value)?;8384			Self::deposit_event(Event::ShouldRollback);8586			Err(<Error<T>>::TriggerRollback.into())87		}8889		#[pallet::weight(10_000)]90		pub fn inc_test_value(origin: OriginFor<T>) -> DispatchResult {91			Self::set_test_value(origin, <TestValue<T>>::get() + 1)92		}9394		#[pallet::weight(10_000)]95		pub fn self_canceling_inc(96			origin: OriginFor<T>,97			id: TaskName,98			max_test_value: u32,99		) -> DispatchResult {100			Self::ensure_origin_and_enabled(origin.clone())?;101102			if <TestValue<T>>::get() < max_test_value {103				Self::inc_test_value(origin)?;104			} else {105				SchedulerPallet::<T>::cancel_named(origin, id)?;106			}107108			Ok(())109		}110111		#[pallet::weight(100_000_000)]112		pub fn just_take_fee(origin: OriginFor<T>) -> DispatchResult {113			Self::ensure_origin_and_enabled(origin)?;114			Ok(())115		}116	}117}118119impl<T: Config> Pallet<T> {120	fn ensure_origin_and_enabled(origin: OriginFor<T>) -> DispatchResult {121		ensure_signed(origin)?;122		<Enabled<T>>::get()123			.then(|| ())124			.ok_or(<Error<T>>::TestPalletDisabled.into())125	}126}