Hey all,
Wanted to create this thread to publicly track and discuss the ongoing effort to migrate to a multi-dimensional weight, which we have named “Weight v2”.
At a high level, Weight is supposed to represent the amount of resources consumed by the blockchain when executing state transitions. Every blockchain is limited on a few factors:
- Computational Time
- Memory Usage
- Storage Usage
At a high level, our current weight system is a single u64
value which measures the computational time to execute some runtime logic, in the Wasm environment, using some reference hardware. These weights are calculated using the benchmarking system.
You can watch this video which is a deep dive into weights and benchmarking for v1: Substrate Seminar: Benchmarking for your Substrate Pallet - YouTube
Weight v1 worked fine for solo-chains, where the only practical limitation was the block time. However, with the parachains protocol, another limit which has been introduced is the proof size, which is needed to execute the proof of validity function by validators on Polkadot.
To satisfy this, we need to update the Weight type to not only represent computational time, but also proof size, to ensure that parachains do not produce blocks which are invalid in the eyes of Polkadot.
pub struct Weight {
/// The computational time used to execute some logic based on reference hardware.
ref_time: u64,
/// The size of the proof needed to execute some logic.
proof_size: u64,
}
The first step will be merged soon which simply updates Weight from a type alias to a single field struct:
As you can see, this will be a painful breaking change, but quite easy to fix, with little chance of making errors as the changes to fix this logic cannot really introduce logical changes.
There will be a few more intermediate steps required to get to the final Weight v2, and I will try my best to keep everyone updated here, as well as on GitHub.