-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Conversation
Besides the renaming it also adds support getting the name of a pallet as configured in the runtime.
… bkchr-pallet-version
frame/support/src/traits.rs
Outdated
/// The storage key postfix that is used to store the [`PalletVersion`] per pallet. | ||
/// | ||
/// The full storage key is build by using: | ||
/// Twox128([`PalletInfo::name`] ++ [`PALLET_VERSION_STORAGE_POSTFIX`]) |
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.
why not Twox128([PalletInfo::name]) ++ Twox128([PALLET_VERSION_STORAGE_POSTFIX])
in order to keep the fact that all usage of a pallet is after some prefix.
Thus once we make pallet storages using PalletInfo::name then we have all pallet storage usage after a unique prefix.
This would ease removal and introspection IMHO
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.
Yeah that sounds good as well;)
frame/support/src/dispatch.rs
Outdated
@@ -1320,19 +1323,40 @@ macro_rules! decl_module { | |||
{ | |||
fn on_runtime_upgrade() -> $return { | |||
$crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!("on_runtime_upgrade")); | |||
{ $( $impl )* } | |||
let result = { $( $impl )* }; |
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.
if user write return Ok(..);
inside the impl block, I think they would expect to have storage version written.
Maybe it is better to wrap it into a closure or something, no ?
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.
Good point
I just want to note the edgecase that I recently saw in the UTXO runtime where the crate of the pallet was the same as the crate of the runtime. |
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.
apply typo suggestions
Sorry for the long quite period. I'm still in favor of this pallet versioning scheme:
|
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
I agree we can use crate version, later if user request to be able to set it inside the pallet then we can introduce it without breaking.
Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
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.
LGTM
Would be interesting to see this in action in a PR that does some migration :) Do we already happen to have one? |
Well how about #7040? ;-) |
@bkchr Just realized that we only set the version |
I think I'm also going to create a dummy migration PR to test this stuff :-) |
Ohh yeah 🙈 I did not thought about this. Give me some time to find a good solution. |
/// | ||
/// Each pallet version is stored in the state under a fixed key. See | ||
/// [`PALLET_VERSION_STORAGE_KEY_POSTFIX`] for how this key is built. | ||
#[derive(RuntimeDebug, Eq, PartialEq, Encode, Decode, Ord)] |
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.
Sorry for the late comments/nitpicks, but I wonder whether this should be Copy
or at least Clone
.
This pull requests adds a new struct
PalletVersion
. This struct holds the membersmajor
,minor
andpatch
to reflect the version of a crate.The pallet version will be automatically bound to each pallet, this means on each time the runtime is upgraded and
on_runtime_upgrade
is called, the latest pallet version is stored in the state. This can be used on a later runtime upgrade to check which kinds of upgrades need to be applied. There is only one point in time where the actual version of a pallet and the version of a pallet in the storage is different and that is after a runtime upgrade and beforeon_runtime_upgrade
of the pallet was called to update the version.There is also a new trait
GetPalletVersion
provided. This trait will be automatically implemented by each pallet. It can be used from the runtime to get the versions of each pallet.Besides that there is also a new macro
crate_to_pallet_version!
. This converts the version of the current crate into aPalletVersion
object.After this pr we should make sure that we update the crate versions accordingly to changes, to make sure we can write upgrades accordingly.
@jacogr maybe this is also something that can be supported from the UI to read the versions per pallet.
addresses #6888