diff --git a/.github/workflows/pr-test-try_runtime.yaml b/.github/workflows/pr-test-try_runtime.yaml new file mode 100644 index 000000000..0e5b888e5 --- /dev/null +++ b/.github/workflows/pr-test-try_runtime.yaml @@ -0,0 +1,36 @@ +name: Check try-runtime +on: + pull_request: + paths: + - '.github/actions/cargo-command/**' + - '.github/workflows/pr-test-try_runtime.yaml' + - 'pallets/**' + - 'primitives/**' + - 'runtime/**' + - 'Cargo.toml' + - 'Cargo.lock' + - 'rust-toolchain.toml' +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true +jobs: + try-runtime: + runs-on: [self-hosted, general] + steps: + - name: Install dependencies + run: sudo apt-get update && sudo apt-get install -y librocksdb-dev + - name: Install try-runtime-cli + run: cargo install --git https://github.com/paritytech/try-runtime-cli --tag v0.7.0 --locked + - name: Checkout sources + uses: actions/checkout@v4 + with: + submodules: recursive + - name: Build testnet runtime + uses: ./.github/actions/cargo-command + with: + package: timechain-runtime + feature: try-runtime + - name: Download current snapshot + run: curl -LO https://github.com/Analog-Labs/nomination-candidates/releases/download/v0.0.0/testnet.v118.snap + - name: Run try-runtime test + run: try-runtime --runtime target/release/wbuild/timechain-runtime/timechain_runtime.wasm on-runtime-upgrade --checks all --disable-idempotency-checks snap --path testnet.v118.snap diff --git a/config/subxt/testnet.default.scale b/config/subxt/testnet.default.scale index ff310e6bf..b1d6a8283 100644 Binary files a/config/subxt/testnet.default.scale and b/config/subxt/testnet.default.scale differ diff --git a/config/subxt/testnet.development.scale b/config/subxt/testnet.development.scale index 2a3449e44..f21236c24 100644 Binary files a/config/subxt/testnet.development.scale and b/config/subxt/testnet.development.scale differ diff --git a/primitives/src/shard.rs b/primitives/src/shard.rs index e1187a8b4..0448f756c 100644 --- a/primitives/src/shard.rs +++ b/primitives/src/shard.rs @@ -56,7 +56,7 @@ pub enum ShardStatus { Created, Committed, Online, - Offline, + Offline = 4, // To remove the "= 4", please write a migration! } impl Default for ShardStatus { diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index a26a9bbc1..4bd2282a3 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -49,6 +49,7 @@ polkadot-sdk = { workspace = true, features = [ "sp-api", "sp-arithmetic", "sp-authority-discovery", + "sp-application-crypto", "sp-block-builder", "sp-consensus-babe", "sp-core", diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index a66c73d14..176cf1f61 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -151,6 +151,14 @@ pub mod opaque { pub type Hash = ::Output; } +impl_opaque_keys! { + pub struct OldSessionKeys { + pub babe: Babe, + pub grandpa: Grandpa, + pub im_online: ImOnline, + } +} + impl_opaque_keys! { pub struct SessionKeys { pub babe: Babe, @@ -160,6 +168,49 @@ impl_opaque_keys! { } } +pub type Migrations = migration::Outstanding; + +pub mod migration { + use super::*; + + /// Upgrade Session keys to include AUDI key. + /// When this is removed, should also remove `OldSessionKeys`. + pub struct UpgradeSessionKeys; + impl frame_support::traits::OnRuntimeUpgrade for UpgradeSessionKeys { + fn on_runtime_upgrade() -> Weight { + Session::upgrade_keys::(transform_session_keys); + Perbill::from_percent(50) * RuntimeBlockWeights::get().max_block + } + } + + pub type Outstanding = + (pallet_staking::migrations::v15::MigrateV14ToV15, UpgradeSessionKeys); +} + +// remove this when removing `OldSessionKeys` +fn transform_session_keys(v: AccountId, old: OldSessionKeys) -> SessionKeys { + SessionKeys { + grandpa: old.grandpa, + babe: old.babe, + im_online: old.im_online, + authority_discovery: { + // From Session::upgrade_keys(): + // + // Care should be taken that the raw versions of the + // added keys are unique for every `ValidatorId, KeyTypeId` combination. + // This is an invariant that the session pallet typically maintains internally. + // + // So, produce a dummy value that's unique for the `ValidatorId, KeyTypeId` combination. + let mut id: AuthorityDiscoveryId = + sp_application_crypto::sr25519::Public::from_raw([0u8; 32]).into(); + let id_raw: &mut [u8] = id.as_mut(); + id_raw[0..32].copy_from_slice(v.as_ref()); + id_raw[0..4].copy_from_slice(b"audi"); + id + }, + } +} + // To learn more about runtime versioning, see: // #[cfg(not(feature = "development"))] @@ -1111,6 +1162,7 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, + Migrations, >; #[cfg(feature = "runtime-benchmarks")]