This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Improve handling of unset StorageVersion
#13417
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
57d5de1
Improve handling of unset `StorageVersion`
bkchr 35ec109
Use correct `Cargo.lock`
bkchr 21595de
Fixes
bkchr 2467c47
Fix test
bkchr f0b844b
Update frame/support/test/tests/pallet.rs
bkchr 1732b68
Merge remote-tracking branch 'origin/master' into bkchr-something-sto…
bkchr 399af7b
Ensure we don't set a storage version when the pallet is missing the …
bkchr f4faffc
Fix merge conflict
bkchr cfefade
Update frame/support/procedural/src/pallet/expand/hooks.rs
bkchr 43ee1a0
Update frame/support/procedural/src/pallet/expand/hooks.rs
bkchr 8021dfa
Fix compilation
bkchr 7f0626b
Do not run everything with `try-runtime`
bkchr 2babce7
Fix test
bkchr 8451fc5
Apply suggestions from code review
bkchr 2ff5428
Fix `no-metadata-docs`
bkchr dd3ccd0
Merge remote-tracking branch 'origin/master' into bkchr-something-sto…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,6 +82,57 @@ pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream { | |
| proc_macro2::TokenStream::new() | ||
| }; | ||
|
|
||
| // If a storage version is set, we should ensure that the storage version on chain matches the | ||
| // current storage version. This assumes that `Executive` is running custom migrations before | ||
| // the pallets are called. | ||
| let post_storage_version_check = if def.pallet_struct.storage_version.is_some() { | ||
| quote::quote! { | ||
| let on_chain_version = <Self as #frame_support::traits::GetStorageVersion>::on_chain_storage_version(); | ||
| let current_version = <Self as #frame_support::traits::GetStorageVersion>::current_storage_version(); | ||
|
|
||
| if on_chain_version != current_version { | ||
| let pallet_name = < | ||
| <T as #frame_system::Config>::PalletInfo | ||
| as | ||
| #frame_support::traits::PalletInfo | ||
| >::name::<Self>().unwrap_or("<unknown pallet name>"); | ||
|
|
||
| #frame_support::log::error!( | ||
| target: #frame_support::LOG_TARGET, | ||
| "{}: On chain storage version {:?} doesn't match current storage version {:?}.", | ||
| pallet_name, | ||
| on_chain_version, | ||
| current_version, | ||
| ); | ||
|
|
||
| return Err("On chain and current storage version do not match. Missing runtime upgrade?"); | ||
bkchr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } else { | ||
| quote::quote! { | ||
| let on_chain_version = <Self as #frame_support::traits::GetStorageVersion>::on_chain_storage_version(); | ||
|
|
||
| if on_chain_version != #frame_support::traits::StorageVersion::new(0) { | ||
| let pallet_name = < | ||
| <T as #frame_system::Config>::PalletInfo | ||
| as | ||
| #frame_support::traits::PalletInfo | ||
| >::name::<Self>().unwrap_or("<unknown pallet name>"); | ||
|
|
||
| #frame_support::log::error!( | ||
| target: #frame_support::LOG_TARGET, | ||
| "{}: On chain storage version {:?} is set to non zero,\ | ||
| while the pallet is missing the `#[pallet::storage_version(VERSION)]` attribute.", | ||
| pallet_name, | ||
| on_chain_version, | ||
| ); | ||
|
|
||
| return Err("On chain storage version set, while the pallet doesn't \ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just one nit: you could collect all those errors in a vector and return them at the end. Then we can debug multiple erroneous pallets at once, like in Rococo. |
||
| have the `#[pallet::storage_version(VERSION)]` attribute."); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| quote::quote_spanned!(span => | ||
| #hooks_impl | ||
|
|
||
|
|
@@ -170,6 +221,8 @@ pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream { | |
|
|
||
| #[cfg(feature = "try-runtime")] | ||
| fn post_upgrade(state: #frame_support::sp_std::vec::Vec<u8>) -> Result<(), &'static str> { | ||
| #post_storage_version_check | ||
|
|
||
| < | ||
| Self | ||
| as | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.