3

We use some external pallets that are highly configurable. The weight of the extrinsics in these pallets is highly dependent on the callback supplied in the config, and the existing benchmarks don't properly account for that. Is there any way to write a custom benchmark for an externally defined pallet?

3
  • Please clarify what you mean by external pallet. Are you importing a pallet and want a custom benchmark for that pallet?
    – Bruno
    Apr 14 at 14:25
  • How does it not account for that? Please provide a link to the code. In general it should not be needed to re-impl a benchmark. Apr 14 at 14:35
  • So for example we specify non-trivial CurrencyHooks in the runtime configuration of orml-tokens but obviously the upstream benchmarks can't account for those. What is the recommended approach here? Apr 14 at 14:47

3 Answers 3

1

In general it should not be necessary to implement custom benchmarks for external pallets.

You just have to configure the concrete callbacks in your runtime and re-run the benchmark. The weight of the callbacks will then be included in the output.

This is easier that to annotate weights in interface. Otherwise all interfaces that can be used as callback would need to expose their weight info as well.

In your example i dont see a difference. Since every runtime config needs to re-run benches, the effort for the CurrencyHooks will be included.

1
  • But the specific CurrencyHooks that we use only have a high cost for some of the currencies, and only when the chain is a particular state. So we need the benchmark to setup that state and use that particular currency, otherwise it won't hit the worst-case
    – Sander
    Apr 20 at 10:45
0

Yes, you always should generate the weights based on your runtime configuration and your hardware requirements.

See and example from one of the FRAME pallets: the pallet_balances: In Polkadot has its own Weights file and is different than the Wights file in another chain, Kusama for example. Then in your Config have to specify your Weights. See the runtime file in Kusama.

Take a look into this previous answer on StackExchange: Benchmark FRAME pallets, for a more complete explanation about it.

3
  • I am aware of how to run benchmarks for external pallets in general, using the benchmarks supplied by the pallets themselves. The question is about supplying a custom benchmark for an external pallet, not about running existing benchmarks
    – Sander
    Apr 14 at 13:47
  • Can you be more specific of the pallet and the configuration you are using? to understand better why the benchmarks are not accurate for your case
    – Alex Bean
    Apr 14 at 14:09
  • To give an example, orml pallets come without benchmarks: github.com/open-web3-stack/open-runtime-module-library/tree/… . You could argue that the project should just add them, but some of these pallets are highly customizable by supplying custom hooks, making generic benchmarks difficult
    – Sander
    Apr 14 at 14:51
0

For anyone finding this post in the future.. We got a working solution based on the frame_system benchmarks. See our custom benchmark here. The idea is to define a new dummy Pallet and Config item, write benchmarks for them, and apply the generated weights to the original pallet.

Your Answer

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

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