git.delta.rocks / unique-network / refs/commits / 786ff7ed1061

difftreelog

fix require service_task_fetched for Preimages

Daniel Shiposha2022-11-10parent: #7319c34.patch.diff
in: master

2 files changed

modifiedpallets/scheduler-v2/src/lib.rsdiffbeforeafterboth
177 }177 }
178}178}
179
180/// Weight Info for the Preimages fetches.
181pub trait SchedulerPreimagesWeightInfo<W: WeightInfo> {
182 /// Get the weight of a task fetches with a given decoded length.
183 fn service_task_fetched(call_length: u32) -> Weight;
184}
185
186impl<W: WeightInfo> SchedulerPreimagesWeightInfo<W> for () {
187 fn service_task_fetched(_call_length: u32) -> Weight {
188 W::service_task_base()
189 }
190}
179191
180/// A scheduler's interface for managing preimages to hashes192/// A scheduler's interface for managing preimages to hashes
181/// and looking up preimages from their hash on-chain.193/// and looking up preimages from their hash on-chain.
182pub trait SchedulerPreimages<T: Config>: PreimageRecipient<T::Hash> {194pub trait SchedulerPreimages<T: Config>:
195 PreimageRecipient<T::Hash> + SchedulerPreimagesWeightInfo<T::WeightInfo>
196{
183 /// No longer request that the data for decoding the given `call` is available.197 /// No longer request that the data for decoding the given `call` is available.
184 fn drop(call: &ScheduledCall<T>);198 fn drop(call: &ScheduledCall<T>);
200 ) -> Result<(<T as pallet::Config>::RuntimeCall, Option<u32>), DispatchError>;214 ) -> Result<(<T as pallet::Config>::RuntimeCall, Option<u32>), DispatchError>;
201}215}
202216
203impl<T: Config, PP: PreimageRecipient<T::Hash>> SchedulerPreimages<T> for PP {217impl<T: Config, PP: PreimageRecipient<T::Hash> + SchedulerPreimagesWeightInfo<T::WeightInfo>>
218 SchedulerPreimages<T> for PP
219{
204 fn drop(call: &ScheduledCall<T>) {220 fn drop(call: &ScheduledCall<T>) {
414 }430 }
415}431}
416432
417pub(crate) trait MarginalWeightInfo: WeightInfo {433pub(crate) struct MarginalWeightInfo<T: Config>(sp_std::marker::PhantomData<T>);
434
435impl<T: Config> MarginalWeightInfo<T> {
418 /// Return the weight of servicing a single task.436 /// Return the weight of servicing a single task.
419 fn service_task(maybe_lookup_len: Option<usize>, named: bool, periodic: bool) -> Weight {437 fn service_task(maybe_lookup_len: Option<usize>, named: bool, periodic: bool) -> Weight {
420 let base = Self::service_task_base();438 let base = T::WeightInfo::service_task_base();
421 let mut total = match maybe_lookup_len {439 let mut total = match maybe_lookup_len {
422 None => base,440 None => base,
423 Some(_l) => {441 Some(l) => T::Preimages::service_task_fetched(l as u32),
424 // TODO uncomment if we will use the Preimages
425 // Self::service_task_fetched(l as u32)
426 base
427 }
428 };442 };
429 if named {443 if named {
430 total.saturating_accrue(Self::service_task_named().saturating_sub(base));444 total.saturating_accrue(T::WeightInfo::service_task_named().saturating_sub(base));
431 }445 }
432 if periodic {446 if periodic {
433 total.saturating_accrue(Self::service_task_periodic().saturating_sub(base));447 total.saturating_accrue(T::WeightInfo::service_task_periodic().saturating_sub(base));
434 }448 }
435 total449 total
436 }450 }
437}451}
438
439impl<T: WeightInfo> MarginalWeightInfo for T {}
440452
441#[frame_support::pallet]453#[frame_support::pallet]
442pub mod pallet {454pub mod pallet {
1119 None => continue,1131 None => continue,
1120 Some(t) => t,1132 Some(t) => t,
1121 };1133 };
1122 let base_weight = T::WeightInfo::service_task(1134 let base_weight = MarginalWeightInfo::<T>::service_task(
1123 task.call.lookup_len().map(|x| x as usize),1135 task.call.lookup_len().map(|x| x as usize),
1124 task.maybe_id.is_some(),1136 task.maybe_id.is_some(),
1125 task.maybe_periodic.is_some(),1137 task.maybe_periodic.is_some(),
1176 }1188 }
1177 };1189 };
11781190
1179 weight.check_accrue(T::WeightInfo::service_task(1191 weight.check_accrue(MarginalWeightInfo::<T>::service_task(
1180 lookup_len.map(|x| x as usize),1192 lookup_len.map(|x| x as usize),
1181 task.maybe_id.is_some(),1193 task.maybe_id.is_some(),
1182 task.maybe_periodic.is_some(),1194 task.maybe_periodic.is_some(),
modifiedpallets/scheduler-v2/src/tests.rsdiffbeforeafterboth
--- a/pallets/scheduler-v2/src/tests.rs
+++ b/pallets/scheduler-v2/src/tests.rs
@@ -514,7 +514,7 @@
 			Scheduler::on_initialize(1),
 			TestWeightInfo::service_agendas_base()
 				+ TestWeightInfo::service_agenda_base(1)
-				+ <TestWeightInfo as MarginalWeightInfo>::service_task(None, true, true)
+				+ <MarginalWeightInfo<Test>>::service_task(None, true, true)
 				+ TestWeightInfo::execute_dispatch_unsigned()
 				+ call_weight + Weight::from_ref_time(4)
 		);
@@ -526,10 +526,10 @@
 			Scheduler::on_initialize(2),
 			TestWeightInfo::service_agendas_base()
 				+ TestWeightInfo::service_agenda_base(2)
-				+ <TestWeightInfo as MarginalWeightInfo>::service_task(None, false, true)
+				+ <MarginalWeightInfo<Test>>::service_task(None, false, true)
 				+ TestWeightInfo::execute_dispatch_unsigned()
 				+ call_weight + Weight::from_ref_time(3)
-				+ <TestWeightInfo as MarginalWeightInfo>::service_task(None, false, false)
+				+ <MarginalWeightInfo<Test>>::service_task(None, false, false)
 				+ TestWeightInfo::execute_dispatch_unsigned()
 				+ call_weight + Weight::from_ref_time(2)
 		);
@@ -544,7 +544,7 @@
 			Scheduler::on_initialize(3),
 			TestWeightInfo::service_agendas_base()
 				+ TestWeightInfo::service_agenda_base(1)
-				+ <TestWeightInfo as MarginalWeightInfo>::service_task(None, true, false)
+				+ <MarginalWeightInfo<Test>>::service_task(None, true, false)
 				+ TestWeightInfo::execute_dispatch_unsigned()
 				+ call_weight + Weight::from_ref_time(1)
 		);