Skip to content

Commit

Permalink
Init System Parachain storage versions and add migration check jobs t…
Browse files Browse the repository at this point in the history
…o CI (paritytech#1344)

Makes SPs first class citizens along with the relay chains in the
context of our CI runtime upgrade checks.

## Code changes

- Sets missing current storage version in `uniques` pallet
- Adds multisig V1 migration to run where it was missing
- Removes executed migration whos pre/post hooks were failing from
collectives runtime
- Initializes storage versions for SP pallets added after genesis
- Originally I was going to wait for
paritytech#1297 to be merged so
this wouldn't need to be done manually, but it doesn't seem like it'll
be merged any time soon so I've decided to set them manually to unblock
this

## CI changes

- Removed dependency of `westend` runtime upgrades being complete prior
to other ones running. I assume it is supposed to cache the
`try-runtime` build for a performance benefit, but it seems it wasn't
working. Maybe someone from the CI team can look into this or explain
why it needs to be there?

- Adds check-runtime-migration jobs for Parity asset-hubs, bridge-hubs
and contract chains

- Updated VARIABLES to accomodate the `kusama-runtime` package being
renamed to `staging-kusama-runtime` in
paritytech#1241

- Added `EXTRA_ARGS` variable to `check-runtime-migration`, and set
`--no-weight-warnings` to the relay chain runtime upgrade checks (relay
chains don't have weight restrictions).
  • Loading branch information
liamaharon authored Oct 2, 2023
1 parent 8628ce6 commit 82665a6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
18 changes: 10 additions & 8 deletions substrate/frame/multisig/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,14 @@ pub mod v1 {
impl<T: Config> OnRuntimeUpgrade for MigrateToV1<T> {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
let onchain = Pallet::<T>::on_chain_storage_version();

ensure!(onchain < 1, "this migration can be deleted");

log!(info, "Number of calls to refund and delete: {}", Calls::<T>::iter().count());

Ok(Vec::new())
}

fn on_runtime_upgrade() -> Weight {
use sp_runtime::Saturating;

let current = Pallet::<T>::current_storage_version();
let onchain = Pallet::<T>::on_chain_storage_version();

Expand All @@ -61,20 +59,24 @@ pub mod v1 {
return T::DbWeight::get().reads(1)
}

let mut call_count = 0u64;
Calls::<T>::drain().for_each(|(_call_hash, (_data, caller, deposit))| {
T::Currency::unreserve(&caller, deposit);
call_count.saturating_inc();
});

current.put::<Pallet<T>>();

<T as frame_system::Config>::BlockWeights::get().max_block
T::DbWeight::get().reads_writes(
// Reads: Get Calls + Get Version
call_count.saturating_add(1),
// Writes: Drain Calls + Unreserves + Set version
call_count.saturating_mul(2).saturating_add(1),
)
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
let onchain = Pallet::<T>::on_chain_storage_version();
ensure!(onchain < 2, "this migration needs to be removed");
ensure!(onchain == 1, "this migration needs to be run");
ensure!(
Calls::<T>::iter().count() == 0,
"there are some dangling calls that need to be destroyed and refunded"
Expand Down
5 changes: 1 addition & 4 deletions substrate/frame/nfts/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ pub mod v1 {

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
let current_version = Pallet::<T>::current_storage_version();
let onchain_version = Pallet::<T>::on_chain_storage_version();
ensure!(onchain_version == 0 && current_version == 1, "migration from version 0 to 1.");
let prev_count = Collection::<T>::iter().count();
Ok((prev_count as u32).encode())
}
Expand All @@ -115,7 +112,7 @@ pub mod v1 {
"the records count before and after the migration should be the same"
);

ensure!(Pallet::<T>::on_chain_storage_version() == 1, "wrong storage version");
ensure!(Pallet::<T>::on_chain_storage_version() >= 1, "wrong storage version");

Ok(())
}
Expand Down
2 changes: 0 additions & 2 deletions substrate/frame/referenda/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ pub mod v1 {
impl<T: Config<I>, I: 'static> OnRuntimeUpgrade for MigrateV0ToV1<T, I> {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
let onchain_version = Pallet::<T, I>::on_chain_storage_version();
ensure!(onchain_version == 0, "migration from version 0 to 1.");
let referendum_count = v0::ReferendumInfoFor::<T, I>::iter().count();
log::info!(
target: TARGET,
Expand Down
3 changes: 3 additions & 0 deletions substrate/frame/uniques/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ pub mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;

const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T, I = ()>(_);

#[cfg(feature = "runtime-benchmarks")]
Expand Down

0 comments on commit 82665a6

Please sign in to comment.