From a36a8c409461f430b5cd9e3eba5ca8dddecf7c72 Mon Sep 17 00:00:00 2001 From: Florian Franzen Date: Sat, 13 Jul 2024 19:39:20 +0200 Subject: [PATCH 1/9] session: correctly migrate session keys --- runtime/Cargo.toml | 1 + runtime/src/lib.rs | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) 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..b99cb5d4f 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,48 @@ 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 = 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 +1161,7 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, + Migrations, >; #[cfg(feature = "runtime-benchmarks")] From 5295f0c9a6a1c137e59dc9ea9159018307173519 Mon Sep 17 00:00:00 2001 From: Florian Franzen Date: Mon, 15 Jul 2024 14:10:46 +0200 Subject: [PATCH 2/9] staking: add missing staking migration --- runtime/src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index b99cb5d4f..8010aa77c 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -183,7 +183,10 @@ pub mod migration { } } - pub type Outstanding = UpgradeSessionKeys; + pub type Outstanding = ( + pallet_staking::migrations::v15::MigrateV14ToV15, + UpgradeSessionKeys, + ); } // remove this when removing `OldSessionKeys` From 8779e58d3bedea0179d8d1abd729790d24c81da6 Mon Sep 17 00:00:00 2001 From: Florian Franzen Date: Mon, 15 Jul 2024 14:56:17 +0200 Subject: [PATCH 3/9] ci: add try-runtime example --- .github/workflows/pr-test-try_runtime.yaml | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/pr-test-try_runtime.yaml diff --git a/.github/workflows/pr-test-try_runtime.yaml b/.github/workflows/pr-test-try_runtime.yaml new file mode 100644 index 000000000..558a8166a --- /dev/null +++ b/.github/workflows/pr-test-try_runtime.yaml @@ -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 From 8555198292dd09abd8ddcfb0f63f4518f329a0b0 Mon Sep 17 00:00:00 2001 From: Florian Franzen Date: Mon, 15 Jul 2024 15:10:17 +0200 Subject: [PATCH 4/9] runtime: fix formatting --- runtime/src/lib.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 8010aa77c..176cf1f61 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -183,10 +183,8 @@ pub mod migration { } } - pub type Outstanding = ( - pallet_staking::migrations::v15::MigrateV14ToV15, - UpgradeSessionKeys, - ); + pub type Outstanding = + (pallet_staking::migrations::v15::MigrateV14ToV15, UpgradeSessionKeys); } // remove this when removing `OldSessionKeys` From c8df219d95002c75e3adaa4ca806317c8f0d0a96 Mon Sep 17 00:00:00 2001 From: Florian Franzen Date: Mon, 15 Jul 2024 21:26:22 +0200 Subject: [PATCH 5/9] ci: use try-runtime snapshot --- .github/workflows/pr-test-try_runtime.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-test-try_runtime.yaml b/.github/workflows/pr-test-try_runtime.yaml index 558a8166a..495f9603e 100644 --- a/.github/workflows/pr-test-try_runtime.yaml +++ b/.github/workflows/pr-test-try_runtime.yaml @@ -30,5 +30,7 @@ jobs: 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 live --uri wss://rpc.testnet.analog.one --pallet staking --pallet session + run: try-runtime --runtime target/release/wbuild/timechain-runtime/timechain_runtime.wasm on-runtime-upgrade snap --path testnet.v118.snap From 51ee85f8b3b3599385ea4002814dbafabd460206 Mon Sep 17 00:00:00 2001 From: Florian Franzen Date: Mon, 15 Jul 2024 22:21:06 +0200 Subject: [PATCH 6/9] shards: fix messed up shard status --- primitives/src/shard.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 { From f1580ea8672a6f5b595c4fde324dc17d78c58434 Mon Sep 17 00:00:00 2001 From: Florian Franzen Date: Mon, 15 Jul 2024 22:22:02 +0200 Subject: [PATCH 7/9] ci: run try-state tests as well --- .github/workflows/pr-test-try_runtime.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-test-try_runtime.yaml b/.github/workflows/pr-test-try_runtime.yaml index 495f9603e..a3871ed5b 100644 --- a/.github/workflows/pr-test-try_runtime.yaml +++ b/.github/workflows/pr-test-try_runtime.yaml @@ -33,4 +33,4 @@ jobs: - 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 snap --path testnet.v118.snap + run: try-runtime --runtime target/release/wbuild/timechain-runtime/timechain_runtime.wasm on-runtime-upgrade --checks all snap --path testnet.v118.snap From 00ae3498e3e0c535125c8d2c7783c8593e73af6d Mon Sep 17 00:00:00 2001 From: Metadata Update Bot Date: Mon, 15 Jul 2024 20:45:07 +0000 Subject: [PATCH 8/9] tc-subxt: Automatic metadata update --- config/subxt/testnet.default.scale | Bin 166981 -> 166981 bytes config/subxt/testnet.development.scale | Bin 166989 -> 166989 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/config/subxt/testnet.default.scale b/config/subxt/testnet.default.scale index ff310e6bf9c1072d370f93017f93560d23440596..b1d6a8283d103d66aa8adb6a5e5590d53a10de63 100644 GIT binary patch delta 19 bcmX>)gX`!Fu7)j)|9Ti%w*T*8bo&ngTFMC< delta 19 bcmX>)gX`!Fu7)j)|9TjixBu^9bo&ngTEht% diff --git a/config/subxt/testnet.development.scale b/config/subxt/testnet.development.scale index 2a3449e44b7a36106a438e9451c1e281c31bdea8..f21236c24f2674a756b548e4df3e96520c967a14 100644 GIT binary patch delta 19 bcmX>*gX`=Ju7)j)|9Ti%w*T*8^!pD0Tk;7r delta 19 bcmX>*gX`=Ju7)j)|9TjixBu^9^!pD0Tk8oj From c39ac6297d9866cec3aee8adba5b97cad91ad20b Mon Sep 17 00:00:00 2001 From: Florian Franzen Date: Mon, 15 Jul 2024 23:52:56 +0200 Subject: [PATCH 9/9] ci: disable idempotency check --- .github/workflows/pr-test-try_runtime.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-test-try_runtime.yaml b/.github/workflows/pr-test-try_runtime.yaml index a3871ed5b..0e5b888e5 100644 --- a/.github/workflows/pr-test-try_runtime.yaml +++ b/.github/workflows/pr-test-try_runtime.yaml @@ -33,4 +33,4 @@ jobs: - 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 snap --path testnet.v118.snap + 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