Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Prev Previous commit
Next Next commit
Renaming and fixing reversedness
  • Loading branch information
gavofyork committed Oct 19, 2021
commit 9dcb776f1682f0ee1ffffdd38e00e97adfbbe2f2
4 changes: 2 additions & 2 deletions bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ pub type Executive = frame_executive::Executive<
Block,
frame_system::ChainContext<Runtime>,
Runtime,
PalletInstances,
PalletInstancesRevExSystem,
>;

impl_runtime_apis! {
Expand Down Expand Up @@ -474,7 +474,7 @@ impl_runtime_apis! {
list_benchmark!(list, extra, pallet_timestamp, Timestamp);
list_benchmark!(list, extra, pallet_template, TemplateModule);

let storage_info = PalletInstancesWithSystem::storage_info();
let storage_info = PalletInstances::storage_info();

return (list, storage_info)
}
Expand Down
4 changes: 2 additions & 2 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,7 @@ pub type Executive = frame_executive::Executive<
Block,
frame_system::ChainContext<Runtime>,
Runtime,
PalletInstances,
PalletInstancesRevExSystem,
(),
>;

Expand Down Expand Up @@ -1653,7 +1653,7 @@ impl_runtime_apis! {
list_benchmark!(list, extra, pallet_utility, Utility);
list_benchmark!(list, extra, pallet_vesting, Vesting);

let storage_info = PalletInstancesWithSystem::storage_info();
let storage_info = PalletInstances::storage_info();

return (list, storage_info)
}
Expand Down
10 changes: 8 additions & 2 deletions frame/executive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ The default Substrate node template declares the [`Executive`](https://docs.rs/f
```rust
#
/// Executive: handles dispatch to the various modules.
pub type Executive = executive::Executive<Runtime, Block, Context, Runtime, PalletInstances>;
pub type Executive = executive::Executive<
Runtime,
Block,
Context,
Runtime,
PalletInstancesRevExSystem,
>;
```

### Custom `OnRuntimeUpgrade` logic
Expand All @@ -59,7 +65,7 @@ pub type Executive = executive::Executive<
Block,
Context,
Runtime,
PalletInstances,
PalletInstancesRevExSystem,
CustomOnRuntimeUpgrade,
>;
```
Expand Down
48 changes: 25 additions & 23 deletions frame/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
//! # type Context = frame_system::ChainContext<Runtime>;
//! # pub type Block = generic::Block<Header, UncheckedExtrinsic>;
//! # pub type Balances = u64;
//! # pub type PalletInstances = u64;
//! # pub type Pallets = u64;
//! # pub enum Runtime {};
//! # use sp_runtime::transaction_validity::{
//! # TransactionValidity, UnknownTransaction, TransactionSource,
Expand All @@ -73,7 +73,7 @@
//! # }
//! # }
//! /// Executive: handles dispatch to the various modules.
//! pub type Executive = executive::Executive<Runtime, Block, Context, Runtime, PalletInstances>;
//! pub type Executive = executive::Executive<Runtime, Block, Context, Runtime, Pallets>;
//! ```
//!
//! ### Custom `OnRuntimeUpgrade` logic
Expand All @@ -90,7 +90,7 @@
//! # type Context = frame_system::ChainContext<Runtime>;
//! # pub type Block = generic::Block<Header, UncheckedExtrinsic>;
//! # pub type Balances = u64;
//! # pub type PalletInstances = u64;
//! # pub type Pallets = u64;
//! # pub enum Runtime {};
//! # use sp_runtime::transaction_validity::{
//! # TransactionValidity, UnknownTransaction, TransactionSource,
Expand All @@ -116,7 +116,7 @@
//! Block,
//! Context,
//! Runtime,
//! PalletInstances,
//! Pallets,
//! CustomOnRuntimeUpgrade,
//! >;
//! ```
Expand Down Expand Up @@ -155,26 +155,28 @@ pub type OriginOf<E, C> = <CallOf<E, C> as Dispatchable>::Origin;
/// - `Block`: The block type of the runtime
/// - `Context`: The context that is used when checking an extrinsic.
/// - `UnsignedValidator`: The unsigned transaction validator of the runtime.
/// - `PalletInstances`: Tuple that contains all modules. Will be used to call e.g. `on_initialize`.
/// - `PalletInstanceOrder`: Tuple that contains all modules in order used to call e.g.
/// `on_initialize`. Generally this should be the `PalletInstancesRevExSystem` type coming from
/// `construct_runtime` macro. This should exclude the System pallet.
/// - `OnRuntimeUpgrade`: Custom logic that should be called after a runtime upgrade. Modules are
/// already called by `PalletInstances`. It will be called before all modules will be called.
pub struct Executive<System, Block, Context, UnsignedValidator, PalletInstances, OnRuntimeUpgrade = ()>(
PhantomData<(System, Block, Context, UnsignedValidator, PalletInstances, OnRuntimeUpgrade)>,
/// already called by `PalletInstanceOrder`. It will be called before all modules will be called.
pub struct Executive<System, Block, Context, UnsignedValidator, PalletInstanceOrder, OnRuntimeUpgrade = ()>(
PhantomData<(System, Block, Context, UnsignedValidator, PalletInstanceOrder, OnRuntimeUpgrade)>,
);

impl<
System: frame_system::Config + EnsureInherentsAreFirst<Block>,
Block: traits::Block<Header = System::Header, Hash = System::Hash>,
Context: Default,
UnsignedValidator,
PalletInstances: OnRuntimeUpgrade
PalletInstanceOrder: OnRuntimeUpgrade
+ OnInitialize<System::BlockNumber>
+ OnIdle<System::BlockNumber>
+ OnFinalize<System::BlockNumber>
+ OffchainWorker<System::BlockNumber>,
COnRuntimeUpgrade: OnRuntimeUpgrade,
> ExecuteBlock<Block>
for Executive<System, Block, Context, UnsignedValidator, PalletInstances, COnRuntimeUpgrade>
for Executive<System, Block, Context, UnsignedValidator, PalletInstanceOrder, COnRuntimeUpgrade>
where
Block::Extrinsic: Checkable<Context> + Codec,
CheckedOf<Block::Extrinsic, Context>: Applyable + GetDispatchInfo,
Expand All @@ -189,7 +191,7 @@ where
Block,
Context,
UnsignedValidator,
PalletInstances,
PalletInstanceOrder,
COnRuntimeUpgrade,
>::execute_block(block);
}
Expand All @@ -200,13 +202,13 @@ impl<
Block: traits::Block<Header = System::Header, Hash = System::Hash>,
Context: Default,
UnsignedValidator,
PalletInstances: OnRuntimeUpgrade
PalletInstanceOrder: OnRuntimeUpgrade
+ OnInitialize<System::BlockNumber>
+ OnIdle<System::BlockNumber>
+ OnFinalize<System::BlockNumber>
+ OffchainWorker<System::BlockNumber>,
COnRuntimeUpgrade: OnRuntimeUpgrade,
> Executive<System, Block, Context, UnsignedValidator, PalletInstances, COnRuntimeUpgrade>
> Executive<System, Block, Context, UnsignedValidator, PalletInstanceOrder, COnRuntimeUpgrade>
where
Block::Extrinsic: Checkable<Context> + Codec,
CheckedOf<Block::Extrinsic, Context>: Applyable + GetDispatchInfo,
Expand All @@ -222,7 +224,7 @@ where
weight = weight.saturating_add(
<frame_system::Pallet<System> as OnRuntimeUpgrade>::on_runtime_upgrade(),
);
weight = weight.saturating_add(<PalletInstances as OnRuntimeUpgrade>::on_runtime_upgrade());
weight = weight.saturating_add(<PalletInstanceOrder as OnRuntimeUpgrade>::on_runtime_upgrade());

weight
}
Expand Down Expand Up @@ -264,15 +266,15 @@ where
#[cfg(feature = "try-runtime")]
pub fn try_runtime_upgrade() -> Result<frame_support::weights::Weight, &'static str> {
<
(frame_system::Pallet::<System>, COnRuntimeUpgrade, PalletInstances)
(frame_system::Pallet::<System>, COnRuntimeUpgrade, PalletInstanceOrder)
as
OnRuntimeUpgrade
>::pre_upgrade().unwrap();

let weight = Self::execute_on_runtime_upgrade();

<
(frame_system::Pallet::<System>, COnRuntimeUpgrade, PalletInstances)
(frame_system::Pallet::<System>, COnRuntimeUpgrade, PalletInstanceOrder)
as
OnRuntimeUpgrade
>::post_upgrade().unwrap();
Expand Down Expand Up @@ -317,7 +319,7 @@ where
System::BlockNumber,
>>::on_initialize(*block_number));
weight = weight.saturating_add(
<PalletInstances as OnInitialize<System::BlockNumber>>::on_initialize(*block_number),
<PalletInstanceOrder as OnInitialize<System::BlockNumber>>::on_initialize(*block_number),
);
weight = weight.saturating_add(
<System::BlockWeights as frame_support::traits::Get<_>>::get().base_block,
Expand Down Expand Up @@ -432,7 +434,7 @@ where
remaining_weight,
);
remaining_weight = remaining_weight.saturating_sub(used_weight);
used_weight = <PalletInstances as OnIdle<System::BlockNumber>>::on_idle(
used_weight = <PalletInstanceOrder as OnIdle<System::BlockNumber>>::on_idle(
block_number,
remaining_weight,
)
Expand All @@ -446,7 +448,7 @@ where
<frame_system::Pallet<System> as OnFinalize<System::BlockNumber>>::on_finalize(
block_number,
);
<PalletInstances as OnFinalize<System::BlockNumber>>::on_finalize(block_number);
<PalletInstanceOrder as OnFinalize<System::BlockNumber>>::on_finalize(block_number);
}

/// Apply extrinsic outside of the block execution function.
Expand Down Expand Up @@ -575,7 +577,7 @@ where
// as well.
frame_system::BlockHash::<System>::insert(header.number(), header.hash());

<PalletInstances as OffchainWorker<System::BlockNumber>>::offchain_worker(*header.number())
<PalletInstanceOrder as OffchainWorker<System::BlockNumber>>::offchain_worker(*header.number())
}
}

Expand Down Expand Up @@ -857,7 +859,7 @@ mod tests {
Block<TestXt>,
ChainContext<Runtime>,
Runtime,
PalletInstances,
PalletInstancesRevExSystem,
CustomOnRuntimeUpgrade,
>;

Expand Down Expand Up @@ -1370,11 +1372,11 @@ mod tests {
// All weights that show up in the `initialize_block_impl`
let frame_system_upgrade_weight = frame_system::Pallet::<Runtime>::on_runtime_upgrade();
let custom_runtime_upgrade_weight = CustomOnRuntimeUpgrade::on_runtime_upgrade();
let runtime_upgrade_weight = <PalletInstances as OnRuntimeUpgrade>::on_runtime_upgrade();
let runtime_upgrade_weight = <PalletInstanceOrder as OnRuntimeUpgrade>::on_runtime_upgrade();
let frame_system_on_initialize_weight =
frame_system::Pallet::<Runtime>::on_initialize(block_number);
let on_initialize_weight =
<PalletInstances as OnInitialize<u64>>::on_initialize(block_number);
<PalletInstanceOrder as OnInitialize<u64>>::on_initialize(block_number);
let base_block_weight =
<Runtime as frame_system::Config>::BlockWeights::get().base_block;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn expand_outer_config(
#build_storage_calls

#scrate::BasicExternalities::execute_with_storage(storage, || {
<PalletInstancesWithSystem as #scrate::traits::OnGenesis>::on_genesis();
<PalletInstancesRev as #scrate::traits::OnGenesis>::on_genesis();
});

Ok(())
Expand Down
29 changes: 18 additions & 11 deletions frame/support/procedural/src/construct_runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,27 +215,34 @@ fn decl_all_pallets<'a>(
.iter()
.fold(TokenStream2::default(), |combined, name| quote!((#name, #combined)));

let flat_pallets_with_system = quote!( (#( #names ),*) );
let names_without_system = names
.iter()
.filter(|n| **n != SYSTEM_PALLET_NAME);
let flat_pallets = quote!( (#( #names_without_system ),*) );
let pallet_instances = quote!( (#( #names ),*) );
let names_rev = names.iter().rev();
let pallet_instances_rev = quote!( (#( #names_rev ),*) );
let names_ex_sys = names.iter().filter(|n| **n != SYSTEM_PALLET_NAME);
let pallet_instances_ex_sys = quote!( (#( #names_ex_sys ),*) );
let names_rev_ex_sys = names.iter().rev().filter(|n| **n != SYSTEM_PALLET_NAME);
let pallet_instances_rev_ex_sys = quote!( (#( #names_rev_ex_sys ),*) );

quote!(
#types

/// All pallets included in the runtime as a flat tuple of types.
/// Excludes the System pallet.
pub type PalletInstances = ( #flat_pallets );
pub type PalletInstances = ( #pallet_instances );

// TODO: Remove these once executive is not sensitive to ordering.
/// All pallet instances excluding System which are in the runtime as a flat tuple of types.
pub type PalletInstancesExSystem = ( #pallet_instances_ex_sys );
/// All pallet instances excluding System which are in the runtime as a flat tuple of types.
pub type PalletInstancesRev = ( #pallet_instances_rev );
/// All pallets included in the runtime as a flat tuple of types.
pub type PalletInstancesWithSystem = ( #flat_pallets_with_system );
pub type PalletInstancesRevExSystem = ( #pallet_instances_rev_ex_sys );

/// All pallets included in the runtime as a nested tuple of types.
/// Excludes the System pallet.
#[deprecated(note = "use `PalletInstances` instead")]
#[deprecated(note = "use `PalletInstancesRev` (or possibly `PalletInstances`) instead")]
pub type AllPallets = ( #all_pallets );
/// All pallets included in the runtime as a nested tuple of types.
#[deprecated(note = "use `PalletInstancesWithSystem` instead")]
#[deprecated(note = "use `PalletInstancesRevWithSystem` (or possibly `PalletInstancesWithSystem`) instead")]
pub type AllPalletsWithSystem = ( #all_pallets_with_system );

/// All modules included in the runtime as a nested tuple of types.
Expand Down Expand Up @@ -333,7 +340,7 @@ fn decl_integrity_test(scrate: &TokenStream2) -> TokenStream2 {

#[test]
pub fn runtime_integrity_tests() {
<PalletInstancesWithSystem as #scrate::traits::IntegrityTest>::integrity_test();
<PalletInstances as #scrate::traits::IntegrityTest>::integrity_test();
}
}
)
Expand Down
15 changes: 15 additions & 0 deletions frame/support/procedural/src/pallet/expand/pallet_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,21 @@ pub fn expand_pallet_struct(def: &mut Def) -> proc_macro2::TokenStream {
}
}

impl<#type_impl_gen> #frame_support::traits::PalletsInfoAccess
for #pallet_ident<#type_use_gen>
#config_where_clause
{
fn info() -> Option<#frame_support::traits::PalletInfoData> {
use #frame_support::traits::PalletInfoAccess;
Some(#frame_support::traits::PalletInfoData {
index: Self::index(),
name: Self::name(),
module_name: Self::module_name(),
crate_version: Self::crate_version(),
})
}
}

#storage_info
)
}
14 changes: 14 additions & 0 deletions frame/support/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2165,6 +2165,20 @@ macro_rules! decl_module {
}
}

impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $crate::traits::PalletsInfoAccess
for $mod_type<$trait_instance $(, $instance)?> where $( $other_where_bounds )*
{
fn info() -> Option<$crate::traits::PalletInfoData> {
use $crate::traits::PalletInfoAccess;
Some($crate::traits::PalletInfoData {
index: Self::index(),
name: Self::name(),
module_name: Self::module_name(),
crate_version: Self::crate_version(),
})
}
}

// Implement GetCallName for the Call.
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $crate::dispatch::GetCallName
for $call_type<$trait_instance $(, $instance)?> where $( $other_where_bounds )*
Expand Down
4 changes: 2 additions & 2 deletions frame/support/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ impl PalletVersionToStorageVersionHelper for T {
///
/// This will remove all `PalletVersion's` from the state and insert the current storage version.
pub fn migrate_from_pallet_version_to_storage_version<
PalletInstances: PalletVersionToStorageVersionHelper,
Pallets: PalletVersionToStorageVersionHelper,
>(
db_weight: &RuntimeDbWeight,
) -> Weight {
PalletInstances::migrate(db_weight)
Pallets::migrate(db_weight)
}
1 change: 1 addition & 0 deletions frame/support/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ mod metadata;
pub use metadata::{
CallMetadata, CrateVersion, GetCallMetadata, GetCallName, GetStorageVersion, PalletInfo,
PalletInfoAccess, PalletInfoData, StorageVersion, STORAGE_VERSION_STORAGE_KEY_POSTFIX,
PalletsInfoAccess,
};

mod hooks;
Expand Down
Loading