1
  • on_initialize returns a weight, but what is the effect of this weight exceeding block weight limit? Is the block valid? can extrinsic still be included?
  • on_finalized does not return a weight, does that mean it always runs regardless of what remains of the block weight budget as a result of extrinsics+on_initialize

1 Answer 1

4

Here is the schematical representation of the block weight:

┌────────────────────────────────────────────────────────────────────────────┐
│┌──────────────────┐┌───────────────────────────────────┐┌─────────────────┐│
││                  ││                                   ││                 ││
││  on_initialize   ││            extrinsics             ││   on_finalize   ││
││                  ││                                   ││                 ││
│└──────────────────┘└───────────────────────────────────┘└─────────────────┘│
└────────────────────────────────────────────────────────────────────────────┘
 ◀─────────────────────────────────Block Weight─────────────────────────────▶ 
                                                                              

The on_initialize is privileged in a way that it can take how much weight it wants. If necessary, the logic there can take almost the whole budget without leaving anything for the extrinsics processing.

on_finalize is always executed and there is no way to skip that. on_finalize takes control after all extrinsics are executed. The problem is that whoever packs the block can fill up the extrinsics so that there is no space left for the on_finalize logic. That's why the convention is on_initialize returns the weight for itself and for on_finalize.

Substrate does not impose any hard limits on weight. However, Polkadot does. If a parachain validation function took more weight than alloted, such a block will be discarded.

2
  • Thank you. Are you saying that in Substrate, on_finalize can even exceed the block weight limit? Aug 15, 2022 at 8:29
  • @BedehoMender yes on_initialize and on_finalize can exceed the block weight and the block will still be valid.
    – pepyakin
    Aug 15, 2022 at 10:06

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.