pallet-scheduler: Send CallUnavailable event if the call isn't present (#1161)

The event was already send before, but it was done at the wrong
position. The pull request all changes the `execute_dispatch` signature
to highlight that there is only one error type.

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Javier Viola <javier@parity.io>
This commit is contained in:
Bastian Köcher
2023-08-29 22:42:54 +02:00
committed by GitHub
parent 1c7ef1f232
commit 844eda7626
2 changed files with 53 additions and 13 deletions
+14 -13
View File
@@ -1096,7 +1096,14 @@ impl<T: Config> Pallet<T> {
let (call, lookup_len) = match T::Preimages::peek(&task.call) {
Ok(c) => c,
Err(_) => return Err((Unavailable, Some(task))),
Err(_) => {
Self::deposit_event(Event::CallUnavailable {
task: (when, agenda_index),
id: task.maybe_id,
});
return Err((Unavailable, Some(task)))
},
};
let _ = weight.try_consume(T::WeightInfo::service_task(
@@ -1106,15 +1113,7 @@ impl<T: Config> Pallet<T> {
));
match Self::execute_dispatch(weight, task.origin.clone(), call) {
Err(Unavailable) => {
debug_assert!(false, "Checked to exist with `peek`");
Self::deposit_event(Event::CallUnavailable {
task: (when, agenda_index),
id: task.maybe_id,
});
Err((Unavailable, Some(task)))
},
Err(Overweight) if is_first => {
Err(()) if is_first => {
T::Preimages::drop(&task.call);
Self::deposit_event(Event::PermanentlyOverweight {
task: (when, agenda_index),
@@ -1122,7 +1121,7 @@ impl<T: Config> Pallet<T> {
});
Err((Unavailable, Some(task)))
},
Err(Overweight) => Err((Overweight, Some(task))),
Err(()) => Err((Overweight, Some(task))),
Ok(result) => {
Self::deposit_event(Event::Dispatched {
task: (when, agenda_index),
@@ -1162,11 +1161,13 @@ impl<T: Config> Pallet<T> {
///
/// NOTE: Only the weight for this function will be counted (origin lookup, dispatch and the
/// call itself).
///
/// Returns an error if the call is overweight.
fn execute_dispatch(
weight: &mut WeightMeter,
origin: T::PalletsOrigin,
call: <T as Config>::RuntimeCall,
) -> Result<DispatchResult, ServiceTaskError> {
) -> Result<DispatchResult, ()> {
let base_weight = match origin.as_system_ref() {
Some(&RawOrigin::Signed(_)) => T::WeightInfo::execute_dispatch_signed(),
_ => T::WeightInfo::execute_dispatch_unsigned(),
@@ -1176,7 +1177,7 @@ impl<T: Config> Pallet<T> {
let max_weight = base_weight.saturating_add(call_weight);
if !weight.can_consume(max_weight) {
return Err(Overweight)
return Err(())
}
let dispatch_origin = origin.into();