diff --git a/.github/workflows/check-migrations.yml b/.github/workflows/check-migrations.yml new file mode 100644 index 0000000000..75a0d14db1 --- /dev/null +++ b/.github/workflows/check-migrations.yml @@ -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 }} diff --git a/.github/workflows/release-matrix.json b/.github/workflows/release-matrix.json deleted file mode 100644 index fa20957212..0000000000 --- a/.github/workflows/release-matrix.json +++ /dev/null @@ -1,10 +0,0 @@ -[ - { "name": "polkadot", "package": "polkadot-runtime", "path": "relay/polkadot" }, - { "name": "kusama", "package": "staging-kusama-runtime", "path": "relay/kusama" }, - { "name": "glutton-kusama", "package": "glutton-kusama-runtime", "path": "system-parachains/gluttons/glutton-kusama" }, - { "name": "asset-hub-kusama", "package": "asset-hub-kusama-runtime", "path": "system-parachains/asset-hubs/asset-hub-kusama" }, - { "name": "asset-hub-polkadot", "package": "asset-hub-polkadot-runtime", "path": "system-parachains/asset-hubs/asset-hub-polkadot" }, - { "name": "bridge-hub-kusama", "package": "bridge-hub-kusama-runtime", "path": "system-parachains/bridge-hubs/bridge-hub-kusama" }, - { "name": "bridge-hub-polkadot", "package": "bridge-hub-polkadot-runtime", "path": "system-parachains/bridge-hubs/bridge-hub-polkadot" }, - { "name": "collectives-polkadot", "package": "collectives-polkadot-runtime", "path": "system-parachains/collectives/collectives-polkadot" } -] diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d2a2afb641..373d14f949 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: diff --git a/.github/workflows/runtimes-matrix.json b/.github/workflows/runtimes-matrix.json new file mode 100644 index 0000000000..ffe99af042 --- /dev/null +++ b/.github/workflows/runtimes-matrix.json @@ -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 + } +] diff --git a/relay/kusama/src/lib.rs b/relay/kusama/src/lib.rs index 8c98d1475c..d1fc659abd 100644 --- a/relay/kusama/src/lib.rs +++ b/relay/kusama/src/lib.rs @@ -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, @@ -2692,8 +2692,6 @@ 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::*; @@ -2701,37 +2699,52 @@ mod init_state_migration { pub struct InitMigrate; impl OnRuntimeUpgrade for InitMigrate { #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, DispatchError> { - frame_support::ensure!( - AutoLimits::::get().is_none(), - DispatchError::Other("Automigration already started.") - ); - Ok(Default::default()) + fn pre_upgrade() -> Result, sp_runtime::DispatchError> { + use parity_scale_codec::Encode; + let migration_should_start = AutoLimits::::get().is_none() && + MigrationProcess::::get() == Default::default(); + Ok(migration_should_start.encode()) } fn on_runtime_upgrade() -> frame_support::weights::Weight { - if MigrationProcess::::get() == Default::default() && - AutoLimits::::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::::put(Some(MigrationLimits { item: 4_800, size: 204800 * 2 })); - log::info!("Automatic trie migration started."); - ::DbWeight::get().reads_writes(2, 1) - } else { - log::info!("Automatic trie migration not started."); - ::DbWeight::get().reads(2) - } + if AutoLimits::::get().is_some() { + log::warn!("Automatic trie migration already started, not proceeding."); + return ::DbWeight::get().reads(1) + }; + + if MigrationProcess::::get() != Default::default() { + log::warn!("MigrationProcess is not Default. Not proceeding."); + return ::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::::put(Some(MigrationLimits { item: 4_800, size: 204800 * 2 })); + log::info!("Automatic trie migration started."); + ::DbWeight::get().reads_writes(2, 1) } #[cfg(feature = "try-runtime")] - fn post_upgrade(_state: Vec) -> Result<(), DispatchError> { - frame_support::ensure!( - AutoLimits::::get().is_some(), - DispatchError::Other("Automigration started.") - ); + fn post_upgrade( + migration_should_start_bytes: Vec, + ) -> 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::::get().is_some(), + sp_runtime::DispatchError::Other("Automigration did not start as expected.") + ); + } + Ok(()) } } diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index a276d45d89..247034be8f 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -1597,6 +1597,8 @@ pub mod migrations { parachains_configuration::migration::v9::MigrateToV9, // Migrate parachain info format paras_registrar::migration::VersionCheckedMigrateToV1, + + runtime_parachains::scheduler::migration::v1::MigrateToV1 ); }