2

In my benchmarks, I've written multiple benchmarks for an extrinsic to cover different scenarios, which gave me WeightIinfo for each of my benchmarks.

Now the question here is how I can pick the worst scenario for my extrinsic dynamically?

1 Answer 1

4

Good question!
The #[pallet::weight(…)] annotation allows you to do some light compile-time computations.
This makes it possible to calculate a maximum like this:

#[pallet::weight(T::WeightInfo::slow().max(T::WeightInfo::slower()))]

One example of this can be found in the bags-list pallet.
It is important to only do very lightweight calculations here, since the terms are evaluated to judge whether or not an extrinsic should be able to execute.
I think the most complicated weight terms are in the utility pallet.

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.