From a3619034b50e9622082d260ecd4cdd69fd97d87c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Fri, 5 May 2023 17:19:38 +0200 Subject: [PATCH] Improve `try-runtime::on_runtime_upgrade` and fix some storage version issues We now run all `try_on_runtime_upgrade` and collect the errors, instead of bailing on the first error. This makes it easier to see directly all the things that are failing instead of fixing one, recompiling and then checking the next one. Then this pr also sets the correct storage version for `pallet-bounties` that was already correctly set in the storage with the appropriate migration. --- frame/bounties/src/lib.rs | 3 ++ .../procedural/src/pallet/expand/hooks.rs | 2 +- frame/support/src/traits/hooks.rs | 30 ++++++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/frame/bounties/src/lib.rs b/frame/bounties/src/lib.rs index e7a3e2053c065..14f7b45cb9aa1 100644 --- a/frame/bounties/src/lib.rs +++ b/frame/bounties/src/lib.rs @@ -187,7 +187,10 @@ pub trait ChildBountyManager { pub mod pallet { use super::*; + const STORAGE_VERSION: StorageVersion = StorageVersion::new(4); + #[pallet::pallet] + #[pallet::storage_version(STORAGE_VERSION)] pub struct Pallet(_); #[pallet::config] diff --git a/frame/support/procedural/src/pallet/expand/hooks.rs b/frame/support/procedural/src/pallet/expand/hooks.rs index df07040b82b1d..d7d8bbded95d6 100644 --- a/frame/support/procedural/src/pallet/expand/hooks.rs +++ b/frame/support/procedural/src/pallet/expand/hooks.rs @@ -121,7 +121,7 @@ pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream { #frame_support::log::error!( target: #frame_support::LOG_TARGET, - "{}: On chain storage version {:?} is set to non zero,\ + "{}: 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, diff --git a/frame/support/src/traits/hooks.rs b/frame/support/src/traits/hooks.rs index 5fea98ee036b5..a4c6776572fac 100644 --- a/frame/support/src/traits/hooks.rs +++ b/frame/support/src/traits/hooks.rs @@ -203,7 +203,35 @@ impl OnRuntimeUpgrade for Tuple { #[cfg(feature = "try-runtime")] fn try_on_runtime_upgrade(checks: bool) -> Result { let mut weight = Weight::zero(); - for_tuples!( #( weight = weight.saturating_add(Tuple::try_on_runtime_upgrade(checks)?); )* ); + + let mut errors = Vec::new(); + + for_tuples!(#( + match Tuple::try_on_runtime_upgrade(checks) { + Ok(weight) => { weight.saturating_add(weight); }, + Err(err) => { errors.push(err); }, + } + )*); + + if errors.len() == 1 { + return Err(errors[0]) + } else if !errors.is_empty() { + log::error!( + target: "try-runtime", + "Detected multiple errors while executing `try_on_runtime_upgrade`:", + ); + + errors.iter().for_each(|err| { + log::error!( + target: "try-runtime", + "{}", + err + ); + }); + + return Err("Detected multiple errors while executing `try_on_runtime_upgrade`, check the logs!") + } + Ok(weight) } }