-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Consider changing Weight to be a 1-element tuple struct rather than a type alias to u64 #9584
Description
Nowadays weights are defined as a type alias to u64:
pub type Weight = u64;This could bring in problems for functions that accept a Weight, e.g. the GasMeter constructor in the contracts pallet:
fn new(gas_limit: Weight) -> SelfThere could be a potential hazard where the caller sent in a u64 that does not represent the gas limit, but instead represents some other quantity (such as a block number or an account ID). The compiler currently does not catch such kinds of errors, and will happily compile the code successfully.
More importantly, converting the type alias to a struct is part of the vision of trying to create Chromatic Weights, where not only do we record the weight of the time used for computation, we'd also include the storage used and the heap memory used to execute a particular extrinsic or function.
We could imagine that Chromatic Weights will have the following format:
struct ChromaticWeight {
pub storage: u64,
pub time: u64,
pub memory: u64,
}If I'm not mistaken, the current Weight records only the computation time used, so its value would belong to the time field. PoV size limits can then also be generalized into storage usage and so be recorded into the storage field.
Code: frame/support/src/weights.rs, and many other files that contain a function accepting Weight as a parameter