paritytech / polkadot-sdk

The Parity Polkadot Blockchain SDK
https://polkadot.network/
1.8k stars 652 forks source link

Automatic weight sanity checker #152

Open kianenigma opened 1 year ago

kianenigma commented 1 year ago

In any given FRAME based runtime, the total block weight is known. Moreover, an extensive list of weight functions is also known. Most often, each weight function corresponds to a single dispatchable, or a single hook. If not, it almost always refers to a subset of them.

We also know that the entire weight system is linear.

Given these two points, it is fair to assume that the following is possibly a mis-configuration of the runtime.

If the execution of any weight function, where all components are Bounded::min_value() already exceeds the maximum block weight.

This can happen as a separate test that lives inside construct_runtime, an independent opt-in test, or seemingly best, happen as a part of the benchmark execution where the component ranges is known, and we don't need to fallback to Bounded::min_value.

jtfirek commented 1 year ago

I've been looking into starting this and I have a few questions / assumptions.

xlc commented 1 year ago

We really should have the benchmark data stored in a proper data file format such as csv and then use the csv file to generate weight file. And then can also do whatever additional checks from the csv file directly without all the complicated Rust changes.

Daanvdplas commented 1 year ago

@jtfirek are you still working on it? Otherwise I'd like to do it!

kianenigma commented 1 year ago

Moreover, an extensive list of weight functions is also known

I want to clarify that I am pretty sure this information is available, but I can't recall the exact trait that would return it. I will post it here if I find it, as it would be the starting point of this issue. @ggwpez maybe you know it in your 🧠? :D

@Daanvdplas feel free to ask questions if you have any!

ggwpez commented 1 year ago

Daan asked me about it and seems to be on his way 😄
The current approach will print the warning when running the CLI, not as part of construct_runtime!.