From 64c9e16cb244bc7b594858a0dc7c6dd61a766270 Mon Sep 17 00:00:00 2001 From: s0me0ne-unkn0wn <48632512+s0me0ne-unkn0wn@users.noreply.github.com> Date: Fri, 15 Mar 2024 15:53:23 +0100 Subject: [PATCH] Keep `im-online` events decodable after pallet removal (#235) This is a follow-up to #178, which aims to keep the `im-online` pallet events decodable after the pallet itself is removed. As [discussed](https://github.com/polkadot-fellows/runtimes/pull/178#issuecomment-1977608363), the inability to decode events may result in missing a candidate in approval voting and a parachain finality stall. Although the circumstances of such an event are unlikely, it's better to safeguard them. The transient code introduced in this PR should be removed after the upgrade is enacted. - [x] Does not require a CHANGELOG entry --- Cargo.lock | 3 +-- relay/kusama/Cargo.toml | 6 ++--- relay/kusama/src/lib.rs | 56 ++++++++++++++++++++++++++++++++++++++- relay/polkadot/Cargo.toml | 4 --- relay/polkadot/src/lib.rs | 54 +++++++++++++++++++++++++++++++++++++ 5 files changed, 112 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 325aa0bbac..0198c078b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9403,7 +9403,6 @@ dependencies = [ "pallet-fast-unstake", "pallet-grandpa", "pallet-identity", - "pallet-im-online", "pallet-indices", "pallet-message-queue", "pallet-mmr", @@ -13236,7 +13235,6 @@ dependencies = [ "pallet-fast-unstake", "pallet-grandpa", "pallet-identity", - "pallet-im-online", "pallet-indices", "pallet-message-queue", "pallet-mmr", @@ -13276,6 +13274,7 @@ dependencies = [ "separator", "serde_json", "sp-api", + "sp-application-crypto", "sp-arithmetic", "sp-authority-discovery", "sp-block-builder", diff --git a/relay/kusama/Cargo.toml b/relay/kusama/Cargo.toml index e05924df6b..3457beaec4 100644 --- a/relay/kusama/Cargo.toml +++ b/relay/kusama/Cargo.toml @@ -22,6 +22,7 @@ sp-api = { default-features = false , version = "27.0.0" } inherents = { package = "sp-inherents", default-features = false , version = "27.0.0" } offchain-primitives = { package = "sp-offchain", default-features = false , version = "27.0.0" } sp-std = { package = "sp-std", default-features = false , version = "14.0.0" } +sp-application-crypto = { default-features = false , version = "31.0.0" } sp-arithmetic = { default-features = false , version = "24.0.0" } sp-genesis-builder = { default-features = false , version = "0.8.0" } sp-io = { default-features = false , version = "31.0.0" } @@ -55,7 +56,6 @@ frame-executive = { default-features = false , version = "29.0.0" } pallet-grandpa = { default-features = false , version = "29.0.0" } pallet-nis = { default-features = false , version = "29.0.0" } pallet-identity = { default-features = false , version = "29.0.0" } -pallet-im-online = { default-features = false , version = "28.0.0" } pallet-indices = { default-features = false , version = "29.0.0" } pallet-message-queue = { default-features = false , version = "32.0.0" } pallet-mmr = { default-features = false , version = "28.0.0" } @@ -154,7 +154,6 @@ std = [ "pallet-fast-unstake/std", "pallet-grandpa/std", "pallet-identity/std", - "pallet-im-online/std", "pallet-indices/std", "pallet-message-queue/std", "pallet-mmr/std", @@ -192,6 +191,7 @@ std = [ "runtime-parachains/std", "scale-info/std", "sp-api/std", + "sp-application-crypto/std", "sp-arithmetic/std", "sp-core/std", "sp-debug-derive/std", @@ -228,7 +228,6 @@ runtime-benchmarks = [ "pallet-fast-unstake/runtime-benchmarks", "pallet-grandpa/runtime-benchmarks", "pallet-identity/runtime-benchmarks", - "pallet-im-online/runtime-benchmarks", "pallet-indices/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", "pallet-mmr/runtime-benchmarks", @@ -285,7 +284,6 @@ try-runtime = [ "pallet-fast-unstake/try-runtime", "pallet-grandpa/try-runtime", "pallet-identity/try-runtime", - "pallet-im-online/try-runtime", "pallet-indices/try-runtime", "pallet-message-queue/try-runtime", "pallet-mmr/try-runtime", diff --git a/relay/kusama/src/lib.rs b/relay/kusama/src/lib.rs index 2cd585377f..835f1a8adc 100644 --- a/relay/kusama/src/lib.rs +++ b/relay/kusama/src/lib.rs @@ -1574,6 +1574,59 @@ impl pallet_asset_rate::Config for Runtime { type BenchmarkHelper = runtime_common::impls::benchmarks::AssetRateArguments; } +// A mock pallet to keep `ImOnline` events decodable after pallet removal +pub mod pallet_im_online { + use frame_support::pallet_prelude::*; + pub use pallet::*; + + pub mod sr25519 { + mod app_sr25519 { + use sp_application_crypto::{app_crypto, key_types::IM_ONLINE, sr25519}; + app_crypto!(sr25519, IM_ONLINE); + } + pub type AuthorityId = app_sr25519::Public; + } + + #[frame_support::pallet] + pub mod pallet { + use super::*; + use frame_support::traits::{ValidatorSet, ValidatorSetWithIdentification}; + + #[pallet::pallet] + pub struct Pallet(_); + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + + IsType<::RuntimeEvent>; + type ValidatorSet: ValidatorSetWithIdentification; + } + + pub type ValidatorId = <::ValidatorSet as ValidatorSet< + ::AccountId, + >>::ValidatorId; + + pub type IdentificationTuple = ( + ValidatorId, + <::ValidatorSet as ValidatorSetWithIdentification< + ::AccountId, + >>::Identification, + ); + + #[pallet::event] + pub enum Event { + HeartbeatReceived { authority_id: super::sr25519::AuthorityId }, + AllGood, + SomeOffline { offline: sp_std::vec::Vec> }, + } + } +} + +impl pallet_im_online::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type ValidatorSet = Historical; +} + construct_runtime! { pub enum Runtime { @@ -1590,7 +1643,7 @@ construct_runtime! { // Consensus support. // Authorship must be before session in order to note author in the correct session and era - // for im-online and staking. + // for staking. Authorship: pallet_authorship = 5, Staking: pallet_staking = 6, Offences: pallet_offences = 7, @@ -1598,6 +1651,7 @@ construct_runtime! { Session: pallet_session = 8, Grandpa: pallet_grandpa = 10, + ImOnline: pallet_im_online::{Event} = 11, AuthorityDiscovery: pallet_authority_discovery = 12, // Governance stuff. diff --git a/relay/polkadot/Cargo.toml b/relay/polkadot/Cargo.toml index 27a5a40f2e..4aae319eed 100644 --- a/relay/polkadot/Cargo.toml +++ b/relay/polkadot/Cargo.toml @@ -52,7 +52,6 @@ pallet-fast-unstake = { default-features = false , version = "28.0.0" } frame-executive = { default-features = false , version = "29.0.0" } pallet-grandpa = { default-features = false , version = "29.0.0" } pallet-identity = { default-features = false , version = "29.0.0" } -pallet-im-online = { default-features = false , version = "28.0.0" } pallet-indices = { default-features = false , version = "29.0.0" } pallet-message-queue = { default-features = false , version = "32.0.0" } pallet-mmr = { default-features = false , version = "28.0.0" } @@ -149,7 +148,6 @@ std = [ "pallet-fast-unstake/std", "pallet-grandpa/std", "pallet-identity/std", - "pallet-im-online/std", "pallet-indices/std", "pallet-message-queue/std", "pallet-mmr/std", @@ -221,7 +219,6 @@ runtime-benchmarks = [ "pallet-fast-unstake/runtime-benchmarks", "pallet-grandpa/runtime-benchmarks", "pallet-identity/runtime-benchmarks", - "pallet-im-online/runtime-benchmarks", "pallet-indices/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", "pallet-mmr/runtime-benchmarks", @@ -273,7 +270,6 @@ try-runtime = [ "pallet-fast-unstake/try-runtime", "pallet-grandpa/try-runtime", "pallet-identity/try-runtime", - "pallet-im-online/try-runtime", "pallet-indices/try-runtime", "pallet-message-queue/try-runtime", "pallet-mmr/try-runtime", diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index e130fbc6ca..179575437b 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -1553,6 +1553,59 @@ impl pallet_asset_rate::Config for Runtime { type BenchmarkHelper = runtime_common::impls::benchmarks::AssetRateArguments; } +// A mock pallet to keep `ImOnline` events decodable after pallet removal +pub mod pallet_im_online { + use frame_support::pallet_prelude::*; + pub use pallet::*; + + pub mod sr25519 { + mod app_sr25519 { + use sp_application_crypto::{app_crypto, key_types::IM_ONLINE, sr25519}; + app_crypto!(sr25519, IM_ONLINE); + } + pub type AuthorityId = app_sr25519::Public; + } + + #[frame_support::pallet] + pub mod pallet { + use super::*; + use frame_support::traits::{ValidatorSet, ValidatorSetWithIdentification}; + + #[pallet::pallet] + pub struct Pallet(_); + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + + IsType<::RuntimeEvent>; + type ValidatorSet: ValidatorSetWithIdentification; + } + + pub type ValidatorId = <::ValidatorSet as ValidatorSet< + ::AccountId, + >>::ValidatorId; + + pub type IdentificationTuple = ( + ValidatorId, + <::ValidatorSet as ValidatorSetWithIdentification< + ::AccountId, + >>::Identification, + ); + + #[pallet::event] + pub enum Event { + HeartbeatReceived { authority_id: super::sr25519::AuthorityId }, + AllGood, + SomeOffline { offline: sp_std::vec::Vec> }, + } + } +} + +impl pallet_im_online::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type ValidatorSet = Historical; +} + construct_runtime! { pub enum Runtime { @@ -1579,6 +1632,7 @@ construct_runtime! { Session: pallet_session = 9, Grandpa: pallet_grandpa = 11, + ImOnline: pallet_im_online::{Event} = 12, AuthorityDiscovery: pallet_authority_discovery = 13, // OpenGov stuff.