-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add some migration helper to help migrating pallet changing pallet prefix #8199
Conversation
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)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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!
There was a problem hiding this 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.
/// | ||
/// 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]) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
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