6

How do I find the maximum weight available to extrinsics in a block for a substrate-, FRAME-based chain such as Polkadot?

  • I know that there is WEIGHT_PER_SECOND value, but it doesn't answer my question since I don't know how many seconds are allowed within a block?
  • I tried googling and got this article which mentions MaximumBlockWeight but that seems to be removed in previous versions of Substrate.

Please help me!

2 Answers 2

9

The various weight configurations on a Substrate chain are all collected in a blockWeights configuration constant which can be found in the System Pallet.

enter image description here

You can see in the image above the Kusama network has a maxBlock configured to 2_000_000_000_000 which is equivalent to "2 seconds of weight".

This is generated via a builder pattern defined here:

https://github.com/paritytech/substrate/blob/master/frame/system/src/limits.rs

In the Substrate node, you can find the builder definition inside the Runtime configuration:

pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
    .base_block(BlockExecutionWeight::get())
    .for_class(DispatchClass::all(), |weights| {
        weights.base_extrinsic = ExtrinsicBaseWeight::get();
    })
    .for_class(DispatchClass::Normal, |weights| {
        weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
    })
    .for_class(DispatchClass::Operational, |weights| {
        weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
        // Operational transactions have some extra reserved space, so that they
        // are included even if block reached `MAXIMUM_BLOCK_WEIGHT`.
        weights.reserved = Some(
            MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT
        );
    })
    .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
    .build_or_panic();

Obviously a lot of assumptions happening here in the background to calculate all these different weight values, but this is the source of that logic.

8

How many seconds are available per block comes down to computation power aka the underlying hardware that is supporting the blockchain.

So you are right:

pub const WEIGHT_PER_SECOND: Weight = 1_000_000_000_000;

Substrate defines one unit of weight as one picosecond of execution time, that is 10^12 weight = 1 second, or 1,000 weight = 1 nanosecond, on fixed reference hardware (Intel Core i7-7700K CPU with 64GB of RAM and an NVMe SSD).

So a recap:

  • 1 unit of weight = 1/1_000_000_000_000 of a second of execution time
  • 1_000_000_000_000 units of weight = 1 second
  • 1_000 units of weight = 1 nanosecond

Maximum Block Weight

The maximum block weight should be equivalent to one-third of the target block time, allocating one third for block construction, one third for network propagation, and one third for import and verification.

So if the block time is 6 seconds then 1/3 would be 2 seconds of weight, which as Shawn mentioned is 2_000_000_000_000 units of weight.

Maximum weight can be tuned.

In order to tune a runtime for different validator hardware assumptions, you can set a different maximum block weight.

These tuning options give runtime developers a way to make the optimal transaction per second vs. hardware requirement trade-offs for their use case. These trade-offs can be tuned with runtime updates to keep up with hardware and software improvements.

Reference: https://docs.substrate.io/v3/concepts/weight

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.