difftreelog
fix require service_task_fetched for Preimages
in: master
2 files changed
pallets/scheduler-v2/src/lib.rsdiffbeforeafterboth177 }177 }178}178}179180/// 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}185186impl<W: WeightInfo> SchedulerPreimagesWeightInfo<W> for () {187 fn service_task_fetched(_call_length: u32) -> Weight {188 W::service_task_base()189 }190}179191180/// A scheduler's interface for managing preimages to hashes192/// A scheduler's interface for managing preimages to hashes181/// 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}202216203impl<T: Config, PP: PreimageRecipient<T::Hash>> SchedulerPreimages<T> for PP {217impl<T: Config, PP: PreimageRecipient<T::Hash> + SchedulerPreimagesWeightInfo<T::WeightInfo>>218 SchedulerPreimages<T> for PP219{204 fn drop(call: &ScheduledCall<T>) {220 fn drop(call: &ScheduledCall<T>) {414 }430 }415}431}416432417pub(crate) trait MarginalWeightInfo: WeightInfo {433pub(crate) struct MarginalWeightInfo<T: Config>(sp_std::marker::PhantomData<T>);434435impl<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 Preimages425 // Self::service_task_fetched(l as u32)426 base427 }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 total436 }450 }437}451}438439impl<T: WeightInfo> MarginalWeightInfo for T {}440452441#[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 };117811901179 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(),pallets/scheduler-v2/src/tests.rsdiffbeforeafterboth514 Scheduler::on_initialize(1),514 Scheduler::on_initialize(1),515 TestWeightInfo::service_agendas_base()515 TestWeightInfo::service_agendas_base()516 + TestWeightInfo::service_agenda_base(1)516 + TestWeightInfo::service_agenda_base(1)517 + <TestWeightInfo as MarginalWeightInfo>::service_task(None, true, true)517 + <MarginalWeightInfo<Test>>::service_task(None, true, true)518 + TestWeightInfo::execute_dispatch_unsigned()518 + TestWeightInfo::execute_dispatch_unsigned()519 + call_weight + Weight::from_ref_time(4)519 + call_weight + Weight::from_ref_time(4)520 );520 );526 Scheduler::on_initialize(2),526 Scheduler::on_initialize(2),527 TestWeightInfo::service_agendas_base()527 TestWeightInfo::service_agendas_base()528 + TestWeightInfo::service_agenda_base(2)528 + TestWeightInfo::service_agenda_base(2)529 + <TestWeightInfo as MarginalWeightInfo>::service_task(None, false, true)529 + <MarginalWeightInfo<Test>>::service_task(None, false, true)530 + TestWeightInfo::execute_dispatch_unsigned()530 + TestWeightInfo::execute_dispatch_unsigned()531 + call_weight + Weight::from_ref_time(3)531 + call_weight + Weight::from_ref_time(3)532 + <TestWeightInfo as MarginalWeightInfo>::service_task(None, false, false)532 + <MarginalWeightInfo<Test>>::service_task(None, false, false)533 + TestWeightInfo::execute_dispatch_unsigned()533 + TestWeightInfo::execute_dispatch_unsigned()534 + call_weight + Weight::from_ref_time(2)534 + call_weight + Weight::from_ref_time(2)535 );535 );544 Scheduler::on_initialize(3),544 Scheduler::on_initialize(3),545 TestWeightInfo::service_agendas_base()545 TestWeightInfo::service_agendas_base()546 + TestWeightInfo::service_agenda_base(1)546 + TestWeightInfo::service_agenda_base(1)547 + <TestWeightInfo as MarginalWeightInfo>::service_task(None, true, false)547 + <MarginalWeightInfo<Test>>::service_task(None, true, false)548 + TestWeightInfo::execute_dispatch_unsigned()548 + TestWeightInfo::execute_dispatch_unsigned()549 + call_weight + Weight::from_ref_time(1)549 + call_weight + Weight::from_ref_time(1)550 );550 );