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

FRAME: Initialize StorageVersion on runtime upgrade #13430

Closed
wants to merge 2 commits into from

Conversation

athei
Copy link
Member

@athei athei commented Feb 21, 2023

The initial StorageVersion of a pallet is only set in its OnGenesis implementation. This works for pallets which exist at genesis. However, if a pallet is added later with a runtime upgrade the version will be uninitialized in storage.

Runtime authors need to manually make sure that they initialize this value when adding a pallet. If they forget it can have bad consequences: An uninitialized value will make StorageVersion::get() return 0. This might lead to storage migrations falsely triggering. This actually happened to some chains adding pallet-contracts.

Downside is that this adds one storage read per pallet on runtime upgrades. The added safety and convenience might be worth it.

Maybe we should also write the genesis configuration of the added pallet (if it exists) to storage if no storage version was set (we assume the pallet was added).

@athei athei added A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit B1-note_worthy Changes should be noted in the release notes T1-runtime This PR/Issue is related to the topic “runtime”. labels Feb 21, 2023
@ggwpez
Copy link
Member

ggwpez commented Feb 21, 2023

Basti is working on something similar #13417

@bkchr
Copy link
Member

bkchr commented Feb 21, 2023

There exists a migration for this

pub fn migrate_from_pallet_version_to_storage_version<

This was added as we introduced storage version.

@bkchr bkchr closed this Feb 21, 2023
@athei athei deleted the at/init-storage-version branch March 10, 2023 11:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B1-note_worthy Changes should be noted in the release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit T1-runtime This PR/Issue is related to the topic “runtime”.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants