From b02fbcfe8bab3a3e2e2b81042abb8ee9a797c2be Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Tue, 12 Mar 2024 20:14:44 +0100 Subject: [PATCH 1/2] Add a mock pallet to keep events decodable --- Cargo.lock | 2 +- relay/kusama/Cargo.toml | 5 +--- relay/kusama/src/lib.rs | 56 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 325aa0bbac..0ff597e720 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13236,7 +13236,6 @@ dependencies = [ "pallet-fast-unstake", "pallet-grandpa", "pallet-identity", - "pallet-im-online", "pallet-indices", "pallet-message-queue", "pallet-mmr", @@ -13276,6 +13275,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..ac139a4062 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", @@ -228,7 +227,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 +283,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. From 1cfbe5643a146e5755c7acee70b3072b647a9237 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Fri, 15 Mar 2024 11:57:52 +0100 Subject: [PATCH 2/2] Implement for Polkadot --- Cargo.lock | 1 - relay/kusama/Cargo.toml | 1 + relay/polkadot/Cargo.toml | 4 --- relay/polkadot/src/lib.rs | 54 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0ff597e720..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", diff --git a/relay/kusama/Cargo.toml b/relay/kusama/Cargo.toml index ac139a4062..3457beaec4 100644 --- a/relay/kusama/Cargo.toml +++ b/relay/kusama/Cargo.toml @@ -191,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", 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 f46ec66e4c..21842b936b 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -1549,6 +1549,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 { @@ -1575,6 +1628,7 @@ construct_runtime! { Session: pallet_session = 9, Grandpa: pallet_grandpa = 11, + ImOnline: pallet_im_online::{Event} = 12, AuthorityDiscovery: pallet_authority_discovery = 13, // OpenGov stuff.