Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Blockchain by (12.8k points)
edited by

I need to be sure that the on_initialize handler for a specific module runs before the same handler before all other modules in my runtime.

a) How do ensure this?

b) Is there some compile or runtime check I can enforce to absolutely guarantee that this will be respected?

1 Answer

0 votes
by (29.8k points)

The 'on_initialize' function for each Substrate runtime module is called via the Executive module, which handles all of the top-level stuff; essentially just executing blocks/extrinsics.

Every time a block is executed (execute_block), first initialize_block is called which ultimately calls the 'on_initalize' block for the
AllModules type:

srml/executive/src/lib.rs

<AllModules as OnInitialize<System::BlockNumber>>::on_initialize(*block_number);

The AllModules type is a tuple of the different module identifiers in your runtime. It generated by the construct_runtime! macro and lists the modules in the order you defined them in the macro

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...