0

The documentation of the on_idle hook states that "Any implementation should always respect _remaining_weight and never consume (and therefore return) more than this amount."

In the contracts pallet, the implementation is as follows:

impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
    fn on_idle(_block: BlockNumberFor<T>, mut remaining_weight: Weight) -> Weight {
        use migration::MigrateResult::*;
        // ...

        ContractInfo::<T>::process_deletion_queue_batch(remaining_weight)
            .saturating_add(T::WeightInfo::on_process_deletion_queue_batch())
    }
}

Let's consider a scenario where process_deletion_queue_batch entirely consumes the remaining_weight. In this case, the return value of on_idle will exceed the authorized limit when adding the overhead weight T::WeightInfo::on_process_deletion_queue_batch().

Intuitively, I would rather have done:

ContractInfo::<T>::process_deletion_queue_batch(remaining_weight.saturating_sub(T::WeightInfo::on_process_deletion_queue_batch()))

To ensure that the return value of on_idle never exceeds the remaining_weight.

Is there something I'm missing?

1 Answer 1

0

It appears that I was missing the let base_weight = T::WeightInfo::on_process_deletion_queue_batch(); statement in the deletion_budget(weight_limit: Weight) function, which is called within the process_deletion_queue_batch(weight_limit: Weight) function. As a result, the returned weight will never exceed the remaining_weight.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.