Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep im-online events decodable after pallet removal #235

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions relay/kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down Expand Up @@ -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" }
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
56 changes: 55 additions & 1 deletion relay/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(_);

#[pallet::config]
pub trait Config: frame_system::Config {
type RuntimeEvent: From<Event<Self>>
+ IsType<<Self as frame_system::Config>::RuntimeEvent>;
type ValidatorSet: ValidatorSetWithIdentification<Self::AccountId>;
}

pub type ValidatorId<T> = <<T as Config>::ValidatorSet as ValidatorSet<
<T as frame_system::Config>::AccountId,
>>::ValidatorId;

pub type IdentificationTuple<T> = (
ValidatorId<T>,
<<T as Config>::ValidatorSet as ValidatorSetWithIdentification<
<T as frame_system::Config>::AccountId,
>>::Identification,
);

#[pallet::event]
pub enum Event<T: Config> {
HeartbeatReceived { authority_id: super::sr25519::AuthorityId },
AllGood,
SomeOffline { offline: sp_std::vec::Vec<IdentificationTuple<T>> },
}
}
}

impl pallet_im_online::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type ValidatorSet = Historical;
}

construct_runtime! {
pub enum Runtime
{
Expand All @@ -1590,14 +1643,15 @@ 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,
Historical: session_historical = 34,

Session: pallet_session = 8,
Grandpa: pallet_grandpa = 10,
ImOnline: pallet_im_online::{Event<T>} = 11,
AuthorityDiscovery: pallet_authority_discovery = 12,

// Governance stuff.
Expand Down
4 changes: 0 additions & 4 deletions relay/polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
54 changes: 54 additions & 0 deletions relay/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(_);

#[pallet::config]
pub trait Config: frame_system::Config {
type RuntimeEvent: From<Event<Self>>
+ IsType<<Self as frame_system::Config>::RuntimeEvent>;
type ValidatorSet: ValidatorSetWithIdentification<Self::AccountId>;
}

pub type ValidatorId<T> = <<T as Config>::ValidatorSet as ValidatorSet<
<T as frame_system::Config>::AccountId,
>>::ValidatorId;

pub type IdentificationTuple<T> = (
ValidatorId<T>,
<<T as Config>::ValidatorSet as ValidatorSetWithIdentification<
<T as frame_system::Config>::AccountId,
>>::Identification,
);

#[pallet::event]
pub enum Event<T: Config> {
HeartbeatReceived { authority_id: super::sr25519::AuthorityId },
AllGood,
SomeOffline { offline: sp_std::vec::Vec<IdentificationTuple<T>> },
}
}
}

impl pallet_im_online::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type ValidatorSet = Historical;
}

construct_runtime! {
pub enum Runtime
{
Expand All @@ -1579,6 +1632,7 @@ construct_runtime! {

Session: pallet_session = 9,
Grandpa: pallet_grandpa = 11,
ImOnline: pallet_im_online::{Event<T>} = 12,
AuthorityDiscovery: pallet_authority_discovery = 13,

// OpenGov stuff.
Expand Down
Loading