Currently we have the WeightInfo trait which exposes several weight functions in the form of:
pub trait WeightInfo {
fn call_a() -> Weight;
fn call_b() -> Weight;
…
}
Sometimes you want to iterate over all weight functions and do something weight their name or result (eg in paritytech/substrate#12485).
One way to do this would be to have another type; WeightMetaInfo whose implementation is auto-generated as well:
pub trait WeighMetatInfo<W: WeightInfo> {
/// Executes a callback for each weight function by passing in its name and return value.
fn visit_weight_functions<F: Fn(&'static str, Weight) -> R, R>(f: F) -> Vec<R>;
}
This would allow us to do:
- Mocked
WeigtInfo implementations such that the weight of a call can be dynamically set in a test (Is already possible, but not in a spell-checked way without ugly macros).
- Checking that all weights of a pallet are in a specific bound as part of the runtime-integrity check (eg. no
Zero or stray todo!()).
I am not entirely convinced that this is the best design, but having this in some way would be nice.
Currently we have the
WeightInfotrait which exposes several weight functions in the form of:Sometimes you want to iterate over all weight functions and do something weight their name or result (eg in paritytech/substrate#12485).
One way to do this would be to have another type;
WeightMetaInfowhose implementation is auto-generated as well:This would allow us to do:
WeigtInfoimplementations such that the weight of a call can be dynamically set in a test (Is already possible, but not in a spell-checked way without ugly macros).Zeroor straytodo!()).I am not entirely convinced that this is the best design, but having this in some way would be nice.