rococo-runtime: Switch to latest construct_runtime! syntax (#4389)

* rococo-runtime: Switch to latest `construct_runtime!` syntax

Besides that it fixes pallet macro errors in other crates that popped up
because of this switch.

* FMT
This commit is contained in:
Bastian Köcher
2021-11-29 21:36:19 +01:00
committed by GitHub
parent b64caf97bf
commit 49d78d99f7
12 changed files with 137 additions and 139 deletions
+42 -43
View File
@@ -202,54 +202,54 @@ construct_runtime! {
NodeBlock = primitives::v1::Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: frame_system::{Pallet, Call, Storage, Config, Event<T>},
System: frame_system,
// Must be before session.
Babe: pallet_babe::{Pallet, Call, Storage, Config, ValidateUnsigned},
Babe: pallet_babe,
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
Indices: pallet_indices::{Pallet, Call, Storage, Config<T>, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
TransactionPayment: pallet_transaction_payment::{Pallet, Storage},
Timestamp: pallet_timestamp,
Indices: pallet_indices,
Balances: pallet_balances,
TransactionPayment: pallet_transaction_payment,
// Consensus support.
Authorship: pallet_authorship::{Pallet, Call, Storage},
Offences: pallet_offences::{Pallet, Storage, Event},
Historical: session_historical::{Pallet},
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>},
Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event, ValidateUnsigned},
ImOnline: pallet_im_online::{Pallet, Call, Storage, Event<T>, ValidateUnsigned, Config<T>},
AuthorityDiscovery: pallet_authority_discovery::{Pallet, Config},
Authorship: pallet_authorship,
Offences: pallet_offences,
Historical: session_historical,
Session: pallet_session,
Grandpa: pallet_grandpa,
ImOnline: pallet_im_online,
AuthorityDiscovery: pallet_authority_discovery,
// Parachains modules.
ParachainsOrigin: parachains_origin::{Pallet, Origin},
Configuration: parachains_configuration::{Pallet, Call, Storage, Config<T>},
ParasShared: parachains_shared::{Pallet, Call, Storage},
ParaInclusion: parachains_inclusion::{Pallet, Call, Storage, Event<T>},
ParaInherent: parachains_paras_inherent::{Pallet, Call, Storage, Inherent},
ParaScheduler: parachains_scheduler::{Pallet, Storage},
Paras: parachains_paras::{Pallet, Call, Storage, Event, Config},
Initializer: parachains_initializer::{Pallet, Call, Storage},
Dmp: parachains_dmp::{Pallet, Call, Storage},
Ump: parachains_ump::{Pallet, Call, Storage, Event},
Hrmp: parachains_hrmp::{Pallet, Call, Storage, Event<T>, Config},
ParaSessionInfo: parachains_session_info::{Pallet, Storage},
ParasDisputes: parachains_disputes::{Pallet, Call, Storage, Event<T>},
ParachainsOrigin: parachains_origin,
Configuration: parachains_configuration,
ParasShared: parachains_shared,
ParaInclusion: parachains_inclusion,
ParaInherent: parachains_paras_inherent,
ParaScheduler: parachains_scheduler,
Paras: parachains_paras,
Initializer: parachains_initializer,
Dmp: parachains_dmp,
Ump: parachains_ump,
Hrmp: parachains_hrmp,
ParaSessionInfo: parachains_session_info,
ParasDisputes: parachains_disputes,
// Parachain Onboarding Pallets
Registrar: paras_registrar::{Pallet, Call, Storage, Event<T>, Config},
Auctions: auctions::{Pallet, Call, Storage, Event<T>},
Crowdloan: crowdloan::{Pallet, Call, Storage, Event<T>},
Slots: slots::{Pallet, Call, Storage, Event<T>},
ParasSudoWrapper: paras_sudo_wrapper::{Pallet, Call},
Registrar: paras_registrar,
Auctions: auctions,
Crowdloan: crowdloan,
Slots: slots,
ParasSudoWrapper: paras_sudo_wrapper,
// Sudo
Sudo: pallet_sudo::{Pallet, Call, Storage, Event<T>, Config<T>},
Sudo: pallet_sudo,
// Bridges support.
Mmr: pallet_mmr::{Pallet, Storage},
Beefy: pallet_beefy::{Pallet, Config<T>, Storage},
MmrLeaf: pallet_beefy_mmr::{Pallet, Storage},
Mmr: pallet_mmr,
Beefy: pallet_beefy,
MmrLeaf: pallet_beefy_mmr,
// It might seem strange that we add both sides of the bridge to the same runtime. We do this because this
// runtime as shared by both the Rococo and Wococo chains. When running as Rococo we only use
@@ -258,7 +258,7 @@ construct_runtime! {
// BridgeWococoGrandpa: pallet_bridge_grandpa::<Instance1>::{Pallet, Call, Storage, Config<T>} = 41,
// Validator Manager pallet.
ValidatorManager: validator_manager::{Pallet, Call, Storage, Event<T>},
ValidatorManager: validator_manager,
// Bridge messages support. The same story as with the bridge grandpa pallet above ^^^ - when we're
// running as Rococo we only use `BridgeWococoMessages`/`BridgeWococoMessagesDispatch`, and vice versa.
@@ -268,15 +268,15 @@ construct_runtime! {
// BridgeWococoMessagesDispatch: pallet_bridge_dispatch::<Instance1>::{Pallet, Event<T>} = 46,
// A "council"
Collective: pallet_collective::{Pallet, Call, Storage, Origin<T>, Event<T>, Config<T>} = 80,
Membership: pallet_membership::{Pallet, Call, Storage, Event<T>, Config<T>} = 81,
Collective: pallet_collective = 80,
Membership: pallet_membership = 81,
Utility: pallet_utility::{Pallet, Call, Event} = 90,
Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 91,
Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>},
Utility: pallet_utility = 90,
Proxy: pallet_proxy = 91,
Multisig: pallet_multisig,
// Pallet for sending XCM.
XcmPallet: pallet_xcm::{Pallet, Call, Storage, Event<T>, Origin, Config} = 99,
XcmPallet: pallet_xcm = 99,
}
}
@@ -614,7 +614,6 @@ impl parachains_inclusion::Config for Runtime {
}
impl parachains_paras::Config for Runtime {
type Origin = Origin;
type Event = Event;
type WeightInfo = weights::runtime_parachains_paras::WeightInfo<Runtime>;
}
@@ -16,84 +16,87 @@
//! A pallet for managing validators on Rococo.
use frame_support::{decl_error, decl_event, decl_module, decl_storage, traits::EnsureOrigin};
use sp_staking::SessionIndex;
use sp_std::vec::Vec;
pub use pallet::*;
type Session<T> = pallet_session::Pallet<T>;
/// Configuration for the parachain proposer.
pub trait Config: pallet_session::Config {
/// The overreaching event type.
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::{dispatch::DispatchResult, pallet_prelude::*, traits::EnsureOrigin};
use frame_system::pallet_prelude::*;
/// Privileged origin that can add or remove validators.
type PrivilegedOrigin: EnsureOrigin<<Self as frame_system::Config>::Origin>;
}
#[pallet::pallet]
pub struct Pallet<T>(_);
decl_event! {
pub enum Event<T> where ValidatorId = <T as pallet_session::Config>::ValidatorId {
/// Configuration for the parachain proposer.
#[pallet::config]
pub trait Config: frame_system::Config + pallet_session::Config {
/// The overreaching event type.
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
/// Privileged origin that can add or remove validators.
type PrivilegedOrigin: EnsureOrigin<<Self as frame_system::Config>::Origin>;
}
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// New validators were added to the set.
ValidatorsRegistered(Vec<ValidatorId>),
ValidatorsRegistered(Vec<T::ValidatorId>),
/// Validators were removed from the set.
ValidatorsDeregistered(Vec<ValidatorId>),
ValidatorsDeregistered(Vec<T::ValidatorId>),
}
}
decl_error! {
pub enum Error for Module<T: Config> {}
}
/// Validators that should be retired, because their Parachain was deregistered.
#[pallet::storage]
pub(crate) type ValidatorsToRetire<T: Config> =
StorageValue<_, Vec<T::ValidatorId>, ValueQuery>;
decl_storage! {
trait Store for Module<T: Config> as ParachainProposer {
/// Validators that should be retired, because their Parachain was deregistered.
ValidatorsToRetire: Vec<T::ValidatorId>;
/// Validators that should be added.
ValidatorsToAdd: Vec<T::ValidatorId>;
}
}
decl_module! {
pub struct Module<T: Config> for enum Call where origin: <T as frame_system::Config>::Origin {
type Error = Error<T>;
fn deposit_event() = default;
/// Validators that should be added.
#[pallet::storage]
pub(crate) type ValidatorsToAdd<T: Config> = StorageValue<_, Vec<T::ValidatorId>, ValueQuery>;
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Add new validators to the set.
///
/// The new validators will be active from current session + 2.
#[weight = 100_000]
fn register_validators(
origin,
#[pallet::weight(100_000)]
pub fn register_validators(
origin: OriginFor<T>,
validators: Vec<T::ValidatorId>,
) {
) -> DispatchResult {
T::PrivilegedOrigin::ensure_origin(origin)?;
validators.clone().into_iter().for_each(|v| ValidatorsToAdd::<T>::append(v));
Self::deposit_event(RawEvent::ValidatorsRegistered(validators));
Self::deposit_event(Event::ValidatorsRegistered(validators));
Ok(())
}
/// Remove validators from the set.
///
/// The removed validators will be deactivated from current session + 2.
#[weight = 100_000]
fn deregister_validators(
origin,
#[pallet::weight(100_000)]
pub fn deregister_validators(
origin: OriginFor<T>,
validators: Vec<T::ValidatorId>,
) {
) -> DispatchResult {
T::PrivilegedOrigin::ensure_origin(origin)?;
validators.clone().into_iter().for_each(|v| ValidatorsToRetire::<T>::append(v));
Self::deposit_event(RawEvent::ValidatorsDeregistered(validators));
Self::deposit_event(Event::ValidatorsDeregistered(validators));
Ok(())
}
}
}
impl<T: Config> Module<T> {}
impl<T: Config> pallet_session::SessionManager<T::ValidatorId> for Module<T> {
impl<T: Config> pallet_session::SessionManager<T::ValidatorId> for Pallet<T> {
fn new_session(new_index: SessionIndex) -> Option<Vec<T::ValidatorId>> {
if new_index <= 1 {
return None
@@ -121,7 +124,7 @@ impl<T: Config> pallet_session::SessionManager<T::ValidatorId> for Module<T> {
fn start_session(_start_index: SessionIndex) {}
}
impl<T: Config> pallet_session::historical::SessionManager<T::ValidatorId, ()> for Module<T> {
impl<T: Config> pallet_session::historical::SessionManager<T::ValidatorId, ()> for Pallet<T> {
fn new_session(new_index: SessionIndex) -> Option<Vec<(T::ValidatorId, ())>> {
<Self as pallet_session::SessionManager<_>>::new_session(new_index)
.map(|r| r.into_iter().map(|v| (v, Default::default())).collect())