Skip to content

Commit ad5163b

Browse files
authored
contracts migration: remove unnecessary panics (#2079)
Runtime migration CI is currently failing (https://gitlab.parity.io/parity/mirrors/polkadot-sdk/builds/4122083) for the contracts testnet due to unnecessary panicing in a `pre_upgrade` hook. Soon idempotency will be enforced paritytech/try-runtime-cli#42, in the mean time we need to manually fix these issues as they arise. --- also removes backticks from the string in `echo`, which caused a 'command not found' error in ci output
1 parent 0aeab38 commit ad5163b

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

.gitlab/pipeline/check.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ check-rust-feature-propagation:
107107
echo "---------- Building ${PACKAGE} runtime ----------"
108108
time cargo build --release --locked -p "$PACKAGE" --features try-runtime
109109
110-
echo "---------- Executing `on-runtime-upgrade` for ${NETWORK} ----------"
110+
echo "---------- Executing on-runtime-upgrade for ${NETWORK} ----------"
111111
time ./try-runtime \
112112
--runtime ./target/release/wbuild/"$PACKAGE"/"$WASM" \
113113
on-runtime-upgrade --checks=pre-and-post ${EXTRA_ARGS} live --uri ${URI}

substrate/frame/contracts/src/migration.rs

+19-18
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,14 @@ impl<T: Config, const TEST_ALL_STEPS: bool> Migration<T, TEST_ALL_STEPS> {
263263
impl<T: Config, const TEST_ALL_STEPS: bool> OnRuntimeUpgrade for Migration<T, TEST_ALL_STEPS> {
264264
fn on_runtime_upgrade() -> Weight {
265265
let name = <Pallet<T>>::name();
266-
let latest_version = <Pallet<T>>::current_storage_version();
267-
let storage_version = <Pallet<T>>::on_chain_storage_version();
266+
let current_version = <Pallet<T>>::current_storage_version();
267+
let on_chain_version = <Pallet<T>>::on_chain_storage_version();
268268

269-
if storage_version == latest_version {
269+
if on_chain_version == current_version {
270270
log::warn!(
271271
target: LOG_TARGET,
272272
"{name}: No Migration performed storage_version = latest_version = {:?}",
273-
&storage_version
273+
&on_chain_version
274274
);
275275
return T::WeightInfo::on_runtime_upgrade_noop()
276276
}
@@ -281,18 +281,18 @@ impl<T: Config, const TEST_ALL_STEPS: bool> OnRuntimeUpgrade for Migration<T, TE
281281
log::warn!(
282282
target: LOG_TARGET,
283283
"{name}: Migration already in progress {:?}",
284-
&storage_version
284+
&on_chain_version
285285
);
286286

287287
return T::WeightInfo::on_runtime_upgrade_in_progress()
288288
}
289289

290290
log::info!(
291291
target: LOG_TARGET,
292-
"{name}: Upgrading storage from {storage_version:?} to {latest_version:?}.",
292+
"{name}: Upgrading storage from {on_chain_version:?} to {current_version:?}.",
293293
);
294294

295-
let cursor = T::Migrations::new(storage_version + 1);
295+
let cursor = T::Migrations::new(on_chain_version + 1);
296296
MigrationInProgress::<T>::set(Some(cursor));
297297

298298
#[cfg(feature = "try-runtime")]
@@ -308,24 +308,25 @@ impl<T: Config, const TEST_ALL_STEPS: bool> OnRuntimeUpgrade for Migration<T, TE
308308
// We can't really do much here as our migrations do not happen during the runtime upgrade.
309309
// Instead, we call the migrations `pre_upgrade` and `post_upgrade` hooks when we iterate
310310
// over our migrations.
311-
let storage_version = <Pallet<T>>::on_chain_storage_version();
312-
let target_version = <Pallet<T>>::current_storage_version();
311+
let on_chain_version = <Pallet<T>>::on_chain_storage_version();
312+
let current_version = <Pallet<T>>::current_storage_version();
313313

314-
ensure!(
315-
storage_version != target_version,
316-
"No upgrade: Please remove this migration from your runtime upgrade configuration."
317-
);
314+
if on_chain_version == current_version {
315+
log::warn!(
316+
target: LOG_TARGET,
317+
"No upgrade: Please remove this migration from your Migrations tuple"
318+
)
319+
}
318320

319321
log::debug!(
320322
target: LOG_TARGET,
321323
"Requested migration of {} from {:?}(on-chain storage version) to {:?}(current storage version)",
322-
<Pallet<T>>::name(), storage_version, target_version
324+
<Pallet<T>>::name(), on_chain_version, current_version
323325
);
324326

325-
ensure!(
326-
T::Migrations::is_upgrade_supported(storage_version, target_version),
327-
"Unsupported upgrade: VERSION_RANGE should be (on-chain storage version + 1, current storage version)"
328-
);
327+
if !T::Migrations::is_upgrade_supported(on_chain_version, current_version) {
328+
log::warn!(target: LOG_TARGET, "Unsupported upgrade: VERSION_RANGE should be (on-chain storage version + 1, current storage version)")
329+
}
329330
Ok(Default::default())
330331
}
331332

0 commit comments

Comments
 (0)