Skip to content

Commit

Permalink
Keep im-online events decodable after pallet removal (polkadot-fell…
Browse files Browse the repository at this point in the history
…ows#235)

This is a follow-up to polkadot-fellows#178, which aims to keep the `im-online` pallet
events decodable after the pallet itself is removed.

As
[discussed](polkadot-fellows#178 (comment)),
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
  • Loading branch information
s0me0ne-unkn0wn authored Mar 15, 2024
1 parent 80aaf79 commit 64c9e16
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 11 deletions.
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

0 comments on commit 64c9e16

Please sign in to comment.