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

Add some migration helper to help migrating pallet changing pallet prefix #8199

Merged
merged 6 commits into from
Mar 2, 2021

Conversation

gui1117
Copy link
Contributor

@gui1117 gui1117 commented Feb 24, 2021

when migrating from decl_storage to frame v2, some pallet needs to migrate their storage too.

This is some helper to move some specific storage in case the pallet prefix is shared by multiple pallets (e.g. treasury and bounty) or to move all pallet.

This can be useful for
#8193
#8196
#8044

@gui1117 gui1117 added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. A3-in_progress Pull request is in progress. No review needed at this stage. and removed A0-please_review Pull request needs code review. labels Feb 24, 2021
@gui1117 gui1117 added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Feb 25, 2021
@gui1117
Copy link
Contributor Author

gui1117 commented Feb 26, 2021

I'm not sure who to ping for review, but those should be easy to review and are helping for migrating to framev2

/// key on storage prefix is also moved.
pub fn move_storage_from_pallet(item: &[u8], old_pallet: &[u8], new_pallet: &[u8]) {
let mut new_prefix = Vec::new();
new_prefix.extend_from_slice(&Twox128::hash(new_pallet));
Copy link
Contributor

@kianenigma kianenigma Feb 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we reuse anything other storage types to generate this key? I am worried that we have hardcoded this pattern of twox(pallet-name) ++ twox(storage name) in many places. External teams have probably made this mistake even more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately I made the generator traits StorageValue, StorageMap and StorageDoubleMap abstract on the key generation with a default implementation :-/ so we can't make use of it directly.
We can still introduce a function for generating this key though.

Also the end I think we can refactor quite a bit if we get rid of decl_storage.

Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was actually waiting for something like this before finishing #8044!

Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but docs need to be improved.

All these from_prefix and to_prefix are sometimes hashed internally, sometimes not. Would be nice to get better docs on this.

frame/support/src/storage/migration.rs Outdated Show resolved Hide resolved
///
/// NOTE: It actually moves every key after the storage prefix to the new storage prefix,
/// key on storage prefix is also moved.
pub fn move_storage_from_pallet(item: &[u8], old_pallet: &[u8], new_pallet: &[u8]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could add some example and more docs on what these parameters are?

This is relative complicated to understand from the current docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, I improved, I hope its clearer now.

///
/// NOTE: It actually moves every key after the pallet prefix to the new pallet prefix,
/// key on pallet prefix is not moved.
pub fn move_pallet(old_pallet: &[u8], new_pallet: &[u8]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

gui1117 and others added 2 commits March 2, 2021 17:23
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
@bkchr bkchr merged commit 73942bc into master Mar 2, 2021
@bkchr bkchr deleted the gui-migration-helper branch March 2, 2021 18:13
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. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants