1

Hi Substrate Community,

is there any way to get the current block weight? This is especially useful, when deciding in on_finalize if there is space left to put in some logic. I know, that on_finalize is guaranteed to run, but I would only run if a block is not full.

How can I manage to do this with Substrate?

I already tried to look into the transaction_payment and frame_system pallet. I could find a BlockWeights struct, but it hasn't the current block weight inside it.

1
  • Did you have a look at on_idle? It gets the remaining weight passed in. Sep 15, 2022 at 10:14

1 Answer 1

0

The on_idle hook is probably closer to what you are looking for.
It gets the remaining weight passed into it like this:

fn on_idle(block: T::BlockNumber, remaining: Weight) -> Weight

This happens after all normal transactions and before on_finalize.

Your Answer

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

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