Skip to content

Commit

Permalink
Merge branch 'main' into bko-short-benchmarks-get_preset
Browse files Browse the repository at this point in the history
  • Loading branch information
bkontur authored Jul 19, 2024
2 parents 1398b62 + d0855a4 commit 7cce007
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 @@ -57,6 +57,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 @@ -227,6 +229,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 @@ -281,6 +284,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 @@ -1507,59 +1507,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 @@ -1584,7 +1531,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 @@ -1879,6 +1825,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 @@ -54,6 +54,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 @@ -225,6 +227,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 @@ -277,6 +280,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 @@ -1575,59 +1575,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 @@ -1654,7 +1601,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 @@ -1785,17 +1731,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 @@ -1985,6 +1922,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 7cce007

Please sign in to comment.