-
Notifications
You must be signed in to change notification settings - Fork 2.6k
migrate pallet-elections-phragmen to attribute macros #8044
Conversation
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.
Needs a companion and some nitpicks, otherwise looks good.
@thiolliere did you see my note about breaking change though? this will sadly need a migration, or we must rename the runtimes in polkadot/kusama. Honestly, I wish we could migrate the prefix to |
Yes that's what I meant by need a companion, but indeed we can also write the migration code in this pallet. or we decide to rename the pallet instead |
Co-authored-by: Guillaume Thiolliere <[email protected]>
I thought about this a bit further and:
|
I would prefer third party tools to fetch the storage from the metadata. If third party tools fetch the storage using the metadata. then they shouldn't break. |
I recall that one of the reasons for preferring to keep the storage of #8254 under |
AFAIK polkadot js already uses the prefix from the metadata and I think we should assume this model for the rest. Overriding the storage prefix is somewhat weird. This is again just a Polkadot specific feature, while we are here in Substrate ;) |
at some point, if third party tools are using metadata to fetch system accounts, then I'm not sure keeping it at the same location will help them. Because the Account storage will no longer be in the metadata in system pallet. |
The conclusion is therefore to change the prefix, and let tools figure it out via the metadata. |
Can't we just change the name in |
We could, but as noted above my preference is to fix this and move the storage as well. I am fine with removing the migration from this PR and adding it as a separate PR, but that should make no difference and the code is not that complicated. Also, we should provide the migration code anyhow, even if we are not going to use it ourselves. This pallet is the only one that I am experimentally trying to maintain with proper versions and all migrations are kept in the code as reusable snippets. |
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 to me. with:
- removal of added origin
- change in pre_migration test function.
- needs to merge master: ModuleId is changed into PalletId
log::info!("pre-migration elections-phragmen test with new = {}", new); | ||
|
||
// ensure some stuff exist in the old prefix. | ||
assert!(sp_io::storage::next_key(OLD_PREFIX).is_some()); |
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.
this only ensures that there exist some key which are after OLD_PREFIX
in the lexical order.
If OLD_PREFIX starts with 0
then any key which starts with 1
will make this succeed.
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.
- // ensure some stuff exist in the old prefix.
- assert!(sp_io::storage::next_key(OLD_PREFIX).is_some());
+ // the next key must exist, and start with the hash of `OLD_PREFIX`.
+ let next_key = sp_io::storage::next_key(OLD_PREFIX).unwrap();
+ assert!(next_key.starts_with(&sp_io::hashing::twox_128(OLD_PREFIX)));
+
I think this makes good sense.
Co-authored-by: Guillaume Thiolliere <[email protected]>
…aritytech/substrate into kiz-elections-phragmen-attribute-macro
as recommended by @shawntabrizi, I removed the migrations from polkadot repo. The companion will instead rename the name of the pallet. Please check it letter by letter! :D And once both PRs are approved I will merge this. Note that I will still provide the migration scripts since other chains might use to actually migrate. I home my changelog is also enough to prevent people from breaking their chain if they accidentally apply this. |
|
||
match maybe_storage_version { | ||
Some(storage_version) if storage_version <= PalletVersion::new(3, 0, 0) => { | ||
log::info!("new prefix: {}", new_pallet_name.as_ref()); |
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 think we should check if old prefix == new prefix and if so we don't do the migration.
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.
addressed.
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.
Not too sure we want to bump the version here, but okay.
@gnunicorn thoughts on that?
FYI I've bumped this crates version in the past as well. I don't think it causes any issues for @gnunicorn as long as we don't release anything solo. |
bot merge |
Waiting for commit status. |
bot merge |
Trying merge. |
part of #7882.
Previous usage of decl_storage set the pallet storage prefix to
PhragmenElection
, while in both Polkadot and kusama it is set toElectionsPhragmen
https://github.com/paritytech/polkadot/blob/4866f8e72029e719d7ce74e341bb1e94ebd724f7/runtime/polkadot/src/lib.rs#L1002
https://github.com/paritytech/polkadot/blob/4866f8e72029e719d7ce74e341bb1e94ebd724f7/runtime/kusama/src/lib.rs#L997
Therefore, this will need
From https://crates.parity.io/frame_support/attr.pallet.html#checking-upgrade-guidelines
So users of the
ElectionsPhragmen
pallet must be careful about the name they used inconstruct_runtime!
. Hence theruntime-migration
label, which might not be needed depending on the configuration of theElectionsPhragmen
pallet.polkadot companion: paritytech/polkadot#2765