on_initializereturns a weight, but what is the effect of this weight exceeding block weight limit? Is the block valid? can extrinsic still be included?
on_finalizeddoes not return a weight, does that mean it always runs regardless of what remains of the block weight budget as a result of extrinsics+
Here is the schematical representation of the block weight:
┌────────────────────────────────────────────────────────────────────────────┐ │┌──────────────────┐┌───────────────────────────────────┐┌─────────────────┐│ ││ ││ ││ ││ ││ on_initialize ││ extrinsics ││ on_finalize ││ ││ ││ ││ ││ │└──────────────────┘└───────────────────────────────────┘└─────────────────┘│ └────────────────────────────────────────────────────────────────────────────┘ ◀─────────────────────────────────Block Weight─────────────────────────────▶
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
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.