Skip to content

Commit 1559ffb

Browse files
bkchrnathanwhit
authored andcommitted
Improve try-runtime::on_runtime_upgrade and fix some storage version issues (paritytech#14083)
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.
1 parent f44bcee commit 1559ffb

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

frame/bounties/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,10 @@ pub trait ChildBountyManager<Balance> {
187187
pub mod pallet {
188188
use super::*;
189189

190+
const STORAGE_VERSION: StorageVersion = StorageVersion::new(4);
191+
190192
#[pallet::pallet]
193+
#[pallet::storage_version(STORAGE_VERSION)]
191194
pub struct Pallet<T, I = ()>(_);
192195

193196
#[pallet::config]

frame/support/procedural/src/pallet/expand/hooks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream {
121121

122122
#frame_support::log::error!(
123123
target: #frame_support::LOG_TARGET,
124-
"{}: On chain storage version {:?} is set to non zero,\
124+
"{}: On chain storage version {:?} is set to non zero, \
125125
while the pallet is missing the `#[pallet::storage_version(VERSION)]` attribute.",
126126
pallet_name,
127127
on_chain_version,

frame/support/src/traits/hooks.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,35 @@ impl OnRuntimeUpgrade for Tuple {
203203
#[cfg(feature = "try-runtime")]
204204
fn try_on_runtime_upgrade(checks: bool) -> Result<Weight, &'static str> {
205205
let mut weight = Weight::zero();
206-
for_tuples!( #( weight = weight.saturating_add(Tuple::try_on_runtime_upgrade(checks)?); )* );
206+
207+
let mut errors = Vec::new();
208+
209+
for_tuples!(#(
210+
match Tuple::try_on_runtime_upgrade(checks) {
211+
Ok(weight) => { weight.saturating_add(weight); },
212+
Err(err) => { errors.push(err); },
213+
}
214+
)*);
215+
216+
if errors.len() == 1 {
217+
return Err(errors[0])
218+
} else if !errors.is_empty() {
219+
log::error!(
220+
target: "try-runtime",
221+
"Detected multiple errors while executing `try_on_runtime_upgrade`:",
222+
);
223+
224+
errors.iter().for_each(|err| {
225+
log::error!(
226+
target: "try-runtime",
227+
"{}",
228+
err
229+
);
230+
});
231+
232+
return Err("Detected multiple errors while executing `try_on_runtime_upgrade`, check the logs!")
233+
}
234+
207235
Ok(weight)
208236
}
209237
}

0 commit comments

Comments
 (0)