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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The initial
StorageVersion
of a pallet is only set in itsOnGenesis
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()
return0
. This might lead to storage migrations falsely triggering. This actually happened to some chains addingpallet-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).