difftreelog
fix require service_task_fetched for Preimages
in: master
2 files changed
pallets/scheduler-v2/src/lib.rsdiffbeforeafterboth--- 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<W: WeightInfo> {
+ /// Get the weight of a task fetches with a given decoded length.
+ fn service_task_fetched(call_length: u32) -> Weight;
+}
+
+impl<W: WeightInfo> SchedulerPreimagesWeightInfo<W> 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<T: Config>: PreimageRecipient<T::Hash> {
+pub trait SchedulerPreimages<T: Config>:
+ PreimageRecipient<T::Hash> + SchedulerPreimagesWeightInfo<T::WeightInfo>
+{
/// No longer request that the data for decoding the given `call` is available.
fn drop(call: &ScheduledCall<T>);
@@ -200,7 +214,9 @@
) -> Result<(<T as pallet::Config>::RuntimeCall, Option<u32>), DispatchError>;
}
-impl<T: Config, PP: PreimageRecipient<T::Hash>> SchedulerPreimages<T> for PP {
+impl<T: Config, PP: PreimageRecipient<T::Hash> + SchedulerPreimagesWeightInfo<T::WeightInfo>>
+ SchedulerPreimages<T> for PP
+{
fn drop(call: &ScheduledCall<T>) {
match call {
ScheduledCall::Inline(_) => {}
@@ -414,29 +430,25 @@
}
}
-pub(crate) trait MarginalWeightInfo: WeightInfo {
+pub(crate) struct MarginalWeightInfo<T: Config>(sp_std::marker::PhantomData<T>);
+
+impl<T: Config> MarginalWeightInfo<T> {
/// Return the weight of servicing a single task.
fn service_task(maybe_lookup_len: Option<usize>, 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<T: WeightInfo> 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::<T>::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::<T>::service_task(
lookup_len.map(|x| x as usize),
task.maybe_id.is_some(),
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 );