From 03984c856fda4baa0024efcc8d0d51dc07278330 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Fri, 10 Nov 2023 09:27:27 +0100 Subject: [PATCH 01/34] Remove pallet from Rococo; Add migrations --- polkadot/runtime/rococo/src/lib.rs | 104 ++++++++++++++++++++++------- 1 file changed, 80 insertions(+), 24 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 4f542354346a..94d0421c246c 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -77,7 +77,6 @@ use frame_support::{ use frame_system::EnsureRoot; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; use pallet_identity::legacy::IdentityInfo; -use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use pallet_session::historical as session_historical; use pallet_transaction_payment::{CurrencyAdapter, FeeDetails, RuntimeDispatchInfo}; use sp_core::{ConstU128, OpaqueMetadata, H256}; @@ -89,7 +88,8 @@ use sp_runtime::{ Verify, }, transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity}, - ApplyExtrinsicResult, FixedU128, KeyTypeId, Perbill, Percent, Permill, RuntimeDebug, + ApplyExtrinsicResult, BoundToRuntimeAppPublic, FixedU128, KeyTypeId, Perbill, Percent, Permill, + RuntimeAppPublic, RuntimeDebug, }; use sp_staking::SessionIndex; #[cfg(any(feature = "std", test))] @@ -338,14 +338,61 @@ impl pallet_timestamp::Config for Runtime { impl pallet_authorship::Config for Runtime { type FindAuthor = pallet_session::FindAccountFromAuthorIndex; - type EventHandler = ImOnline; + type EventHandler = (); +} + +#[derive(Clone, Debug, PartialEq, Eq, Encode, Decode)] +pub struct OldSessionKeys { + pub grandpa: ::Public, + pub babe: ::Public, + pub im_online: (), + pub para_validator: ::Public, + pub para_assignment: ::Public, + pub authority_discovery: ::Public, + pub beefy: ::Public, +} + +impl OpaqueKeys for OldSessionKeys { + type KeyTypeIdProviders = + (Grandpa, Babe, (), Initializer, ParaSessionInfo, AuthorityDiscovery, Beefy); + fn key_ids() -> &'static [KeyTypeId] { + &[<::Public>::ID, + <::Public>::ID, + sp_core::crypto::key_types::IM_ONLINE, + <::Public as + ::sp_runtime::RuntimeAppPublic>::ID, + <::Public as + ::sp_runtime::RuntimeAppPublic>::ID, + <::Public as + ::sp_runtime::RuntimeAppPublic>::ID, + <::Public as + ::sp_runtime::RuntimeAppPublic>::ID] + } + fn get_raw(&self, i: KeyTypeId) -> &[u8] { + match i { + <::Public as RuntimeAppPublic>::ID => + self.grandpa.as_ref(), + <::Public as RuntimeAppPublic>::ID => + self.babe.as_ref(), + <::Public as RuntimeAppPublic>::ID => + self.para_validator.as_ref(), + <::Public as RuntimeAppPublic>::ID => + self.para_assignment.as_ref(), + <::Public as RuntimeAppPublic>::ID => + self.authority_discovery.as_ref(), + <::Public as RuntimeAppPublic>::ID => + self.beefy.as_ref(), + _ => &[], + } + } } impl_opaque_keys! { pub struct SessionKeys { pub grandpa: Grandpa, pub babe: Babe, - pub im_online: ImOnline, pub para_validator: Initializer, pub para_assignment: ParaSessionInfo, pub authority_discovery: AuthorityDiscovery, @@ -353,6 +400,18 @@ impl_opaque_keys! { } } +// remove this when removing `OldSessionKeys` +fn transform_session_keys(_val: AccountId, old: OldSessionKeys) -> SessionKeys { + SessionKeys { + grandpa: old.grandpa, + babe: old.babe, + para_validator: old.para_validator, + para_assignment: old.para_assignment, + authority_discovery: old.authority_discovery, + beefy: old.beefy, + } +} + /// Special `ValidatorIdOf` implementation that is just returning the input as result. pub struct ValidatorIdOf; impl sp_runtime::traits::Convert> for ValidatorIdOf { @@ -497,22 +556,6 @@ impl pallet_authority_discovery::Config for Runtime { type MaxAuthorities = MaxAuthorities; } -parameter_types! { - pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value(); -} - -impl pallet_im_online::Config for Runtime { - type AuthorityId = ImOnlineId; - type RuntimeEvent = RuntimeEvent; - type ValidatorSet = Historical; - type NextSessionRotation = Babe; - type ReportUnresponsiveness = Offences; - type UnsignedPriority = ImOnlineUnsignedPriority; - type WeightInfo = weights::pallet_im_online::WeightInfo; - type MaxKeys = MaxKeys; - type MaxPeerInHeartbeats = MaxPeerInHeartbeats; -} - parameter_types! { pub const MaxSetIdSessionEntries: u32 = BondingDuration::get() * SessionsPerEra::get(); } @@ -762,7 +805,6 @@ impl InstanceFilter for ProxyType { // Specifically omitting the entire Balances pallet RuntimeCall::Session(..) | RuntimeCall::Grandpa(..) | - RuntimeCall::ImOnline(..) | RuntimeCall::Treasury(..) | RuntimeCall::Bounties(..) | RuntimeCall::ChildBounties(..) | @@ -1283,7 +1325,6 @@ construct_runtime! { Session: pallet_session::{Pallet, Call, Storage, Event, Config} = 8, Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event, ValidateUnsigned} = 10, - ImOnline: pallet_im_online::{Pallet, Call, Storage, Event, ValidateUnsigned, Config} = 11, AuthorityDiscovery: pallet_authority_discovery::{Pallet, Config} = 12, // Governance stuff; uncallable initially. @@ -1434,6 +1475,7 @@ pub mod migrations { pub const PhragmenElectionPalletName: &'static str = "PhragmenElection"; pub const TechnicalMembershipPalletName: &'static str = "TechnicalMembership"; pub const TipsPalletName: &'static str = "Tips"; + pub const ImOnlinePalletName: &'static str = "ImOnline"; pub const PhragmenElectionPalletId: LockIdentifier = *b"phrelect"; } @@ -1470,10 +1512,19 @@ pub mod migrations { type PalletName = TipsPalletName; } + /// Upgrade Session keys to exclude ImOnline 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) * BlockWeights::get().max_block + } + } + /// Unreleased migrations. Add new ones here: pub type Unreleased = ( pallet_society::migrations::VersionCheckedMigrateToV2, - pallet_im_online::migration::v1::Migration, parachains_configuration::migration::v7::MigrateToV7, assigned_slots::migration::v1::VersionCheckedMigrateToV1, parachains_scheduler::migration::v1::MigrateToV1, @@ -1497,6 +1548,12 @@ pub mod migrations { frame_support::migrations::RemovePallet::DbWeight>, frame_support::migrations::RemovePallet::DbWeight>, frame_support::migrations::RemovePallet::DbWeight>, + + // Upgrade `SessionKeys` to exclude `ImOnline` + UpgradeSessionKeys, + + // Remove im-online pallet storage + frame_support::migrations::RemovePallet::DbWeight>, ); } @@ -1566,7 +1623,6 @@ mod benches { [pallet_conviction_voting, ConvictionVoting] [pallet_nis, Nis] [pallet_identity, Identity] - [pallet_im_online, ImOnline] [pallet_indices, Indices] [pallet_message_queue, MessageQueue] [pallet_multisig, Multisig] From 7eebe6d125f46277ed95e070ff17785eb448db31 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Fri, 10 Nov 2023 12:05:33 +0100 Subject: [PATCH 02/34] Fix chainspec --- polkadot/node/service/src/chain_spec.rs | 30 ------------------- polkadot/runtime/rococo/src/lib.rs | 38 ++++++++++--------------- 2 files changed, 15 insertions(+), 53 deletions(-) diff --git a/polkadot/node/service/src/chain_spec.rs b/polkadot/node/service/src/chain_spec.rs index 871d7e82911a..f482c51270b8 100644 --- a/polkadot/node/service/src/chain_spec.rs +++ b/polkadot/node/service/src/chain_spec.rs @@ -183,7 +183,6 @@ fn westend_session_keys( fn rococo_session_keys( babe: BabeId, grandpa: GrandpaId, - im_online: ImOnlineId, para_validator: ValidatorId, para_assignment: AssignmentId, authority_discovery: AuthorityDiscoveryId, @@ -192,7 +191,6 @@ fn rococo_session_keys( rococo_runtime::SessionKeys { babe, grandpa, - im_online, para_validator, para_assignment, authority_discovery, @@ -408,7 +406,6 @@ fn rococo_staging_testnet_config_genesis() -> serde_json::Value { AccountId, BabeId, GrandpaId, - ImOnlineId, ValidatorId, AssignmentId, AuthorityDiscoveryId, @@ -425,9 +422,6 @@ fn rococo_staging_testnet_config_genesis() -> serde_json::Value { //5CPd3zoV9Aaah4xWucuDivMHJ2nEEmpdi864nPTiyRZp4t87 hex!["0e6d7d1afbcc6547b92995a394ba0daed07a2420be08220a5a1336c6731f0bfa"] .unchecked_into(), - //5F7BEa1LGFksUihyatf3dCDYneB8pWzVyavnByCsm5nBgezi - hex!["86975a37211f8704e947a365b720f7a3e2757988eaa7d0f197e83dba355ef743"] - .unchecked_into(), //5CP6oGfwqbEfML8efqm1tCZsUgRsJztp9L8ZkEUxA16W8PPz hex!["0e07a51d3213842f8e9363ce8e444255990a225f87e80a3d651db7841e1a0205"] .unchecked_into(), @@ -452,9 +446,6 @@ fn rococo_staging_testnet_config_genesis() -> serde_json::Value { //5HnDVBN9mD6mXyx8oryhDbJtezwNSj1VRXgLoYCBA6uEkiao hex!["fcd5f87a6fd5707a25122a01b4dac0a8482259df7d42a9a096606df1320df08d"] .unchecked_into(), - //5DhyXZiuB1LvqYKFgT5tRpgGsN3is2cM9QxgW7FikvakbAZP - hex!["48a910c0af90898f11bd57d37ceaea53c78994f8e1833a7ade483c9a84bde055"] - .unchecked_into(), //5EPEWRecy2ApL5n18n3aHyU1956zXTRqaJpzDa9DoqiggNwF hex!["669a10892119453e9feb4e3f1ee8e028916cc3240022920ad643846fbdbee816"] .unchecked_into(), @@ -479,9 +470,6 @@ fn rococo_staging_testnet_config_genesis() -> serde_json::Value { //5HAes2RQYPbYKbLBfKb88f4zoXv6pPA6Ke8CjN7dob3GpmSP hex!["e1b68fbd84333e31486c08e6153d9a1415b2e7e71b413702b7d64e9b631184a1"] .unchecked_into(), - //5HTXBf36LXmkFWJLokNUK6fPxVpkr2ToUnB1pvaagdGu4c1T - hex!["ee93e26259decb89afcf17ef2aa0fa2db2e1042fb8f56ecfb24d19eae8629878"] - .unchecked_into(), //5FtAGDZYJKXkhVhAxCQrXmaP7EE2mGbBMfmKDHjfYDgq2BiU hex!["a8e61ffacafaf546283dc92d14d7cc70ea0151a5dd81fdf73ff5a2951f2b6037"] .unchecked_into(), @@ -506,9 +494,6 @@ fn rococo_staging_testnet_config_genesis() -> serde_json::Value { //5DJV3zCBTJBLGNDCcdWrYxWDacSz84goGTa4pFeKVvehEBte hex!["36be9069cdb4a8a07ecd51f257875150f0a8a1be44a10d9d98dabf10a030aef4"] .unchecked_into(), - //5FHf8kpK4fPjEJeYcYon2gAPwEBubRvtwpzkUbhMWSweKPUY - hex!["8e95b9b5b4dc69790b67b566567ca8bf8cdef3a3a8bb65393c0d1d1c87cd2d2c"] - .unchecked_into(), //5F9FsRjpecP9GonktmtFL3kjqNAMKjHVFjyjRdTPa4hbQRZA hex!["882d72965e642677583b333b2d173ac94b5fd6c405c76184bb14293be748a13b"] .unchecked_into(), @@ -533,9 +518,6 @@ fn rococo_staging_testnet_config_genesis() -> serde_json::Value { //5EX1JBghGbQqWohTPU6msR9qZ2nYPhK9r3RTQ2oD1K8TCxaG hex!["6c878e33b83c20324238d22240f735457b6fba544b383e70bb62a27b57380c81"] .unchecked_into(), - //5GqL8RbVAuNXpDhjQi1KrS1MyNuKhvus2AbmQwRGjpuGZmFu - hex!["d2f9d537ffa59919a4028afdb627c14c14c97a1547e13e8e82203d2049b15b1a"] - .unchecked_into(), //5EUNaBpX9mJgcmLQHyG5Pkms6tbDiKuLbeTEJS924Js9cA1N hex!["6a8570b9c6408e54bacf123cc2bb1b0f087f9c149147d0005badba63a5a4ac01"] .unchecked_into(), @@ -560,9 +542,6 @@ fn rococo_staging_testnet_config_genesis() -> serde_json::Value { //5GzDPGbUM9uH52ZEwydasTj8edokGUJ7vEpoFWp9FE1YNuFB hex!["d9c056c98ca0e6b4eb7f5c58c007c1db7be0fe1f3776108f797dd4990d1ccc33"] .unchecked_into(), - //5GWZbVkJEfWZ7fRca39YAQeqri2Z7pkeHyd7rUctUHyQifLp - hex!["c4a980da30939d5bb9e4a734d12bf81259ae286aa21fa4b65405347fa40eff35"] - .unchecked_into(), //5CmLCFeSurRXXtwMmLcVo7sdJ9EqDguvJbuCYDcHkr3cpqyE hex!["1efc23c0b51ad609ab670ecf45807e31acbd8e7e5cb7c07cf49ee42992d2867c"] .unchecked_into(), @@ -587,9 +566,6 @@ fn rococo_staging_testnet_config_genesis() -> serde_json::Value { //5DnEySxbnppWEyN8cCLqvGjAorGdLRg2VmkY96dbJ1LHFK8N hex!["4bea0b37e0cce9bddd80835fa2bfd5606f5dcfb8388bbb10b10c483f0856cf14"] .unchecked_into(), - //5E1Y1FJ7dVP7qtE3wm241pTm72rTMcDT5Jd8Czv7Pwp7N3AH - hex!["560d90ca51e9c9481b8a9810060e04d0708d246714960439f804e5c6f40ca651"] - .unchecked_into(), //5CAC278tFCHAeHYqE51FTWYxHmeLcENSS1RG77EFRTvPZMJT hex!["042f07fc5268f13c026bbe199d63e6ac77a0c2a780f71cda05cee5a6f1b3f11f"] .unchecked_into(), @@ -614,9 +590,6 @@ fn rococo_staging_testnet_config_genesis() -> serde_json::Value { //5DrA2fZdzmNqT5j6DXNwVxPBjDV9jhkAqvjt6Us3bQHKy3cF hex!["4ee66173993dd0db5d628c4c9cb61a27b76611ad3c3925947f0d0011ee2c5dcc"] .unchecked_into(), - //5FNFDUGNLUtqg5LgrwYLNmBiGoP8KRxsvQpBkc7GQP6qaBUG - hex!["92156f54a114ee191415898f2da013d9db6a5362d6b36330d5fc23e27360ab66"] - .unchecked_into(), //5Gx6YeNhynqn8qkda9QKpc9S7oDr4sBrfAu516d3sPpEt26F hex!["d822d4088b20dca29a580a577a97d6f024bb24c9550bebdfd7d2d18e946a1c7d"] .unchecked_into(), @@ -657,7 +630,6 @@ fn rococo_staging_testnet_config_genesis() -> serde_json::Value { x.5.clone(), x.6.clone(), x.7.clone(), - x.8.clone(), ), ) }) @@ -899,7 +871,6 @@ pub fn rococo_testnet_genesis( AccountId, BabeId, GrandpaId, - ImOnlineId, ValidatorId, AssignmentId, AuthorityDiscoveryId, @@ -930,7 +901,6 @@ pub fn rococo_testnet_genesis( x.5.clone(), x.6.clone(), x.7.clone(), - x.8.clone(), ), ) }) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 94d0421c246c..d1863c633be9 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -356,34 +356,26 @@ impl OpaqueKeys for OldSessionKeys { type KeyTypeIdProviders = (Grandpa, Babe, (), Initializer, ParaSessionInfo, AuthorityDiscovery, Beefy); fn key_ids() -> &'static [KeyTypeId] { - &[<::Public>::ID, - <::Public>::ID, - sp_core::crypto::key_types::IM_ONLINE, - <::Public as - ::sp_runtime::RuntimeAppPublic>::ID, - <::Public as - ::sp_runtime::RuntimeAppPublic>::ID, - <::Public as - ::sp_runtime::RuntimeAppPublic>::ID, - <::Public as - ::sp_runtime::RuntimeAppPublic>::ID] + &[ + <::Public>::ID, + <::Public>::ID, + sp_core::crypto::key_types::IM_ONLINE, + <::Public>::ID, + <::Public>::ID, + <::Public>::ID, + <::Public>::ID, + ] } fn get_raw(&self, i: KeyTypeId) -> &[u8] { match i { - <::Public as RuntimeAppPublic>::ID => - self.grandpa.as_ref(), - <::Public as RuntimeAppPublic>::ID => - self.babe.as_ref(), - <::Public as RuntimeAppPublic>::ID => - self.para_validator.as_ref(), - <::Public as RuntimeAppPublic>::ID => + <::Public>::ID => self.grandpa.as_ref(), + <::Public>::ID => self.babe.as_ref(), + <::Public>::ID => self.para_validator.as_ref(), + <::Public>::ID => self.para_assignment.as_ref(), - <::Public as RuntimeAppPublic>::ID => + <::Public>::ID => self.authority_discovery.as_ref(), - <::Public as RuntimeAppPublic>::ID => - self.beefy.as_ref(), + <::Public>::ID => self.beefy.as_ref(), _ => &[], } } From 370e5fce280696778eca1433bc91c5c541aa16a0 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Fri, 10 Nov 2023 12:35:23 +0100 Subject: [PATCH 03/34] Fix session key type --- polkadot/runtime/rococo/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index d1863c633be9..ef3dc88cd59d 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -345,7 +345,7 @@ impl pallet_authorship::Config for Runtime { pub struct OldSessionKeys { pub grandpa: ::Public, pub babe: ::Public, - pub im_online: (), + pub im_online: pallet_im_online::sr25519::AuthorityId, pub para_validator: ::Public, pub para_assignment: ::Public, pub authority_discovery: ::Public, From 6f78e95219fe8b9546dc97ad25da5bf1c9eb63b0 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Fri, 10 Nov 2023 12:43:35 +0100 Subject: [PATCH 04/34] Fix chainspec --- polkadot/node/service/src/chain_spec.rs | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/polkadot/node/service/src/chain_spec.rs b/polkadot/node/service/src/chain_spec.rs index f482c51270b8..b4aad561fead 100644 --- a/polkadot/node/service/src/chain_spec.rs +++ b/polkadot/node/service/src/chain_spec.rs @@ -18,7 +18,6 @@ use beefy_primitives::ecdsa_crypto::AuthorityId as BeefyId; use grandpa::AuthorityId as GrandpaId; -use pallet_im_online::sr25519::AuthorityId as ImOnlineId; #[cfg(feature = "westend-native")] use pallet_staking::Forcing; use polkadot_primitives::{AccountId, AccountPublic, AssignmentId, ValidatorId}; @@ -162,7 +161,6 @@ fn default_parachains_host_configuration_is_consistent() { fn westend_session_keys( babe: BabeId, grandpa: GrandpaId, - im_online: ImOnlineId, para_validator: ValidatorId, para_assignment: AssignmentId, authority_discovery: AuthorityDiscoveryId, @@ -171,7 +169,6 @@ fn westend_session_keys( westend::SessionKeys { babe, grandpa, - im_online, para_validator, para_assignment, authority_discovery, @@ -218,7 +215,6 @@ fn westend_staging_testnet_config_genesis() -> serde_json::Value { AccountId, BabeId, GrandpaId, - ImOnlineId, ValidatorId, AssignmentId, AuthorityDiscoveryId, @@ -235,9 +231,6 @@ fn westend_staging_testnet_config_genesis() -> serde_json::Value { //5Eb7wM65PNgtY6e33FEAzYtU5cRTXt6WQvZTnzaKQwkVcABk hex!["6faae44b21c6f2681a7f60df708e9f79d340f7d441d28bd987fab8d05c6487e8"] .unchecked_into(), - //5CdS2wGo4qdTQceVfEnbZH8vULeBrnGYCxSCxDna4tQSMV6y - hex!["18f5d55f138bfa8e0ea26ed6fa56817b247de3c2e2030a908c63fb37c146473f"] - .unchecked_into(), //5FqMLAgygdX9UqzukDp15Uid9PAKdFAR621U7xtp5ut2NfrW hex!["a6c1a5b501985a83cb1c37630c5b41e6b0a15b3675b2fd94694758e6cfa6794d"] .unchecked_into(), @@ -262,9 +255,6 @@ fn westend_staging_testnet_config_genesis() -> serde_json::Value { //5FXFsPReTUEYPRNKhbTdUathcWBsxTNsLbk2mTpYdKCJewjA hex!["98f4d81cb383898c2c3d54dab28698c0f717c81b509cb32dc6905af3cc697b18"] .unchecked_into(), - //5CDYSCJK91r8y2r1V4Ddrit4PFMEkwZXJe8mNBqGXJ4xWCWq - hex!["06bd7dd4ab4c808c7d09d9cb6bd27fbcd99ad8400e99212b335056c475c24031"] - .unchecked_into(), //5CZjurB78XbSHf6SLkLhCdkqw52Zm7aBYUDdfkLqEDWJ9Zhj hex!["162508accd470e379b04cb0c7c60b35a7d5357e84407a89ed2dd48db4b726960"] .unchecked_into(), @@ -289,9 +279,6 @@ fn westend_staging_testnet_config_genesis() -> serde_json::Value { //5G4kCbgqUhEyrRHCyFwFEkgBZXoYA8sbgsRxT9rY8Tp5Jj5F hex!["b0f8d2b9e4e1eafd4dab6358e0b9d5380d78af27c094e69ae9d6d30ca300fd86"] .unchecked_into(), - //5HVhFBLFTKSZK9fX6RktckWDTgYNoSd33fgonsEC8zfr4ddm - hex!["f03c3e184b2883eec9beaeb97f54321587e7476b228831ea0b5fc6da847ea975"] - .unchecked_into(), //5CS7thd2n54WfqeKU3cjvZzK4z5p7zku1Zw97mSzXgPioAAs hex!["1055100a283968271a0781450b389b9093231be809be1e48a305ebad2a90497e"] .unchecked_into(), @@ -316,9 +303,6 @@ fn westend_staging_testnet_config_genesis() -> serde_json::Value { //5ChfdrAqmLjCeDJvynbMjcxYLHYzPe8UWXd3HnX9JDThUMbn hex!["1c309a70b4e274314b84c9a0a1f973c9c4fc084df5479ef686c54b1ae4950424"] .unchecked_into(), - //5DnsMm24575xK2b2aGfmafiDxwCet6Mr4iiZQeDdWvi8CzuF - hex!["4c64868ba6d8ace235d3efb4c10d745a67cf3bdfeae23b264d7ea2f3439dec42"] - .unchecked_into(), //5D8C3HHEp5E8fJsXRD56494F413CdRSR9QKGXe7v5ZEfymdj hex!["2ee4d78f328db178c54f205ac809da12e291a33bcbd4f29f081ce7e74bdc5044"] .unchecked_into(), @@ -359,7 +343,6 @@ fn westend_staging_testnet_config_genesis() -> serde_json::Value { x.5.clone(), x.6.clone(), x.7.clone(), - x.8.clone(), ), ) }) @@ -740,14 +723,13 @@ pub fn get_authority_keys_from_seed( AccountId, BabeId, GrandpaId, - ImOnlineId, ValidatorId, AssignmentId, AuthorityDiscoveryId, BeefyId, ) { let keys = get_authority_keys_from_seed_no_beefy(seed); - (keys.0, keys.1, keys.2, keys.3, keys.4, keys.5, keys.6, keys.7, get_from_seed::(seed)) + (keys.0, keys.1, keys.2, keys.3, keys.4, keys.5, keys.6, get_from_seed::(seed)) } /// Helper function to generate stash, controller and session key from seed @@ -758,7 +740,6 @@ pub fn get_authority_keys_from_seed_no_beefy( AccountId, BabeId, GrandpaId, - ImOnlineId, ValidatorId, AssignmentId, AuthorityDiscoveryId, @@ -768,7 +749,6 @@ pub fn get_authority_keys_from_seed_no_beefy( get_account_id_from_seed::(seed), get_from_seed::(seed), get_from_seed::(seed), - get_from_seed::(seed), get_from_seed::(seed), get_from_seed::(seed), get_from_seed::(seed), @@ -801,7 +781,6 @@ pub fn westend_testnet_genesis( AccountId, BabeId, GrandpaId, - ImOnlineId, ValidatorId, AssignmentId, AuthorityDiscoveryId, @@ -833,7 +812,6 @@ pub fn westend_testnet_genesis( x.5.clone(), x.6.clone(), x.7.clone(), - x.8.clone(), ), ) }) From 89bf5857793e443d2ab6317f27ec58692d58b6eb Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Fri, 10 Nov 2023 13:00:24 +0100 Subject: [PATCH 05/34] Duplicate changes in Westend --- polkadot/node/service/src/chain_spec.rs | 10 +--- polkadot/runtime/westend/src/lib.rs | 74 +++++++++++++++---------- 2 files changed, 45 insertions(+), 39 deletions(-) diff --git a/polkadot/node/service/src/chain_spec.rs b/polkadot/node/service/src/chain_spec.rs index b4aad561fead..fd35a4aaf6ab 100644 --- a/polkadot/node/service/src/chain_spec.rs +++ b/polkadot/node/service/src/chain_spec.rs @@ -735,15 +735,7 @@ pub fn get_authority_keys_from_seed( /// Helper function to generate stash, controller and session key from seed pub fn get_authority_keys_from_seed_no_beefy( seed: &str, -) -> ( - AccountId, - AccountId, - BabeId, - GrandpaId, - ValidatorId, - AssignmentId, - AuthorityDiscoveryId, -) { +) -> (AccountId, AccountId, BabeId, GrandpaId, ValidatorId, AssignmentId, AuthorityDiscoveryId) { ( get_account_id_from_seed::(&format!("{}//stash", seed)), get_account_id_from_seed::(seed), diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index ec94973af4f3..016d648c688f 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -41,7 +41,6 @@ use frame_support::{ use frame_system::EnsureRoot; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; use pallet_identity::legacy::IdentityInfo; -use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use pallet_session::historical as session_historical; use pallet_transaction_payment::{CurrencyAdapter, FeeDetails, RuntimeDispatchInfo}; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; @@ -88,7 +87,8 @@ use sp_runtime::{ IdentityLookup, Keccak256, OpaqueKeys, SaturatedConversion, Verify, }, transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity}, - ApplyExtrinsicResult, FixedU128, KeyTypeId, Perbill, Percent, Permill, + ApplyExtrinsicResult, BoundToRuntimeAppPublic, FixedU128, KeyTypeId, Perbill, Percent, Permill, + RuntimeAppPublic, }; use sp_staking::SessionIndex; use sp_std::{collections::btree_map::BTreeMap, prelude::*}; @@ -402,7 +402,7 @@ impl pallet_timestamp::Config for Runtime { impl pallet_authorship::Config for Runtime { type FindAuthor = pallet_session::FindAccountFromAuthorIndex; - type EventHandler = (Staking, ImOnline); + type EventHandler = (Staking); } parameter_types! { @@ -410,14 +410,39 @@ parameter_types! { pub const Offset: BlockNumber = 0; } -impl_opaque_keys! { - pub struct OldSessionKeys { - pub grandpa: Grandpa, - pub babe: Babe, - pub im_online: ImOnline, - pub para_validator: Initializer, - pub para_assignment: ParaSessionInfo, - pub authority_discovery: AuthorityDiscovery, +#[derive(Clone, Debug, PartialEq, Eq, Encode, Decode)] +pub struct OldSessionKeys { + pub grandpa: ::Public, + pub babe: ::Public, + pub im_online: pallet_im_online::sr25519::AuthorityId, + pub para_validator: ::Public, + pub para_assignment: ::Public, + pub authority_discovery: ::Public, +} + +impl OpaqueKeys for OldSessionKeys { + type KeyTypeIdProviders = (Grandpa, Babe, (), Initializer, ParaSessionInfo, AuthorityDiscovery); + fn key_ids() -> &'static [KeyTypeId] { + &[ + <::Public>::ID, + <::Public>::ID, + sp_core::crypto::key_types::IM_ONLINE, + <::Public>::ID, + <::Public>::ID, + <::Public>::ID, + ] + } + fn get_raw(&self, i: KeyTypeId) -> &[u8] { + match i { + <::Public>::ID => self.grandpa.as_ref(), + <::Public>::ID => self.babe.as_ref(), + <::Public>::ID => self.para_validator.as_ref(), + <::Public>::ID => + self.para_assignment.as_ref(), + <::Public>::ID => + self.authority_discovery.as_ref(), + _ => &[], + } } } @@ -425,7 +450,6 @@ impl_opaque_keys! { pub struct SessionKeys { pub grandpa: Grandpa, pub babe: Babe, - pub im_online: ImOnline, pub para_validator: Initializer, pub para_assignment: ParaSessionInfo, pub authority_discovery: AuthorityDiscovery, @@ -438,7 +462,6 @@ fn transform_session_keys(v: AccountId, old: OldSessionKeys) -> SessionKeys { SessionKeys { grandpa: old.grandpa, babe: old.babe, - im_online: old.im_online, para_validator: old.para_validator, para_assignment: old.para_assignment, authority_discovery: old.authority_discovery, @@ -766,19 +789,6 @@ impl pallet_authority_discovery::Config for Runtime { parameter_types! { pub const NposSolutionPriority: TransactionPriority = TransactionPriority::max_value() / 2; - pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value(); -} - -impl pallet_im_online::Config for Runtime { - type AuthorityId = ImOnlineId; - type RuntimeEvent = RuntimeEvent; - type ValidatorSet = Historical; - type NextSessionRotation = Babe; - type ReportUnresponsiveness = Offences; - type UnsignedPriority = ImOnlineUnsignedPriority; - type WeightInfo = weights::pallet_im_online::WeightInfo; - type MaxKeys = MaxKeys; - type MaxPeerInHeartbeats = MaxPeerInHeartbeats; } parameter_types! { @@ -1008,7 +1018,6 @@ impl InstanceFilter for ProxyType { RuntimeCall::Staking(..) | RuntimeCall::Session(..) | RuntimeCall::Grandpa(..) | - RuntimeCall::ImOnline(..) | RuntimeCall::Utility(..) | RuntimeCall::Identity(..) | RuntimeCall::ConvictionVoting(..) | @@ -1404,7 +1413,6 @@ construct_runtime! { Session: pallet_session::{Pallet, Call, Storage, Event, Config} = 8, Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event, ValidateUnsigned} = 10, - ImOnline: pallet_im_online::{Pallet, Call, Storage, Event, ValidateUnsigned, Config} = 11, AuthorityDiscovery: pallet_authority_discovery::{Pallet, Config} = 12, // Utility module. @@ -1534,6 +1542,10 @@ pub type Migrations = migrations::Unreleased; pub mod migrations { use super::*; + parameter_types! { + pub const ImOnlinePalletName: &'static str = "ImOnline"; + } + /// Upgrade Session keys to include BEEFY key. /// When this is removed, should also remove `OldSessionKeys`. pub struct UpgradeSessionKeys; @@ -1546,7 +1558,6 @@ pub mod migrations { /// Unreleased migrations. Add new ones here: pub type Unreleased = ( - pallet_im_online::migration::v1::Migration, parachains_configuration::migration::v7::MigrateToV7, pallet_staking::migrations::v14::MigrateToV14, assigned_slots::migration::v1::VersionCheckedMigrateToV1, @@ -1558,6 +1569,10 @@ pub mod migrations { pallet_nomination_pools::migration::versioned_migrations::V5toV6, pallet_referenda::migration::v1::MigrateV0ToV1, pallet_nomination_pools::migration::versioned_migrations::V6ToV7, + frame_support::migrations::RemovePallet< + ImOnlinePalletName, + ::DbWeight, + >, ); } @@ -1603,7 +1618,6 @@ mod benches { [frame_election_provider_support, ElectionProviderBench::] [pallet_fast_unstake, FastUnstake] [pallet_identity, Identity] - [pallet_im_online, ImOnline] [pallet_indices, Indices] [pallet_message_queue, MessageQueue] [pallet_multisig, Multisig] From b390a4e4cd30e9006f2f1dc3ec07dd10e2f3fe17 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Fri, 10 Nov 2023 13:19:18 +0100 Subject: [PATCH 06/34] Fix test --- cumulus/parachains/integration-tests/emulated/common/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs index 952b053f2aa2..58222f622c2a 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs @@ -21,7 +21,6 @@ pub use xcm_emulator; // Substrate use grandpa::AuthorityId as GrandpaId; -use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; use sp_consensus_babe::AuthorityId as BabeId; use sp_core::{sr25519, storage::Storage, Pair, Public}; @@ -163,7 +162,6 @@ pub mod validators { AccountId, BabeId, GrandpaId, - ImOnlineId, ValidatorId, AssignmentId, AuthorityDiscoveryId, From 70cdc293dbe34d4dc99ce5ba2fda27ac0e04fd85 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Fri, 10 Nov 2023 13:30:50 +0100 Subject: [PATCH 07/34] Fix tests --- .../emulated/chains/relays/rococo/src/genesis.rs | 3 --- .../emulated/chains/relays/westend/src/genesis.rs | 3 --- 2 files changed, 6 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/chains/relays/rococo/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/relays/rococo/src/genesis.rs index 6f5f3923ead9..2f8385f9315c 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/relays/rococo/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/relays/rococo/src/genesis.rs @@ -38,7 +38,6 @@ const ENDOWMENT: u128 = 1_000_000 * ROC; fn session_keys( babe: BabeId, grandpa: GrandpaId, - im_online: ImOnlineId, para_validator: ValidatorId, para_assignment: AssignmentId, authority_discovery: AuthorityDiscoveryId, @@ -47,7 +46,6 @@ fn session_keys( rococo_runtime::SessionKeys { babe, grandpa, - im_online, para_validator, para_assignment, authority_discovery, @@ -74,7 +72,6 @@ pub fn genesis() -> Storage { x.4.clone(), x.5.clone(), x.6.clone(), - x.7.clone(), get_from_seed::("Alice"), ), ) diff --git a/cumulus/parachains/integration-tests/emulated/chains/relays/westend/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/relays/westend/src/genesis.rs index e87b85881d3c..89d746c07afa 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/relays/westend/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/relays/westend/src/genesis.rs @@ -39,7 +39,6 @@ const STASH: u128 = 100 * WND; fn session_keys( babe: BabeId, grandpa: GrandpaId, - im_online: ImOnlineId, para_validator: ValidatorId, para_assignment: AssignmentId, authority_discovery: AuthorityDiscoveryId, @@ -48,7 +47,6 @@ fn session_keys( westend_runtime::SessionKeys { babe, grandpa, - im_online, para_validator, para_assignment, authority_discovery, @@ -75,7 +73,6 @@ pub fn genesis() -> Storage { x.4.clone(), x.5.clone(), x.6.clone(), - x.7.clone(), get_from_seed::("Alice"), ), ) From de66ba8d96fa35e5db3a37fce3aeac7436ffedfb Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Fri, 10 Nov 2023 17:38:08 +0100 Subject: [PATCH 08/34] Fix syntax --- polkadot/runtime/westend/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 016d648c688f..0367bea9e3c2 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -402,7 +402,7 @@ impl pallet_timestamp::Config for Runtime { impl pallet_authorship::Config for Runtime { type FindAuthor = pallet_session::FindAccountFromAuthorIndex; - type EventHandler = (Staking); + type EventHandler = Staking; } parameter_types! { From c947a44a03dd9f9f04026d529960088a3f40e521 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Fri, 10 Nov 2023 19:48:33 +0100 Subject: [PATCH 09/34] Fix tests --- .../emulated/chains/relays/rococo/src/genesis.rs | 1 - .../emulated/chains/relays/westend/src/genesis.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/chains/relays/rococo/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/relays/rococo/src/genesis.rs index 2f8385f9315c..45e1e94de010 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/relays/rococo/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/relays/rococo/src/genesis.rs @@ -16,7 +16,6 @@ // Substrate use beefy_primitives::ecdsa_crypto::AuthorityId as BeefyId; use grandpa::AuthorityId as GrandpaId; -use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; use sp_consensus_babe::AuthorityId as BabeId; use sp_core::{sr25519, storage::Storage}; diff --git a/cumulus/parachains/integration-tests/emulated/chains/relays/westend/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/relays/westend/src/genesis.rs index 89d746c07afa..e2297100a452 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/relays/westend/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/relays/westend/src/genesis.rs @@ -16,7 +16,6 @@ // Substrate use beefy_primitives::ecdsa_crypto::AuthorityId as BeefyId; use grandpa::AuthorityId as GrandpaId; -use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; use sp_consensus_babe::AuthorityId as BabeId; use sp_core::storage::Storage; From 481364aebb59c2385beb0b9fd9c3baeb5c49c4c2 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Fri, 10 Nov 2023 21:06:56 +0100 Subject: [PATCH 10/34] Implement off-chain storage removal for Rococo --- polkadot/runtime/rococo/src/lib.rs | 51 +++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index be36c74325f5..1ea369a8cff4 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1514,6 +1514,52 @@ pub mod migrations { } } + // This is never called; remove together with `RemoveImOnlineOffchainStorageValues` + impl From> for RuntimeEvent { + fn from(_v: pallet_im_online::Event) -> Self { + unreachable!() + } + } + + // This is never called; remove together with `RemoveImOnlineOffchainStorageValues` + impl From> for RuntimeCall { + fn from(_v: pallet_im_online::Call) -> Self { + unreachable!() + } + } + + // Mock config just to access the storage values; + // remove together with `RemoveImOnlineOffchainStorageValues` + impl pallet_im_online::Config for Runtime { + type AuthorityId = pallet_im_online::sr25519::AuthorityId; + type RuntimeEvent = RuntimeEvent; + type ValidatorSet = Historical; + type NextSessionRotation = Babe; + type ReportUnresponsiveness = Offences; + type UnsignedPriority = (); + type WeightInfo = weights::pallet_im_online::WeightInfo; + type MaxKeys = MaxKeys; + type MaxPeerInHeartbeats = MaxPeerInHeartbeats; + } + + // Remove offchain storage values of `im-online` pallet + pub struct RemoveImOnlineOffchainStorageValues; + impl frame_support::traits::OnRuntimeUpgrade for RemoveImOnlineOffchainStorageValues { + fn on_runtime_upgrade() -> Weight { + const DB_PREFIX: &[u8] = b"parity/im-online-heartbeat/"; + let keys_len = pallet_im_online::Pallet::::keys().len() as u32; + (0..keys_len).for_each(|idx| { + let key = { + let mut key = DB_PREFIX.to_vec(); + key.extend(idx.encode()); + key + }; + sp_runtime::offchain::storage::StorageValueRef::persistent(&key).clear(); + }); + Weight::zero() + } + } + /// Unreleased migrations. Add new ones here: pub type Unreleased = ( pallet_society::migrations::MigrateToV2, @@ -1544,7 +1590,10 @@ pub mod migrations { // Upgrade `SessionKeys` to exclude `ImOnline` UpgradeSessionKeys, - // Remove im-online pallet storage + // Remove im-online pallet off-chain storage + RemoveImOnlineOffchainStorageValues, + + // Remove im-online pallet on-chain storage frame_support::migrations::RemovePallet::DbWeight>, ); } From e334415585e845fbbf0d265e79fab8c5d7d8541a Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Fri, 10 Nov 2023 21:25:34 +0100 Subject: [PATCH 11/34] `cargo fmt` --- polkadot/runtime/rococo/src/lib.rs | 36 +++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 1ea369a8cff4..089dcd5298d0 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1516,9 +1516,9 @@ pub mod migrations { // This is never called; remove together with `RemoveImOnlineOffchainStorageValues` impl From> for RuntimeEvent { - fn from(_v: pallet_im_online::Event) -> Self { - unreachable!() - } + fn from(_v: pallet_im_online::Event) -> Self { + unreachable!() + } } // This is never called; remove together with `RemoveImOnlineOffchainStorageValues` @@ -1531,15 +1531,15 @@ pub mod migrations { // Mock config just to access the storage values; // remove together with `RemoveImOnlineOffchainStorageValues` impl pallet_im_online::Config for Runtime { - type AuthorityId = pallet_im_online::sr25519::AuthorityId; - type RuntimeEvent = RuntimeEvent; - type ValidatorSet = Historical; - type NextSessionRotation = Babe; - type ReportUnresponsiveness = Offences; - type UnsignedPriority = (); - type WeightInfo = weights::pallet_im_online::WeightInfo; - type MaxKeys = MaxKeys; - type MaxPeerInHeartbeats = MaxPeerInHeartbeats; + type AuthorityId = pallet_im_online::sr25519::AuthorityId; + type RuntimeEvent = RuntimeEvent; + type ValidatorSet = Historical; + type NextSessionRotation = Babe; + type ReportUnresponsiveness = Offences; + type UnsignedPriority = (); + type WeightInfo = weights::pallet_im_online::WeightInfo; + type MaxKeys = MaxKeys; + type MaxPeerInHeartbeats = MaxPeerInHeartbeats; } // Remove offchain storage values of `im-online` pallet @@ -1549,12 +1549,12 @@ pub mod migrations { const DB_PREFIX: &[u8] = b"parity/im-online-heartbeat/"; let keys_len = pallet_im_online::Pallet::::keys().len() as u32; (0..keys_len).for_each(|idx| { - let key = { - let mut key = DB_PREFIX.to_vec(); - key.extend(idx.encode()); - key - }; - sp_runtime::offchain::storage::StorageValueRef::persistent(&key).clear(); + let key = { + let mut key = DB_PREFIX.to_vec(); + key.extend(idx.encode()); + key + }; + sp_runtime::offchain::storage::StorageValueRef::persistent(&key).clear(); }); Weight::zero() } From c3fc48385338a5b96583872c89dcfd5570d8bb82 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Sat, 11 Nov 2023 12:48:44 +0100 Subject: [PATCH 12/34] Remove `im-online` dependency from `offences-benchmarking` --- .../frame/offences/benchmarking/src/lib.rs | 76 +------------------ 1 file changed, 4 insertions(+), 72 deletions(-) diff --git a/substrate/frame/offences/benchmarking/src/lib.rs b/substrate/frame/offences/benchmarking/src/lib.rs index c190927b84bf..7599bd295184 100644 --- a/substrate/frame/offences/benchmarking/src/lib.rs +++ b/substrate/frame/offences/benchmarking/src/lib.rs @@ -41,7 +41,6 @@ use pallet_balances::Config as BalancesConfig; use pallet_grandpa::{ EquivocationOffence as GrandpaEquivocationOffence, TimeSlot as GrandpaTimeSlot, }; -use pallet_im_online::{Config as ImOnlineConfig, Pallet as ImOnline, UnresponsivenessOffence}; use pallet_offences::{Config as OffencesConfig, Pallet as Offences}; use pallet_session::{ historical::{Config as HistoricalConfig, IdentificationTuple}, @@ -66,7 +65,6 @@ pub trait Config: SessionConfig + StakingConfig + OffencesConfig - + ImOnlineConfig + HistoricalConfig + BalancesConfig + IdTupleConvert @@ -184,39 +182,6 @@ fn make_offenders( Ok((id_tuples, offenders)) } -fn make_offenders_im_online( - num_offenders: u32, - num_nominators: u32, -) -> Result<(Vec>, Vec>), &'static str> { - Staking::::new_session(0); - - let mut offenders = vec![]; - for i in 0..num_offenders { - let offender = create_offender::(i + 1, num_nominators)?; - offenders.push(offender); - } - - Staking::::start_session(0); - - let id_tuples = offenders - .iter() - .map(|offender| { - < - ::ValidatorSet as ValidatorSet - >::ValidatorIdOf::convert(offender.controller.clone()) - .expect("failed to get validator id from account id") - }) - .map(|validator_id| { - < - ::ValidatorSet as ValidatorSetWithIdentification - >::IdentificationOf::convert(validator_id.clone()) - .map(|full_id| (validator_id, full_id)) - .expect("failed to convert validator id to full identification") - }) - .collect::>>(); - Ok((id_tuples, offenders)) -} - #[cfg(test)] fn check_events< T: Config, @@ -279,39 +244,6 @@ fn check_events< } benchmarks! { - report_offence_im_online { - let r in 1 .. MAX_REPORTERS; - // we skip 1 offender, because in such case there is no slashing - let o in 2 .. MAX_OFFENDERS; - let n in 0 .. MAX_NOMINATORS.min(MaxNominationsOf::::get()); - - // Make r reporters - let mut reporters = vec![]; - for i in 0 .. r { - let reporter = account("reporter", i, SEED); - reporters.push(reporter); - } - - // make sure reporters actually get rewarded - Staking::::set_slash_reward_fraction(Perbill::one()); - - let (offenders, raw_offenders) = make_offenders_im_online::(o, n)?; - let keys = ImOnline::::keys(); - let validator_set_count = keys.len() as u32; - let offenders_count = offenders.len() as u32; - let offence = UnresponsivenessOffence { - session_index: 0, - validator_set_count, - offenders, - }; - let slash_fraction = offence.slash_fraction(offenders_count); - assert_eq!(System::::event_count(), 0); - }: { - let _ = ::ReportUnresponsiveness::report_offence( - reporters.clone(), - offence - ); - } verify { #[cfg(test)] { @@ -409,12 +341,12 @@ benchmarks! { Staking::::set_slash_reward_fraction(Perbill::one()); let (mut offenders, raw_offenders) = make_offenders::(1, n)?; - let keys = ImOnline::::keys(); + let validator_set_count = Session::::validators().len() as u32; let offence = GrandpaEquivocationOffence { time_slot: GrandpaTimeSlot { set_id: 0, round: 0 }, session_index: 0, - validator_set_count: keys.len() as u32, + validator_set_count, offender: T::convert(offenders.pop().unwrap()), }; assert_eq!(System::::event_count(), 0); @@ -446,12 +378,12 @@ benchmarks! { Staking::::set_slash_reward_fraction(Perbill::one()); let (mut offenders, raw_offenders) = make_offenders::(1, n)?; - let keys = ImOnline::::keys(); + let validator_set_count = Session::::validators().len() as u32; let offence = BabeEquivocationOffence { slot: 0u64.into(), session_index: 0, - validator_set_count: keys.len() as u32, + validator_set_count, offender: T::convert(offenders.pop().unwrap()), }; assert_eq!(System::::event_count(), 0); From 6ee3a63e367aec44b9225b0412ebde4e03e0d07a Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Sat, 11 Nov 2023 13:05:20 +0100 Subject: [PATCH 13/34] Simplify migration --- polkadot/runtime/rococo/src/lib.rs | 32 ++---------------------------- 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 089dcd5298d0..25ac687a8bc4 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1514,41 +1514,13 @@ pub mod migrations { } } - // This is never called; remove together with `RemoveImOnlineOffchainStorageValues` - impl From> for RuntimeEvent { - fn from(_v: pallet_im_online::Event) -> Self { - unreachable!() - } - } - - // This is never called; remove together with `RemoveImOnlineOffchainStorageValues` - impl From> for RuntimeCall { - fn from(_v: pallet_im_online::Call) -> Self { - unreachable!() - } - } - - // Mock config just to access the storage values; - // remove together with `RemoveImOnlineOffchainStorageValues` - impl pallet_im_online::Config for Runtime { - type AuthorityId = pallet_im_online::sr25519::AuthorityId; - type RuntimeEvent = RuntimeEvent; - type ValidatorSet = Historical; - type NextSessionRotation = Babe; - type ReportUnresponsiveness = Offences; - type UnsignedPriority = (); - type WeightInfo = weights::pallet_im_online::WeightInfo; - type MaxKeys = MaxKeys; - type MaxPeerInHeartbeats = MaxPeerInHeartbeats; - } - // Remove offchain storage values of `im-online` pallet pub struct RemoveImOnlineOffchainStorageValues; impl frame_support::traits::OnRuntimeUpgrade for RemoveImOnlineOffchainStorageValues { fn on_runtime_upgrade() -> Weight { const DB_PREFIX: &[u8] = b"parity/im-online-heartbeat/"; - let keys_len = pallet_im_online::Pallet::::keys().len() as u32; - (0..keys_len).for_each(|idx| { + let validator_set_size = pallet_session::Pallet::::validators().len() as u32; + (0..validator_set_size).for_each(|idx| { let key = { let mut key = DB_PREFIX.to_vec(); key.extend(idx.encode()); From 926aad6d739e785acb0a9ff0b45bee7816bf5db7 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Sat, 11 Nov 2023 15:53:55 +0100 Subject: [PATCH 14/34] Fix benchmark --- .../frame/offences/benchmarking/src/lib.rs | 94 +------------------ 1 file changed, 3 insertions(+), 91 deletions(-) diff --git a/substrate/frame/offences/benchmarking/src/lib.rs b/substrate/frame/offences/benchmarking/src/lib.rs index 7599bd295184..8ae0f189849e 100644 --- a/substrate/frame/offences/benchmarking/src/lib.rs +++ b/substrate/frame/offences/benchmarking/src/lib.rs @@ -25,7 +25,7 @@ mod mock; use sp_std::{prelude::*, vec}; use frame_benchmarking::v1::{account, benchmarks}; -use frame_support::traits::{Currency, Get, ValidatorSet, ValidatorSetWithIdentification}; +use frame_support::traits::{Currency, Get}; use frame_system::{Config as SystemConfig, Pallet as System, RawOrigin}; #[cfg(test)] @@ -34,7 +34,7 @@ use sp_runtime::{ traits::{Convert, Saturating, StaticLookup}, Perbill, }; -use sp_staking::offence::{Offence, ReportOffence}; +use sp_staking::offence::ReportOffence; use pallet_babe::EquivocationOffence as BabeEquivocationOffence; use pallet_balances::Config as BalancesConfig; @@ -44,7 +44,7 @@ use pallet_grandpa::{ use pallet_offences::{Config as OffencesConfig, Pallet as Offences}; use pallet_session::{ historical::{Config as HistoricalConfig, IdentificationTuple}, - Config as SessionConfig, SessionManager, + Config as SessionConfig, Pallet as Session, SessionManager, }; #[cfg(test)] use pallet_staking::Event as StakingEvent; @@ -55,8 +55,6 @@ use pallet_staking::{ const SEED: u32 = 0; -const MAX_REPORTERS: u32 = 100; -const MAX_OFFENDERS: u32 = 100; const MAX_NOMINATORS: u32 = 100; pub struct Pallet(Offences); @@ -244,92 +242,6 @@ fn check_events< } benchmarks! { - verify { - #[cfg(test)] - { - let bond_amount: u32 = UniqueSaturatedInto::::unique_saturated_into(bond_amount::()); - let slash_amount = slash_fraction * bond_amount; - let reward_amount = slash_amount.saturating_mul(1 + n) / 2; - let reward = reward_amount / r; - let slash_report = |id| core::iter::once( - ::RuntimeEvent::from(StakingEvent::::SlashReported{ validator: id, fraction: slash_fraction, slash_era: 0}) - ); - let slash = |id| core::iter::once( - ::RuntimeEvent::from(StakingEvent::::Slashed{ staker: id, amount: BalanceOf::::from(slash_amount) }) - ); - let balance_slash = |id| core::iter::once( - ::RuntimeEvent::from(pallet_balances::Event::::Slashed{ who: id, amount: slash_amount.into() }) - ); - let balance_locked = |id| core::iter::once( - ::RuntimeEvent::from(pallet_balances::Event::::Locked{ who: id, amount: slash_amount.into() }) - ); - let balance_unlocked = |id| core::iter::once( - ::RuntimeEvent::from(pallet_balances::Event::::Unlocked{ who: id, amount: slash_amount.into() }) - ); - let chill = |id| core::iter::once( - ::RuntimeEvent::from(StakingEvent::::Chilled{ stash: id }) - ); - let balance_deposit = |id, amount: u32| - ::RuntimeEvent::from(pallet_balances::Event::::Deposit{ who: id, amount: amount.into() }); - let mut first = true; - - // We need to box all events to prevent running into too big allocations in wasm. - // The event in FRAME is represented as an enum and the size of the enum depends on the biggest variant. - // So, instead of requiring `size_of() * expected_events` we only need to - // allocate `size_of>() * expected_events`. - let slash_events = raw_offenders.into_iter() - .flat_map(|offender| { - let nom_slashes = offender.nominator_stashes.into_iter().flat_map(|nom| { - balance_slash(nom.clone()).map(Into::into) - .chain(balance_unlocked(nom.clone()).map(Into::into)) - .chain(slash(nom).map(Into::into)).map(Box::new) - }); - - let events = chill(offender.stash.clone()).map(Into::into).map(Box::new) - .chain(slash_report(offender.stash.clone()).map(Into::into).map(Box::new)) - .chain(balance_slash(offender.stash.clone()).map(Into::into).map(Box::new)) - .chain(balance_unlocked(offender.stash.clone()).map(Into::into).map(Box::new)) - .chain(slash(offender.stash).map(Into::into).map(Box::new)) - .chain(nom_slashes) - .collect::>(); - - // the first deposit creates endowed events, see `endowed_reward_events` - if first { - first = false; - let reward_events = reporters.iter() - .flat_map(|reporter| vec![ - Box::new(balance_deposit(reporter.clone(), reward).into()), - Box::new(frame_system::Event::::NewAccount { account: reporter.clone() }.into()), - Box::new(::RuntimeEvent::from( - pallet_balances::Event::::Endowed{ account: reporter.clone(), free_balance: reward.into() } - ).into()), - ]) - .collect::>(); - events.into_iter().chain(reward_events) - } else { - let reward_events = reporters.iter() - .map(|reporter| Box::new(balance_deposit(reporter.clone(), reward).into())) - .collect::>(); - events.into_iter().chain(reward_events) - } - }); - - // In case of error it's useful to see the inputs - log::info!("Inputs: r: {}, o: {}, n: {}", r, o, n); - // make sure that all slashes have been applied - check_events::( - sp_std::iter::empty() - .chain(slash_events) - .chain(sp_std::iter::once(Box::new(::RuntimeEvent::from( - pallet_offences::Event::Offence{ - kind: UnresponsivenessOffence::::ID, - timeslot: 0_u32.to_le_bytes().to_vec(), - } - ).into()))) - ); - } - } - report_offence_grandpa { let n in 0 .. MAX_NOMINATORS.min(MaxNominationsOf::::get()); From 78d50256ac8287105900fcc12ac521c4b2052d63 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Sun, 12 Nov 2023 16:52:18 +0100 Subject: [PATCH 15/34] Try to remove offchain storage with a mock pallet --- polkadot/runtime/rococo/src/lib.rs | 74 ++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 23 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 25ac687a8bc4..3b54fde69261 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1287,6 +1287,52 @@ impl pallet_asset_rate::Config for Runtime { type BenchmarkHelper = runtime_common::impls::benchmarks::AssetRateArguments; } +#[frame_support::pallet] +pub mod im_online_remover { + use frame_support::pallet_prelude::*; + use frame_system::pallet_prelude::*; + + #[pallet::pallet] + pub struct Pallet(_); + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::hooks] + impl Hooks> for Pallet { + fn on_initialize(n: BlockNumberFor) -> Weight { + if RemoveAtBlock::::get() == None { + RemoveAtBlock::::set(Some(n)); + } + Weight::zero() + } + + fn offchain_worker(n: BlockNumberFor) { + const DB_PREFIX: &[u8] = b"parity/im-online-heartbeat/"; + if let Some(remove_at) = RemoveAtBlock::::get() { + if remove_at == n { + let validator_set_size = + pallet_session::Pallet::::validators().len() as u32; + (0..validator_set_size).for_each(|idx| { + let key = { + let mut key = DB_PREFIX.to_vec(); + key.extend(idx.encode()); + key + }; + // FIXME: `StorageLock` needed? + sp_runtime::offchain::storage::StorageValueRef::persistent(&key).clear(); + }); + } + } + } + } + + #[pallet::storage] + pub(super) type RemoveAtBlock = StorageValue<_, BlockNumberFor, OptionQuery>; +} + +impl im_online_remover::Config for Runtime {} + construct_runtime! { pub enum Runtime { @@ -1403,6 +1449,8 @@ construct_runtime! { // Pallet for sending XCM. XcmPallet: pallet_xcm::{Pallet, Call, Storage, Event, Origin, Config} = 99, + ImOnlineRemover: im_online_remover::{Pallet, Storage} = 100, + ParasSudoWrapper: paras_sudo_wrapper::{Pallet, Call} = 250, AssignedSlots: assigned_slots::{Pallet, Call, Storage, Event, Config} = 251, @@ -1504,7 +1552,7 @@ pub mod migrations { type PalletName = TipsPalletName; } - /// Upgrade Session keys to exclude ImOnline key. + /// Upgrade Session keys to exclude `ImOnline` key. /// When this is removed, should also remove `OldSessionKeys`. pub struct UpgradeSessionKeys; impl frame_support::traits::OnRuntimeUpgrade for UpgradeSessionKeys { @@ -1514,24 +1562,6 @@ pub mod migrations { } } - // Remove offchain storage values of `im-online` pallet - pub struct RemoveImOnlineOffchainStorageValues; - impl frame_support::traits::OnRuntimeUpgrade for RemoveImOnlineOffchainStorageValues { - fn on_runtime_upgrade() -> Weight { - const DB_PREFIX: &[u8] = b"parity/im-online-heartbeat/"; - let validator_set_size = pallet_session::Pallet::::validators().len() as u32; - (0..validator_set_size).for_each(|idx| { - let key = { - let mut key = DB_PREFIX.to_vec(); - key.extend(idx.encode()); - key - }; - sp_runtime::offchain::storage::StorageValueRef::persistent(&key).clear(); - }); - Weight::zero() - } - } - /// Unreleased migrations. Add new ones here: pub type Unreleased = ( pallet_society::migrations::MigrateToV2, @@ -1562,10 +1592,7 @@ pub mod migrations { // Upgrade `SessionKeys` to exclude `ImOnline` UpgradeSessionKeys, - // Remove im-online pallet off-chain storage - RemoveImOnlineOffchainStorageValues, - - // Remove im-online pallet on-chain storage + // Remove `im-online` pallet on-chain storage frame_support::migrations::RemovePallet::DbWeight>, ); } @@ -1627,6 +1654,7 @@ mod benches { [runtime_parachains::paras_inherent, ParaInherent] [runtime_parachains::paras, Paras] [runtime_parachains::assigner_on_demand, OnDemandAssignmentProvider] + [im_online_remover, ImOnlineRemover] // Substrate [pallet_balances, Balances] [pallet_balances, NisCounterpartBalances] From 34b8f61106180975b3a78379808cfd91476453b3 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Mon, 13 Nov 2023 11:26:14 +0100 Subject: [PATCH 16/34] Revert "Try to remove offchain storage with a mock pallet" This reverts commit 78d50256ac8287105900fcc12ac521c4b2052d63. --- polkadot/runtime/rococo/src/lib.rs | 74 ++++++++++-------------------- 1 file changed, 23 insertions(+), 51 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 3b54fde69261..25ac687a8bc4 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1287,52 +1287,6 @@ impl pallet_asset_rate::Config for Runtime { type BenchmarkHelper = runtime_common::impls::benchmarks::AssetRateArguments; } -#[frame_support::pallet] -pub mod im_online_remover { - use frame_support::pallet_prelude::*; - use frame_system::pallet_prelude::*; - - #[pallet::pallet] - pub struct Pallet(_); - - #[pallet::config] - pub trait Config: frame_system::Config {} - - #[pallet::hooks] - impl Hooks> for Pallet { - fn on_initialize(n: BlockNumberFor) -> Weight { - if RemoveAtBlock::::get() == None { - RemoveAtBlock::::set(Some(n)); - } - Weight::zero() - } - - fn offchain_worker(n: BlockNumberFor) { - const DB_PREFIX: &[u8] = b"parity/im-online-heartbeat/"; - if let Some(remove_at) = RemoveAtBlock::::get() { - if remove_at == n { - let validator_set_size = - pallet_session::Pallet::::validators().len() as u32; - (0..validator_set_size).for_each(|idx| { - let key = { - let mut key = DB_PREFIX.to_vec(); - key.extend(idx.encode()); - key - }; - // FIXME: `StorageLock` needed? - sp_runtime::offchain::storage::StorageValueRef::persistent(&key).clear(); - }); - } - } - } - } - - #[pallet::storage] - pub(super) type RemoveAtBlock = StorageValue<_, BlockNumberFor, OptionQuery>; -} - -impl im_online_remover::Config for Runtime {} - construct_runtime! { pub enum Runtime { @@ -1449,8 +1403,6 @@ construct_runtime! { // Pallet for sending XCM. XcmPallet: pallet_xcm::{Pallet, Call, Storage, Event, Origin, Config} = 99, - ImOnlineRemover: im_online_remover::{Pallet, Storage} = 100, - ParasSudoWrapper: paras_sudo_wrapper::{Pallet, Call} = 250, AssignedSlots: assigned_slots::{Pallet, Call, Storage, Event, Config} = 251, @@ -1552,7 +1504,7 @@ pub mod migrations { type PalletName = TipsPalletName; } - /// Upgrade Session keys to exclude `ImOnline` key. + /// Upgrade Session keys to exclude ImOnline key. /// When this is removed, should also remove `OldSessionKeys`. pub struct UpgradeSessionKeys; impl frame_support::traits::OnRuntimeUpgrade for UpgradeSessionKeys { @@ -1562,6 +1514,24 @@ pub mod migrations { } } + // Remove offchain storage values of `im-online` pallet + pub struct RemoveImOnlineOffchainStorageValues; + impl frame_support::traits::OnRuntimeUpgrade for RemoveImOnlineOffchainStorageValues { + fn on_runtime_upgrade() -> Weight { + const DB_PREFIX: &[u8] = b"parity/im-online-heartbeat/"; + let validator_set_size = pallet_session::Pallet::::validators().len() as u32; + (0..validator_set_size).for_each(|idx| { + let key = { + let mut key = DB_PREFIX.to_vec(); + key.extend(idx.encode()); + key + }; + sp_runtime::offchain::storage::StorageValueRef::persistent(&key).clear(); + }); + Weight::zero() + } + } + /// Unreleased migrations. Add new ones here: pub type Unreleased = ( pallet_society::migrations::MigrateToV2, @@ -1592,7 +1562,10 @@ pub mod migrations { // Upgrade `SessionKeys` to exclude `ImOnline` UpgradeSessionKeys, - // Remove `im-online` pallet on-chain storage + // Remove im-online pallet off-chain storage + RemoveImOnlineOffchainStorageValues, + + // Remove im-online pallet on-chain storage frame_support::migrations::RemovePallet::DbWeight>, ); } @@ -1654,7 +1627,6 @@ mod benches { [runtime_parachains::paras_inherent, ParaInherent] [runtime_parachains::paras, Paras] [runtime_parachains::assigner_on_demand, OnDemandAssignmentProvider] - [im_online_remover, ImOnlineRemover] // Substrate [pallet_balances, Balances] [pallet_balances, NisCounterpartBalances] From 4c6d02cd644683597d96048eee27f4778160de0f Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Mon, 13 Nov 2023 11:33:44 +0100 Subject: [PATCH 17/34] Do not clean up off-chain storage; leave it for a follow-up --- polkadot/runtime/rococo/src/lib.rs | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 25ac687a8bc4..6c7089dbc5cf 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1302,8 +1302,7 @@ construct_runtime! { TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event} = 33, // Consensus support. - // Authorship must be before session in order to note author in the correct session and era - // for im-online. + // Authorship must be before session in order to note author in the correct session and era. Authorship: pallet_authorship::{Pallet, Storage} = 5, Offences: pallet_offences::{Pallet, Storage, Event} = 7, Historical: session_historical::{Pallet} = 34, @@ -1504,7 +1503,7 @@ pub mod migrations { type PalletName = TipsPalletName; } - /// Upgrade Session keys to exclude ImOnline key. + /// Upgrade Session keys to exclude `ImOnline` key. /// When this is removed, should also remove `OldSessionKeys`. pub struct UpgradeSessionKeys; impl frame_support::traits::OnRuntimeUpgrade for UpgradeSessionKeys { @@ -1514,24 +1513,6 @@ pub mod migrations { } } - // Remove offchain storage values of `im-online` pallet - pub struct RemoveImOnlineOffchainStorageValues; - impl frame_support::traits::OnRuntimeUpgrade for RemoveImOnlineOffchainStorageValues { - fn on_runtime_upgrade() -> Weight { - const DB_PREFIX: &[u8] = b"parity/im-online-heartbeat/"; - let validator_set_size = pallet_session::Pallet::::validators().len() as u32; - (0..validator_set_size).for_each(|idx| { - let key = { - let mut key = DB_PREFIX.to_vec(); - key.extend(idx.encode()); - key - }; - sp_runtime::offchain::storage::StorageValueRef::persistent(&key).clear(); - }); - Weight::zero() - } - } - /// Unreleased migrations. Add new ones here: pub type Unreleased = ( pallet_society::migrations::MigrateToV2, @@ -1562,10 +1543,7 @@ pub mod migrations { // Upgrade `SessionKeys` to exclude `ImOnline` UpgradeSessionKeys, - // Remove im-online pallet off-chain storage - RemoveImOnlineOffchainStorageValues, - - // Remove im-online pallet on-chain storage + // Remove `im-online` pallet on-chain storage frame_support::migrations::RemovePallet::DbWeight>, ); } From bd39ae12afd1292f31ba31b66cde25c73d43637a Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Mon, 13 Nov 2023 11:46:49 +0100 Subject: [PATCH 18/34] Remove unused code --- .../frame/offences/benchmarking/src/lib.rs | 63 ------------------- 1 file changed, 63 deletions(-) diff --git a/substrate/frame/offences/benchmarking/src/lib.rs b/substrate/frame/offences/benchmarking/src/lib.rs index 8ae0f189849e..801496dec96a 100644 --- a/substrate/frame/offences/benchmarking/src/lib.rs +++ b/substrate/frame/offences/benchmarking/src/lib.rs @@ -29,7 +29,6 @@ use frame_support::traits::{Currency, Get}; use frame_system::{Config as SystemConfig, Pallet as System, RawOrigin}; #[cfg(test)] -use sp_runtime::traits::UniqueSaturatedInto; use sp_runtime::{ traits::{Convert, Saturating, StaticLookup}, Perbill, @@ -47,7 +46,6 @@ use pallet_session::{ Config as SessionConfig, Pallet as Session, SessionManager, }; #[cfg(test)] -use pallet_staking::Event as StakingEvent; use pallet_staking::{ Config as StakingConfig, Exposure, IndividualExposure, MaxNominationsOf, Pallet as Staking, RewardDestination, ValidatorPrefs, @@ -180,67 +178,6 @@ fn make_offenders( Ok((id_tuples, offenders)) } -#[cfg(test)] -fn check_events< - T: Config, - I: Iterator, - Item: sp_std::borrow::Borrow<::RuntimeEvent> + sp_std::fmt::Debug, ->( - expected: I, -) { - let events = System::::events() - .into_iter() - .map(|frame_system::EventRecord { event, .. }| event) - .collect::>(); - let expected = expected.collect::>(); - - fn pretty(header: &str, ev: &[D], offset: usize) { - log::info!("{}", header); - for (idx, ev) in ev.iter().enumerate() { - log::info!("\t[{:04}] {:?}", idx + offset, ev); - } - } - fn print_events( - idx: usize, - events: &[D], - expected: &[E], - ) { - let window = 10; - let start = idx.saturating_sub(window / 2); - let end_got = (idx + window / 2).min(events.len()); - pretty("Got(window):", &events[start..end_got], start); - let end_expected = (idx + window / 2).min(expected.len()); - pretty("Expected(window):", &expected[start..end_expected], start); - log::info!("---------------"); - let start_got = events.len().saturating_sub(window); - pretty("Got(end):", &events[start_got..], start_got); - let start_expected = expected.len().saturating_sub(window); - pretty("Expected(end):", &expected[start_expected..], start_expected); - } - - for (idx, (a, b)) in events.iter().zip(expected.iter()).enumerate() { - if a != sp_std::borrow::Borrow::borrow(b) { - print_events(idx, &events, &expected); - log::info!("Mismatch at: {}", idx); - log::info!(" Got: {:?}", b); - log::info!("Expected: {:?}", a); - if events.len() != expected.len() { - log::info!( - "Mismatching lengths. Got: {}, Expected: {}", - events.len(), - expected.len() - ) - } - panic!("Mismatching events."); - } - } - - if events.len() != expected.len() { - print_events(0, &events, &expected); - panic!("Mismatching lengths. Got: {}, Expected: {}", events.len(), expected.len(),) - } -} - benchmarks! { report_offence_grandpa { let n in 0 .. MAX_NOMINATORS.min(MaxNominationsOf::::get()); From edbec9d421596f5af7b95aa9fb5df562cb7c2802 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Mon, 13 Nov 2023 12:32:12 +0100 Subject: [PATCH 19/34] Minor fixes --- polkadot/runtime/westend/src/lib.rs | 3 +-- substrate/frame/offences/benchmarking/src/lib.rs | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 1c10eba0d570..447be5012ef1 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -1397,8 +1397,7 @@ construct_runtime! { TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event} = 26, // Consensus support. - // Authorship must be before session in order to note author in the correct session and era - // for im-online and staking. + // Authorship must be before session in order to note author in the correct session and era. Authorship: pallet_authorship::{Pallet, Storage} = 5, Staking: pallet_staking::{Pallet, Call, Storage, Config, Event} = 6, Offences: pallet_offences::{Pallet, Storage, Event} = 7, diff --git a/substrate/frame/offences/benchmarking/src/lib.rs b/substrate/frame/offences/benchmarking/src/lib.rs index 801496dec96a..563aa4755cec 100644 --- a/substrate/frame/offences/benchmarking/src/lib.rs +++ b/substrate/frame/offences/benchmarking/src/lib.rs @@ -28,7 +28,6 @@ use frame_benchmarking::v1::{account, benchmarks}; use frame_support::traits::{Currency, Get}; use frame_system::{Config as SystemConfig, Pallet as System, RawOrigin}; -#[cfg(test)] use sp_runtime::{ traits::{Convert, Saturating, StaticLookup}, Perbill, @@ -45,7 +44,6 @@ use pallet_session::{ historical::{Config as HistoricalConfig, IdentificationTuple}, Config as SessionConfig, Pallet as Session, SessionManager, }; -#[cfg(test)] use pallet_staking::{ Config as StakingConfig, Exposure, IndividualExposure, MaxNominationsOf, Pallet as Staking, RewardDestination, ValidatorPrefs, From f1af593d1fe36cdbbec01c8ad4b42ddd073c5dcc Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Mon, 13 Nov 2023 17:19:16 +0100 Subject: [PATCH 20/34] Fix formatting --- polkadot/runtime/rococo/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 91864429c58a..58fcb41521b7 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1541,7 +1541,7 @@ pub mod migrations { frame_support::migrations::RemovePallet::DbWeight>, pallet_grandpa::migrations::MigrateV4ToV5, - + // Upgrade `SessionKeys` to exclude `ImOnline` UpgradeSessionKeys, From 79b1d78f5808373ad8dc27cf75899f392d02f438 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Wed, 15 Nov 2023 19:40:40 +0100 Subject: [PATCH 21/34] Address discussions --- polkadot/runtime/rococo/src/lib.rs | 4 ++-- polkadot/runtime/westend/src/lib.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 7b24c30de421..1f2fc6a7612e 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -354,8 +354,7 @@ pub struct OldSessionKeys { } impl OpaqueKeys for OldSessionKeys { - type KeyTypeIdProviders = - (Grandpa, Babe, (), Initializer, ParaSessionInfo, AuthorityDiscovery, Beefy); + type KeyTypeIdProviders = (); fn key_ids() -> &'static [KeyTypeId] { &[ <::Public>::ID, @@ -371,6 +370,7 @@ impl OpaqueKeys for OldSessionKeys { match i { <::Public>::ID => self.grandpa.as_ref(), <::Public>::ID => self.babe.as_ref(), + sp_core::crypto::key_types::IM_ONLINE => self.im_online.as_ref(), <::Public>::ID => self.para_validator.as_ref(), <::Public>::ID => self.para_assignment.as_ref(), diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 207c28995b8c..f36469d11e4d 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -421,7 +421,7 @@ pub struct OldSessionKeys { } impl OpaqueKeys for OldSessionKeys { - type KeyTypeIdProviders = (Grandpa, Babe, (), Initializer, ParaSessionInfo, AuthorityDiscovery); + type KeyTypeIdProviders = (); fn key_ids() -> &'static [KeyTypeId] { &[ <::Public>::ID, @@ -436,12 +436,12 @@ impl OpaqueKeys for OldSessionKeys { match i { <::Public>::ID => self.grandpa.as_ref(), <::Public>::ID => self.babe.as_ref(), + sp_core::crypto::key_types::IM_ONLINE => self.im_online.as_ref(), <::Public>::ID => self.para_validator.as_ref(), <::Public>::ID => self.para_assignment.as_ref(), <::Public>::ID => self.authority_discovery.as_ref(), - _ => &[], } } } From 9f7ab51cc564f451a72265d5cf07281d5000a1b5 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Wed, 15 Nov 2023 20:14:08 +0100 Subject: [PATCH 22/34] Fix build --- polkadot/runtime/westend/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index b0245ff7cf5e..c1192fc58b15 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -457,6 +457,7 @@ impl OpaqueKeys for OldSessionKeys { self.para_assignment.as_ref(), <::Public>::ID => self.authority_discovery.as_ref(), + _ => &[], } } } From c65e882e21383c9cc9975d0b9ed0bd81e9fcc01e Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Fri, 17 Nov 2023 11:22:29 +0100 Subject: [PATCH 23/34] Fix log level --- polkadot/runtime/rococo/src/lib.rs | 2 +- polkadot/runtime/westend/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 5d5d8de833a0..8229771c0af5 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1536,7 +1536,7 @@ pub mod migrations { impl frame_support::traits::OnRuntimeUpgrade for UpgradeSessionKeys { fn on_runtime_upgrade() -> Weight { if System::last_runtime_upgrade_spec_version() > 103001 { - log::warn!("Skipping session keys upgrade: already applied"); + log::info!("Skipping session keys upgrade: already applied"); } log::trace!("Upgrading session keys"); Session::upgrade_keys::(transform_session_keys); diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 8078bd1b3250..8e7d8256bf0f 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -1570,7 +1570,7 @@ pub mod migrations { if System::last_runtime_upgrade_spec_version() > 103000 { log::warn!("Skipping session keys upgrade: already applied"); } - log::trace!("Upgrading session keys"); + log::info!("Upgrading session keys"); Session::upgrade_keys::(transform_session_keys); Perbill::from_percent(50) * BlockWeights::get().max_block } From 091bf87f336ed3bdcaa1c5fa1620d1e19ea05028 Mon Sep 17 00:00:00 2001 From: s0me0ne-unkn0wn <48632512+s0me0ne-unkn0wn@users.noreply.github.com> Date: Tue, 21 Nov 2023 12:16:27 +0100 Subject: [PATCH 24/34] Fix comment Co-authored-by: ordian --- polkadot/runtime/westend/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 5d0cb7401dce..f033d62ee23a 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -1562,7 +1562,7 @@ pub mod migrations { pub const ImOnlinePalletName: &'static str = "ImOnline"; } - /// Upgrade Session keys to include BEEFY key. + /// Upgrade Session keys to exclude `ImOnline` key. /// When this is removed, should also remove `OldSessionKeys`. pub struct UpgradeSessionKeys; impl frame_support::traits::OnRuntimeUpgrade for UpgradeSessionKeys { From 26755a7d2aa9967be91bcc86f23c05da8efce715 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Tue, 21 Nov 2023 12:30:23 +0100 Subject: [PATCH 25/34] Fix version checking --- polkadot/runtime/rococo/src/lib.rs | 1 + polkadot/runtime/westend/src/lib.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 8dbb846975ee..18e91bd992fa 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1537,6 +1537,7 @@ pub mod migrations { fn on_runtime_upgrade() -> Weight { if System::last_runtime_upgrade_spec_version() > 103001 { log::info!("Skipping session keys upgrade: already applied"); + return ::DbWeight::get().reads(1) } log::trace!("Upgrading session keys"); Session::upgrade_keys::(transform_session_keys); diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 5d0cb7401dce..9ae190c83c03 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -1569,6 +1569,7 @@ pub mod migrations { fn on_runtime_upgrade() -> Weight { if System::last_runtime_upgrade_spec_version() > 103000 { log::warn!("Skipping session keys upgrade: already applied"); + return ::DbWeight::get().reads(1) } log::info!("Upgrading session keys"); Session::upgrade_keys::(transform_session_keys); From 78995ca652538ee8c817fb9377c3f00552c15e32 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Wed, 22 Nov 2023 16:29:43 +0100 Subject: [PATCH 26/34] Add try-runtime hooks --- polkadot/runtime/rococo/src/lib.rs | 57 +++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 18e91bd992fa..a40edae8b203 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1485,6 +1485,7 @@ pub mod migrations { use frame_support::traits::LockIdentifier; use frame_system::pallet_prelude::BlockNumberFor; + use sp_core::ByteArray; parameter_types! { pub const DemocracyPalletName: &'static str = "Democracy"; @@ -1533,9 +1534,37 @@ pub mod migrations { /// Upgrade Session keys to exclude `ImOnline` key. /// When this is removed, should also remove `OldSessionKeys`. pub struct UpgradeSessionKeys; + const UPGRADE_SESSION_KEYS_FROM_SPEC: u32 = 103001; + impl frame_support::traits::OnRuntimeUpgrade for UpgradeSessionKeys { + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { + if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC { + log::warn!(target: "runtime::session_keys", "Skipping session keys migration pre-upgrade check due to spec version (already applied?)"); + return Ok(Vec::new()) + } + + log::info!(target: "runtime::session_keys", "Collecting pre-upgrade session keys state"); + let key_ids = SessionKeys::key_ids(); + let storage_key = pallet_session::QueuedKeys::::hashed_key(); + let mut state: Vec = Vec::new(); + frame_support::storage::unhashed::get::>( + &storage_key, + ) + .ok_or::("Queued keys are not available".into())? + .into_iter() + .for_each(|(id, keys)| { + state.extend_from_slice(id.as_slice()); + for key_id in key_ids { + state.extend_from_slice(keys.get_raw(*key_id)); + } + }); + frame_support::ensure!(state.len() > 0, "Queued keys are not empty before upgrade"); + Ok(state) + } + fn on_runtime_upgrade() -> Weight { - if System::last_runtime_upgrade_spec_version() > 103001 { + if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC { log::info!("Skipping session keys upgrade: already applied"); return ::DbWeight::get().reads(1) } @@ -1543,6 +1572,32 @@ pub mod migrations { Session::upgrade_keys::(transform_session_keys); Perbill::from_percent(50) * BlockWeights::get().max_block } + + #[cfg(feature = "try-runtime")] + fn post_upgrade( + old_state: sp_std::vec::Vec, + ) -> Result<(), sp_runtime::TryRuntimeError> { + if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC { + log::warn!(target: "runtime::session_keys", "Skipping session keys migration post-upgrade check due to spec version (already applied?)"); + return Ok(()) + } + + let key_ids = SessionKeys::key_ids(); + let mut new_state: Vec = Vec::new(); + pallet_session::QueuedKeys::::get().into_iter().for_each(|(id, keys)| { + new_state.extend_from_slice(id.as_slice()); + for key_id in key_ids { + new_state.extend_from_slice(keys.get_raw(*key_id)); + } + }); + frame_support::ensure!(new_state.len() > 0, "Queued keys are not empty after upgrade"); + frame_support::ensure!( + old_state == new_state, + "Pre-upgrade and post-upgrade keys do not match!" + ); + log::info!(target: "runtime::session_keys", "Session keys migrated successfully"); + Ok(()) + } } /// Unreleased migrations. Add new ones here: From ab4c1dcccc9c2492986b620da7a961945a9125a8 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Wed, 22 Nov 2023 17:07:38 +0100 Subject: [PATCH 27/34] Fix import --- polkadot/runtime/rococo/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index a40edae8b203..609872b2f230 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1485,7 +1485,8 @@ pub mod migrations { use frame_support::traits::LockIdentifier; use frame_system::pallet_prelude::BlockNumberFor; - use sp_core::ByteArray; + #[cfg(feature = "try-runtime")] + use sp_core::crypto::ByteArray; parameter_types! { pub const DemocracyPalletName: &'static str = "Democracy"; From f621cbb26cc8af3e57f762871d41d0d3b11f2d9b Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Thu, 23 Nov 2023 12:30:18 +0100 Subject: [PATCH 28/34] Add try-runtime checks to Westend and bump required spec version --- polkadot/runtime/westend/src/lib.rs | 56 ++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index c2925a432b3b..6a3258bbf345 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -1565,9 +1565,37 @@ pub mod migrations { /// Upgrade Session keys to exclude `ImOnline` key. /// When this is removed, should also remove `OldSessionKeys`. pub struct UpgradeSessionKeys; + const UPGRADE_SESSION_KEYS_FROM_SPEC: u32 = 104000; + impl frame_support::traits::OnRuntimeUpgrade for UpgradeSessionKeys { + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { + if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC { + log::warn!(target: "runtime::session_keys", "Skipping session keys migration pre-upgrade check due to spec version (already applied?)"); + return Ok(Vec::new()) + } + + log::info!(target: "runtime::session_keys", "Collecting pre-upgrade session keys state"); + let key_ids = SessionKeys::key_ids(); + let storage_key = pallet_session::QueuedKeys::::hashed_key(); + let mut state: Vec = Vec::new(); + frame_support::storage::unhashed::get::>( + &storage_key, + ) + .ok_or::("Queued keys are not available".into())? + .into_iter() + .for_each(|(id, keys)| { + state.extend_from_slice(id.as_slice()); + for key_id in key_ids { + state.extend_from_slice(keys.get_raw(*key_id)); + } + }); + frame_support::ensure!(state.len() > 0, "Queued keys are not empty before upgrade"); + Ok(state) + } + fn on_runtime_upgrade() -> Weight { - if System::last_runtime_upgrade_spec_version() > 103000 { + if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC { log::warn!("Skipping session keys upgrade: already applied"); return ::DbWeight::get().reads(1) } @@ -1575,6 +1603,32 @@ pub mod migrations { Session::upgrade_keys::(transform_session_keys); Perbill::from_percent(50) * BlockWeights::get().max_block } + + #[cfg(feature = "try-runtime")] + fn post_upgrade( + old_state: sp_std::vec::Vec, + ) -> Result<(), sp_runtime::TryRuntimeError> { + if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC { + log::warn!(target: "runtime::session_keys", "Skipping session keys migration post-upgrade check due to spec version (already applied?)"); + return Ok(()) + } + + let key_ids = SessionKeys::key_ids(); + let mut new_state: Vec = Vec::new(); + pallet_session::QueuedKeys::::get().into_iter().for_each(|(id, keys)| { + new_state.extend_from_slice(id.as_slice()); + for key_id in key_ids { + new_state.extend_from_slice(keys.get_raw(*key_id)); + } + }); + frame_support::ensure!(new_state.len() > 0, "Queued keys are not empty after upgrade"); + frame_support::ensure!( + old_state == new_state, + "Pre-upgrade and post-upgrade keys do not match!" + ); + log::info!(target: "runtime::session_keys", "Session keys migrated successfully"); + Ok(()) + } } /// Unreleased migrations. Add new ones here: From 8dbcc414666437491ea32c37c21677c88ece67f8 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Thu, 23 Nov 2023 13:45:14 +0100 Subject: [PATCH 29/34] Add more checks --- polkadot/runtime/rococo/src/lib.rs | 6 +++++- polkadot/runtime/westend/src/lib.rs | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 609872b2f230..2698bf77c75c 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1535,7 +1535,7 @@ pub mod migrations { /// Upgrade Session keys to exclude `ImOnline` key. /// When this is removed, should also remove `OldSessionKeys`. pub struct UpgradeSessionKeys; - const UPGRADE_SESSION_KEYS_FROM_SPEC: u32 = 103001; + const UPGRADE_SESSION_KEYS_FROM_SPEC: u32 = 104000; impl frame_support::traits::OnRuntimeUpgrade for UpgradeSessionKeys { #[cfg(feature = "try-runtime")] @@ -1547,6 +1547,10 @@ pub mod migrations { log::info!(target: "runtime::session_keys", "Collecting pre-upgrade session keys state"); let key_ids = SessionKeys::key_ids(); + frame_support::ensure!( + key_ids.into_iter().find(|&k| *k == sp_core::crypto::key_types::IM_ONLINE) == None, + "New session keys contain the ImOnline key that should have been removed", + ); let storage_key = pallet_session::QueuedKeys::::hashed_key(); let mut state: Vec = Vec::new(); frame_support::storage::unhashed::get::>( diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 6a3258bbf345..e83586316bd0 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -1557,6 +1557,8 @@ pub type Migrations = migrations::Unreleased; #[allow(deprecated, missing_docs)] pub mod migrations { use super::*; + #[cfg(feature = "try-runtime")] + use sp_core::crypto::ByteArray; parameter_types! { pub const ImOnlinePalletName: &'static str = "ImOnline"; @@ -1577,6 +1579,10 @@ pub mod migrations { log::info!(target: "runtime::session_keys", "Collecting pre-upgrade session keys state"); let key_ids = SessionKeys::key_ids(); + frame_support::ensure!( + key_ids.into_iter().find(|&k| *k == sp_core::crypto::key_types::IM_ONLINE) == None, + "New session keys contain the ImOnline key that should have been removed", + ); let storage_key = pallet_session::QueuedKeys::::hashed_key(); let mut state: Vec = Vec::new(); frame_support::storage::unhashed::get::>( From ec0e48a4cfd902979f2d9f97985aa3e11818b13f Mon Sep 17 00:00:00 2001 From: Vladimir Istyufeev Date: Mon, 27 Nov 2023 17:13:46 +0400 Subject: [PATCH 30/34] Remove timestamp handler --- .gitlab-ci.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f7e54961fa98..aada30f1dda0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -69,7 +69,6 @@ default: .common-before-script: before_script: - !reference [.job-switcher, before_script] - - !reference [.timestamp, before_script] - !reference [.pipeline-stopper-vars, script] .job-switcher: @@ -211,10 +210,6 @@ include: - .gitlab/pipeline/publish.yml # zombienet jobs - .gitlab/pipeline/zombienet.yml - # timestamp handler - - project: parity/infrastructure/ci_cd/shared - ref: v0.2 - file: /common/timestamp.yml # ci image - project: parity/infrastructure/ci_cd/shared ref: main From fbda23cf565ca79a01f1940ec73c7819f7a1252e Mon Sep 17 00:00:00 2001 From: Vladimir Istyufeev Date: Mon, 27 Nov 2023 19:28:09 +0400 Subject: [PATCH 31/34] TERM=dumb --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index aada30f1dda0..4442fee7cdff 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -31,6 +31,7 @@ variables: NEXTEST_FAILURE_OUTPUT: immediate-final NEXTEST_SUCCESS_OUTPUT: final DOCKER_IMAGES_VERSION: "${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}" + TERM: dumb default: retry: From aa813f82a315e5494e6a35e13df8b8e8811527f0 Mon Sep 17 00:00:00 2001 From: Vladimir Istyufeev Date: Mon, 27 Nov 2023 23:13:09 +0400 Subject: [PATCH 32/34] Don't wrap `try-runtime` with `time` --- .gitlab-ci.yml | 1 - .gitlab/pipeline/check.yml | 12 ++++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4442fee7cdff..aada30f1dda0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -31,7 +31,6 @@ variables: NEXTEST_FAILURE_OUTPUT: immediate-final NEXTEST_SUCCESS_OUTPUT: final DOCKER_IMAGES_VERSION: "${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}" - TERM: dumb default: retry: diff --git a/.gitlab/pipeline/check.yml b/.gitlab/pipeline/check.yml index b2f2efc5e667..652ec77467e4 100644 --- a/.gitlab/pipeline/check.yml +++ b/.gitlab/pipeline/check.yml @@ -105,12 +105,16 @@ check-rust-feature-propagation: chmod +x ./try-runtime echo "---------- Building ${PACKAGE} runtime ----------" - time cargo build --release --locked -p "$PACKAGE" --features try-runtime + start=$(date +%s) + cargo build --release --locked -p "$PACKAGE" --features try-runtime + echo "Execution time: $(( $(date +%s) - start )) seconds" echo "---------- Executing on-runtime-upgrade for ${NETWORK} ----------" - time ./try-runtime ${COMMAND_EXTRA_ARGS} \ - --runtime ./target/release/wbuild/"$PACKAGE"/"$WASM" \ - on-runtime-upgrade --disable-spec-version-check --checks=all ${SUBCOMMAND_EXTRA_ARGS} live --uri ${URI} + start=$(date +%s) + ./try-runtime ${COMMAND_EXTRA_ARGS} \ + --runtime ./target/release/wbuild/"$PACKAGE"/"$WASM" \ + on-runtime-upgrade --disable-spec-version-check --checks=all ${SUBCOMMAND_EXTRA_ARGS} live --uri ${URI} + echo "Execution time: $(( $(date +%s) - start )) seconds" # Check runtime migrations for Parity managed relay chains check-runtime-migration-westend: From a0cd856d0b2ff5b1a2622371f3f191d4fa8d055c Mon Sep 17 00:00:00 2001 From: Vladimir Istyufeev Date: Mon, 27 Nov 2023 23:39:06 +0400 Subject: [PATCH 33/34] Forcefully disable output buffering --- .gitlab/pipeline/check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab/pipeline/check.yml b/.gitlab/pipeline/check.yml index 652ec77467e4..5cab36301c63 100644 --- a/.gitlab/pipeline/check.yml +++ b/.gitlab/pipeline/check.yml @@ -111,7 +111,7 @@ check-rust-feature-propagation: echo "---------- Executing on-runtime-upgrade for ${NETWORK} ----------" start=$(date +%s) - ./try-runtime ${COMMAND_EXTRA_ARGS} \ + stdbuf -o0 -e0 ./try-runtime ${COMMAND_EXTRA_ARGS} \ --runtime ./target/release/wbuild/"$PACKAGE"/"$WASM" \ on-runtime-upgrade --disable-spec-version-check --checks=all ${SUBCOMMAND_EXTRA_ARGS} live --uri ${URI} echo "Execution time: $(( $(date +%s) - start )) seconds" From b8d015e56901bf3f943aa107787d0fe05f1a07bd Mon Sep 17 00:00:00 2001 From: Vladimir Istyufeev Date: Tue, 28 Nov 2023 00:52:22 +0400 Subject: [PATCH 34/34] =?UTF-8?q?Use=20`sleep`=20=F0=9F=99=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab/pipeline/check.yml | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/.gitlab/pipeline/check.yml b/.gitlab/pipeline/check.yml index 5cab36301c63..3ef3865aa43b 100644 --- a/.gitlab/pipeline/check.yml +++ b/.gitlab/pipeline/check.yml @@ -105,16 +105,13 @@ check-rust-feature-propagation: chmod +x ./try-runtime echo "---------- Building ${PACKAGE} runtime ----------" - start=$(date +%s) - cargo build --release --locked -p "$PACKAGE" --features try-runtime - echo "Execution time: $(( $(date +%s) - start )) seconds" + time cargo build --release --locked -p "$PACKAGE" --features try-runtime echo "---------- Executing on-runtime-upgrade for ${NETWORK} ----------" - start=$(date +%s) - stdbuf -o0 -e0 ./try-runtime ${COMMAND_EXTRA_ARGS} \ - --runtime ./target/release/wbuild/"$PACKAGE"/"$WASM" \ - on-runtime-upgrade --disable-spec-version-check --checks=all ${SUBCOMMAND_EXTRA_ARGS} live --uri ${URI} - echo "Execution time: $(( $(date +%s) - start )) seconds" + time ./try-runtime ${COMMAND_EXTRA_ARGS} \ + --runtime ./target/release/wbuild/"$PACKAGE"/"$WASM" \ + on-runtime-upgrade --disable-spec-version-check --checks=all ${SUBCOMMAND_EXTRA_ARGS} live --uri ${URI} + sleep 5 # Check runtime migrations for Parity managed relay chains check-runtime-migration-westend: