Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 16 additions & 2 deletions .github/workflows/check-runtime-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:

env:
SUBWASM_VERSION: 0.21.3
TRYRUNTIME_VERSION: 0.8.0
TRYRUNTIME_VERSION: 0.10.1
RELEASE_TAG: ${{ github.event.inputs.release_tag || github.event.release.tag_name }}

jobs:
Expand Down Expand Up @@ -151,11 +151,25 @@ jobs:
echo "Upgrade needed: $onchain_version -> $release_version"
echo "Running migration checks..."

# Derive the block time from the runtime *being tested*, not a hard-coded value, so this
# works for any runtime (current 6s, old 12s, or a future elastic-scaling target). Aura's
# slot duration is twice `Timestamp::MinimumPeriod`; subwasm reads that constant (a
# little-endian u64, in ms) straight from the built wasm's metadata.
MIN_PERIOD=$(subwasm metadata "$RUNTIME_BLOB_PATH" --format json \
| jq -r '[.. | objects | select(.name=="MinimumPeriod") | .value][0]
| to_entries | map(.value * pow(256; .key)) | add')
if ! [[ "$MIN_PERIOD" =~ ^[0-9]+$ ]] || [ "$MIN_PERIOD" -le 0 ]; then
echo "Failed to read Timestamp::MinimumPeriod from runtime metadata (got '$MIN_PERIOD')"
exit 1
fi
BLOCKTIME=$((MIN_PERIOD * 2))
echo "Derived block time: ${BLOCKTIME}ms (MinimumPeriod=${MIN_PERIOD}ms)"

export RUST_LOG=remote-ext=debug,runtime=debug

COMMAND="./try-runtime \
--runtime $RUNTIME_BLOB_PATH \
on-runtime-upgrade --blocktime 12000 \
on-runtime-upgrade --blocktime $BLOCKTIME \
live --uri ${{ matrix.runtime.uri }}"

echo "Running command:"
Expand Down
79 changes: 72 additions & 7 deletions .github/workflows/try-runtime.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
name: Check try-runtime

# Runs `try-runtime on-runtime-upgrade --checks=all` for each runtime against live chain state,
# exercising the runtime's migration `pre_upgrade`/`on_runtime_upgrade`/`post_upgrade` hooks and the
# `try_state` checks of every pallet. This is the canonical pre-merge check that a runtime upgrade
# (and any storage migration it carries) applies cleanly, is idempotent, and preserves invariants.
#
# NOTE: this repo's cargo workspace lives under `parachain/`, so we build and run try-runtime
# ourselves (the `paritytech/try-runtime-gha` action assumes a repo-root manifest and cannot find
# `parachain/Cargo.toml`). The build/run steps mirror the `try-runtime` job in
# `check-runtime-upgrade.yml`.

# Manual trigger only: try-runtime compiles both runtimes from scratch and scrapes full live chain
# state (~10+ min), which is too heavy to run on every PR. Dispatch it on a feature branch when a
# runtime change carries a migration or otherwise warrants pre-merge migration testing.
on:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
# try-runtime CLI version. Must support `on-runtime-upgrade --blocktime`.
TRYRUNTIME_VERSION: 0.10.1
# subwasm is used to read the block time out of the built runtime (see the run step).
SUBWASM_VERSION: 0.21.3

jobs:
runtime-matrix:
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -38,11 +57,57 @@ jobs:
- uses: actions/checkout@v6
with:
fetch-depth: 0


- name: Install rust toolchain
run: rustup show

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -yq protobuf-compiler

- name: Download try-runtime-cli
run: |
curl -sL https://github.com/paritytech/try-runtime-cli/releases/download/v${{ env.TRYRUNTIME_VERSION }}/try-runtime-x86_64-unknown-linux-musl -o try-runtime
chmod +x ./try-runtime
mv try-runtime parachain

- name: Build ${{ matrix.runtime.name }} runtime
run: |
cd parachain
cargo build --profile production -p ${{ matrix.runtime.package }} --features try-runtime -q --locked

- name: Install subwasm ${{ env.SUBWASM_VERSION }}
run: |
wget https://github.com/chevdor/subwasm/releases/download/v${{ env.SUBWASM_VERSION }}/subwasm_linux_amd64_v${{ env.SUBWASM_VERSION }}.deb
sudo dpkg -i subwasm_linux_amd64_v${{ env.SUBWASM_VERSION }}.deb
subwasm --version

- name: Run ${{ matrix.runtime.name }} try-runtime check
uses: paritytech/try-runtime-gha@v0.2.0
with:
runtime-package: ${{ matrix.runtime.package }}
node-uri: ${{ matrix.runtime.uri }}
checks: "all"
extra-args: ""
run: |
cd parachain
PACKAGE_NAME=${{ matrix.runtime.package }}
RUNTIME_BLOB_NAME=$(echo $PACKAGE_NAME | sed 's/-/_/g').compact.compressed.wasm
RUNTIME_BLOB_PATH=./target/production/wbuild/$PACKAGE_NAME/$RUNTIME_BLOB_NAME

# Derive the block time from the runtime *being tested*, not a hard-coded value, so this
# works for any runtime (the current 6s, the old 12s, or a future elastic-scaling target).
# Aura's slot duration is twice `Timestamp::MinimumPeriod`; subwasm reads that constant
# (a little-endian u64, in ms) straight from the built wasm's metadata.
MIN_PERIOD=$(subwasm metadata "$RUNTIME_BLOB_PATH" --format json \
| jq -r '[.. | objects | select(.name=="MinimumPeriod") | .value][0]
| to_entries | map(.value * pow(256; .key)) | add')
if ! [[ "$MIN_PERIOD" =~ ^[0-9]+$ ]] || [ "$MIN_PERIOD" -le 0 ]; then
echo "Failed to read Timestamp::MinimumPeriod from runtime metadata (got '$MIN_PERIOD')"
exit 1
fi
BLOCKTIME=$((MIN_PERIOD * 2))
echo "Derived block time: ${BLOCKTIME}ms (MinimumPeriod=${MIN_PERIOD}ms)"

export RUST_LOG=remote-ext=info,runtime=info

./try-runtime \
--runtime "$RUNTIME_BLOB_PATH" \
on-runtime-upgrade --checks=all --blocktime "$BLOCKTIME" \
live --uri ${{ matrix.runtime.uri }}
shell: bash
2 changes: 2 additions & 0 deletions parachain/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion parachain/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ mod constants {
/// up by `pallet_aura` to implement `fn slot_duration()`.
///
/// Change this to adjust the block time.
pub const MILLISECS_PER_BLOCK: u64 = 12000;
pub const MILLISECS_PER_BLOCK: u64 = 6000;

// NOTE: Currently it is not possible to change the slot duration after the chain has started.
// Attempting to do so will brick block production.
Expand Down
2 changes: 1 addition & 1 deletion parachain/runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub const WEIGHT_TO_FEE_FACTOR: u128 = 1_000_000u128;

/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included into the
/// relay chain.
pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1;
pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 2;
/// How many parachain blocks are processed by the relay chain per parent. Limits the number of
/// blocks authored per slot.
pub const BLOCK_PROCESSING_VELOCITY: u32 = 1;
Expand Down
1 change: 1 addition & 0 deletions parachain/runtime/heima/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ polkadot-runtime-parachains = { workspace = true, features = ["std"] }
runtime-common = { workspace = true, features = ["tests"] }
xcm-simulator = { workspace = true }
pallet-message-queue = { workspace = true, features = ["std"] }
sp-io = { workspace = true, features = ["std"] }

[build-dependencies]
substrate-wasm-builder = { workspace = true, optional = true }
Expand Down
17 changes: 14 additions & 3 deletions parachain/runtime/heima/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ pub type SignedPayload = generic::SignedPayload<RuntimeCall, SignedExtra>;

/// Migrations to apply on runtime upgrade.
pub type Migrations = (
// one-shot: rescale bounded block-number/per-block state for the 12s -> 6s block-time change
// (spec_version 9270). Remove in the release after this one. The large `pallet_vesting` map is
// migrated separately as a multi-block migration, see `pallet_migrations::Config::Migrations`.
migration::block_time_6s::OnePassRescale<Runtime>,
// permanent
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
);
Expand Down Expand Up @@ -245,7 +249,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_name: alloc::borrow::Cow::Borrowed("heima"),
authoring_version: 1,
// same versioning-mechanism as polkadot: use last digit for minor updates
spec_version: 9261,
spec_version: 9270,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
Expand Down Expand Up @@ -469,7 +473,12 @@ parameter_types! {
impl pallet_migrations::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
#[cfg(not(feature = "runtime-benchmarks"))]
type Migrations = pallet_identity::migration::v2::LazyMigrationV1ToV2<Runtime>;
type Migrations = (
pallet_identity::migration::v2::LazyMigrationV1ToV2<Runtime>,
// one-shot: rescale vesting schedules for the 12s -> 6s block-time change (spec 9270).
// Remove in the release after this one.
migration::block_time_6s::VestingRescaleMigration<Runtime>,
);
// Benchmarks need mocked migrations to guarantee that they succeed.
#[cfg(feature = "runtime-benchmarks")]
type Migrations = pallet_migrations::mock_helpers::MockedMigrations;
Expand Down Expand Up @@ -1067,7 +1076,9 @@ impl pallet_parachain_staking::Config for Runtime {

parameter_types! {
pub const BridgeChainId: u8 = 2;
pub const ProposalLifetime: BlockNumber = 50400; // ~7 days
// Derived from `DAYS` so it auto-rescales with the block time (was hard-coded `50400` for 12s
// blocks, which would have silently halved to ~3.5 days once block time dropped to 6s).
pub const ProposalLifetime: BlockNumber = 7 * DAYS;
}

impl pallet_chain_bridge::Config for Runtime {
Expand Down
33 changes: 33 additions & 0 deletions parachain/runtime/heima/src/migration/block_time_6s/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2020-2025 Trust Computing GmbH.
// This file is part of Litentry.
//
// Litentry is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Litentry is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Litentry. If not, see <https://www.gnu.org/licenses/>.

//! Migrations for the 12s -> 6s block-time change.
//!
//! Two pieces, wired into the runtime in different places:
//! * [`onepass::OnePassRescale`] — a single-pass `OnRuntimeUpgrade` for the bounded state
//! (parachain-staking round, score-staking round config, scheduler agenda). Register it in the
//! executive `Migrations` tuple in `lib.rs`.
//! * [`vesting::VestingRescaleMigration`] — a `SteppedMigration` (multi-block) for the large
//! `pallet_vesting` map. Register it in `pallet_migrations::Config::Migrations` in `lib.rs`.
//!
//! Both are one-shot: remove them in the release *after* the one that ships spec_version 9270, once
//! the upgrade has been enacted and finalized on every network.

pub mod onepass;
pub mod vesting;

pub use onepass::OnePassRescale;
pub use vesting::VestingRescaleMigration;
Loading
Loading