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

Fix migrations and add migration CI checks #75

Merged
merged 29 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8efa467
wip runtime migration ci
liamaharon Oct 24, 2023
a00667a
fix name
liamaharon Oct 24, 2023
f591de6
enable builds
liamaharon Oct 24, 2023
a79a71f
fix runtime path
liamaharon Oct 24, 2023
7ff8976
minor fixes
liamaharon Oct 24, 2023
5bead26
conditionally disable weight warnings
liamaharon Oct 24, 2023
6b887ee
remove unneeded conditionals
liamaharon Oct 24, 2023
a9b92b1
fix flag
liamaharon Oct 24, 2023
195adf5
build without srtool
liamaharon Oct 25, 2023
6e9fa9b
install missing deps
liamaharon Oct 25, 2023
9decbb3
fix runtime path
liamaharon Oct 25, 2023
2af7445
fix features
liamaharon Oct 25, 2023
e988576
Merge branch 'main' into liam-runtime-migration-ci
liamaharon Oct 31, 2023
becded4
Merge branch 'main' into liam-runtime-migration-ci
liamaharon Nov 21, 2023
7076cc1
Update .github/workflows/check-migrations.yml
liamaharon Nov 21, 2023
e0e85ff
Update .github/workflows/check-migrations.yml
liamaharon Nov 21, 2023
d820719
fix syntax error
liamaharon Nov 21, 2023
a8baeec
add missing polkadot migration
liamaharon Nov 22, 2023
e8599fe
fix kusama trie migration
liamaharon Nov 22, 2023
c7896aa
fix trie migration
liamaharon Nov 22, 2023
f0bf2af
fix reads
liamaharon Nov 22, 2023
0ee8b34
bump asset hub kusama runtime version
liamaharon Nov 22, 2023
e22f759
bump bridge hub kusama spec version
liamaharon Nov 22, 2023
79255f8
set concurrency
liamaharon Nov 22, 2023
d5d1bc7
Update .github/workflows/runtimes-matrix.json
liamaharon Nov 22, 2023
bf099db
Apply suggestions from code review
bkchr Nov 22, 2023
ab90c7e
Merge branch 'main' into liam-runtime-migration-ci
bkchr Nov 22, 2023
6bbd9d4
disable spec version checks
liamaharon Nov 22, 2023
13d175e
Merge branch 'liam-runtime-migration-ci' of github.com:liamaharon/run…
liamaharon Nov 22, 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
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: |
liamaharon marked this conversation as resolved.
Show resolved Hide resolved
# 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
liamaharon marked this conversation as resolved.
Show resolved Hide resolved

- 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"
liamaharon marked this conversation as resolved.
Show resolved Hide resolved
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
Loading