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

difftreelog

fix scheduler v2 after rebase

Daniel Shiposha2022-10-24parent: #40ae5ae.patch.diff
in: master

4 files changed

modifiedpallets/scheduler-v2/Cargo.tomldiffbeforeafterboth
--- a/pallets/scheduler-v2/Cargo.toml
+++ b/pallets/scheduler-v2/Cargo.toml
@@ -13,18 +13,18 @@
 codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
 log = { version = "0.4.17", default-features = false }
 scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
-frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }
-frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }
-frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }
-sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }
-sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }
-sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }
-sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }
+frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
+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" }
+sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
+sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
+sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
+sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
 
 [dev-dependencies]
-pallet-preimage = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }
-sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }
-substrate-test-utils = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }
+pallet-preimage = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
+sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
+substrate-test-utils = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
 
 [features]
 default = ["std"]
modifiedpallets/scheduler-v2/src/lib.rsdiffbeforeafterboth
--- a/pallets/scheduler-v2/src/lib.rs
+++ b/pallets/scheduler-v2/src/lib.rs
@@ -113,7 +113,7 @@
 }
 
 impl<T: Config> ScheduledCall<T> {
-	pub fn new(call: <T as Config>::Call) -> Result<Self, DispatchError> {
+	pub fn new(call: <T as Config>::RuntimeCall) -> Result<Self, DispatchError> {
 		let encoded = call.encode();
 		let len = encoded.len();
 
@@ -151,8 +151,8 @@
 		}
 	}
 
-	fn decode(mut data: &[u8]) -> Result<<T as Config>::Call, DispatchError> {
-		<T as Config>::Call::decode(&mut data)
+	fn decode(mut data: &[u8]) -> Result<<T as Config>::RuntimeCall, DispatchError> {
+		<T as Config>::RuntimeCall::decode(&mut data)
 			.map_err(|_| <Error<T>>::ScheduledCallCorrupted.into())
 	}
 }
@@ -162,14 +162,14 @@
 
 	fn peek(
 		call: &ScheduledCall<T>,
-	) -> Result<(<T as pallet::Config>::Call, Option<u32>), DispatchError>;
+	) -> Result<(<T as pallet::Config>::RuntimeCall, 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>;
+	) -> Result<(<T as pallet::Config>::RuntimeCall, Option<u32>), DispatchError>;
 }
 
 impl<T: Config, PP: PreimageRecipient<T::Hash>> SchedulerPreimages<T> for PP {
@@ -182,7 +182,7 @@
 
 	fn peek(
 		call: &ScheduledCall<T>,
-	) -> Result<(<T as pallet::Config>::Call, Option<u32>), DispatchError> {
+	) -> Result<(<T as pallet::Config>::RuntimeCall, Option<u32>), DispatchError> {
 		match call {
 			ScheduledCall::Inline(data) => Ok((ScheduledCall::<T>::decode(data)?, None)),
 			ScheduledCall::PreimageLookup {
@@ -200,7 +200,7 @@
 
 	fn realize(
 		call: &ScheduledCall<T>,
-	) -> Result<(<T as pallet::Config>::Call, Option<u32>), DispatchError> {
+	) -> Result<(<T as pallet::Config>::RuntimeCall, Option<u32>), DispatchError> {
 		let r = Self::peek(call)?;
 		Self::drop(call);
 		Ok(r)
@@ -252,7 +252,7 @@
 impl WeightCounter {
 	fn check_accrue(&mut self, w: Weight) -> bool {
 		let test = self.used.saturating_add(w);
-		if test > self.limit {
+		if test.any_gt(self.limit) {
 			false
 		} else {
 			self.used = test;
@@ -261,7 +261,7 @@
 	}
 
 	fn can_accrue(&mut self, w: Weight) -> bool {
-		self.used.saturating_add(w) <= self.limit
+		self.used.saturating_add(w).all_lte(self.limit)
 	}
 }
 
@@ -300,12 +300,12 @@
 
 	#[pallet::config]
 	pub trait Config: frame_system::Config {
-		type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
+		type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
 
 		/// The aggregated origin which the dispatch will take.
-		type Origin: OriginTrait<PalletsOrigin = Self::PalletsOrigin>
+		type RuntimeOrigin: OriginTrait<PalletsOrigin = Self::PalletsOrigin>
 			+ From<Self::PalletsOrigin>
-			+ IsType<<Self as system::Config>::Origin>
+			+ IsType<<Self as system::Config>::RuntimeOrigin>
 			+ Clone;
 
 		/// The caller origin, overarching type of all pallets origins.
@@ -317,9 +317,9 @@
 			+ MaxEncodedLen;
 
 		/// The aggregated call type.
-		type Call: Parameter
-			+ Dispatchable<Origin = <Self as Config>::Origin, PostInfo = PostDispatchInfo>
-			+ UnfilteredDispatchable<Origin = <Self as system::Config>::Origin>
+		type RuntimeCall: Parameter
+			+ Dispatchable<RuntimeOrigin = <Self as Config>::RuntimeOrigin, PostInfo = PostDispatchInfo>
+			+ UnfilteredDispatchable<RuntimeOrigin = <Self as system::Config>::RuntimeOrigin>
 			+ GetDispatchInfo
 			+ From<system::Call<Self>>;
 
@@ -329,7 +329,7 @@
 
 		/// Required origin to schedule or cancel calls.
 		type ScheduleOrigin: EnsureOrigin<
-			<Self as system::Config>::Origin,
+			<Self as system::Config>::RuntimeOrigin,
 			Success = ScheduledEnsureOriginSuccess<Self::AccountId>,
 		>;
 
@@ -356,7 +356,7 @@
 		type CallExecutor: DispatchCall<Self, H160>;
 
 		/// Required origin to set/change calls' priority.
-		type PrioritySetOrigin: EnsureOrigin<<Self as system::Config>::Origin>;
+		type PrioritySetOrigin: EnsureOrigin<<Self as system::Config>::RuntimeOrigin>;
 	}
 
 	#[pallet::storage]
@@ -458,7 +458,7 @@
 			when: T::BlockNumber,
 			maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
 			priority: Option<schedule::Priority>,
-			call: Box<<T as Config>::Call>,
+			call: Box<<T as Config>::RuntimeCall>,
 		) -> DispatchResult {
 			T::ScheduleOrigin::ensure_origin(origin.clone())?;
 
@@ -466,7 +466,7 @@
 				T::PrioritySetOrigin::ensure_origin(origin.clone())?;
 			}
 
-			let origin = <T as Config>::Origin::from(origin);
+			let origin = <T as Config>::RuntimeOrigin::from(origin);
 			Self::do_schedule(
 				DispatchTime::At(when),
 				maybe_periodic,
@@ -481,7 +481,7 @@
 		#[pallet::weight(<T as Config>::WeightInfo::cancel(T::MaxScheduledPerBlock::get()))]
 		pub fn cancel(origin: OriginFor<T>, when: T::BlockNumber, index: u32) -> DispatchResult {
 			T::ScheduleOrigin::ensure_origin(origin.clone())?;
-			let origin = <T as Config>::Origin::from(origin);
+			let origin = <T as Config>::RuntimeOrigin::from(origin);
 			Self::do_cancel(Some(origin.caller().clone()), (when, index))?;
 			Ok(())
 		}
@@ -494,7 +494,7 @@
 			when: T::BlockNumber,
 			maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
 			priority: Option<schedule::Priority>,
-			call: Box<<T as Config>::Call>,
+			call: Box<<T as Config>::RuntimeCall>,
 		) -> DispatchResult {
 			T::ScheduleOrigin::ensure_origin(origin.clone())?;
 
@@ -502,7 +502,7 @@
 				T::PrioritySetOrigin::ensure_origin(origin.clone())?;
 			}
 
-			let origin = <T as Config>::Origin::from(origin);
+			let origin = <T as Config>::RuntimeOrigin::from(origin);
 			Self::do_schedule_named(
 				id,
 				DispatchTime::At(when),
@@ -518,7 +518,7 @@
 		#[pallet::weight(<T as Config>::WeightInfo::cancel_named(T::MaxScheduledPerBlock::get()))]
 		pub fn cancel_named(origin: OriginFor<T>, id: TaskName) -> DispatchResult {
 			T::ScheduleOrigin::ensure_origin(origin.clone())?;
-			let origin = <T as Config>::Origin::from(origin);
+			let origin = <T as Config>::RuntimeOrigin::from(origin);
 			Self::do_cancel_named(Some(origin.caller().clone()), id)?;
 			Ok(())
 		}
@@ -534,7 +534,7 @@
 			after: T::BlockNumber,
 			maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
 			priority: Option<schedule::Priority>,
-			call: Box<<T as Config>::Call>,
+			call: Box<<T as Config>::RuntimeCall>,
 		) -> DispatchResult {
 			T::ScheduleOrigin::ensure_origin(origin.clone())?;
 
@@ -542,7 +542,7 @@
 				T::PrioritySetOrigin::ensure_origin(origin.clone())?;
 			}
 
-			let origin = <T as Config>::Origin::from(origin);
+			let origin = <T as Config>::RuntimeOrigin::from(origin);
 			Self::do_schedule(
 				DispatchTime::After(after),
 				maybe_periodic,
@@ -565,7 +565,7 @@
 			after: T::BlockNumber,
 			maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
 			priority: Option<schedule::Priority>,
-			call: Box<<T as Config>::Call>,
+			call: Box<<T as Config>::RuntimeCall>,
 		) -> DispatchResult {
 			T::ScheduleOrigin::ensure_origin(origin.clone())?;
 
@@ -573,7 +573,7 @@
 				T::PrioritySetOrigin::ensure_origin(origin.clone())?;
 			}
 
-			let origin = <T as Config>::Origin::from(origin);
+			let origin = <T as Config>::RuntimeOrigin::from(origin);
 			Self::do_schedule_named(
 				id,
 				DispatchTime::After(after),
@@ -592,7 +592,7 @@
 			priority: schedule::Priority,
 		) -> DispatchResult {
 			T::PrioritySetOrigin::ensure_origin(origin.clone())?;
-			let origin = <T as Config>::Origin::from(origin);
+			let origin = <T as Config>::RuntimeOrigin::from(origin);
 			Self::do_change_named_priority(origin.caller().clone(), id, priority)
 		}
 	}
@@ -816,7 +816,7 @@
 	/// Resolve the call dispatch, including any post-dispatch operations.
 	fn dispatch_call(
 		signer: Option<T::AccountId>,
-		function: <T as Config>::Call,
+		function: <T as Config>::RuntimeCall,
 	) -> Result<
 		Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,
 		TransactionValidityError,
@@ -1036,9 +1036,9 @@
 	fn execute_dispatch(
 		weight: &mut WeightCounter,
 		origin: T::PalletsOrigin,
-		call: <T as Config>::Call,
+		call: <T as Config>::RuntimeCall,
 	) -> Result<DispatchResult, ServiceTaskError> {
-		let dispatch_origin: <T as Config>::Origin = origin.into();
+		let dispatch_origin: <T as Config>::RuntimeOrigin = origin.into();
 		let base_weight = match dispatch_origin.clone().as_signed() {
 			Some(_) => T::WeightInfo::execute_dispatch_signed(),
 			_ => T::WeightInfo::execute_dispatch_unsigned(),
modifiedruntime/common/config/pallets/scheduler.rsdiffbeforeafterboth
before · runtime/common/config/pallets/scheduler.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/>.1617use frame_support::{18	traits::{PrivilegeCmp, EnsureOrigin},19	weights::Weight,20	parameter_types,21};22use frame_system::{EnsureRoot, RawOrigin};23use sp_runtime::Perbill;24use core::cmp::Ordering;25use codec::Decode;26use crate::{27	runtime_common::{scheduler::SchedulerPaymentExecutor, config::substrate::RuntimeBlockWeights},28	Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, OriginCaller, Balances,29};30use pallet_unique_scheduler_v2::ScheduledEnsureOriginSuccess;31use up_common::types::AccountId;3233parameter_types! {34	pub MaximumSchedulerWeight: Weight = Perbill::from_percent(50) *35		RuntimeBlockWeights::get().max_block;36	pub const MaxScheduledPerBlock: u32 = 50;3738	pub const NoPreimagePostponement: Option<u32> = Some(10);39	pub const Preimage: Option<u32> = Some(10);40}4142pub struct EnsureSignedOrRoot<AccountId>(sp_std::marker::PhantomData<AccountId>);43impl<O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>, AccountId: Decode>44	EnsureOrigin<O> for EnsureSignedOrRoot<AccountId>45{46	type Success = ScheduledEnsureOriginSuccess<AccountId>;47	fn try_origin(o: O) -> Result<Self::Success, O> {48		o.into().and_then(|o| match o {49			RawOrigin::Root => Ok(ScheduledEnsureOriginSuccess::Root),50			RawOrigin::Signed(who) => Ok(ScheduledEnsureOriginSuccess::Signed(who)),51			r => Err(O::from(r)),52		})53	}54}5556pub struct EqualOrRootOnly;57impl PrivilegeCmp<OriginCaller> for EqualOrRootOnly {58	fn cmp_privilege(left: &OriginCaller, right: &OriginCaller) -> Option<Ordering> {59		use RawOrigin::*;6061		let left = left.clone().try_into().ok()?;62		let right = right.clone().try_into().ok()?;6364		match (left, right) {65			(Root, Root) => Some(Ordering::Equal),66			(Root, _) => Some(Ordering::Greater),67			(_, Root) => Some(Ordering::Less),68			lr @ _ => (lr.0 == lr.1).then(|| Ordering::Equal),69		}70	}71}7273// impl pallet_unique_scheduler::Config for Runtime {74// 	type RuntimeEvent = RuntimeEvent;75// 	type RuntimeOrigin = RuntimeOrigin;76// 	type Currency = Balances;77// 	type PalletsOrigin = OriginCaller;78// 	type RuntimeCall = RuntimeCall;79// 	type MaximumWeight = MaximumSchedulerWeight;80// 	type ScheduleOrigin = EnsureSignedOrRoot<AccountId>;81// 	type PrioritySetOrigin = EnsureRoot<AccountId>;82// 	type MaxScheduledPerBlock = MaxScheduledPerBlock;83// 	type WeightInfo = ();84// 	type CallExecutor = SchedulerPaymentExecutor;85// 	type OriginPrivilegeCmp = EqualOrRootOnly;86// 	type PreimageProvider = ();87// 	type NoPreimagePostponement = NoPreimagePostponement;88// }8990impl pallet_unique_scheduler_v2::Config for Runtime {91	type Event = Event;92	type Origin = Origin;93	type PalletsOrigin = OriginCaller;94	type Call = Call;95	type MaximumWeight = MaximumSchedulerWeight;96	type ScheduleOrigin = EnsureSignedOrRoot<AccountId>;97	type OriginPrivilegeCmp = EqualOrRootOnly;98	type MaxScheduledPerBlock = MaxScheduledPerBlock;99	type WeightInfo = ();100	type Preimages = ();101	type CallExecutor = SchedulerPaymentExecutor;102	type PrioritySetOrigin = EnsureRoot<AccountId>;103}
after · runtime/common/config/pallets/scheduler.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/>.1617use frame_support::{18	traits::{PrivilegeCmp, EnsureOrigin},19	weights::Weight,20	parameter_types,21};22use frame_system::{EnsureRoot, RawOrigin};23use sp_runtime::Perbill;24use core::cmp::Ordering;25use codec::Decode;26use crate::{27	runtime_common::{scheduler::SchedulerPaymentExecutor, config::substrate::RuntimeBlockWeights},28	Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, OriginCaller, Balances,29};30use pallet_unique_scheduler_v2::ScheduledEnsureOriginSuccess;31use up_common::types::AccountId;3233parameter_types! {34	pub MaximumSchedulerWeight: Weight = Perbill::from_percent(50) *35		RuntimeBlockWeights::get().max_block;36	pub const MaxScheduledPerBlock: u32 = 50;3738	pub const NoPreimagePostponement: Option<u32> = Some(10);39	pub const Preimage: Option<u32> = Some(10);40}4142pub struct EnsureSignedOrRoot<AccountId>(sp_std::marker::PhantomData<AccountId>);43impl<O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>, AccountId: Decode>44	EnsureOrigin<O> for EnsureSignedOrRoot<AccountId>45{46	type Success = ScheduledEnsureOriginSuccess<AccountId>;47	fn try_origin(o: O) -> Result<Self::Success, O> {48		o.into().and_then(|o| match o {49			RawOrigin::Root => Ok(ScheduledEnsureOriginSuccess::Root),50			RawOrigin::Signed(who) => Ok(ScheduledEnsureOriginSuccess::Signed(who)),51			r => Err(O::from(r)),52		})53	}54}5556pub struct EqualOrRootOnly;57impl PrivilegeCmp<OriginCaller> for EqualOrRootOnly {58	fn cmp_privilege(left: &OriginCaller, right: &OriginCaller) -> Option<Ordering> {59		use RawOrigin::*;6061		let left = left.clone().try_into().ok()?;62		let right = right.clone().try_into().ok()?;6364		match (left, right) {65			(Root, Root) => Some(Ordering::Equal),66			(Root, _) => Some(Ordering::Greater),67			(_, Root) => Some(Ordering::Less),68			lr @ _ => (lr.0 == lr.1).then(|| Ordering::Equal),69		}70	}71}7273// impl pallet_unique_scheduler::Config for Runtime {74// 	type RuntimeEvent = RuntimeEvent;75// 	type RuntimeOrigin = RuntimeOrigin;76// 	type Currency = Balances;77// 	type PalletsOrigin = OriginCaller;78// 	type RuntimeCall = RuntimeCall;79// 	type MaximumWeight = MaximumSchedulerWeight;80// 	type ScheduleOrigin = EnsureSignedOrRoot<AccountId>;81// 	type PrioritySetOrigin = EnsureRoot<AccountId>;82// 	type MaxScheduledPerBlock = MaxScheduledPerBlock;83// 	type WeightInfo = ();84// 	type CallExecutor = SchedulerPaymentExecutor;85// 	type OriginPrivilegeCmp = EqualOrRootOnly;86// 	type PreimageProvider = ();87// 	type NoPreimagePostponement = NoPreimagePostponement;88// }8990impl pallet_unique_scheduler_v2::Config for Runtime {91	type RuntimeEvent = RuntimeEvent;92	type RuntimeOrigin = RuntimeOrigin;93	type PalletsOrigin = OriginCaller;94	type RuntimeCall = RuntimeCall;95	type MaximumWeight = MaximumSchedulerWeight;96	type ScheduleOrigin = EnsureSignedOrRoot<AccountId>;97	type OriginPrivilegeCmp = EqualOrRootOnly;98	type MaxScheduledPerBlock = MaxScheduledPerBlock;99	type WeightInfo = ();100	type Preimages = ();101	type CallExecutor = SchedulerPaymentExecutor;102	type PrioritySetOrigin = EnsureRoot<AccountId>;103}
modifiedtest-pallets/utils/src/lib.rsdiffbeforeafterboth
--- a/test-pallets/utils/src/lib.rs
+++ b/test-pallets/utils/src/lib.rs
@@ -27,7 +27,7 @@
 	use pallet_unique_scheduler_v2::{TaskName, Pallet as SchedulerPallet};
 
 	#[pallet::config]
-	pub trait Config: frame_system::Config + pallet_unique_scheduler::Config {
+	pub trait Config: frame_system::Config + pallet_unique_scheduler_v2::Config {
 		type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
 	}