--- a/pallets/scheduler-v2/src/lib.rs +++ b/pallets/scheduler-v2/src/lib.rs @@ -177,9 +177,23 @@ } } +/// Weight Info for the Preimages fetches. +pub trait SchedulerPreimagesWeightInfo { + /// Get the weight of a task fetches with a given decoded length. + fn service_task_fetched(call_length: u32) -> Weight; +} + +impl SchedulerPreimagesWeightInfo for () { + fn service_task_fetched(_call_length: u32) -> Weight { + W::service_task_base() + } +} + /// A scheduler's interface for managing preimages to hashes /// and looking up preimages from their hash on-chain. -pub trait SchedulerPreimages: PreimageRecipient { +pub trait SchedulerPreimages: + PreimageRecipient + SchedulerPreimagesWeightInfo +{ /// No longer request that the data for decoding the given `call` is available. fn drop(call: &ScheduledCall); @@ -200,7 +214,9 @@ ) -> Result<(::RuntimeCall, Option), DispatchError>; } -impl> SchedulerPreimages for PP { +impl + SchedulerPreimagesWeightInfo> + SchedulerPreimages for PP +{ fn drop(call: &ScheduledCall) { match call { ScheduledCall::Inline(_) => {} @@ -414,29 +430,25 @@ } } -pub(crate) trait MarginalWeightInfo: WeightInfo { +pub(crate) struct MarginalWeightInfo(sp_std::marker::PhantomData); + +impl MarginalWeightInfo { /// Return the weight of servicing a single task. fn service_task(maybe_lookup_len: Option, named: bool, periodic: bool) -> Weight { - let base = Self::service_task_base(); + let base = T::WeightInfo::service_task_base(); let mut total = match maybe_lookup_len { None => base, - Some(_l) => { - // TODO uncomment if we will use the Preimages - // Self::service_task_fetched(l as u32) - base - } + Some(l) => T::Preimages::service_task_fetched(l as u32), }; if named { - total.saturating_accrue(Self::service_task_named().saturating_sub(base)); + total.saturating_accrue(T::WeightInfo::service_task_named().saturating_sub(base)); } if periodic { - total.saturating_accrue(Self::service_task_periodic().saturating_sub(base)); + total.saturating_accrue(T::WeightInfo::service_task_periodic().saturating_sub(base)); } total } } - -impl MarginalWeightInfo for T {} #[frame_support::pallet] pub mod pallet { @@ -1119,7 +1131,7 @@ None => continue, Some(t) => t, }; - let base_weight = T::WeightInfo::service_task( + let base_weight = MarginalWeightInfo::::service_task( task.call.lookup_len().map(|x| x as usize), task.maybe_id.is_some(), task.maybe_periodic.is_some(), @@ -1176,7 +1188,7 @@ } }; - weight.check_accrue(T::WeightInfo::service_task( + weight.check_accrue(MarginalWeightInfo::::service_task( lookup_len.map(|x| x as usize), task.maybe_id.is_some(), task.maybe_periodic.is_some(), --- 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) - + ::service_task(None, true, true) + + >::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) - + ::service_task(None, false, true) + + >::service_task(None, false, true) + TestWeightInfo::execute_dispatch_unsigned() + call_weight + Weight::from_ref_time(3) - + ::service_task(None, false, false) + + >::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) - + ::service_task(None, true, false) + + >::service_task(None, true, false) + TestWeightInfo::execute_dispatch_unsigned() + call_weight + Weight::from_ref_time(1) );