What happens if the value of #[weight] I choose is higher than the real life weight usage? According to frame documentation, it says :

Fees are then based on the worst case weight. If the actual call performs better than the worst case, the weight is adjusted and any excess fees can be returned.

Is this step automatic or do I need to write code to make this happen?

1 Answer 1


The adjustment has to happen manually indeed.
The return value of a call is either DispatchResult or DispatchResultWithPostInfo. The first type cannot refund any weight and implies that the user always pays the worst-case fee.
When using DispatchResultWithPostInfo; you can adjust the actually used weight by returning it.
One example would be in the Alliance pallet, which gets in a worst-case witness and then adjusts to the actually used weight. Another one is in the Ranked-Collective, where the transaction will cost nothing in certain cases.

There is an issue open in Substrate that will address automatic refunds, but only for the PoV dimension of the Weight. The execution time will still need to be adjusted for manually.

To answer the Q in the title:
The consequence is that the users pays more fees than are actually required for spam protection of the chain. Depending on the discrepancy between worst-case and actual-case weight, this can be no problem at all or a huge problem. All depending on how large that discrepancy is.
Therefore in Substrate we normally do the manual refunding when we assume the discrepancy to be large enough to justify the additional code, benchmarking and testing effort.

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.