Skip to content

Commit

Permalink
im-online cleanup: phase 1 (polkadot-fellows#267)
Browse files Browse the repository at this point in the history
This PR removes migrations and transient code connected with `im-online`
removal. It introduces an offchain db cleanup migration that must be
removed later.

- [x] Does not require a CHANGELOG entry
  • Loading branch information
s0me0ne-unkn0wn authored Jul 19, 2024
1 parent db3ac1a commit d0855a4
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 117 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ pallet-fast-unstake = { version = "34.0.0", default-features = false }
pallet-glutton = { version = "21.0.0", default-features = false }
pallet-grandpa = { version = "35.0.0", default-features = false }
pallet-identity = { version = "35.0.0", default-features = false }
pallet-im-online = { version = "34.0.0", default-features = false }
pallet-indices = { version = "35.0.0", default-features = false }
pallet-insecure-randomness-collective-flip = { version = "23.0.0", default-features = false }
pallet-membership = { version = "35.0.0", default-features = false }
Expand Down
4 changes: 4 additions & 0 deletions relay/kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ frame-executive = { workspace = true }
frame-metadata-hash-extension = { workspace = true }
pallet-grandpa = { workspace = true }
pallet-nis = { workspace = true }
pallet-im-online = { workspace = true }
pallet-indices = { workspace = true }
pallet-message-queue = { workspace = true }
pallet-mmr = { workspace = true }
Expand Down Expand Up @@ -151,6 +152,7 @@ std = [
"pallet-election-provider-support-benchmarking?/std",
"pallet-fast-unstake/std",
"pallet-grandpa/std",
"pallet-im-online/std",
"pallet-indices/std",
"pallet-message-queue/std",
"pallet-mmr/std",
Expand Down Expand Up @@ -226,6 +228,7 @@ runtime-benchmarks = [
"pallet-election-provider-support-benchmarking/runtime-benchmarks",
"pallet-fast-unstake/runtime-benchmarks",
"pallet-grandpa/runtime-benchmarks",
"pallet-im-online/runtime-benchmarks",
"pallet-indices/runtime-benchmarks",
"pallet-message-queue/runtime-benchmarks",
"pallet-mmr/runtime-benchmarks",
Expand Down Expand Up @@ -280,6 +283,7 @@ try-runtime = [
"pallet-election-provider-multi-phase/try-runtime",
"pallet-fast-unstake/try-runtime",
"pallet-grandpa/try-runtime",
"pallet-im-online/try-runtime",
"pallet-indices/try-runtime",
"pallet-message-queue/try-runtime",
"pallet-mmr/try-runtime",
Expand Down
60 changes: 6 additions & 54 deletions relay/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1506,59 +1506,6 @@ impl pallet_asset_rate::Config for Runtime {
type BenchmarkHelper = polkadot_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 @@ -1583,7 +1530,6 @@ construct_runtime! {

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

// Governance stuff.
Expand Down Expand Up @@ -1878,6 +1824,12 @@ sp_api::impl_runtime_apis! {

impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
fn offchain_worker(header: &<Block as BlockT>::Header) {
use sp_runtime::{traits::Header, DigestItem};

if header.digest().logs().iter().any(|di| di == &DigestItem::RuntimeEnvironmentUpdated) {
pallet_im_online::migration::clear_offchain_storage(Session::validators().len() as u32);
}

Executive::offchain_worker(header)
}
}
Expand Down
4 changes: 4 additions & 0 deletions relay/polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ frame-executive = { workspace = true }
frame-metadata-hash-extension = { workspace = true }
pallet-grandpa = { workspace = true }
pallet-identity = { workspace = true }
pallet-im-online = { workspace = true }
pallet-indices = { workspace = true }
pallet-message-queue = { workspace = true }
pallet-mmr = { workspace = true }
Expand Down Expand Up @@ -149,6 +150,7 @@ 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 @@ -224,6 +226,7 @@ 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 @@ -276,6 +279,7 @@ 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
69 changes: 6 additions & 63 deletions relay/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1576,59 +1576,6 @@ impl pallet_asset_rate::Config for Runtime {
type BenchmarkHelper = polkadot_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 @@ -1655,7 +1602,6 @@ 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 Expand Up @@ -1786,17 +1732,8 @@ pub type Migrations = (migrations::Unreleased, migrations::Permanent);
pub mod migrations {
use super::*;

parameter_types! {
pub const ImOnlinePalletName: &'static str = "ImOnline";
}

/// Unreleased migrations. Add new ones here:
pub type Unreleased = (
// Remove `im-online` pallet on-chain storage
frame_support::migrations::RemovePallet<
ImOnlinePalletName,
<Runtime as frame_system::Config>::DbWeight,
>,
parachains_configuration::migration::v12::MigrateToV12<Runtime>,
parachains_inclusion::migration::MigrateToV1<Runtime>,
pallet_staking::migrations::v15::MigrateV14ToV15<Runtime>,
Expand Down Expand Up @@ -1986,6 +1923,12 @@ sp_api::impl_runtime_apis! {

impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
fn offchain_worker(header: &<Block as BlockT>::Header) {
use sp_runtime::{traits::Header, DigestItem};

if header.digest().logs().iter().any(|di| di == &DigestItem::RuntimeEnvironmentUpdated) {
pallet_im_online::migration::clear_offchain_storage(Session::validators().len() as u32);
}

Executive::offchain_worker(header)
}
}
Expand Down

0 comments on commit d0855a4

Please sign in to comment.