-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Consider changing Weight to be a 1-element tuple struct rather than a type alias to u64 #9584
Comments
Is this still important? I was doing some initial investigation into this and the changes would be extremely wide scoping. There are roughly 4,000 references to the fn on_initialize_per_trie_key(k: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 2_000
.saturating_add((2_178_000 as Weight).saturating_mul(k as Weight))
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(k as Weight))) Would it be completely crazy to customize the |
@ericjmiller Unfortunately you can't customize how the However, since the change is so extensive, we haven't really had a consensus yet as to whether this is a desirable change. There could be a potential way forward via constructing a nice API around the new |
If we strongly type Weight and PoVSize then we can have a single tuple of all metadata of a dispatchable to define all of them: |
From a |
I've updated the description to this issue so that we now actually have a clear goal of why we'd need this aside from type safety -- we would eventually want to introduce the concept of Chromatic Weights. |
Will be closed by #10918 |
This is already done with the advent of #12138. |
Nowadays weights are defined as a type alias to
u64
:This could bring in problems for functions that accept a
Weight
, e.g. theGasMeter
constructor in the contracts pallet:There 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:
If I'm not mistaken, the current
Weight
records only the computation time used, so its value would belong to thetime
field. PoV size limits can then also be generalized into storage usage and so be recorded into thestorage
field.Code:
frame/support/src/weights.rs
, and many other files that contain a function acceptingWeight
as a parameterThe text was updated successfully, but these errors were encountered: