From 177469de5c5f030bf06390c20e6f5d259fa7b092 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 13 Sep 2023 12:23:14 +0200 Subject: [PATCH 01/15] Update Polkadot inflation --- Cargo.lock | 1 + relay/polkadot/Cargo.toml | 1 + relay/polkadot/src/lib.rs | 50 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index ead89e7d36..8b22a1bf9e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7511,6 +7511,7 @@ dependencies = [ "pallet-session-benchmarking", "pallet-staking", "pallet-staking-reward-curve", + "pallet-staking-reward-fn", "pallet-staking-runtime-api", "pallet-timestamp", "pallet-tips", diff --git a/relay/polkadot/Cargo.toml b/relay/polkadot/Cargo.toml index 8e6739dee7..89183af6fd 100644 --- a/relay/polkadot/Cargo.toml +++ b/relay/polkadot/Cargo.toml @@ -69,6 +69,7 @@ pallet-session = { git = "https://github.com/paritytech/substrate", branch = "ma frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-staking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-staking-reward-curve = { git = "https://github.com/paritytech/substrate", branch = "master" } +pallet-staking-reward-fn = { git = "https://github.com/paritytech/substrate", branch = "master" } pallet-staking-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } frame-system = {git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index 19f47c204f..7e4d9544c0 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -543,6 +543,54 @@ parameter_types! { pub const MaxNominations: u32 = ::LIMIT as u32; } +/// Custom version of `runtime_commong::era_payout` somewhat tailored for Polkadot's crowdloan +/// unlock history. The only tweak should be +/// +/// ```diff +/// - let auction_proportion = Perquintill::from_rational(auctioned_slots.min(60), 200u64); +/// + let auction_proportion = Perquintill::from_rational(auctioned_slots.min(60), 300u64); +/// ``` +/// +/// See https://forum.polkadot.network/t/adjusting-polkadots-ideal-staking-rate-calculation/3897/2 +fn polkadot_era_payout( + total_staked: Balance, + total_stakable: Balance, + max_annual_inflation: Perquintill, + period_fraction: Perquintill, + auctioned_slots: u64, +) -> (Balance, Balance) { + use pallet_staking_reward_fn::compute_inflation; + use sp_runtime::traits::Saturating; + + let min_annual_inflation = Perquintill::from_rational(25u64, 1000u64); + let delta_annual_inflation = max_annual_inflation.saturating_sub(min_annual_inflation); + + // 20% reserved for up to 60 slots. + let auction_proportion = Perquintill::from_rational(auctioned_slots.min(60), 300u64); + + // Therefore the ideal amount at stake (as a percentage of total issuance) is 75% less the + // amount that we expect to be taken up with auctions. + let ideal_stake = Perquintill::from_percent(75).saturating_sub(auction_proportion); + + let stake = Perquintill::from_rational(total_staked, total_stakable); + let falloff = Perquintill::from_percent(5); + let adjustment = compute_inflation(stake, ideal_stake, falloff); + let staking_inflation = + min_annual_inflation.saturating_add(delta_annual_inflation * adjustment); + + let max_payout = period_fraction * max_annual_inflation * total_stakable; + let staking_payout = (period_fraction * staking_inflation) * total_stakable; + let rest = max_payout.saturating_sub(staking_payout); + + let other_issuance = total_stakable.saturating_sub(total_staked); + if total_staked > other_issuance { + let _cap_rest = Perquintill::from_rational(other_issuance, total_staked) * staking_payout; + // We don't do anything with this, but if we wanted to, we could introduce a cap on the + // treasury amount with: `rest = rest.min(cap_rest);` + } + (staking_payout, rest) +} + pub struct EraPayout; impl pallet_staking::EraPayout for EraPayout { fn era_payout( @@ -561,7 +609,7 @@ impl pallet_staking::EraPayout for EraPayout { const MAX_ANNUAL_INFLATION: Perquintill = Perquintill::from_percent(10); const MILLISECONDS_PER_YEAR: u64 = 1000 * 3600 * 24 * 36525 / 100; - runtime_common::impls::era_payout( + polkadot_era_payout( total_staked, total_issuance, MAX_ANNUAL_INFLATION, From aa0d2920507de8914649efdffba0afcc6de23517 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Sat, 30 Sep 2023 17:06:21 +0200 Subject: [PATCH 02/15] fmr --- relay/polkadot/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/relay/polkadot/Cargo.toml b/relay/polkadot/Cargo.toml index 89183af6fd..25008a5810 100644 --- a/relay/polkadot/Cargo.toml +++ b/relay/polkadot/Cargo.toml @@ -81,7 +81,7 @@ pallet-whitelist = { git = "https://github.com/paritytech/substrate", branch = " pallet-vesting = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-utility = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } frame-election-provider-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -pallet-xcm = { default-features = false , git = "https://github.com/paritytech/polkadot.git", branch = "master" } +pallet-xcm = { default-features = false, git = "https://github.com/paritytech/polkadot.git", branch = "master" } frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } frame-try-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } From 1c3542ac44af3e93d0d74e87ff81b6330168f5d4 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Sat, 30 Sep 2023 18:04:58 +0200 Subject: [PATCH 03/15] add test to dispatch all proposals --- Cargo.lock | 1 + relay/polkadot/Cargo.toml | 2 + relay/polkadot/src/lib.rs | 80 ++++++++++++++++++++++++++++++++------- 3 files changed, 69 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9ce4f24cb9..75bbb285b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7865,6 +7865,7 @@ dependencies = [ "pallet-session-benchmarking", "pallet-staking", "pallet-staking-reward-curve", + "pallet-staking-reward-fn", "pallet-staking-runtime-api", "pallet-timestamp", "pallet-tips", diff --git a/relay/polkadot/Cargo.toml b/relay/polkadot/Cargo.toml index f8e7ded089..4eb3bec132 100644 --- a/relay/polkadot/Cargo.toml +++ b/relay/polkadot/Cargo.toml @@ -71,6 +71,7 @@ pallet-scheduler = { default-features = false , version = "24.0.0" } pallet-session = { default-features = false , version = "23.0.0" } frame-support = { default-features = false , version = "23.0.0" } pallet-staking = { default-features = false , version = "23.0.0" } +pallet-staking-reward-fn = { default-features = false, version = "14.0.0" } pallet-staking-reward-curve = { version = "8.0.0" } pallet-staking-runtime-api = { default-features = false , version = "9.0.0" } frame-system = { default-features = false , version = "23.0.0" } @@ -171,6 +172,7 @@ std = [ "pallet-session-benchmarking?/std", "pallet-session/std", "pallet-staking-runtime-api/std", + "pallet-staking-reward-fn/std", "pallet-staking/std", "pallet-timestamp/std", "pallet-tips/std", diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index 8d1635e6c0..c00819bfe1 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -115,6 +115,8 @@ use governance::{ pub mod xcm_config; +pub const LOG_TARGET: &'static str = "runtime::polkadot"; + impl_runtime_weights!(polkadot_runtime_constants); // Make the WASM binary available. @@ -843,7 +845,7 @@ where ); let raw_payload = SignedPayload::new(call, extra) .map_err(|e| { - log::warn!("Unable to create signed payload: {:?}", e); + log::warn!(target: LOG_TARGET, "Unable to create signed payload: {:?}", e); }) .ok()?; let signature = raw_payload.using_encoded(|payload| C::sign(payload, public))?; @@ -1359,10 +1361,10 @@ impl frame_support::traits::OnRuntimeUpgrade for InitiateNominationPools { pallet_nomination_pools::MaxPoolMembersPerPool::::put(0); pallet_nomination_pools::MaxPoolMembers::::put(0); - log::info!(target: "runtime::polkadot", "pools config initiated πŸŽ‰"); + log::info!(target: LOG_TARGET, "pools config initiated πŸŽ‰"); ::DbWeight::get().reads_writes(1, 5) } else { - log::info!(target: "runtime::polkadot", "pools config already initiated 😏"); + log::info!(target: LOG_TARGET, "pools config already initiated 😏"); ::DbWeight::get().reads(1) } } @@ -2093,7 +2095,7 @@ sp_api::impl_runtime_apis! { #[cfg(feature = "try-runtime")] impl frame_try_runtime::TryRuntime for Runtime { fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) { - log::info!("try-runtime::on_runtime_upgrade polkadot."); + log::info!(target: LOG_TARGET, "try-runtime::on_runtime_upgrade polkadot."); let weight = Executive::try_runtime_upgrade(checks).unwrap(); (weight, BlockWeights::get().max_block) } @@ -2585,21 +2587,15 @@ mod remote_tests { use super::*; use frame_try_runtime::{runtime_decl_for_try_runtime::TryRuntime, UpgradeCheckSelect}; use remote_externalities::{ - Builder, Mode, OfflineConfig, OnlineConfig, SnapshotConfig, Transport, + Builder, Mode, OfflineConfig, OnlineConfig, RemoteExternalities, SnapshotConfig, Transport, }; use std::env::var; - #[tokio::test] - async fn run_migrations() { - if var("RUN_MIGRATION_TESTS").is_err() { - return - } - - sp_tracing::try_init_simple(); + async fn remote_ext_test_setup() -> RemoteExternalities { let transport: Transport = var("WS").unwrap_or("wss://rpc.polkadot.io:443".to_string()).into(); let maybe_state_snapshot: Option = var("SNAP").map(|s| s.into()).ok(); - let mut ext = Builder::::default() + Builder::::default() .mode(if let Some(state_snapshot) = maybe_state_snapshot { Mode::OfflineOrElseOnline( OfflineConfig { state_snapshot: state_snapshot.clone() }, @@ -2614,7 +2610,63 @@ mod remote_tests { }) .build() .await - .unwrap(); + .unwrap() + } + + #[tokio::test] + async fn dispatch_all_proposals() { + if var("RUN_OPENGOV_TEST").is_err() { + return + } + + sp_tracing::try_init_simple(); + let mut ext = remote_ext_test_setup().await; + ext.execute_with(|| { + type Ref = pallet_referenda::ReferendumInfoOf; + type RefStatus = pallet_referenda::ReferendumStatusOf; + use sp_runtime::traits::Dispatchable; + let all_refs: Vec<(u32, RefStatus)> = + pallet_referenda::ReferendumInfoFor::::iter() + .filter_map(|(idx, reff): (_, Ref)| { + if let Ref::Ongoing(ref_status) = reff { + Some((idx, ref_status)) + } else { + None + } + }) + .collect::>(); + + for (ref_index, referenda) in all_refs { + log::info!(target: LOG_TARGET, "πŸš€ executing referenda #{}", ref_index); + let RefStatus { origin, proposal, .. } = referenda; + // we do more or less what the scheduler will do under the hood, as bes tas we can + // imitate: + let (call, _len) = match < + ::Preimages + as + frame_support::traits::QueryPreimage + >::peek(&proposal) { + Ok(x) => x, + Err(e) => { + log::error!(target: LOG_TARGET, "failed to get preimage: {:?}", e); + continue; + } + }; + + let dispatch_result = call.dispatch(origin.clone().into()); + log::info!(target: LOG_TARGET, "outcome of dispatch with origin {:?}: {:?}", origin, dispatch_result); + } + }); + } + + #[tokio::test] + async fn run_migrations() { + if var("RUN_MIGRATION_TESTS").is_err() { + return + } + + sp_tracing::try_init_simple(); + let mut ext = remote_ext_test_setup().await; ext.execute_with(|| Runtime::on_runtime_upgrade(UpgradeCheckSelect::PreAndPost)); } From 5fbfdab8c1792e0f777a37fcd8f6a660fbc56740 Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Sat, 30 Sep 2023 18:06:08 +0200 Subject: [PATCH 04/15] Update relay/polkadot/src/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: GonΓ§alo Pestana --- relay/polkadot/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index c00819bfe1..d27a6a8a7d 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -547,7 +547,7 @@ parameter_types! { /// + let auction_proportion = Perquintill::from_rational(auctioned_slots.min(60), 300u64); /// ``` /// -/// See https://forum.polkadot.network/t/adjusting-polkadots-ideal-staking-rate-calculation/3897/2 +/// See . fn polkadot_era_payout( total_staked: Balance, total_stakable: Balance, From d08a6874fa134cf0ec06bbeaad9a911604136255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Thu, 19 Oct 2023 13:12:49 +0200 Subject: [PATCH 05/15] Bump spec versions --- relay/kusama/src/lib.rs | 2 +- relay/polkadot/src/lib.rs | 2 +- system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs | 4 ++-- system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs | 2 +- system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs | 2 +- system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs | 2 +- system-parachains/collectives/collectives-polkadot/src/lib.rs | 2 +- system-parachains/gluttons/glutton-kusama/src/lib.rs | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/relay/kusama/src/lib.rs b/relay/kusama/src/lib.rs index 659a7052d2..c56d13644a 100644 --- a/relay/kusama/src/lib.rs +++ b/relay/kusama/src/lib.rs @@ -137,7 +137,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("kusama"), impl_name: create_runtime_str!("parity-kusama"), authoring_version: 2, - spec_version: 9430, + spec_version: 1_000_000, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 23, diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index d27a6a8a7d..cde2839a25 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -130,7 +130,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("polkadot"), impl_name: create_runtime_str!("parity-polkadot"), authoring_version: 0, - spec_version: 9430, + spec_version: 1_000_000, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 24, diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs index 12633ce5b9..7d2fafbafa 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs @@ -111,7 +111,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("statemine"), impl_name: create_runtime_str!("statemine"), authoring_version: 1, - spec_version: 10000, + spec_version: 1_000_000, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 13, @@ -127,7 +127,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("statemine"), impl_name: create_runtime_str!("statemine"), authoring_version: 1, - spec_version: 10000, + spec_version: 1_000_000, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 13, diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index f5117490dd..2498ce7cc4 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -137,7 +137,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("statemint"), impl_name: create_runtime_str!("statemint"), authoring_version: 1, - spec_version: 10000, + spec_version: 1_000_000, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 13, diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs index 7a95e2e6b9..206f306843 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs @@ -154,7 +154,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("bridge-hub-kusama"), impl_name: create_runtime_str!("bridge-hub-kusama"), authoring_version: 1, - spec_version: 10000, + spec_version: 1_000_000, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 3, diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs index dbfdc249a3..48d0744ff0 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs @@ -129,7 +129,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("bridge-hub-polkadot"), impl_name: create_runtime_str!("bridge-hub-polkadot"), authoring_version: 1, - spec_version: 10000, + spec_version: 1_000_000, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 2, diff --git a/system-parachains/collectives/collectives-polkadot/src/lib.rs b/system-parachains/collectives/collectives-polkadot/src/lib.rs index e79a5bb15b..31c6923e85 100644 --- a/system-parachains/collectives/collectives-polkadot/src/lib.rs +++ b/system-parachains/collectives/collectives-polkadot/src/lib.rs @@ -105,7 +105,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("collectives"), impl_name: create_runtime_str!("collectives"), authoring_version: 1, - spec_version: 10000, + spec_version: 1_000_000, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 5, diff --git a/system-parachains/gluttons/glutton-kusama/src/lib.rs b/system-parachains/gluttons/glutton-kusama/src/lib.rs index dde8f747d4..a6153952de 100644 --- a/system-parachains/gluttons/glutton-kusama/src/lib.rs +++ b/system-parachains/gluttons/glutton-kusama/src/lib.rs @@ -87,7 +87,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("glutton"), impl_name: create_runtime_str!("glutton"), authoring_version: 1, - spec_version: 10000, + spec_version: 1_000_000, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 87c61615c88507036ae0e763aaf64600d6e64898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Thu, 19 Oct 2023 13:15:37 +0200 Subject: [PATCH 06/15] Update changelog and make it release --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbc6143dc8..a04c6c5b7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,11 @@ Changelog for the runtimes governed by the Polkadot Fellowship. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). -## [Unreleased] +## [1.0.0] 19.10.2023 ### Changed +- Update Polkadot ideal staking rate ([polkadot-fellows/runtimes#26](https://github.com/polkadot-fellows/runtimes/pull/26)) - Treasury deprecate `propose_spend` dispatchable ([paritytech/substrate#14538](https://github.com/paritytech/substrate/pull/14538)) - Use benchmarked weights for `XCM` ([paritytech/polkadot#7077](https://github.com/paritytech/polkadot/pull/7077)) - Put HRMP Channel Management on General Admin Track ([paritytech/polkadot#7477](https://github.com/paritytech/polkadot/pull/7477)) From 197b3b947c846736456dd2026903a5fa3a937886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Thu, 19 Oct 2023 23:57:15 +0200 Subject: [PATCH 07/15] Bump Kusama `transaction_version` The new society is at the same index as the old one, but has different `calls`. --- relay/kusama/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/relay/kusama/src/lib.rs b/relay/kusama/src/lib.rs index c56d13644a..3d9c514db7 100644 --- a/relay/kusama/src/lib.rs +++ b/relay/kusama/src/lib.rs @@ -140,7 +140,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_version: 1_000_000, impl_version: 0, apis: RUNTIME_API_VERSIONS, - transaction_version: 23, + transaction_version: 24, state_version: 1, }; From d661c6b5cf7500a85835ed786e0ee068aa2ca2b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Fri, 20 Oct 2023 00:10:19 +0200 Subject: [PATCH 08/15] Update `xcm-builder` --- Cargo.lock | 4 ++-- relay/kusama/Cargo.toml | 2 +- relay/polkadot/Cargo.toml | 2 +- system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml | 2 +- system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml | 2 +- system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml | 2 +- system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml | 2 +- system-parachains/collectives/collectives-polkadot/Cargo.toml | 2 +- system-parachains/gluttons/glutton-kusama/Cargo.toml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 75bbb285b4..5d9301657c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11255,9 +11255,9 @@ dependencies = [ [[package]] name = "staging-xcm-builder" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd00b720a97ad1304684c07eea14fb3615dd2e26569d29876e9b40ff9c334eca" +checksum = "07c1ca6d8f2b7fcbfe8866c1a1cb8105b62c72a74e727dd8c9943e8ac0c410eb" dependencies = [ "frame-support", "frame-system", diff --git a/relay/kusama/Cargo.toml b/relay/kusama/Cargo.toml index 76eb17ea5e..f1503baa8a 100644 --- a/relay/kusama/Cargo.toml +++ b/relay/kusama/Cargo.toml @@ -111,7 +111,7 @@ primitives = { package = "polkadot-primitives", default-features = false , versi xcm = { package = "staging-xcm", default-features = false , version = "2.0.0" } xcm-executor = { package = "staging-xcm-executor", default-features = false , version = "2.0.0" } -xcm-builder = { package = "staging-xcm-builder", default-features = false , version = "2.0.0" } +xcm-builder = { package = "staging-xcm-builder", default-features = false , version = "2.0.1" } [dev-dependencies] tiny-keccak = { version = "2.0.2", features = ["keccak"] } diff --git a/relay/polkadot/Cargo.toml b/relay/polkadot/Cargo.toml index 4eb3bec132..2b87c6904a 100644 --- a/relay/polkadot/Cargo.toml +++ b/relay/polkadot/Cargo.toml @@ -102,7 +102,7 @@ primitives = { package = "polkadot-primitives", default-features = false , versi xcm = { package = "staging-xcm", default-features = false , version = "2.0.0" } xcm-executor = { package = "staging-xcm-executor", default-features = false , version = "2.0.0" } -xcm-builder = { package = "staging-xcm-builder", default-features = false , version = "2.0.0" } +xcm-builder = { package = "staging-xcm-builder", default-features = false , version = "2.0.1" } [dev-dependencies] hex-literal = "0.4.1" diff --git a/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml b/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml index fc0402a46c..62559503fd 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml +++ b/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml @@ -65,7 +65,7 @@ polkadot-core-primitives = { default-features = false, version = "2.0.0" } polkadot-parachain-primitives = { default-features = false, version = "1.0.0" } polkadot-runtime-common = { default-features = false, version = "2.0.0" } xcm = { package = "staging-xcm", default-features = false, version = "2.0.0" } -xcm-builder = { package = "staging-xcm-builder", default-features = false, version = "2.0.0" } +xcm-builder = { package = "staging-xcm-builder", default-features = false, version = "2.0.1" } xcm-executor = { package = "staging-xcm-executor", default-features = false, version = "2.0.0" } # Cumulus diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml b/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml index 4898564c6c..3f412a4fe2 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml +++ b/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml @@ -60,7 +60,7 @@ polkadot-parachain-primitives = { default-features = false, version = "1.0.0" } polkadot-runtime-common = { default-features = false, version = "2.0.0" } polkadot-runtime-constants = { path = "../../../relay/polkadot/constants", default-features = false} xcm = { package = "staging-xcm", default-features = false, version = "2.0.0" } -xcm-builder = { package = "staging-xcm-builder", default-features = false, version = "2.0.0" } +xcm-builder = { package = "staging-xcm-builder", default-features = false, version = "2.0.1" } xcm-executor = { package = "staging-xcm-executor", default-features = false, version = "2.0.0" } # Cumulus diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml b/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml index 03d82da68c..0c8f2b2136 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml @@ -58,7 +58,7 @@ polkadot-core-primitives = { default-features = false, version = "2.0.0" } polkadot-parachain-primitives = { default-features = false, version = "1.0.0" } polkadot-runtime-common = { default-features = false, version = "2.0.0" } xcm = { package = "staging-xcm", default-features = false, version = "2.0.0" } -xcm-builder = { package = "staging-xcm-builder", default-features = false, version = "2.0.0" } +xcm-builder = { package = "staging-xcm-builder", default-features = false, version = "2.0.1" } xcm-executor = { package = "staging-xcm-executor", default-features = false, version = "2.0.0" } # Cumulus diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml b/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml index 587595bc98..9f53ee3c9c 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml @@ -58,7 +58,7 @@ polkadot-core-primitives = { default-features = false, version = "2.0.0" } polkadot-parachain-primitives = { default-features = false, version = "1.0.0" } polkadot-runtime-common = { default-features = false, version = "2.0.0" } xcm = { package = "staging-xcm", default-features = false, version = "2.0.0" } -xcm-builder = { package = "staging-xcm-builder", default-features = false, version = "2.0.0" } +xcm-builder = { package = "staging-xcm-builder", default-features = false, version = "2.0.1" } xcm-executor = { package = "staging-xcm-executor", default-features = false, version = "2.0.0" } # Cumulus diff --git a/system-parachains/collectives/collectives-polkadot/Cargo.toml b/system-parachains/collectives/collectives-polkadot/Cargo.toml index f36b68a646..8b28e2d80c 100644 --- a/system-parachains/collectives/collectives-polkadot/Cargo.toml +++ b/system-parachains/collectives/collectives-polkadot/Cargo.toml @@ -62,7 +62,7 @@ polkadot-parachain-primitives = { default-features = false, version = "1.0.0" } polkadot-runtime-common = { default-features = false, version = "2.0.0" } polkadot-runtime-constants = { path = "../../../relay/polkadot/constants", default-features = false} xcm = { package = "staging-xcm", default-features = false, version = "2.0.0" } -xcm-builder = { package = "staging-xcm-builder", default-features = false, version = "2.0.0" } +xcm-builder = { package = "staging-xcm-builder", default-features = false, version = "2.0.1" } xcm-executor = { package = "staging-xcm-executor", default-features = false, version = "2.0.0" } # Cumulus diff --git a/system-parachains/gluttons/glutton-kusama/Cargo.toml b/system-parachains/gluttons/glutton-kusama/Cargo.toml index 9bf6646ea6..2b46d2c043 100644 --- a/system-parachains/gluttons/glutton-kusama/Cargo.toml +++ b/system-parachains/gluttons/glutton-kusama/Cargo.toml @@ -36,7 +36,7 @@ sp-version = { default-features = false, version = "24.0.0" } # Polkadot xcm = { package = "staging-xcm", default-features = false, version = "2.0.0" } -xcm-builder = { package = "staging-xcm-builder", default-features = false, version = "2.0.0" } +xcm-builder = { package = "staging-xcm-builder", default-features = false, version = "2.0.1" } xcm-executor = { package = "staging-xcm-executor", default-features = false, version = "2.0.0" } # Cumulus From 92e378adedead4657e50fb073c9333228eab3244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Fri, 20 Oct 2023 00:11:32 +0200 Subject: [PATCH 09/15] Update relay/polkadot/src/lib.rs Co-authored-by: Oliver Tale-Yazdi --- relay/polkadot/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index cde2839a25..16b29a12e5 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -2639,7 +2639,7 @@ mod remote_tests { for (ref_index, referenda) in all_refs { log::info!(target: LOG_TARGET, "πŸš€ executing referenda #{}", ref_index); let RefStatus { origin, proposal, .. } = referenda; - // we do more or less what the scheduler will do under the hood, as bes tas we can + // we do more or less what the scheduler will do under the hood, as best as we can // imitate: let (call, _len) = match < ::Preimages From d65c9e09c46fbd0a7fc65d4b7c16ac3871ba0901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Fri, 20 Oct 2023 00:13:10 +0200 Subject: [PATCH 10/15] Be optimistic!! --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a04c6c5b7f..8d42e69e01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Changelog for the runtimes governed by the Polkadot Fellowship. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). -## [1.0.0] 19.10.2023 +## [1.0.0] 20.10.2023 ### Changed From 5f7230e2152645e989db96b06c2987f239be461c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Sat, 21 Oct 2023 18:24:05 +0200 Subject: [PATCH 11/15] Upgrade staging xcm to get the fix for the metadata --- Cargo.lock | 12 ++++++------ relay/kusama/Cargo.toml | 2 +- relay/polkadot/Cargo.toml | 2 +- .../asset-hubs/asset-hub-kusama/Cargo.toml | 2 +- .../asset-hubs/asset-hub-polkadot/Cargo.toml | 2 +- .../bridge-hubs/bridge-hub-kusama/Cargo.toml | 2 +- .../bridge-hubs/bridge-hub-polkadot/Cargo.toml | 2 +- .../collectives/collectives-polkadot/Cargo.toml | 2 +- system-parachains/gluttons/glutton-kusama/Cargo.toml | 2 +- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5d9301657c..c9865981cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9790,9 +9790,9 @@ dependencies = [ [[package]] name = "scale-info" -version = "2.9.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35c0a159d0c45c12b20c5a844feb1fe4bea86e28f17b92a5f0c42193634d3782" +checksum = "7f7d66a1128282b7ef025a8ead62a4a9fcf017382ec53b8ffbf4d7bf77bd3c60" dependencies = [ "bitvec", "cfg-if", @@ -9804,9 +9804,9 @@ dependencies = [ [[package]] name = "scale-info-derive" -version = "2.9.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "912e55f6d20e0e80d63733872b40e1227c0bce1e1ab81ba67d696339bfd7fd29" +checksum = "abf2c68b89cafb3b8d918dd07b42be0da66ff202cf1155c5739a4e0c1ea0dc19" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -11237,9 +11237,9 @@ dependencies = [ [[package]] name = "staging-xcm" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1712d3ab65f9f09c2f7c281106d45589182e71950279b98db83ce89125067d26" +checksum = "eec456fd5fcbc4dffe9c6042b452c1930eb1d5af5534d6ef36b8238b4517c9b7" dependencies = [ "bounded-collections", "derivative", diff --git a/relay/kusama/Cargo.toml b/relay/kusama/Cargo.toml index f1503baa8a..7911a54974 100644 --- a/relay/kusama/Cargo.toml +++ b/relay/kusama/Cargo.toml @@ -109,7 +109,7 @@ runtime-common = { package = "polkadot-runtime-common", default-features = false runtime-parachains = { package = "polkadot-runtime-parachains", default-features = false , version = "2.0.0" } primitives = { package = "polkadot-primitives", default-features = false , version = "2.0.0" } -xcm = { package = "staging-xcm", default-features = false , version = "2.0.0" } +xcm = { package = "staging-xcm", default-features = false , version = "2.0.1" } xcm-executor = { package = "staging-xcm-executor", default-features = false , version = "2.0.0" } xcm-builder = { package = "staging-xcm-builder", default-features = false , version = "2.0.1" } diff --git a/relay/polkadot/Cargo.toml b/relay/polkadot/Cargo.toml index 2b87c6904a..3c72f30e09 100644 --- a/relay/polkadot/Cargo.toml +++ b/relay/polkadot/Cargo.toml @@ -100,7 +100,7 @@ runtime-common = { package = "polkadot-runtime-common", default-features = false runtime-parachains = { package = "polkadot-runtime-parachains", default-features = false , version = "2.0.0" } primitives = { package = "polkadot-primitives", default-features = false , version = "2.0.0" } -xcm = { package = "staging-xcm", default-features = false , version = "2.0.0" } +xcm = { package = "staging-xcm", default-features = false , version = "2.0.1" } xcm-executor = { package = "staging-xcm-executor", default-features = false , version = "2.0.0" } xcm-builder = { package = "staging-xcm-builder", default-features = false , version = "2.0.1" } diff --git a/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml b/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml index 62559503fd..13d150bc87 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml +++ b/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml @@ -64,7 +64,7 @@ pallet-xcm-benchmarks = { default-features = false, optional = true , version = polkadot-core-primitives = { default-features = false, version = "2.0.0" } polkadot-parachain-primitives = { default-features = false, version = "1.0.0" } polkadot-runtime-common = { default-features = false, version = "2.0.0" } -xcm = { package = "staging-xcm", default-features = false, version = "2.0.0" } +xcm = { package = "staging-xcm", default-features = false, version = "2.0.1" } xcm-builder = { package = "staging-xcm-builder", default-features = false, version = "2.0.1" } xcm-executor = { package = "staging-xcm-executor", default-features = false, version = "2.0.0" } diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml b/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml index 3f412a4fe2..973f527540 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml +++ b/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml @@ -59,7 +59,7 @@ polkadot-core-primitives = { default-features = false, version = "2.0.0" } polkadot-parachain-primitives = { default-features = false, version = "1.0.0" } polkadot-runtime-common = { default-features = false, version = "2.0.0" } polkadot-runtime-constants = { path = "../../../relay/polkadot/constants", default-features = false} -xcm = { package = "staging-xcm", default-features = false, version = "2.0.0" } +xcm = { package = "staging-xcm", default-features = false, version = "2.0.1" } xcm-builder = { package = "staging-xcm-builder", default-features = false, version = "2.0.1" } xcm-executor = { package = "staging-xcm-executor", default-features = false, version = "2.0.0" } diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml b/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml index 0c8f2b2136..11225c620b 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml @@ -57,7 +57,7 @@ pallet-xcm-benchmarks = { default-features = false, optional = true , version = polkadot-core-primitives = { default-features = false, version = "2.0.0" } polkadot-parachain-primitives = { default-features = false, version = "1.0.0" } polkadot-runtime-common = { default-features = false, version = "2.0.0" } -xcm = { package = "staging-xcm", default-features = false, version = "2.0.0" } +xcm = { package = "staging-xcm", default-features = false, version = "2.0.1" } xcm-builder = { package = "staging-xcm-builder", default-features = false, version = "2.0.1" } xcm-executor = { package = "staging-xcm-executor", default-features = false, version = "2.0.0" } diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml b/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml index 9f53ee3c9c..cac2fcc358 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml @@ -57,7 +57,7 @@ pallet-xcm-benchmarks = { default-features = false, optional = true , version = polkadot-core-primitives = { default-features = false, version = "2.0.0" } polkadot-parachain-primitives = { default-features = false, version = "1.0.0" } polkadot-runtime-common = { default-features = false, version = "2.0.0" } -xcm = { package = "staging-xcm", default-features = false, version = "2.0.0" } +xcm = { package = "staging-xcm", default-features = false, version = "2.0.1" } xcm-builder = { package = "staging-xcm-builder", default-features = false, version = "2.0.1" } xcm-executor = { package = "staging-xcm-executor", default-features = false, version = "2.0.0" } diff --git a/system-parachains/collectives/collectives-polkadot/Cargo.toml b/system-parachains/collectives/collectives-polkadot/Cargo.toml index 8b28e2d80c..5af3c75bed 100644 --- a/system-parachains/collectives/collectives-polkadot/Cargo.toml +++ b/system-parachains/collectives/collectives-polkadot/Cargo.toml @@ -61,7 +61,7 @@ polkadot-core-primitives = { default-features = false, version = "2.0.0" } polkadot-parachain-primitives = { default-features = false, version = "1.0.0" } polkadot-runtime-common = { default-features = false, version = "2.0.0" } polkadot-runtime-constants = { path = "../../../relay/polkadot/constants", default-features = false} -xcm = { package = "staging-xcm", default-features = false, version = "2.0.0" } +xcm = { package = "staging-xcm", default-features = false, version = "2.0.1" } xcm-builder = { package = "staging-xcm-builder", default-features = false, version = "2.0.1" } xcm-executor = { package = "staging-xcm-executor", default-features = false, version = "2.0.0" } diff --git a/system-parachains/gluttons/glutton-kusama/Cargo.toml b/system-parachains/gluttons/glutton-kusama/Cargo.toml index 2b46d2c043..c7552d0e2c 100644 --- a/system-parachains/gluttons/glutton-kusama/Cargo.toml +++ b/system-parachains/gluttons/glutton-kusama/Cargo.toml @@ -35,7 +35,7 @@ sp-transaction-pool = { default-features = false, version = "21.0.0" } sp-version = { default-features = false, version = "24.0.0" } # Polkadot -xcm = { package = "staging-xcm", default-features = false, version = "2.0.0" } +xcm = { package = "staging-xcm", default-features = false, version = "2.0.1" } xcm-builder = { package = "staging-xcm-builder", default-features = false, version = "2.0.1" } xcm-executor = { package = "staging-xcm-executor", default-features = false, version = "2.0.0" } From 307005eafbf9c4af7173518a3de855d14d6c301d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Sat, 21 Oct 2023 18:32:23 +0200 Subject: [PATCH 12/15] Add a test --- relay/polkadot/src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index 16b29a12e5..fa90be132f 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -2458,6 +2458,7 @@ mod multiplier_tests { use super::*; use frame_support::{dispatch::DispatchInfo, traits::OnFinalize}; use runtime_common::{MinimumMultiplier, TargetBlockFullness}; + use scale_info::TypeInfo; use separator::Separatable; use sp_runtime::traits::Convert; @@ -2580,6 +2581,13 @@ mod multiplier_tests { blocks += 1; } } + + #[test] + fn ensure_xcm_metadata_is_correct() { + let path = xcm::VersionedXcm::<()>::type_info().path; + // Ensure that the name doesn't include `staging` (from the pallet name) + assert_eq!(vec!["xcm", "VersionedXcm"], path.segments); + } } #[cfg(all(test, feature = "try-runtime"))] From 7aa69fa8cabfd6429956c9ed59dede0f5d6fd729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Sat, 21 Oct 2023 21:32:04 +0200 Subject: [PATCH 13/15] Adds custom paras scheduler migration This is a backport from polkadot-sdk master that includes some fixes. --- relay/polkadot/src/lib.rs | 4 +- .../polkadot/src/paras_scheduler_migration.rs | 218 ++++++++++++++++++ 2 files changed, 221 insertions(+), 1 deletion(-) create mode 100644 relay/polkadot/src/paras_scheduler_migration.rs diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index fa90be132f..97ceedb0cd 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -106,6 +106,8 @@ mod weights; mod bag_thresholds; +mod paras_scheduler_migration; + // Governance configurations. pub mod governance; use governance::{ @@ -1571,7 +1573,7 @@ pub mod migrations { pub type Unreleased = ( pallet_im_online::migration::v1::Migration, parachains_configuration::migration::v7::MigrateToV7, - parachains_scheduler::migration::v1::MigrateToV1, + crate::paras_scheduler_migration::v1::MigrateToV1, parachains_configuration::migration::v8::MigrateToV8, // Gov v1 storage migrations diff --git a/relay/polkadot/src/paras_scheduler_migration.rs b/relay/polkadot/src/paras_scheduler_migration.rs new file mode 100644 index 0000000000..d294861843 --- /dev/null +++ b/relay/polkadot/src/paras_scheduler_migration.rs @@ -0,0 +1,218 @@ +//! A copy of the migration found in the polkadot sdk repo. +//! +//! It is copied as the version of the migration found in the crate used by this runtime is broken. + +use frame_support::{ + migrations::VersionedMigration, pallet_prelude::ValueQuery, storage_alias, + traits::OnRuntimeUpgrade, weights::Weight, +}; +use frame_system::pallet_prelude::BlockNumberFor; +use parity_scale_codec::{Decode, Encode}; +use primitives::{ + v5::{Assignment, ParasEntry}, + CoreIndex, CoreOccupied, GroupIndex, Id as ParaId, +}; +use runtime_parachains::scheduler::*; +use scale_info::TypeInfo; +use sp_core::{Get, RuntimeDebug}; +use sp_std::{ + collections::{btree_map::BTreeMap, vec_deque::VecDeque}, + prelude::*, +}; + +const LOG_TARGET: &str = "runtime::parachains::scheduler"; + +mod v0 { + use super::*; + + use primitives::{CollatorId, Id}; + + #[storage_alias] + pub(super) type Scheduled = StorageValue, Vec, ValueQuery>; + + #[derive(Clone, Encode, Decode)] + #[cfg_attr(feature = "std", derive(PartialEq))] + pub struct ParathreadClaim(pub Id, pub CollatorId); + + #[derive(Clone, Encode, Decode)] + #[cfg_attr(feature = "std", derive(PartialEq))] + pub struct ParathreadEntry { + /// The claim. + pub claim: ParathreadClaim, + /// Number of retries. + pub retries: u32, + } + + /// What is occupying a specific availability core. + #[derive(Clone, Encode, Decode)] + #[cfg_attr(feature = "std", derive(PartialEq))] + pub enum CoreOccupied { + /// A parathread. + Parathread(ParathreadEntry), + /// A parachain. + Parachain, + } + + /// The actual type isn't important, as we only delete the key in the state. + #[storage_alias] + pub(crate) type AvailabilityCores = + StorageValue, Vec>, ValueQuery>; + + /// The actual type isn't important, as we only delete the key in the state. + #[storage_alias] + pub(super) type ParathreadQueue = StorageValue, (), ValueQuery>; + + #[storage_alias] + pub(super) type ParathreadClaimIndex = StorageValue, (), ValueQuery>; + + /// The assignment type. + #[derive(Clone, Encode, Decode, TypeInfo, RuntimeDebug)] + #[cfg_attr(feature = "std", derive(PartialEq))] + pub enum AssignmentKind { + /// A parachain. + Parachain, + /// A parathread. + Parathread(CollatorId, u32), + } + + /// How a free core is scheduled to be assigned. + #[derive(Clone, Encode, Decode, TypeInfo, RuntimeDebug)] + #[cfg_attr(feature = "std", derive(PartialEq))] + pub struct CoreAssignment { + /// The core that is assigned. + pub core: CoreIndex, + /// The unique ID of the para that is assigned to the core. + pub para_id: ParaId, + /// The kind of the assignment. + pub kind: AssignmentKind, + /// The index of the validator group assigned to the core. + pub group_idx: GroupIndex, + } +} + +pub mod v1 { + use super::*; + + #[storage_alias] + pub(crate) type AvailabilityCores = + StorageValue, Vec>>, ValueQuery>; + + #[storage_alias] + pub(crate) type ClaimQueue = StorageValue< + Pallet, + BTreeMap>>>>, + ValueQuery, + >; + + #[allow(deprecated)] + pub type MigrateToV1 = VersionedMigration< + 0, + 1, + UncheckedMigrateToV1, + Pallet, + ::DbWeight, + >; + + #[deprecated(note = "Use MigrateToV1 instead")] + pub struct UncheckedMigrateToV1(sp_std::marker::PhantomData); + #[allow(deprecated)] + impl OnRuntimeUpgrade for UncheckedMigrateToV1 { + fn on_runtime_upgrade() -> Weight { + let weight_consumed = migrate_to_v1::(); + + log::info!(target: LOG_TARGET, "Migrating para scheduler storage to v1"); + + weight_consumed + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, sp_runtime::DispatchError> { + let n: u32 = v0::Scheduled::::get().len() as u32 + + v0::AvailabilityCores::::get().iter().filter(|c| c.is_some()).count() as u32; + + log::info!( + target: LOG_TARGET, + "Number of scheduled and waiting for availability before: {n}", + ); + + Ok(n.encode()) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(state: Vec) -> Result<(), sp_runtime::DispatchError> { + log::info!(target: LOG_TARGET, "Running post_upgrade()"); + + frame_support::ensure!( + v0::Scheduled::::get().is_empty(), + "Scheduled should be empty after the migration" + ); + + let expected_len = u32::decode(&mut &state[..]).unwrap(); + let availability_cores_waiting = AvailabilityCores::::get() + .iter() + .filter(|c| !matches!(c, CoreOccupied::Free)) + .count(); + + frame_support::ensure!( + ClaimQueue::::get().iter().map(|la_vec| la_vec.1.len()).sum::() as u32 + + availability_cores_waiting as u32 == + expected_len, + "ClaimQueue and AvailabilityCores should have the correct length", + ); + + Ok(()) + } + } +} + +pub fn migrate_to_v1() -> Weight { + let mut weight: Weight = Weight::zero(); + + v0::ParathreadQueue::::kill(); + v0::ParathreadClaimIndex::::kill(); + + let now = >::block_number(); + let scheduled = v0::Scheduled::::take(); + let sched_len = scheduled.len() as u64; + for core_assignment in scheduled { + let core_idx = core_assignment.core; + let assignment = Assignment::new(core_assignment.para_id); + let pe = ParasEntry::new(assignment, now); + + v1::ClaimQueue::::mutate(|la| { + la.entry(core_idx).or_default().push_back(Some(pe)); + }); + } + + let parachains = runtime_parachains::paras::Pallet::::parachains(); + let availability_cores = v0::AvailabilityCores::::take(); + let mut new_availability_cores = Vec::new(); + + for (core_index, core) in availability_cores.into_iter().enumerate() { + let new_core = if let Some(core) = core { + match core { + v0::CoreOccupied::Parachain => CoreOccupied::Paras(ParasEntry::new( + Assignment::new(parachains[core_index]), + now, + )), + v0::CoreOccupied::Parathread(entry) => + CoreOccupied::Paras(ParasEntry::new(Assignment::new(entry.claim.0), now)), + } + } else { + CoreOccupied::Free + }; + + new_availability_cores.push(new_core); + } + + v1::AvailabilityCores::::set(new_availability_cores); + + // 2x as once for Scheduled and once for Claimqueue + weight = weight.saturating_add(T::DbWeight::get().reads_writes(2 * sched_len, 2 * sched_len)); + // reading parachains + availability_cores, writing AvailabilityCores + weight = weight.saturating_add(T::DbWeight::get().reads_writes(2, 1)); + // 2x kill + weight = weight.saturating_add(T::DbWeight::get().writes(2)); + + weight +} From ac31c629c011a5360f1d3722a847ee895d749203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Sat, 21 Oct 2023 23:46:39 +0200 Subject: [PATCH 14/15] Also copy the migration over to Kusama --- relay/kusama/src/lib.rs | 4 +- relay/kusama/src/paras_scheduler_migration.rs | 218 ++++++++++++++++++ 2 files changed, 221 insertions(+), 1 deletion(-) create mode 100644 relay/kusama/src/paras_scheduler_migration.rs diff --git a/relay/kusama/src/lib.rs b/relay/kusama/src/lib.rs index 3d9c514db7..8900d60d0b 100644 --- a/relay/kusama/src/lib.rs +++ b/relay/kusama/src/lib.rs @@ -109,6 +109,8 @@ mod weights; // Voter bag threshold definitions. mod bag_thresholds; +mod paras_scheduler_migration; + // Historical information of society finances. mod past_payouts; @@ -1734,7 +1736,7 @@ pub mod migrations { >, pallet_im_online::migration::v1::Migration, parachains_configuration::migration::v7::MigrateToV7, - parachains_scheduler::migration::v1::MigrateToV1, + paras_scheduler_migration::v1::MigrateToV1, parachains_configuration::migration::v8::MigrateToV8, // Unlock/unreserve balances from Gov v1 pallets that hold them diff --git a/relay/kusama/src/paras_scheduler_migration.rs b/relay/kusama/src/paras_scheduler_migration.rs new file mode 100644 index 0000000000..d294861843 --- /dev/null +++ b/relay/kusama/src/paras_scheduler_migration.rs @@ -0,0 +1,218 @@ +//! A copy of the migration found in the polkadot sdk repo. +//! +//! It is copied as the version of the migration found in the crate used by this runtime is broken. + +use frame_support::{ + migrations::VersionedMigration, pallet_prelude::ValueQuery, storage_alias, + traits::OnRuntimeUpgrade, weights::Weight, +}; +use frame_system::pallet_prelude::BlockNumberFor; +use parity_scale_codec::{Decode, Encode}; +use primitives::{ + v5::{Assignment, ParasEntry}, + CoreIndex, CoreOccupied, GroupIndex, Id as ParaId, +}; +use runtime_parachains::scheduler::*; +use scale_info::TypeInfo; +use sp_core::{Get, RuntimeDebug}; +use sp_std::{ + collections::{btree_map::BTreeMap, vec_deque::VecDeque}, + prelude::*, +}; + +const LOG_TARGET: &str = "runtime::parachains::scheduler"; + +mod v0 { + use super::*; + + use primitives::{CollatorId, Id}; + + #[storage_alias] + pub(super) type Scheduled = StorageValue, Vec, ValueQuery>; + + #[derive(Clone, Encode, Decode)] + #[cfg_attr(feature = "std", derive(PartialEq))] + pub struct ParathreadClaim(pub Id, pub CollatorId); + + #[derive(Clone, Encode, Decode)] + #[cfg_attr(feature = "std", derive(PartialEq))] + pub struct ParathreadEntry { + /// The claim. + pub claim: ParathreadClaim, + /// Number of retries. + pub retries: u32, + } + + /// What is occupying a specific availability core. + #[derive(Clone, Encode, Decode)] + #[cfg_attr(feature = "std", derive(PartialEq))] + pub enum CoreOccupied { + /// A parathread. + Parathread(ParathreadEntry), + /// A parachain. + Parachain, + } + + /// The actual type isn't important, as we only delete the key in the state. + #[storage_alias] + pub(crate) type AvailabilityCores = + StorageValue, Vec>, ValueQuery>; + + /// The actual type isn't important, as we only delete the key in the state. + #[storage_alias] + pub(super) type ParathreadQueue = StorageValue, (), ValueQuery>; + + #[storage_alias] + pub(super) type ParathreadClaimIndex = StorageValue, (), ValueQuery>; + + /// The assignment type. + #[derive(Clone, Encode, Decode, TypeInfo, RuntimeDebug)] + #[cfg_attr(feature = "std", derive(PartialEq))] + pub enum AssignmentKind { + /// A parachain. + Parachain, + /// A parathread. + Parathread(CollatorId, u32), + } + + /// How a free core is scheduled to be assigned. + #[derive(Clone, Encode, Decode, TypeInfo, RuntimeDebug)] + #[cfg_attr(feature = "std", derive(PartialEq))] + pub struct CoreAssignment { + /// The core that is assigned. + pub core: CoreIndex, + /// The unique ID of the para that is assigned to the core. + pub para_id: ParaId, + /// The kind of the assignment. + pub kind: AssignmentKind, + /// The index of the validator group assigned to the core. + pub group_idx: GroupIndex, + } +} + +pub mod v1 { + use super::*; + + #[storage_alias] + pub(crate) type AvailabilityCores = + StorageValue, Vec>>, ValueQuery>; + + #[storage_alias] + pub(crate) type ClaimQueue = StorageValue< + Pallet, + BTreeMap>>>>, + ValueQuery, + >; + + #[allow(deprecated)] + pub type MigrateToV1 = VersionedMigration< + 0, + 1, + UncheckedMigrateToV1, + Pallet, + ::DbWeight, + >; + + #[deprecated(note = "Use MigrateToV1 instead")] + pub struct UncheckedMigrateToV1(sp_std::marker::PhantomData); + #[allow(deprecated)] + impl OnRuntimeUpgrade for UncheckedMigrateToV1 { + fn on_runtime_upgrade() -> Weight { + let weight_consumed = migrate_to_v1::(); + + log::info!(target: LOG_TARGET, "Migrating para scheduler storage to v1"); + + weight_consumed + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, sp_runtime::DispatchError> { + let n: u32 = v0::Scheduled::::get().len() as u32 + + v0::AvailabilityCores::::get().iter().filter(|c| c.is_some()).count() as u32; + + log::info!( + target: LOG_TARGET, + "Number of scheduled and waiting for availability before: {n}", + ); + + Ok(n.encode()) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(state: Vec) -> Result<(), sp_runtime::DispatchError> { + log::info!(target: LOG_TARGET, "Running post_upgrade()"); + + frame_support::ensure!( + v0::Scheduled::::get().is_empty(), + "Scheduled should be empty after the migration" + ); + + let expected_len = u32::decode(&mut &state[..]).unwrap(); + let availability_cores_waiting = AvailabilityCores::::get() + .iter() + .filter(|c| !matches!(c, CoreOccupied::Free)) + .count(); + + frame_support::ensure!( + ClaimQueue::::get().iter().map(|la_vec| la_vec.1.len()).sum::() as u32 + + availability_cores_waiting as u32 == + expected_len, + "ClaimQueue and AvailabilityCores should have the correct length", + ); + + Ok(()) + } + } +} + +pub fn migrate_to_v1() -> Weight { + let mut weight: Weight = Weight::zero(); + + v0::ParathreadQueue::::kill(); + v0::ParathreadClaimIndex::::kill(); + + let now = >::block_number(); + let scheduled = v0::Scheduled::::take(); + let sched_len = scheduled.len() as u64; + for core_assignment in scheduled { + let core_idx = core_assignment.core; + let assignment = Assignment::new(core_assignment.para_id); + let pe = ParasEntry::new(assignment, now); + + v1::ClaimQueue::::mutate(|la| { + la.entry(core_idx).or_default().push_back(Some(pe)); + }); + } + + let parachains = runtime_parachains::paras::Pallet::::parachains(); + let availability_cores = v0::AvailabilityCores::::take(); + let mut new_availability_cores = Vec::new(); + + for (core_index, core) in availability_cores.into_iter().enumerate() { + let new_core = if let Some(core) = core { + match core { + v0::CoreOccupied::Parachain => CoreOccupied::Paras(ParasEntry::new( + Assignment::new(parachains[core_index]), + now, + )), + v0::CoreOccupied::Parathread(entry) => + CoreOccupied::Paras(ParasEntry::new(Assignment::new(entry.claim.0), now)), + } + } else { + CoreOccupied::Free + }; + + new_availability_cores.push(new_core); + } + + v1::AvailabilityCores::::set(new_availability_cores); + + // 2x as once for Scheduled and once for Claimqueue + weight = weight.saturating_add(T::DbWeight::get().reads_writes(2 * sched_len, 2 * sched_len)); + // reading parachains + availability_cores, writing AvailabilityCores + weight = weight.saturating_add(T::DbWeight::get().reads_writes(2, 1)); + // 2x kill + weight = weight.saturating_add(T::DbWeight::get().writes(2)); + + weight +} From e6789f9c7eae08aa838b6db26a74e87dd4e76024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Sat, 21 Oct 2023 23:52:52 +0200 Subject: [PATCH 15/15] Update CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d42e69e01..bcfa459650 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Changelog for the runtimes governed by the Polkadot Fellowship. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). -## [1.0.0] 20.10.2023 +## [1.0.0] 22.10.2023 ### Changed