-
Notifications
You must be signed in to change notification settings - Fork 707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FRAME: Avoid boilerplate weight macros #205
Comments
I'll add this to the macros meta issue #264, good one! |
Yea or some kind of meta-functions (V2 only) that can be used to do these calculations and then become part of the mod benchmarks {
use super::*;
// other benchmarks…
#[weight_function]
fn transfer() -> Weight {
transfer_worst_case()
.max(transfer_best_case())
}
} These could also accept components. |
@sam0x17 can this be incorporated as a part of #380, and placed in the roadmap? All in all, I am not super versed in the latest suggested features for benchmarking and weight. It seems like even #380 is not a good representation of all the items we want to achieve. Perhaps you can re-evaluate everything that you foresee, and make a new tracking issue for the roadmap? happy to help brainstorming if needed. |
The first part was done here paritytech/substrate#13932. I implemented the second part locally, but it was quite general. It resulted in possible syntax like this: #[benchmarks]
mod benches {
#[aggregated]
fn my_max() {
T::WeightInfo::fast()
.max(T::WeightInfo::slow())
}
} Any arbitrary code could be written in |
So you just get a really confusing error message basically? |
Yea basically. The problem is that the code gets pasted into here and the errors when trying to compile it next time. |
Do we want to restrict what you can do in there, like maybe const fn only? Whitelist of function calls? |
This is already done. |
Currently we specify weights individually for each call. In cases of complex weights, this is fine. But often times pallets have very simple
O(1)
weights. An example is the new core-fellowship pallet, whose call block looks like this:This is a bit tedious, but more importantly it's very error-prone. If the line reading:
were accidentally written:
Then there would be no build error or warning and everything would appear to proceed well but the chain would be at risk of a potentially devastating DoS attack.
Instead, we should dispense with per-function weights in the general case and instead have a directive at the level of the call-block instructing the default weight to be determined as the function call in the
WeightInfo
of the same name as the call function. Thus the previous code becomes:Ideally, we could come up with a combination of pallet macros,
WeightInfo
API/convention and benchmarking macros to allow the complete avoidance of manual weight specification logic in the call block.For a start, one other pattern which is quite common to see is multi-modal-maximum, whereby a call has two or more benchmarks, each forcing a different control-flow, and the call's weight is the per-component
max
. See thebump
call in the core-fellowship pallet:We might have some better (more declarative, less procedural) means of expressing this:
A better way would be to avoid relying on purely string prefixes, and actually have tagged groupings in the benchmarking/WeightInfo APIs but this would be a bigger job.
The text was updated successfully, but these errors were encountered: