1

As far as I understand, weights for a runtime's pallets can be generated in two ways:

  • Altogether by using this script provided by the polkadot-sdk, with the output typically stored in the runtime module.
  • Specifically for each pallet, with the output usually stored in the pallet module.

I assume both methods generate pretty much the same output in terms of weight. However, when using those weights in the runtime configuration, they are not always used in the same way:

For example, here Moonbeam generates weights for pallet-balances even though it could import the weights generated by the pallet, as Astar does here.

Two questions come to my mind:

  • Is this because Moonbeam wants to ensure the same machine is used to generate all the weights?
  • In the case where I need to configure the WeightInfo type in the runtime config for a custom pallet, would it matter if I import weights from the runtime or pallet module, considering that both weights are generated on the same machine?

1 Answer 1

2

Weights are runtime-dependant. Do not use the weights from the SDK in your production runtimes!

For example, here Moonbeam generates weights for pallet-balances even though it could import the weights generated by the pallet, as Astar does here.

Yes this is how it should be done.

There are two ways to generate weights depending on what you want to do. If you want to create a new pallet, then it should provide default weights, so that other people can use those for testing (not production).
For that case there is a specific template that then generates the WeightInfo trait and default impls for SubstrateWeight and ().

Now if you only want to integrate a pallet into your runtime, it is enough to use the reduced template. This is also the default when running benchmark pallet. This does not generate the WeightInfo trait, but a WeightInfo struct.

In general, its a good idea to take a look at how Polkadot does it. The configuration is in line with all recommendations.
It generates weights for each pallet and then uses these weights in its runtime configuration. This ensures that all factors are accounted for. Just using the default SubstrateWeight is a bad idea because it does not test custom configured callbacks etc.

Altogether by using this script provided by the polkadot-sdk, with the output typically stored in the runtime module.

Could work - but the script is meant to be internal and poorly maintained. Would also need to remove the template argument.

Specifically for each pallet, with the output usually stored in the pallet module.

This is for the case that you developed a pallet yourself. Which is why we do it in the SDK, but not in the Polkadot runtimes repo.

Is this because Moonbeam wants to ensure the same machine is used to generate all the weights?

Dont know. They should do it anyway.

In the case where I need to configure the WeightInfo type in the runtime config for a custom pallet, would it matter if I import weights from the runtime or pallet module, considering that both weights are generated on the same machine?

Best practice would mandate the former. We do the same in Rococo+Westend runtimes.
People just copy&paste everything, so its probably better do do it right.

1
  • 1
    understood, really appreciate the detailed answer
    – magecnion
    Apr 3 at 9:10

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.