Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

OnInitialize must run in order of declaration in construct_runtime (not in reversed as currently) #6280

@gui1117

Description

@gui1117

Currently OnInitialize is run in the reversed order of their declaration in construct_runtime.

construct_runtime expand AllModules to:

((last, (last-1, ..., (first,))))

and on_initialize for tuple is implemented using first and then second element.

The fix is:

diff --git a/frame/support/procedural/src/construct_runtime/mod.rs b/frame/support/procedural/src/construct_runtime/mod.rs
index d7529cd27..27fd4c3de 100644
--- a/frame/support/procedural/src/construct_runtime/mod.rs
+++ b/frame/support/procedural/src/construct_runtime/mod.rs
@@ -359,10 +359,11 @@ fn decl_all_modules<'a>(
                types.extend(type_decl);
                names.push(&module_declaration.name);
        }
-       // Make nested tuple structure like (((Babe, Consensus), Grandpa), ...)
+       // Make nested tuple structure like ((FirstModule, (SecondModule, (..., (LastModule)...))))
        // But ignore the system module.
        let all_modules = names.iter()
                .filter(|n| **n != SYSTEM_MODULE_NAME)
+               .rev()
                .fold(TokenStream2::default(), |combined, name| quote!((#name, #combined)));
 
        quote!(

But it needs tests and to make sure it doesn't break anything in kusama/polkadot.

Maybe this should be fixed with a flag in construct_runtime so it is opt-in for other chains.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions