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

runtime: fix missing migrations #1008

Merged
merged 9 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
34 changes: 34 additions & 0 deletions .github/workflows/pr-test-try_runtime.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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: Run try-runtime test
run: try-runtime --runtime target/release/wbuild/timechain-runtime/timechain_runtime.wasm on-runtime-upgrade live --uri wss://rpc.testnet.analog.one --pallet staking --pallet session
1 change: 1 addition & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
52 changes: 52 additions & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ pub mod opaque {
pub type Hash = <BlakeTwo256 as HashT>::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,
Expand All @@ -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::<OldSessionKeys, _>(transform_session_keys);
Perbill::from_percent(50) * RuntimeBlockWeights::get().max_block
}
}

pub type Outstanding =
(pallet_staking::migrations::v15::MigrateV14ToV15<Runtime>, 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:
// <https://docs.substrate.io/main-docs/build/upgrade#runtime-versioning>
#[cfg(not(feature = "development"))]
Expand Down Expand Up @@ -1111,6 +1162,7 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
Migrations,
>;

#[cfg(feature = "runtime-benchmarks")]
Expand Down