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
13codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }13codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
14log = { version = "0.4.17", default-features = false }14log = { version = "0.4.17", default-features = false }
15scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }15scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
16frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }16frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
17frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }17frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
18frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }18frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
19sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }19sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
20sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }20sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
21sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }21sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
22sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }22sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
2323
24[dev-dependencies]24[dev-dependencies]
25pallet-preimage = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }25pallet-preimage = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
26sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }26sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
27substrate-test-utils = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }27substrate-test-utils = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
2828
29[features]29[features]
30default = ["std"]30default = ["std"]
modifiedpallets/scheduler-v2/src/lib.rsdiffbeforeafterboth
113}113}
114114
115impl<T: Config> ScheduledCall<T> {115impl<T: Config> ScheduledCall<T> {
116 pub fn new(call: <T as Config>::Call) -> Result<Self, DispatchError> {116 pub fn new(call: <T as Config>::RuntimeCall) -> Result<Self, DispatchError> {
117 let encoded = call.encode();117 let encoded = call.encode();
118 let len = encoded.len();118 let len = encoded.len();
119119
151 }151 }
152 }152 }
153153
154 fn decode(mut data: &[u8]) -> Result<<T as Config>::Call, DispatchError> {154 fn decode(mut data: &[u8]) -> Result<<T as Config>::RuntimeCall, DispatchError> {
155 <T as Config>::Call::decode(&mut data)155 <T as Config>::RuntimeCall::decode(&mut data)
156 .map_err(|_| <Error<T>>::ScheduledCallCorrupted.into())156 .map_err(|_| <Error<T>>::ScheduledCallCorrupted.into())
157 }157 }
158}158}
162162
163 fn peek(163 fn peek(
164 call: &ScheduledCall<T>,164 call: &ScheduledCall<T>,
165 ) -> Result<(<T as pallet::Config>::Call, Option<u32>), DispatchError>;165 ) -> Result<(<T as pallet::Config>::RuntimeCall, Option<u32>), DispatchError>;
166166
167 /// Convert the given scheduled `call` value back into its original instance. If successful,167 /// Convert the given scheduled `call` value back into its original instance. If successful,
168 /// `drop` any data backing it. This will not break the realisability of independently168 /// `drop` any data backing it. This will not break the realisability of independently
169 /// created instances of `ScheduledCall` which happen to have identical data.169 /// created instances of `ScheduledCall` which happen to have identical data.
170 fn realize(170 fn realize(
171 call: &ScheduledCall<T>,171 call: &ScheduledCall<T>,
172 ) -> Result<(<T as pallet::Config>::Call, Option<u32>), DispatchError>;172 ) -> Result<(<T as pallet::Config>::RuntimeCall, Option<u32>), DispatchError>;
173}173}
174174
175impl<T: Config, PP: PreimageRecipient<T::Hash>> SchedulerPreimages<T> for PP {175impl<T: Config, PP: PreimageRecipient<T::Hash>> SchedulerPreimages<T> for PP {
182182
183 fn peek(183 fn peek(
184 call: &ScheduledCall<T>,184 call: &ScheduledCall<T>,
185 ) -> Result<(<T as pallet::Config>::Call, Option<u32>), DispatchError> {185 ) -> Result<(<T as pallet::Config>::RuntimeCall, Option<u32>), DispatchError> {
186 match call {186 match call {
187 ScheduledCall::Inline(data) => Ok((ScheduledCall::<T>::decode(data)?, None)),187 ScheduledCall::Inline(data) => Ok((ScheduledCall::<T>::decode(data)?, None)),
188 ScheduledCall::PreimageLookup {188 ScheduledCall::PreimageLookup {
200200
201 fn realize(201 fn realize(
202 call: &ScheduledCall<T>,202 call: &ScheduledCall<T>,
203 ) -> Result<(<T as pallet::Config>::Call, Option<u32>), DispatchError> {203 ) -> Result<(<T as pallet::Config>::RuntimeCall, Option<u32>), DispatchError> {
204 let r = Self::peek(call)?;204 let r = Self::peek(call)?;
205 Self::drop(call);205 Self::drop(call);
206 Ok(r)206 Ok(r)
252impl WeightCounter {252impl WeightCounter {
253 fn check_accrue(&mut self, w: Weight) -> bool {253 fn check_accrue(&mut self, w: Weight) -> bool {
254 let test = self.used.saturating_add(w);254 let test = self.used.saturating_add(w);
255 if test > self.limit {255 if test.any_gt(self.limit) {
256 false256 false
257 } else {257 } else {
258 self.used = test;258 self.used = test;
261 }261 }
262262
263 fn can_accrue(&mut self, w: Weight) -> bool {263 fn can_accrue(&mut self, w: Weight) -> bool {
264 self.used.saturating_add(w) <= self.limit264 self.used.saturating_add(w).all_lte(self.limit)
265 }265 }
266}266}
267267
300300
301 #[pallet::config]301 #[pallet::config]
302 pub trait Config: frame_system::Config {302 pub trait Config: frame_system::Config {
303 type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;303 type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
304304
305 /// The aggregated origin which the dispatch will take.305 /// The aggregated origin which the dispatch will take.
306 type Origin: OriginTrait<PalletsOrigin = Self::PalletsOrigin>306 type RuntimeOrigin: OriginTrait<PalletsOrigin = Self::PalletsOrigin>
307 + From<Self::PalletsOrigin>307 + From<Self::PalletsOrigin>
308 + IsType<<Self as system::Config>::Origin>308 + IsType<<Self as system::Config>::RuntimeOrigin>
309 + Clone;309 + Clone;
310310
311 /// The caller origin, overarching type of all pallets origins.311 /// The caller origin, overarching type of all pallets origins.
317 + MaxEncodedLen;317 + MaxEncodedLen;
318318
319 /// The aggregated call type.319 /// The aggregated call type.
320 type Call: Parameter320 type RuntimeCall: Parameter
321 + Dispatchable<Origin = <Self as Config>::Origin, PostInfo = PostDispatchInfo>321 + Dispatchable<RuntimeOrigin = <Self as Config>::RuntimeOrigin, PostInfo = PostDispatchInfo>
322 + UnfilteredDispatchable<Origin = <Self as system::Config>::Origin>322 + UnfilteredDispatchable<RuntimeOrigin = <Self as system::Config>::RuntimeOrigin>
323 + GetDispatchInfo323 + GetDispatchInfo
324 + From<system::Call<Self>>;324 + From<system::Call<Self>>;
325325
329329
330 /// Required origin to schedule or cancel calls.330 /// Required origin to schedule or cancel calls.
331 type ScheduleOrigin: EnsureOrigin<331 type ScheduleOrigin: EnsureOrigin<
332 <Self as system::Config>::Origin,332 <Self as system::Config>::RuntimeOrigin,
333 Success = ScheduledEnsureOriginSuccess<Self::AccountId>,333 Success = ScheduledEnsureOriginSuccess<Self::AccountId>,
334 >;334 >;
335335
356 type CallExecutor: DispatchCall<Self, H160>;356 type CallExecutor: DispatchCall<Self, H160>;
357357
358 /// Required origin to set/change calls' priority.358 /// Required origin to set/change calls' priority.
359 type PrioritySetOrigin: EnsureOrigin<<Self as system::Config>::Origin>;359 type PrioritySetOrigin: EnsureOrigin<<Self as system::Config>::RuntimeOrigin>;
360 }360 }
361361
362 #[pallet::storage]362 #[pallet::storage]
458 when: T::BlockNumber,458 when: T::BlockNumber,
459 maybe_periodic: Option<schedule::Period<T::BlockNumber>>,459 maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
460 priority: Option<schedule::Priority>,460 priority: Option<schedule::Priority>,
461 call: Box<<T as Config>::Call>,461 call: Box<<T as Config>::RuntimeCall>,
462 ) -> DispatchResult {462 ) -> DispatchResult {
463 T::ScheduleOrigin::ensure_origin(origin.clone())?;463 T::ScheduleOrigin::ensure_origin(origin.clone())?;
464464
465 if priority.is_some() {465 if priority.is_some() {
466 T::PrioritySetOrigin::ensure_origin(origin.clone())?;466 T::PrioritySetOrigin::ensure_origin(origin.clone())?;
467 }467 }
468468
469 let origin = <T as Config>::Origin::from(origin);469 let origin = <T as Config>::RuntimeOrigin::from(origin);
470 Self::do_schedule(470 Self::do_schedule(
471 DispatchTime::At(when),471 DispatchTime::At(when),
472 maybe_periodic,472 maybe_periodic,
481 #[pallet::weight(<T as Config>::WeightInfo::cancel(T::MaxScheduledPerBlock::get()))]481 #[pallet::weight(<T as Config>::WeightInfo::cancel(T::MaxScheduledPerBlock::get()))]
482 pub fn cancel(origin: OriginFor<T>, when: T::BlockNumber, index: u32) -> DispatchResult {482 pub fn cancel(origin: OriginFor<T>, when: T::BlockNumber, index: u32) -> DispatchResult {
483 T::ScheduleOrigin::ensure_origin(origin.clone())?;483 T::ScheduleOrigin::ensure_origin(origin.clone())?;
484 let origin = <T as Config>::Origin::from(origin);484 let origin = <T as Config>::RuntimeOrigin::from(origin);
485 Self::do_cancel(Some(origin.caller().clone()), (when, index))?;485 Self::do_cancel(Some(origin.caller().clone()), (when, index))?;
486 Ok(())486 Ok(())
487 }487 }
494 when: T::BlockNumber,494 when: T::BlockNumber,
495 maybe_periodic: Option<schedule::Period<T::BlockNumber>>,495 maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
496 priority: Option<schedule::Priority>,496 priority: Option<schedule::Priority>,
497 call: Box<<T as Config>::Call>,497 call: Box<<T as Config>::RuntimeCall>,
498 ) -> DispatchResult {498 ) -> DispatchResult {
499 T::ScheduleOrigin::ensure_origin(origin.clone())?;499 T::ScheduleOrigin::ensure_origin(origin.clone())?;
500500
501 if priority.is_some() {501 if priority.is_some() {
502 T::PrioritySetOrigin::ensure_origin(origin.clone())?;502 T::PrioritySetOrigin::ensure_origin(origin.clone())?;
503 }503 }
504504
505 let origin = <T as Config>::Origin::from(origin);505 let origin = <T as Config>::RuntimeOrigin::from(origin);
506 Self::do_schedule_named(506 Self::do_schedule_named(
507 id,507 id,
508 DispatchTime::At(when),508 DispatchTime::At(when),
518 #[pallet::weight(<T as Config>::WeightInfo::cancel_named(T::MaxScheduledPerBlock::get()))]518 #[pallet::weight(<T as Config>::WeightInfo::cancel_named(T::MaxScheduledPerBlock::get()))]
519 pub fn cancel_named(origin: OriginFor<T>, id: TaskName) -> DispatchResult {519 pub fn cancel_named(origin: OriginFor<T>, id: TaskName) -> DispatchResult {
520 T::ScheduleOrigin::ensure_origin(origin.clone())?;520 T::ScheduleOrigin::ensure_origin(origin.clone())?;
521 let origin = <T as Config>::Origin::from(origin);521 let origin = <T as Config>::RuntimeOrigin::from(origin);
522 Self::do_cancel_named(Some(origin.caller().clone()), id)?;522 Self::do_cancel_named(Some(origin.caller().clone()), id)?;
523 Ok(())523 Ok(())
524 }524 }
534 after: T::BlockNumber,534 after: T::BlockNumber,
535 maybe_periodic: Option<schedule::Period<T::BlockNumber>>,535 maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
536 priority: Option<schedule::Priority>,536 priority: Option<schedule::Priority>,
537 call: Box<<T as Config>::Call>,537 call: Box<<T as Config>::RuntimeCall>,
538 ) -> DispatchResult {538 ) -> DispatchResult {
539 T::ScheduleOrigin::ensure_origin(origin.clone())?;539 T::ScheduleOrigin::ensure_origin(origin.clone())?;
540540
541 if priority.is_some() {541 if priority.is_some() {
542 T::PrioritySetOrigin::ensure_origin(origin.clone())?;542 T::PrioritySetOrigin::ensure_origin(origin.clone())?;
543 }543 }
544544
545 let origin = <T as Config>::Origin::from(origin);545 let origin = <T as Config>::RuntimeOrigin::from(origin);
546 Self::do_schedule(546 Self::do_schedule(
547 DispatchTime::After(after),547 DispatchTime::After(after),
548 maybe_periodic,548 maybe_periodic,
565 after: T::BlockNumber,565 after: T::BlockNumber,
566 maybe_periodic: Option<schedule::Period<T::BlockNumber>>,566 maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
567 priority: Option<schedule::Priority>,567 priority: Option<schedule::Priority>,
568 call: Box<<T as Config>::Call>,568 call: Box<<T as Config>::RuntimeCall>,
569 ) -> DispatchResult {569 ) -> DispatchResult {
570 T::ScheduleOrigin::ensure_origin(origin.clone())?;570 T::ScheduleOrigin::ensure_origin(origin.clone())?;
571571
572 if priority.is_some() {572 if priority.is_some() {
573 T::PrioritySetOrigin::ensure_origin(origin.clone())?;573 T::PrioritySetOrigin::ensure_origin(origin.clone())?;
574 }574 }
575575
576 let origin = <T as Config>::Origin::from(origin);576 let origin = <T as Config>::RuntimeOrigin::from(origin);
577 Self::do_schedule_named(577 Self::do_schedule_named(
578 id,578 id,
579 DispatchTime::After(after),579 DispatchTime::After(after),
592 priority: schedule::Priority,592 priority: schedule::Priority,
593 ) -> DispatchResult {593 ) -> DispatchResult {
594 T::PrioritySetOrigin::ensure_origin(origin.clone())?;594 T::PrioritySetOrigin::ensure_origin(origin.clone())?;
595 let origin = <T as Config>::Origin::from(origin);595 let origin = <T as Config>::RuntimeOrigin::from(origin);
596 Self::do_change_named_priority(origin.caller().clone(), id, priority)596 Self::do_change_named_priority(origin.caller().clone(), id, priority)
597 }597 }
598 }598 }
816 /// Resolve the call dispatch, including any post-dispatch operations.816 /// Resolve the call dispatch, including any post-dispatch operations.
817 fn dispatch_call(817 fn dispatch_call(
818 signer: Option<T::AccountId>,818 signer: Option<T::AccountId>,
819 function: <T as Config>::Call,819 function: <T as Config>::RuntimeCall,
820 ) -> Result<820 ) -> Result<
821 Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,821 Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,
822 TransactionValidityError,822 TransactionValidityError,
1036 fn execute_dispatch(1036 fn execute_dispatch(
1037 weight: &mut WeightCounter,1037 weight: &mut WeightCounter,
1038 origin: T::PalletsOrigin,1038 origin: T::PalletsOrigin,
1039 call: <T as Config>::Call,1039 call: <T as Config>::RuntimeCall,
1040 ) -> Result<DispatchResult, ServiceTaskError> {1040 ) -> Result<DispatchResult, ServiceTaskError> {
1041 let dispatch_origin: <T as Config>::Origin = origin.into();1041 let dispatch_origin: <T as Config>::RuntimeOrigin = origin.into();
1042 let base_weight = match dispatch_origin.clone().as_signed() {1042 let base_weight = match dispatch_origin.clone().as_signed() {
1043 Some(_) => T::WeightInfo::execute_dispatch_signed(),1043 Some(_) => T::WeightInfo::execute_dispatch_signed(),
1044 _ => T::WeightInfo::execute_dispatch_unsigned(),1044 _ => T::WeightInfo::execute_dispatch_unsigned(),
modifiedruntime/common/config/pallets/scheduler.rsdiffbeforeafterboth
88// }88// }
8989
90impl pallet_unique_scheduler_v2::Config for Runtime {90impl pallet_unique_scheduler_v2::Config for Runtime {
91 type Event = Event;91 type RuntimeEvent = RuntimeEvent;
92 type Origin = Origin;92 type RuntimeOrigin = RuntimeOrigin;
93 type PalletsOrigin = OriginCaller;93 type PalletsOrigin = OriginCaller;
94 type Call = Call;94 type RuntimeCall = RuntimeCall;
95 type MaximumWeight = MaximumSchedulerWeight;95 type MaximumWeight = MaximumSchedulerWeight;
96 type ScheduleOrigin = EnsureSignedOrRoot<AccountId>;96 type ScheduleOrigin = EnsureSignedOrRoot<AccountId>;
97 type OriginPrivilegeCmp = EqualOrRootOnly;97 type OriginPrivilegeCmp = EqualOrRootOnly;
modifiedtest-pallets/utils/src/lib.rsdiffbeforeafterboth
27 use pallet_unique_scheduler_v2::{TaskName, Pallet as SchedulerPallet};27 use pallet_unique_scheduler_v2::{TaskName, Pallet as SchedulerPallet};
2828
29 #[pallet::config]29 #[pallet::config]
30 pub trait Config: frame_system::Config + pallet_unique_scheduler::Config {30 pub trait Config: frame_system::Config + pallet_unique_scheduler_v2::Config {
31 type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;31 type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
32 }32 }
3333