Skip to content

Commit db3fd68

Browse files
authored
Init System Parachain storage versions and add migration check jobs to CI (#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 #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 #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).
1 parent c54ea64 commit db3fd68

File tree

7 files changed

+140
-24
lines changed

7 files changed

+140
-24
lines changed

.gitlab/pipeline/check.yml

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,16 @@ test-rust-feature-propagation:
113113
script:
114114
- |
115115
export RUST_LOG=remote-ext=debug,runtime=debug
116-
echo "---------- Running try-runtime for ${NETWORK} ----------"
117-
time cargo install --locked --git https://github.com/paritytech/try-runtime-cli --rev a93c9b5abe5d31a4cf1936204f7e5c489184b521
118-
time cargo build --release --locked -p "$NETWORK"-runtime --features try-runtime
116+
echo "---------- Installing try-runtime-cli ----------"
117+
time cargo install --locked --git https://github.com/paritytech/try-runtime-cli --tag v0.3.0
118+
echo "---------- Building ${PACKAGE} runtime ----------"
119+
time cargo build --release --locked -p "$PACKAGE" --features try-runtime
120+
echo "---------- Executing `on-runtime-upgrade` for ${NETWORK} ----------"
119121
time try-runtime \
120-
--runtime ./target/release/wbuild/"$NETWORK"-runtime/target/wasm32-unknown-unknown/release/"$NETWORK"_runtime.wasm \
121-
on-runtime-upgrade --checks=pre-and-post live --uri wss://${NETWORK}-try-runtime-node.parity-chains.parity.io:443
122+
--runtime ./target/release/wbuild/"$PACKAGE"/"$WASM" \
123+
on-runtime-upgrade --checks=pre-and-post ${EXTRA_ARGS} live --uri ${URI}
122124
125+
# Check runtime migrations for Parity managed relay chains
123126
check-runtime-migration-westend:
124127
stage: check
125128
extends:
@@ -128,19 +131,61 @@ check-runtime-migration-westend:
128131
- .check-runtime-migration
129132
variables:
130133
NETWORK: "westend"
134+
PACKAGE: "westend-runtime"
135+
WASM: "westend_runtime.compact.compressed.wasm"
136+
URI: "wss://westend-try-runtime-node.parity-chains.parity.io:443"
137+
EXTRA_ARGS: "--no-weight-warnings"
131138

132139
check-runtime-migration-rococo:
133140
stage: check
134-
# DAG
135-
needs:
136-
- job: check-runtime-migration-westend
137-
artifacts: false
138141
extends:
139142
- .docker-env
140143
- .test-pr-refs
141144
- .check-runtime-migration
142145
variables:
143146
NETWORK: "rococo"
147+
PACKAGE: "rococo-runtime"
148+
WASM: "rococo_runtime.compact.compressed.wasm"
149+
URI: "wss://rococo-try-runtime-node.parity-chains.parity.io:443"
150+
EXTRA_ARGS: "--no-weight-warnings"
151+
152+
# Check runtime migrations for Parity managed asset hub chains
153+
check-runtime-migration-asset-hub-westend:
154+
stage: check
155+
extends:
156+
- .docker-env
157+
- .test-pr-refs
158+
- .check-runtime-migration
159+
variables:
160+
NETWORK: "asset-hub-westend"
161+
PACKAGE: "asset-hub-westend-runtime"
162+
WASM: "asset_hub_westend_runtime.compact.compressed.wasm"
163+
URI: "wss://westend-asset-hub-rpc.polkadot.io:443"
164+
165+
check-runtime-migration-bridge-hub-rococo:
166+
stage: check
167+
extends:
168+
- .docker-env
169+
- .test-pr-refs
170+
- .check-runtime-migration
171+
variables:
172+
NETWORK: "bridge-hub-rococo"
173+
PACKAGE: "bridge-hub-rococo-runtime"
174+
WASM: "bridge_hub_rococo_runtime.compact.compressed.wasm"
175+
URI: "wss://rococo-bridge-hub-rpc.polkadot.io:443"
176+
177+
# Check runtime migrations for Parity managed contract chains
178+
check-runtime-migration-contracts-rococo:
179+
stage: check
180+
extends:
181+
- .docker-env
182+
- .test-pr-refs
183+
- .check-runtime-migration
184+
variables:
185+
NETWORK: "contracts-rococo"
186+
PACKAGE: "contracts-rococo-runtime"
187+
WASM: "contracts_rococo_runtime.compact.compressed.wasm"
188+
URI: "wss://rococo-contracts-rpc.polkadot.io:443"
144189

145190
find-fail-ci-phrase:
146191
stage: check

cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,8 +857,46 @@ pub type Migrations = (
857857
pallet_collator_selection::migration::v1::MigrateToV1<Runtime>,
858858
// unreleased
859859
migrations::NativeAssetParents0ToParents1Migration<Runtime>,
860+
// unreleased
861+
pallet_multisig::migrations::v1::MigrateToV1<Runtime>,
862+
// unreleased
863+
InitStorageVersions,
860864
);
861865

866+
/// Migration to initialize storage versions for pallets added after genesis.
867+
///
868+
/// Ideally this would be done automatically (see
869+
/// <https://github.com/paritytech/polkadot-sdk/pull/1297>), but it probably won't be ready for some
870+
/// time and it's beneficial to get try-runtime-cli on-runtime-upgrade checks into the CI, so we're
871+
/// doing it manually.
872+
pub struct InitStorageVersions;
873+
874+
impl frame_support::traits::OnRuntimeUpgrade for InitStorageVersions {
875+
fn on_runtime_upgrade() -> Weight {
876+
use frame_support::traits::{GetStorageVersion, StorageVersion};
877+
use sp_runtime::traits::Saturating;
878+
879+
let mut writes = 0;
880+
881+
if PolkadotXcm::on_chain_storage_version() == StorageVersion::new(0) {
882+
PolkadotXcm::current_storage_version().put::<PolkadotXcm>();
883+
writes.saturating_inc();
884+
}
885+
886+
if ForeignAssets::on_chain_storage_version() == StorageVersion::new(0) {
887+
ForeignAssets::current_storage_version().put::<ForeignAssets>();
888+
writes.saturating_inc();
889+
}
890+
891+
if PoolAssets::on_chain_storage_version() == StorageVersion::new(0) {
892+
PoolAssets::current_storage_version().put::<PoolAssets>();
893+
writes.saturating_inc();
894+
}
895+
896+
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(3, writes)
897+
}
898+
}
899+
862900
/// Executive: handles dispatch to the various modules.
863901
pub type Executive = frame_executive::Executive<
864902
Runtime,

cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,40 @@ pub type UncheckedExtrinsic =
123123
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
124124

125125
/// Migrations to apply on runtime upgrade.
126-
pub type Migrations = (pallet_collator_selection::migration::v1::MigrateToV1<Runtime>,);
126+
pub type Migrations = (
127+
pallet_collator_selection::migration::v1::MigrateToV1<Runtime>,
128+
pallet_multisig::migrations::v1::MigrateToV1<Runtime>,
129+
InitStorageVersions,
130+
);
131+
132+
/// Migration to initialize storage versions for pallets added after genesis.
133+
///
134+
/// Ideally this would be done automatically (see
135+
/// <https://github.com/paritytech/polkadot-sdk/pull/1297>), but it probably won't be ready for some
136+
/// time and it's beneficial to get try-runtime-cli on-runtime-upgrade checks into the CI, so we're
137+
/// doing it manually.
138+
pub struct InitStorageVersions;
139+
140+
impl frame_support::traits::OnRuntimeUpgrade for InitStorageVersions {
141+
fn on_runtime_upgrade() -> Weight {
142+
use frame_support::traits::{GetStorageVersion, StorageVersion};
143+
use sp_runtime::traits::Saturating;
144+
145+
let mut writes = 0;
146+
147+
if PolkadotXcm::on_chain_storage_version() == StorageVersion::new(0) {
148+
PolkadotXcm::current_storage_version().put::<PolkadotXcm>();
149+
writes.saturating_inc();
150+
}
151+
152+
if Balances::on_chain_storage_version() == StorageVersion::new(0) {
153+
Balances::current_storage_version().put::<Balances>();
154+
writes.saturating_inc();
155+
}
156+
157+
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(2, writes)
158+
}
159+
}
127160

128161
/// Executive: handles dispatch to the various modules.
129162
pub type Executive = frame_executive::Executive<

substrate/frame/multisig/src/migrations.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,14 @@ pub mod v1 {
4343
impl<T: Config> OnRuntimeUpgrade for MigrateToV1<T> {
4444
#[cfg(feature = "try-runtime")]
4545
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
46-
let onchain = Pallet::<T>::on_chain_storage_version();
47-
48-
ensure!(onchain < 1, "this migration can be deleted");
49-
5046
log!(info, "Number of calls to refund and delete: {}", Calls::<T>::iter().count());
5147

5248
Ok(Vec::new())
5349
}
5450

5551
fn on_runtime_upgrade() -> Weight {
52+
use sp_runtime::Saturating;
53+
5654
let current = Pallet::<T>::current_storage_version();
5755
let onchain = Pallet::<T>::on_chain_storage_version();
5856

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

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

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

70-
<T as frame_system::Config>::BlockWeights::get().max_block
70+
T::DbWeight::get().reads_writes(
71+
// Reads: Get Calls + Get Version
72+
call_count.saturating_add(1),
73+
// Writes: Drain Calls + Unreserves + Set version
74+
call_count.saturating_mul(2).saturating_add(1),
75+
)
7176
}
7277

7378
#[cfg(feature = "try-runtime")]
7479
fn post_upgrade(_state: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
75-
let onchain = Pallet::<T>::on_chain_storage_version();
76-
ensure!(onchain < 2, "this migration needs to be removed");
77-
ensure!(onchain == 1, "this migration needs to be run");
7880
ensure!(
7981
Calls::<T>::iter().count() == 0,
8082
"there are some dangling calls that need to be destroyed and refunded"

substrate/frame/nfts/src/migration.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ pub mod v1 {
9797

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

118-
ensure!(Pallet::<T>::on_chain_storage_version() == 1, "wrong storage version");
115+
ensure!(Pallet::<T>::on_chain_storage_version() >= 1, "wrong storage version");
119116

120117
Ok(())
121118
}

substrate/frame/referenda/src/migration.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ pub mod v1 {
9999
impl<T: Config<I>, I: 'static> OnRuntimeUpgrade for MigrateV0ToV1<T, I> {
100100
#[cfg(feature = "try-runtime")]
101101
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
102-
let onchain_version = Pallet::<T, I>::on_chain_storage_version();
103-
ensure!(onchain_version == 0, "migration from version 0 to 1.");
104102
let referendum_count = v0::ReferendumInfoFor::<T, I>::iter().count();
105103
log::info!(
106104
target: TARGET,

substrate/frame/uniques/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ pub mod pallet {
6969
use frame_support::pallet_prelude::*;
7070
use frame_system::pallet_prelude::*;
7171

72+
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
73+
7274
#[pallet::pallet]
75+
#[pallet::storage_version(STORAGE_VERSION)]
7376
pub struct Pallet<T, I = ()>(_);
7477

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

0 commit comments

Comments
 (0)