Explore Courses Blog Tutorials Interview Questions
0 votes
in Blockchain by (12.7k 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.5k 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:


<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

Browse Categories