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

Move PalletVersion away from the crate version #9165

Merged
15 commits merged into from
Jul 27, 2021
Merged

Conversation

bkchr
Copy link
Member

@bkchr bkchr commented Jun 21, 2021

Before this pr, PalletVersion was referring to the crate version that
hosted the pallet. This pr introduces a custom package.metadata.frame
section in the Cargo.toml that can contain a pallet-version key
value pair. While the value is expected to be a valid u16. If this
key/value pair isn't given, the version is set to 1.

It also changes the PalletVersion declaration. We now only have one
u16 that represents the version. Not a major/minor/patch version. As
the old PalletVersion was starting with the u16 major, decoding the
old values will work.

polkadot companion: paritytech/polkadot#3526

Before this pr, `PalletVersion` was referring to the crate version that
hosted the pallet. This pr introduces a custom `package.metadata.frame`
section in the `Cargo.toml` that can contain a `pallet-version` key
value pair. While the value is expected to be a valid u16. If this
key/value pair isn't given, the version is set to 1.

It also changes the `PalletVersion` declaration. We now only have one
`u16` that represents the version. Not a major/minor/patch version. As
the old `PalletVersion` was starting with the `u16` major, decoding the
old values will work.
@bkchr bkchr added A0-please_review Pull request needs code review. B7-runtimenoteworthy 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 labels Jun 21, 2021
@shawntabrizi
Copy link
Member

As the old PalletVersion was starting with the u16 major, decoding the old values will work.

nice

@athei
Copy link
Member

athei commented Jun 22, 2021

Why is this useful and to which version (crate or pallet) do I refer to in my CHANGELOG.md from now on?

gui1117
gui1117 previously approved these changes Jun 23, 2021
Copy link
Contributor

@gui1117 gui1117 left a comment

Choose a reason for hiding this comment

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

code looks good to me,

I don't have strong opinion between storage-version and pallet-version.

  • storage-version makes it more close to its current usage: we bump it when storage is breaking and do some conditional with it in storage migrations
  • pallet-version makes it more close to its original goal (as I understand it): having a stored number which can identifier clearly the pallet. So we can easily checkout the pallet code. But if we don't bump this number when the pallet behaviour changes, then the name is more misleading than helpful.

Also I agree 0 could make more sense when no version is defined https://github.com/paritytech/substrate/pull/9165/files#r655954312

@apopiak
Copy link
Contributor

apopiak commented Jun 24, 2021

Just FYI that this XCM PR currently assumes (major, minor, patch) for pallet versions:
polkadot-fellows/xcm-format#22

@bkchr
Copy link
Member Author

bkchr commented Jun 29, 2021

Just FYI that this XCM PR currently assumes (major, minor, patch) for pallet versions:
paritytech/xcm-format#22

Hmm good point. Yeah, I don't know. I'm still seeing the "need" for this, but currently no one bumps any versions anyway... So, yeah... It is hard.

@bkchr
Copy link
Member Author

bkchr commented Jul 1, 2021

Or we just keep the PalletVersion with major, minor and patch and make these values set able through the Cargo.toml as I have done it here already in the pr?

CC @shawntabrizi

@bkchr
Copy link
Member Author

bkchr commented Jul 1, 2021

@kianenigma @thiolliere @athei what do you think?

@kianenigma
Copy link
Contributor

kianenigma commented Jul 1, 2021

TBH I am only interested in this for storage migrations (see my linked issue), so that we can get rid of all the transient storage items. For that, a single version is enough. If the triplet is also useful in certain cases, we can

version = "x.y.z" // This is written as 'PalletVersion', basically the old system

[package.metadata.frame]  
storage-version = "v" // This is written as `StorageVersion`

version is only about crates.io and semver. storage-version is only about the version of storage, and with each change, it should be bumped. In an ideal world, any storage-version bump must have a major version update as well. But the opposite is not true.

@shawntabrizi
Copy link
Member

shawntabrizi commented Jul 2, 2021

I think this should be named storage-version and contain just a single value, similar to spec_version and stuff

storage is either backwards compatible or not. afaik, there is not a need for minor and patch version numbers

@athei
Copy link
Member

athei commented Jul 2, 2021

I agree with shawn and kian. We only need one number because this version seems to be about storage only (for everything else we have the crate version). We should name it storage-version and it should be a single number.

@apopiak
Copy link
Contributor

apopiak commented Jul 5, 2021

Agree as well. Just linked the XCM PR to make sure that we adjust that once we change this.

bkchr added 2 commits July 6, 2021 12:32
- Drop PalletVersion
- Introduce StorageVersion
- StorageVersion needs to be set in the crate and set for the macros
- Added migration
@bkchr
Copy link
Member Author

bkchr commented Jul 8, 2021

Okay I have rewritten the entire thing.

  • PalletVersion was removed and replaced by StorageVersion
  • We don't have any magical macro anymore that pulls data out of the Cargo.toml. I decided for making the storage version explicit as a const in the top of the crate. However, we still need to tell the pallet macros about it.
  • The pallet author is also now required to set the correct storage version after a migration.
  • I added a migration for migrating from PalletVersion to StorageVersion.

Copy link
Contributor

@gui1117 gui1117 left a comment

Choose a reason for hiding this comment

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

needs to fix the on genesis for decl_storage macro: #9165 (comment)

But otherwise it is good to me

@gui1117
Copy link
Contributor

gui1117 commented Jul 27, 2021

Note for other about migration:

The storage version is now stored under a different prefix than the old pallet version. To upgrade you can use migrate_from_pallet_version_to_storage_version like in https://github.com/paritytech/polkadot/pull/3526/files
Basically adding the struct:

/// Migrate from `PalletVersion` to the new `StorageVersion`
pub struct MigratePalletVersionToStorageVersion;

impl OnRuntimeUpgrade for MigratePalletVersionToStorageVersion {
	fn on_runtime_upgrade() -> frame_support::weights::Weight {
		frame_support::migrations::migrate_from_pallet_version_to_storage_version::<AllPalletsWithSystem>(
				&RocksDbWeight::get()
		)
	}
}

And add this struct to the generic CustomOnRuntimeUpgrade of Executive

Warning: The custom runtime upgrade happens before the pallet's runtime upgrede (defined inside hooks). Thus any hook who rely on the pallet version won't be triggered and migration must be done manually. in substrate repo, pallet-contracts is the only pallet which look into the stored pallet version.

@bkchr
Copy link
Member Author

bkchr commented Jul 27, 2021

@thiolliere ty

bkchr and others added 2 commits July 27, 2021 22:49
Co-authored-by: Guillaume Thiolliere <[email protected]>
@bkchr
Copy link
Member Author

bkchr commented Jul 27, 2021

bot merge

@ghost
Copy link

ghost commented Jul 27, 2021

Waiting for commit status.

@ghost ghost merged commit 97131a9 into master Jul 27, 2021
@ghost ghost deleted the bkchr-pallet-version-next-gen branch July 27, 2021 21:21
ghost pushed a commit to paritytech/polkadot that referenced this pull request Jul 27, 2021
* Companion for Substrate#9165

paritytech/substrate#9165

* update Substrate

Co-authored-by: parity-processbot <>
icodezjb added a commit to chainx-org/ChainX that referenced this pull request Feb 8, 2022
gguoss pushed a commit to chainx-org/ChainX that referenced this pull request Feb 25, 2022
* Remove VestingAccount

* Fix chain specs

* Update rust-toolchain

* Update make test and benchmark

* Update CI

* Run `make format` and `make clippy`

* Update CI

* Quick fix

* Support try-runtime

* Remove pallet-randomness-collective-flip

* Migrate elections-phragmen
(paritytech/substrate#7040)

* Migrate PalletVersion to StorageVersion
(paritytech/substrate#9165)

* Migrate pallet-babe epoch config
(paritytech/substrate#8072)

* Migrate frame-system AccountInfo to AccountInfoWithTripleRefCount
(paritytech/substrate#8221)

* Migrate prefix `GrandpaFinality` -> `Grandpa`

* Migrate prefix `Instance1Collective` -> `Council`

* Migrate prefix `Instance2Collective` -> `TechnicalCommittee`

* Migrate prefix `Instance1Membership` -> `TechnicalMembership`

* Migrate pallet-tips prefix from `Treasury` -> `Tips`

* Migrate pallet-bounties prefix from `Treasury` -> `Bounties`

* Migrate prefix from `PhragmenElection` -> `Elections`

* Revert `dev` spec_name

* Confirm migrations order

* Use ChainX substrate patch for system migration

* Run `make format`

* Reset spec_name `dev` -> `chainx`

* Add migrations.rs for mainnet and testnet

* Bump ChainX version to `4.0.0`

* Bump ChainX version to `4.0.0`

* Update governance parameters for dev and malan

* Update malan chainspec

* Quick fix

* Quick fix

* Update generate_keys.sh

* Adjust malan parameters

* Update malan chainspec

* Update malan chainspec

* Update malan chainspec

* Rename malan testnet name

* Add bootnodes url

* Run `make format`

* Regenerate weights

* Disable pre_release.yml CI

* Regenerate benchmark weights

* Run `make clippy`

* Run `make format`

Co-authored-by: icodezjb <[email protected]>
gguoss pushed a commit to chainx-org/ChainX that referenced this pull request Feb 25, 2022
* Remove VestingAccount

* Fix chain specs

* Update rust-toolchain

* Update make test and benchmark

* Update CI

* Run `make format` and `make clippy`

* Update CI

* Quick fix

* Support try-runtime

* Remove pallet-randomness-collective-flip

* Migrate elections-phragmen
(paritytech/substrate#7040)

* Migrate PalletVersion to StorageVersion
(paritytech/substrate#9165)

* Migrate pallet-babe epoch config
(paritytech/substrate#8072)

* Migrate frame-system AccountInfo to AccountInfoWithTripleRefCount
(paritytech/substrate#8221)

* Migrate prefix `GrandpaFinality` -> `Grandpa`

* Migrate prefix `Instance1Collective` -> `Council`

* Migrate prefix `Instance2Collective` -> `TechnicalCommittee`

* Migrate prefix `Instance1Membership` -> `TechnicalMembership`

* Migrate pallet-tips prefix from `Treasury` -> `Tips`

* Migrate pallet-bounties prefix from `Treasury` -> `Bounties`

* Migrate prefix from `PhragmenElection` -> `Elections`

* Revert `dev` spec_name

* Confirm migrations order

* Use ChainX substrate patch for system migration

* Run `make format`

* Reset spec_name `dev` -> `chainx`

* Add migrations.rs for mainnet and testnet

* Bump ChainX version to `4.0.0`

* Bump ChainX version to `4.0.0`

* Update governance parameters for dev and malan

* Update malan chainspec

* Quick fix

* Quick fix

* Update generate_keys.sh

* Adjust malan parameters

* Update malan chainspec

* Update malan chainspec

* Update malan chainspec

* Rename malan testnet name

* Add bootnodes url

* Run `make format`

* Regenerate weights

* Disable pre_release.yml CI

* Regenerate benchmark weights

* Run `make clippy`

* Run `make format`

Co-authored-by: icodezjb <[email protected]>
ggwpez pushed a commit to ggwpez/runtimes that referenced this pull request Mar 10, 2023
* Companion for Substrate#9165

paritytech/substrate#9165

* update Substrate

Co-authored-by: parity-processbot <>
ggwpez pushed a commit to ggwpez/runtimes that referenced this pull request Jul 13, 2023
* Companion for Substrate#9165

paritytech/substrate#9165

* update Substrate

Co-authored-by: parity-processbot <>
This pull request was closed.
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. 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants