Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init System Parachain storage versions and add migration check jobs to CI #1344

Merged
merged 46 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
65e5720
add jobs for polkadot and kusama
liamaharon Aug 31, 2023
b20dea3
add polkadot and kusama jobs
liamaharon Aug 31, 2023
136b150
pin to tag
liamaharon Aug 31, 2023
663b2a8
dag
liamaharon Aug 31, 2023
2bff174
debug logs
liamaharon Sep 1, 2023
ffecc69
debug: only run kusama
liamaharon Sep 1, 2023
0ce9882
debug: only kusama
liamaharon Sep 1, 2023
5826d24
staging-kusama
liamaharon Sep 1, 2023
74d2e32
network package wasm variables
liamaharon Sep 1, 2023
f4f4843
fix package name
liamaharon Sep 1, 2023
6af3482
enable for all chains
liamaharon Sep 1, 2023
4547517
fix typo
liamaharon Sep 1, 2023
8f03362
fix uniques storage version
liamaharon Sep 1, 2023
7000648
Merge branch 'master' into liam/ci-polkadot-kusama-runtime-migration
liamaharon Sep 2, 2023
b9a3da8
Merge branch 'master' into liam/ci-polkadot-kusama-runtime-migration
liamaharon Sep 14, 2023
52a9955
init sp storage versions
liamaharon Sep 14, 2023
e1ea5db
add extra args
liamaharon Sep 14, 2023
f2323ba
remove redundant check
liamaharon Sep 14, 2023
f797e33
remove dag
liamaharon Sep 14, 2023
73d94c0
remove redundant check
liamaharon Sep 14, 2023
8d1c121
run missing migration
liamaharon Sep 14, 2023
f546958
fix migration
liamaharon Sep 14, 2023
93980b7
fix multisig migration
liamaharon Sep 14, 2023
d2126d3
fix reads
liamaharon Sep 14, 2023
874eb13
kick ci
liamaharon Sep 14, 2023
d6feb43
kick ci
liamaharon Sep 14, 2023
e865aff
remove unused vars
liamaharon Sep 14, 2023
b199330
fix fellowship referenda version
liamaharon Sep 14, 2023
898b12c
Merge branch 'master' into liam/ci-polkadot-kusama-runtime-migration
liamaharon Sep 14, 2023
e0facd5
Merge branch 'liam/ci-polkadot-kusama-runtime-migration' of github.co…
liamaharon Sep 14, 2023
b6bb996
Merge branch 'master' into liam/ci-polkadot-kusama-runtime-migration
liamaharon Sep 14, 2023
43a13c3
remove executed migration
liamaharon Sep 14, 2023
9bf5394
Merge branch 'liam/ci-polkadot-kusama-runtime-migration' of github.co…
liamaharon Sep 14, 2023
715642d
Merge branch 'master' of github.com:paritytech/polkadot-sdk into liam…
liamaharon Sep 22, 2023
5c5b3e4
reset changes to fellowship runtimes
liamaharon Sep 22, 2023
e2fc388
fix multisig migration return weight
liamaharon Sep 22, 2023
c659135
reset cancel pipelines
liamaharon Sep 22, 2023
3dc6b44
remove checks for fellowship runtimes
liamaharon Sep 22, 2023
ee12159
remove redundant comment
liamaharon Sep 22, 2023
08c85f1
use compact compressed wasm
liamaharon Sep 25, 2023
51a731e
set current storage versoin
liamaharon Sep 25, 2023
25db974
fix --runtime path
liamaharon Sep 25, 2023
33d181d
Merge branch 'master' into liam/ci-polkadot-kusama-runtime-migration
liamaharon Sep 25, 2023
0f3a8ba
Merge branch 'master' into liam/ci-polkadot-kusama-runtime-migration
liamaharon Sep 26, 2023
f2ac8ce
Merge branch 'master' into liam/ci-polkadot-kusama-runtime-migration
liamaharon Sep 29, 2023
1edd597
Merge branch 'master' into liam/ci-polkadot-kusama-runtime-migration
liamaharon Sep 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 54 additions & 9 deletions .gitlab/pipeline/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,16 @@ test-rust-feature-propagation:
script:
- |
export RUST_LOG=remote-ext=debug,runtime=debug
echo "---------- Running try-runtime for ${NETWORK} ----------"
time cargo install --locked --git https://github.com/paritytech/try-runtime-cli --rev a93c9b5abe5d31a4cf1936204f7e5c489184b521
time cargo build --release --locked -p "$NETWORK"-runtime --features try-runtime
echo "---------- Installing try-runtime-cli ----------"
time cargo install --locked --git https://github.com/paritytech/try-runtime-cli --tag v0.3.0
echo "---------- Building ${PACKAGE} runtime ----------"
time cargo build --release --locked -p "$PACKAGE" --features try-runtime
echo "---------- Executing `on-runtime-upgrade` for ${NETWORK} ----------"
time try-runtime \
--runtime ./target/release/wbuild/"$NETWORK"-runtime/target/wasm32-unknown-unknown/release/"$NETWORK"_runtime.wasm \
on-runtime-upgrade --checks=pre-and-post live --uri wss://${NETWORK}-try-runtime-node.parity-chains.parity.io:443
--runtime ./target/release/wbuild/"$PACKAGE"/"$WASM" \
on-runtime-upgrade --checks=pre-and-post ${EXTRA_ARGS} live --uri ${URI}

# Check runtime migrations for Parity managed relay chains
check-runtime-migration-westend:
stage: check
extends:
Expand All @@ -128,19 +131,61 @@ check-runtime-migration-westend:
- .check-runtime-migration
variables:
NETWORK: "westend"
PACKAGE: "westend-runtime"
WASM: "westend_runtime.compact.compressed.wasm"
URI: "wss://westend-try-runtime-node.parity-chains.parity.io:443"
EXTRA_ARGS: "--no-weight-warnings"

check-runtime-migration-rococo:
stage: check
# DAG
needs:
- job: check-runtime-migration-westend
artifacts: false
extends:
- .docker-env
- .test-pr-refs
- .check-runtime-migration
variables:
NETWORK: "rococo"
PACKAGE: "rococo-runtime"
WASM: "rococo_runtime.compact.compressed.wasm"
URI: "wss://rococo-try-runtime-node.parity-chains.parity.io:443"
EXTRA_ARGS: "--no-weight-warnings"

# Check runtime migrations for Parity managed asset hub chains
check-runtime-migration-asset-hub-westend:
stage: check
extends:
- .docker-env
- .test-pr-refs
- .check-runtime-migration
variables:
NETWORK: "asset-hub-westend"
PACKAGE: "asset-hub-westend-runtime"
WASM: "asset_hub_westend_runtime.compact.compressed.wasm"
URI: "wss://westend-asset-hub-rpc.polkadot.io:443"

check-runtime-migration-bridge-hub-rococo:
stage: check
extends:
- .docker-env
- .test-pr-refs
- .check-runtime-migration
variables:
NETWORK: "bridge-hub-rococo"
PACKAGE: "bridge-hub-rococo-runtime"
WASM: "bridge_hub_rococo_runtime.compact.compressed.wasm"
URI: "wss://rococo-bridge-hub-rpc.polkadot.io:443"

# Check runtime migrations for Parity managed contract chains
check-runtime-migration-contracts-rococo:
stage: check
extends:
- .docker-env
- .test-pr-refs
- .check-runtime-migration
variables:
NETWORK: "contracts-rococo"
PACKAGE: "contracts-rococo-runtime"
WASM: "contracts_rococo_runtime.compact.compressed.wasm"
URI: "wss://rococo-contracts-rpc.polkadot.io:443"

find-fail-ci-phrase:
stage: check
Expand Down
38 changes: 38 additions & 0 deletions cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,46 @@ pub type Migrations = (
pallet_collator_selection::migration::v1::MigrateToV1<Runtime>,
// unreleased
migrations::NativeAssetParents0ToParents1Migration<Runtime>,
// unreleased
pallet_multisig::migrations::v1::MigrateToV1<Runtime>,
// unreleased
InitStorageVersions,
);

/// Migration to initialize storage versions for pallets added after genesis.
///
/// Ideally this would be done automatically (see
/// <https://github.com/paritytech/polkadot-sdk/pull/1297>), but it probably won't be ready for some
/// time and it's beneficial to get try-runtime-cli on-runtime-upgrade checks into the CI, so we're
/// doing it manually.
pub struct InitStorageVersions;

impl frame_support::traits::OnRuntimeUpgrade for InitStorageVersions {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is e.g. NFTs/Uniques needed in other networks but not here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably because NFT/Unique pallets were in this runtime at genesis, so the on-chain storage version was set

fn on_runtime_upgrade() -> Weight {
use frame_support::traits::{GetStorageVersion, StorageVersion};
use sp_runtime::traits::Saturating;

let mut writes = 0;

if PolkadotXcm::on_chain_storage_version() == StorageVersion::new(0) {
PolkadotXcm::current_storage_version().put::<PolkadotXcm>();
writes.saturating_inc();
}

if ForeignAssets::on_chain_storage_version() == StorageVersion::new(0) {
ForeignAssets::current_storage_version().put::<ForeignAssets>();
writes.saturating_inc();
}

if PoolAssets::on_chain_storage_version() == StorageVersion::new(0) {
PoolAssets::current_storage_version().put::<PoolAssets>();
writes.saturating_inc();
}

<Runtime as frame_system::Config>::DbWeight::get().reads_writes(3, writes)
}
}

/// Executive: handles dispatch to the various modules.
pub type Executive = frame_executive::Executive<
Runtime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,40 @@ pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;

/// Migrations to apply on runtime upgrade.
pub type Migrations = (pallet_collator_selection::migration::v1::MigrateToV1<Runtime>,);
pub type Migrations = (
pallet_collator_selection::migration::v1::MigrateToV1<Runtime>,
pallet_multisig::migrations::v1::MigrateToV1<Runtime>,
InitStorageVersions,
);

/// Migration to initialize storage versions for pallets added after genesis.
///
/// Ideally this would be done automatically (see
/// <https://github.com/paritytech/polkadot-sdk/pull/1297>), but it probably won't be ready for some
/// time and it's beneficial to get try-runtime-cli on-runtime-upgrade checks into the CI, so we're
/// doing it manually.
pub struct InitStorageVersions;

impl frame_support::traits::OnRuntimeUpgrade for InitStorageVersions {
fn on_runtime_upgrade() -> Weight {
use frame_support::traits::{GetStorageVersion, StorageVersion};
use sp_runtime::traits::Saturating;

let mut writes = 0;

if PolkadotXcm::on_chain_storage_version() == StorageVersion::new(0) {
PolkadotXcm::current_storage_version().put::<PolkadotXcm>();
writes.saturating_inc();
}

if Balances::on_chain_storage_version() == StorageVersion::new(0) {
Balances::current_storage_version().put::<Balances>();
writes.saturating_inc();
}

<Runtime as frame_system::Config>::DbWeight::get().reads_writes(2, writes)
}
}

/// Executive: handles dispatch to the various modules.
pub type Executive = frame_executive::Executive<
Expand Down
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
Loading