Skip to main content
edited tags
Link
Bruno
  • 8.5k
  • 1
  • 13
  • 37
edited tags
Link
Source Link

Does anybody pays for computation inside hooks?

Hooks can do computation and read/write storage. Operations that usually comes at price. Those hooks return a -> Weight value, but from my understanding nobody is paying for this. It's just used to increment BlockWeights a counter that must not go above base_block.

This given while reading FRAME pallets it's unclear for me what part of the hook computation should be taken into account into this returned Weight.

I more or less found two cases:

But in some pallets, part of the operation seems to be not taken into account: https://paritytech.github.io/substrate/latest/src/pallet_election_provider_multi_phase/lib.rs.html#700. The let current_phase = Self::current_phase(); is a read that I don't see being added to the weight.

And the last category is hooks that return 0, such as autorship, babe.

I would greatly appreciate to have at least a rule of thumb on what I am suppose to do with my on_initialize hooks, and if that exist a clear guide on what to do and list of the different cases I can face.