Skip to content

Commit

Permalink
Fix migrations and add migration CI checks (#75)
Browse files Browse the repository at this point in the history
Closes #70 

The error with Asset Hub Kusama will be fixed when [this
commit](paritytech/polkadot-sdk@db3fd68)
lands in the runtime.

---------

Co-authored-by: Oliver Tale-Yazdi <[email protected]>
Co-authored-by: ordian <[email protected]>
Co-authored-by: Bastian Köcher <[email protected]>
  • Loading branch information
4 people authored Nov 22, 2023
1 parent 41d3ca6 commit 569787c
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 39 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/check-migrations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Check Migrations

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
workflow_dispatch:

# Cancel a currently running workflow from the same PR, branch or tag when a new workflow is
# triggered (ref https://stackoverflow.com/a/72408109)
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
runtime-matrix:
runs-on: ubuntu-latest
outputs:
runtime: ${{ steps.runtime.outputs.runtime }}
name: Extract tasks from matrix
steps:
- uses: actions/checkout@v2
- id: runtime
run: |
# Filter out runtimes that don't have a URI
TASKS=$(jq '[.[] | select(.uri != null)]' .github/workflows/runtimes-matrix.json)
SKIPPED_TASKS=$(jq '[.[] | select(.uri == null)]' .github/workflows/runtimes-matrix.json)
echo --- Running the following tasks ---
echo $TASKS
echo --- Skipping the following tasks due to not having a uri field ---
echo $SKIPPED_TASKS
# Strip whitespace from Tasks now that we've logged it
TASKS=$(echo $TASKS | jq -c .)
echo "runtime=$TASKS" >> $GITHUB_OUTPUT
check-migrations:
needs: [runtime-matrix]
continue-on-error: true
runs-on: ubuntu-latest
strategy:
matrix:
runtime: ${{ fromJSON(needs.runtime-matrix.outputs.runtime) }}
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Download try-runtime-cli
run: |
curl -sL https://github.com/paritytech/try-runtime-cli/releases/download/v0.5.0/try-runtime-x86_64-unknown-linux-musl -o try-runtime
chmod +x ./try-runtime
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
version: "3.6.1"

- name: Add wasm32-unknown-unknown target
run: rustup target add wasm32-unknown-unknown

- name: Build ${{ matrix.runtime.name }}
run: |
cargo build --profile production -p ${{ matrix.runtime.package }} --features try-runtime
- name: Check migrations
run: |
PACKAGE_NAME=${{ matrix.runtime.package }}
RUNTIME_BLOB_NAME=$(echo $PACKAGE_NAME | sed 's/-/_/g').compact.compressed.wasm
# When running on relay, we don't need weight checks.
NO_WEIGHT_WARNINGS_FLAG=""
if [[ "${{ matrix.runtime.is_relay }}" == "true" ]]; then
NO_WEIGHT_WARNINGS_FLAG="--no-weight-warnings"
fi
# Disable idempotency checks for now because the Scheduler pallet MigrateToV1 migration is
# non-idempotent at its root in Polkadot SDK V1.2.0. In V1.3.0 we can re-enable
# idempotency checks.
EXTRA_ARGS="--disable-spec-version-check --disable-idempotency-checks"
./try-runtime \
--runtime ./target/production/wbuild/$PACKAGE_NAME/$RUNTIME_BLOB_NAME \
on-runtime-upgrade --checks=pre-and-post $EXTRA_ARGS $NO_WEIGHT_WARNINGS_FLAG live --uri ${{ matrix.runtime.uri }}
10 changes: 0 additions & 10 deletions .github/workflows/release-matrix.json

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- uses: actions/checkout@v2
- id: runtime
run: |
TASKS=$(echo $(cat .github/workflows/release-matrix.json) | sed 's/ //g' )
TASKS=$(echo $(cat .github/workflows/runtimes-matrix.json) | sed 's/ //g' )
echo $TASKS
echo "runtime=$TASKS" >> $GITHUB_OUTPUT
build-runtimes:
Expand Down
57 changes: 57 additions & 0 deletions .github/workflows/runtimes-matrix.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[
{
"name": "polkadot",
"package": "polkadot-runtime",
"path": "relay/polkadot",
"uri": "wss://polkadot-try-runtime-node.parity-chains.parity.io:443",
"is_relay": true
},
{
"name": "kusama",
"package": "staging-kusama-runtime",
"path": "relay/kusama",
"uri": "wss://kusama-try-runtime-node.parity-chains.parity.io:443",
"is_relay": true
},
{
"name": "glutton-kusama",
"package": "glutton-kusama-runtime",
"path": "system-parachains/gluttons/glutton-kusama",
"is_relay": false
},
{
"name": "asset-hub-kusama",
"package": "asset-hub-kusama-runtime",
"path": "system-parachains/asset-hubs/asset-hub-kusama",
"uri": "wss://kusama-asset-hub-rpc.polkadot.io:443",
"is_relay": false
},
{
"name": "asset-hub-polkadot",
"package": "asset-hub-polkadot-runtime",
"path": "system-parachains/asset-hubs/asset-hub-polkadot",
"uri": "wss://polkadot-asset-hub-rpc.polkadot.io:443",
"is_relay": false
},
{
"name": "bridge-hub-kusama",
"package": "bridge-hub-kusama-runtime",
"path": "system-parachains/bridge-hubs/bridge-hub-kusama",
"uri": "wss://kusama-bridge-hub-rpc.polkadot.io:443",
"is_relay": false
},
{
"name": "bridge-hub-polkadot",
"package": "bridge-hub-polkadot-runtime",
"path": "system-parachains/bridge-hubs/bridge-hub-polkadot",
"uri": "wss://polkadot-bridge-hub-rpc.polkadot.io:443",
"is_relay": false
},
{
"name": "collectives-polkadot",
"package": "collectives-polkadot-runtime",
"path": "system-parachains/collectives/collectives-polkadot",
"uri": "wss://polkadot-collectives-rpc.polkadot.io:443",
"is_relay": false
}
]
69 changes: 41 additions & 28 deletions relay/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("kusama"),
impl_name: create_runtime_str!("parity-kusama"),
authoring_version: 2,
spec_version: 1_000_000,
spec_version: 1_000_001,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 24,
Expand Down Expand Up @@ -2692,46 +2692,59 @@ mod init_state_migration {
use super::Runtime;
use frame_support::traits::OnRuntimeUpgrade;
use pallet_state_trie_migration::{AutoLimits, MigrationLimits, MigrationProcess};
#[cfg(feature = "try-runtime")]
use sp_runtime::DispatchError;
#[cfg(not(feature = "std"))]
use sp_std::prelude::*;

/// Initialize an automatic migration process.
pub struct InitMigrate;
impl OnRuntimeUpgrade for InitMigrate {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, DispatchError> {
frame_support::ensure!(
AutoLimits::<Runtime>::get().is_none(),
DispatchError::Other("Automigration already started.")
);
Ok(Default::default())
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::DispatchError> {
use parity_scale_codec::Encode;
let migration_should_start = AutoLimits::<Runtime>::get().is_none() &&
MigrationProcess::<Runtime>::get() == Default::default();
Ok(migration_should_start.encode())
}

fn on_runtime_upgrade() -> frame_support::weights::Weight {
if MigrationProcess::<Runtime>::get() == Default::default() &&
AutoLimits::<Runtime>::get().is_none()
{
// We use limits to target 600ko proofs per block and
// avg 800_000_000_000 of weight per block.
// See spreadsheet 4800_400 in
// https://raw.githubusercontent.com/cheme/substrate/try-runtime-mig/ksm.ods
AutoLimits::<Runtime>::put(Some(MigrationLimits { item: 4_800, size: 204800 * 2 }));
log::info!("Automatic trie migration started.");
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(2, 1)
} else {
log::info!("Automatic trie migration not started.");
<Runtime as frame_system::Config>::DbWeight::get().reads(2)
}
if AutoLimits::<Runtime>::get().is_some() {
log::warn!("Automatic trie migration already started, not proceeding.");
return <Runtime as frame_system::Config>::DbWeight::get().reads(1)
};

if MigrationProcess::<Runtime>::get() != Default::default() {
log::warn!("MigrationProcess is not Default. Not proceeding.");
return <Runtime as frame_system::Config>::DbWeight::get().reads(2)
};

// Migration is not already running and `MigraitonProcess` is Default. Ready to run
// migrations.
//
// We use limits to target 600ko proofs per block and
// avg 800_000_000_000 of weight per block.
// See spreadsheet 4800_400 in
// https://raw.githubusercontent.com/cheme/substrate/try-runtime-mig/ksm.ods
AutoLimits::<Runtime>::put(Some(MigrationLimits { item: 4_800, size: 204800 * 2 }));
log::info!("Automatic trie migration started.");
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(2, 1)
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), DispatchError> {
frame_support::ensure!(
AutoLimits::<Runtime>::get().is_some(),
DispatchError::Other("Automigration started.")
);
fn post_upgrade(
migration_should_start_bytes: Vec<u8>,
) -> Result<(), sp_runtime::DispatchError> {
use parity_scale_codec::Decode;
let migration_should_start: bool =
Decode::decode(&mut migration_should_start_bytes.as_slice())
.expect("failed to decode migration should start");

if migration_should_start {
frame_support::ensure!(
AutoLimits::<Runtime>::get().is_some(),
sp_runtime::DispatchError::Other("Automigration did not start as expected.")
);
}

Ok(())
}
}
Expand Down
2 changes: 2 additions & 0 deletions relay/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,8 @@ pub mod migrations {
parachains_configuration::migration::v9::MigrateToV9<Runtime>,
// Migrate parachain info format
paras_registrar::migration::VersionCheckedMigrateToV1<Runtime, ParachainsToUnlock>,

runtime_parachains::scheduler::migration::v1::MigrateToV1<Runtime>
);
}

Expand Down

0 comments on commit 569787c

Please sign in to comment.