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.

Introduce on_runtime_upgrade similarly to on_initialize but executed before. #4056

@gui1117

Description

@gui1117

With the recent introduction of StorageValue::translate a new pattern appeared in on_initialize:

fn on_initialize() {
    if new_runtime.get() == true {
        MyStorageValue::translate(...);
        new_runtime.put(false);
    }
}

The error proneness is that on_initialize are executed in the order declaration in construct_runtime. Thus if one upper module in on_initialize call your module and use this storage, then the value is still the old encoded one. And thus can leads to very error.

To solve this we can introduce a new function: on_runtime_upgrade_initialize which will be call before all on_initialize.
With this the code to check is just the code contained in on_runtime_upgrade_initialize of other module which logic is easier to audit.

cc @shawntabrizi

Metadata

Metadata

Assignees

No one assigned

    Labels

    J0-enhancementAn additional feature request.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions