mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 09:51:02 +00:00
Remove im-online pallet from Rococo and Westend (#2265)
Co-authored-by: ordian <write@reusable.software> Co-authored-by: Vladimir Istyufeev <vladimir@parity.io>
This commit is contained in:
@@ -41,7 +41,6 @@ use frame_support::{
|
||||
use frame_system::EnsureRoot;
|
||||
use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId};
|
||||
use pallet_identity::legacy::IdentityInfo;
|
||||
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
|
||||
use pallet_session::historical as session_historical;
|
||||
use pallet_transaction_payment::{CurrencyAdapter, FeeDetails, RuntimeDispatchInfo};
|
||||
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
|
||||
@@ -88,7 +87,8 @@ use sp_runtime::{
|
||||
IdentityLookup, Keccak256, OpaqueKeys, SaturatedConversion, Verify,
|
||||
},
|
||||
transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity},
|
||||
ApplyExtrinsicResult, FixedU128, KeyTypeId, Perbill, Percent, Permill,
|
||||
ApplyExtrinsicResult, BoundToRuntimeAppPublic, FixedU128, KeyTypeId, Perbill, Percent, Permill,
|
||||
RuntimeAppPublic,
|
||||
};
|
||||
use sp_staking::SessionIndex;
|
||||
use sp_std::{collections::btree_map::BTreeMap, prelude::*};
|
||||
@@ -417,7 +417,7 @@ impl pallet_timestamp::Config for Runtime {
|
||||
|
||||
impl pallet_authorship::Config for Runtime {
|
||||
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Babe>;
|
||||
type EventHandler = (Staking, ImOnline);
|
||||
type EventHandler = Staking;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
@@ -425,11 +425,50 @@ parameter_types! {
|
||||
pub const Offset: BlockNumber = 0;
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Encode, Decode)]
|
||||
pub struct OldSessionKeys {
|
||||
pub grandpa: <Grandpa as BoundToRuntimeAppPublic>::Public,
|
||||
pub babe: <Babe as BoundToRuntimeAppPublic>::Public,
|
||||
pub im_online: pallet_im_online::sr25519::AuthorityId,
|
||||
pub para_validator: <Initializer as BoundToRuntimeAppPublic>::Public,
|
||||
pub para_assignment: <ParaSessionInfo as BoundToRuntimeAppPublic>::Public,
|
||||
pub authority_discovery: <AuthorityDiscovery as BoundToRuntimeAppPublic>::Public,
|
||||
pub beefy: <Beefy as BoundToRuntimeAppPublic>::Public,
|
||||
}
|
||||
|
||||
impl OpaqueKeys for OldSessionKeys {
|
||||
type KeyTypeIdProviders = ();
|
||||
fn key_ids() -> &'static [KeyTypeId] {
|
||||
&[
|
||||
<<Grandpa as BoundToRuntimeAppPublic>::Public>::ID,
|
||||
<<Babe as BoundToRuntimeAppPublic>::Public>::ID,
|
||||
sp_core::crypto::key_types::IM_ONLINE,
|
||||
<<Initializer as BoundToRuntimeAppPublic>::Public>::ID,
|
||||
<<ParaSessionInfo as BoundToRuntimeAppPublic>::Public>::ID,
|
||||
<<AuthorityDiscovery as BoundToRuntimeAppPublic>::Public>::ID,
|
||||
<<Beefy as BoundToRuntimeAppPublic>::Public>::ID,
|
||||
]
|
||||
}
|
||||
fn get_raw(&self, i: KeyTypeId) -> &[u8] {
|
||||
match i {
|
||||
<<Grandpa as BoundToRuntimeAppPublic>::Public>::ID => self.grandpa.as_ref(),
|
||||
<<Babe as BoundToRuntimeAppPublic>::Public>::ID => self.babe.as_ref(),
|
||||
sp_core::crypto::key_types::IM_ONLINE => self.im_online.as_ref(),
|
||||
<<Initializer as BoundToRuntimeAppPublic>::Public>::ID => self.para_validator.as_ref(),
|
||||
<<ParaSessionInfo as BoundToRuntimeAppPublic>::Public>::ID =>
|
||||
self.para_assignment.as_ref(),
|
||||
<<AuthorityDiscovery as BoundToRuntimeAppPublic>::Public>::ID =>
|
||||
self.authority_discovery.as_ref(),
|
||||
<<Beefy as BoundToRuntimeAppPublic>::Public>::ID => self.beefy.as_ref(),
|
||||
_ => &[],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl_opaque_keys! {
|
||||
pub struct SessionKeys {
|
||||
pub grandpa: Grandpa,
|
||||
pub babe: Babe,
|
||||
pub im_online: ImOnline,
|
||||
pub para_validator: Initializer,
|
||||
pub para_assignment: ParaSessionInfo,
|
||||
pub authority_discovery: AuthorityDiscovery,
|
||||
@@ -437,6 +476,18 @@ impl_opaque_keys! {
|
||||
}
|
||||
}
|
||||
|
||||
// remove this when removing `OldSessionKeys`
|
||||
fn transform_session_keys(_v: AccountId, old: OldSessionKeys) -> SessionKeys {
|
||||
SessionKeys {
|
||||
grandpa: old.grandpa,
|
||||
babe: old.babe,
|
||||
para_validator: old.para_validator,
|
||||
para_assignment: old.para_assignment,
|
||||
authority_discovery: old.authority_discovery,
|
||||
beefy: old.beefy,
|
||||
}
|
||||
}
|
||||
|
||||
impl pallet_session::Config for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type ValidatorId = AccountId;
|
||||
@@ -744,19 +795,6 @@ impl pallet_authority_discovery::Config for Runtime {
|
||||
|
||||
parameter_types! {
|
||||
pub const NposSolutionPriority: TransactionPriority = TransactionPriority::max_value() / 2;
|
||||
pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value();
|
||||
}
|
||||
|
||||
impl pallet_im_online::Config for Runtime {
|
||||
type AuthorityId = ImOnlineId;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type ValidatorSet = Historical;
|
||||
type NextSessionRotation = Babe;
|
||||
type ReportUnresponsiveness = Offences;
|
||||
type UnsignedPriority = ImOnlineUnsignedPriority;
|
||||
type WeightInfo = weights::pallet_im_online::WeightInfo<Runtime>;
|
||||
type MaxKeys = MaxKeys;
|
||||
type MaxPeerInHeartbeats = MaxPeerInHeartbeats;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
@@ -986,7 +1024,6 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
|
||||
RuntimeCall::Staking(..) |
|
||||
RuntimeCall::Session(..) |
|
||||
RuntimeCall::Grandpa(..) |
|
||||
RuntimeCall::ImOnline(..) |
|
||||
RuntimeCall::Utility(..) |
|
||||
RuntimeCall::Identity(..) |
|
||||
RuntimeCall::ConvictionVoting(..) |
|
||||
@@ -1374,8 +1411,7 @@ construct_runtime! {
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>} = 26,
|
||||
|
||||
// Consensus support.
|
||||
// Authorship must be before session in order to note author in the correct session and era
|
||||
// for im-online and staking.
|
||||
// Authorship must be before session in order to note author in the correct session and era.
|
||||
Authorship: pallet_authorship::{Pallet, Storage} = 5,
|
||||
Staking: pallet_staking::{Pallet, Call, Storage, Config<T>, Event<T>} = 6,
|
||||
Offences: pallet_offences::{Pallet, Storage, Event} = 7,
|
||||
@@ -1390,7 +1426,6 @@ construct_runtime! {
|
||||
|
||||
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>} = 8,
|
||||
Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config<T>, Event, ValidateUnsigned} = 10,
|
||||
ImOnline: pallet_im_online::{Pallet, Call, Storage, Event<T>, ValidateUnsigned, Config<T>} = 11,
|
||||
AuthorityDiscovery: pallet_authority_discovery::{Pallet, Config<T>} = 12,
|
||||
|
||||
// Utility module.
|
||||
@@ -1522,10 +1557,88 @@ pub type Migrations = migrations::Unreleased;
|
||||
#[allow(deprecated, missing_docs)]
|
||||
pub mod migrations {
|
||||
use super::*;
|
||||
#[cfg(feature = "try-runtime")]
|
||||
use sp_core::crypto::ByteArray;
|
||||
|
||||
parameter_types! {
|
||||
pub const ImOnlinePalletName: &'static str = "ImOnline";
|
||||
}
|
||||
|
||||
/// Upgrade Session keys to exclude `ImOnline` key.
|
||||
/// When this is removed, should also remove `OldSessionKeys`.
|
||||
pub struct UpgradeSessionKeys;
|
||||
const UPGRADE_SESSION_KEYS_FROM_SPEC: u32 = 104000;
|
||||
|
||||
impl frame_support::traits::OnRuntimeUpgrade for UpgradeSessionKeys {
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, sp_runtime::TryRuntimeError> {
|
||||
if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC {
|
||||
log::warn!(target: "runtime::session_keys", "Skipping session keys migration pre-upgrade check due to spec version (already applied?)");
|
||||
return Ok(Vec::new())
|
||||
}
|
||||
|
||||
log::info!(target: "runtime::session_keys", "Collecting pre-upgrade session keys state");
|
||||
let key_ids = SessionKeys::key_ids();
|
||||
frame_support::ensure!(
|
||||
key_ids.into_iter().find(|&k| *k == sp_core::crypto::key_types::IM_ONLINE) == None,
|
||||
"New session keys contain the ImOnline key that should have been removed",
|
||||
);
|
||||
let storage_key = pallet_session::QueuedKeys::<Runtime>::hashed_key();
|
||||
let mut state: Vec<u8> = Vec::new();
|
||||
frame_support::storage::unhashed::get::<Vec<(ValidatorId, OldSessionKeys)>>(
|
||||
&storage_key,
|
||||
)
|
||||
.ok_or::<sp_runtime::TryRuntimeError>("Queued keys are not available".into())?
|
||||
.into_iter()
|
||||
.for_each(|(id, keys)| {
|
||||
state.extend_from_slice(id.as_slice());
|
||||
for key_id in key_ids {
|
||||
state.extend_from_slice(keys.get_raw(*key_id));
|
||||
}
|
||||
});
|
||||
frame_support::ensure!(state.len() > 0, "Queued keys are not empty before upgrade");
|
||||
Ok(state)
|
||||
}
|
||||
|
||||
fn on_runtime_upgrade() -> Weight {
|
||||
if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC {
|
||||
log::warn!("Skipping session keys upgrade: already applied");
|
||||
return <Runtime as frame_system::Config>::DbWeight::get().reads(1)
|
||||
}
|
||||
log::info!("Upgrading session keys");
|
||||
Session::upgrade_keys::<OldSessionKeys, _>(transform_session_keys);
|
||||
Perbill::from_percent(50) * BlockWeights::get().max_block
|
||||
}
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn post_upgrade(
|
||||
old_state: sp_std::vec::Vec<u8>,
|
||||
) -> Result<(), sp_runtime::TryRuntimeError> {
|
||||
if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC {
|
||||
log::warn!(target: "runtime::session_keys", "Skipping session keys migration post-upgrade check due to spec version (already applied?)");
|
||||
return Ok(())
|
||||
}
|
||||
|
||||
let key_ids = SessionKeys::key_ids();
|
||||
let mut new_state: Vec<u8> = Vec::new();
|
||||
pallet_session::QueuedKeys::<Runtime>::get().into_iter().for_each(|(id, keys)| {
|
||||
new_state.extend_from_slice(id.as_slice());
|
||||
for key_id in key_ids {
|
||||
new_state.extend_from_slice(keys.get_raw(*key_id));
|
||||
}
|
||||
});
|
||||
frame_support::ensure!(new_state.len() > 0, "Queued keys are not empty after upgrade");
|
||||
frame_support::ensure!(
|
||||
old_state == new_state,
|
||||
"Pre-upgrade and post-upgrade keys do not match!"
|
||||
);
|
||||
log::info!(target: "runtime::session_keys", "Session keys migrated successfully");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Unreleased migrations. Add new ones here:
|
||||
pub type Unreleased = (
|
||||
pallet_im_online::migration::v1::Migration<Runtime>,
|
||||
parachains_configuration::migration::v7::MigrateToV7<Runtime>,
|
||||
pallet_staking::migrations::v14::MigrateToV14<Runtime>,
|
||||
assigned_slots::migration::v1::MigrateToV1<Runtime>,
|
||||
@@ -1537,6 +1650,11 @@ pub mod migrations {
|
||||
pallet_grandpa::migrations::MigrateV4ToV5<Runtime>,
|
||||
parachains_configuration::migration::v10::MigrateToV10<Runtime>,
|
||||
pallet_nomination_pools::migration::versioned::V7ToV8<Runtime>,
|
||||
UpgradeSessionKeys,
|
||||
frame_support::migrations::RemovePallet<
|
||||
ImOnlinePalletName,
|
||||
<Runtime as frame_system::Config>::DbWeight,
|
||||
>,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1583,7 +1701,6 @@ mod benches {
|
||||
[frame_election_provider_support, ElectionProviderBench::<Runtime>]
|
||||
[pallet_fast_unstake, FastUnstake]
|
||||
[pallet_identity, Identity]
|
||||
[pallet_im_online, ImOnline]
|
||||
[pallet_indices, Indices]
|
||||
[pallet_message_queue, MessageQueue]
|
||||
[pallet_multisig, Multisig]
|
||||
|
||||
Reference in New Issue
Block a user