Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

[WIP]: Construct Runtime v2 #14788

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,23 @@ impl pallet_template::Config for Runtime {
}

// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub struct Runtime {
#[frame_support::construct_runtime_v2]
mod runtime {
#[frame::runtime]
pub struct Runtime;

#[frame::pallets]
#[frame::derive(
RuntimeCall,
RuntimeEvent,
RuntimeError,
RuntimeOrigin,
RuntimeFreezeReason,
RuntimeHoldReason,
RuntimeSlashReason,
RuntimeLockId
)]
pub struct Pallets {
System: frame_system,
Timestamp: pallet_timestamp,
Aura: pallet_aura,
Expand All @@ -289,9 +304,11 @@ construct_runtime!(
TransactionPayment: pallet_transaction_payment,
Sudo: pallet_sudo,
// Include the custom logic from the pallet-template in the runtime.
#[frame::pallet_index(8)]
#[frame::disable_call]
TemplateModule: pallet_template,
}
);
}

/// The address format for describing accounts.
pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
Expand Down
31 changes: 17 additions & 14 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use frame_election_provider_support::{
onchain, BalancingConfig, ElectionDataProvider, SequentialPhragmen, VoteWeight,
};
use frame_support::{
construct_runtime,
dispatch::DispatchClass,
instances::{Instance1, Instance2},
ord_parameter_types,
Expand Down Expand Up @@ -1876,9 +1875,13 @@ impl pallet_statement::Config for Runtime {
type MaxAllowedBytes = MaxAllowedBytes;
}

construct_runtime!(
pub struct Runtime
{
#[frame_support::construct_runtime_v2]
mod runtime {
#[frame::runtime]
pub struct Runtime;

#[frame::pallets]
pub struct Pallets {
System: frame_system,
Utility: pallet_utility,
Babe: pallet_babe,
Expand All @@ -1895,10 +1898,10 @@ construct_runtime!(
Staking: pallet_staking,
Session: pallet_session,
Democracy: pallet_democracy,
Council: pallet_collective::<Instance1>,
TechnicalCommittee: pallet_collective::<Instance2>,
Council: pallet_collective<Instance1>,
TechnicalCommittee: pallet_collective<Instance2>,
Elections: pallet_elections_phragmen,
TechnicalMembership: pallet_membership::<Instance1>,
TechnicalMembership: pallet_membership<Instance1>,
Grandpa: pallet_grandpa,
Treasury: pallet_treasury,
AssetRate: pallet_asset_rate,
Expand All @@ -1907,7 +1910,7 @@ construct_runtime!(
ImOnline: pallet_im_online,
AuthorityDiscovery: pallet_authority_discovery,
Offences: pallet_offences,
Historical: pallet_session_historical::{Pallet},
Historical: pallet_session_historical + Pallet,
RandomnessCollectiveFlip: pallet_insecure_randomness_collective_flip,
Identity: pallet_identity,
Society: pallet_society,
Expand All @@ -1920,8 +1923,8 @@ construct_runtime!(
Multisig: pallet_multisig,
Bounties: pallet_bounties,
Tips: pallet_tips,
Assets: pallet_assets::<Instance1>,
PoolAssets: pallet_assets::<Instance2>,
Assets: pallet_assets<Instance1>,
PoolAssets: pallet_assets<Instance2>,
Mmr: pallet_mmr,
Lottery: pallet_lottery,
Nis: pallet_nis,
Expand All @@ -1931,26 +1934,26 @@ construct_runtime!(
Salary: pallet_salary,
CoreFellowship: pallet_core_fellowship,
TransactionStorage: pallet_transaction_storage,
VoterList: pallet_bags_list::<Instance1>,
VoterList: pallet_bags_list<Instance1>,
StateTrieMigration: pallet_state_trie_migration,
ChildBounties: pallet_child_bounties,
Referenda: pallet_referenda,
Remark: pallet_remark,
RootTesting: pallet_root_testing,
ConvictionVoting: pallet_conviction_voting,
Whitelist: pallet_whitelist,
AllianceMotion: pallet_collective::<Instance3>,
AllianceMotion: pallet_collective<Instance3>,
Alliance: pallet_alliance,
NominationPools: pallet_nomination_pools,
RankedPolls: pallet_referenda::<Instance2>,
RankedPolls: pallet_referenda<Instance2>,
RankedCollective: pallet_ranked_collective,
AssetConversion: pallet_asset_conversion,
FastUnstake: pallet_fast_unstake,
MessageQueue: pallet_message_queue,
Pov: frame_benchmarking_pallet_pov,
Statement: pallet_statement,
}
);
}

/// The address format for describing accounts.
pub type Address = sp_runtime::MultiAddress<AccountId, AccountIndex>;
Expand Down
14 changes: 7 additions & 7 deletions frame/support/procedural/src/construct_runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@
//! This macro returns the ` :: expanded { Error }` list of additional parts we would like to
//! expose.

mod expand;
mod parse;
pub mod expand;
pub mod parse;

use cfg_expr::Predicate;
use frame_support_procedural_tools::{
Expand Down Expand Up @@ -496,7 +496,7 @@ fn construct_runtime_final_expansion(
Ok(res)
}

fn decl_all_pallets<'a>(
pub fn decl_all_pallets<'a>(
runtime: &'a Ident,
pallet_declarations: impl Iterator<Item = &'a Pallet>,
features: &HashSet<&str>,
Expand Down Expand Up @@ -660,7 +660,7 @@ fn decl_all_pallets<'a>(
)
}

fn decl_pallet_runtime_setup(
pub fn decl_pallet_runtime_setup(
runtime: &Ident,
pallet_declarations: &[Pallet],
scrate: &TokenStream2,
Expand Down Expand Up @@ -752,7 +752,7 @@ fn decl_pallet_runtime_setup(
)
}

fn decl_integrity_test(scrate: &TokenStream2) -> TokenStream2 {
pub fn decl_integrity_test(scrate: &TokenStream2) -> TokenStream2 {
quote!(
#[cfg(test)]
mod __construct_runtime_integrity_test {
Expand All @@ -767,7 +767,7 @@ fn decl_integrity_test(scrate: &TokenStream2) -> TokenStream2 {
)
}

fn decl_static_assertions(
pub fn decl_static_assertions(
runtime: &Ident,
pallet_decls: &[Pallet],
scrate: &TokenStream2,
Expand Down Expand Up @@ -798,7 +798,7 @@ fn decl_static_assertions(
}
}

fn check_pallet_number(input: TokenStream2, pallet_num: usize) -> Result<()> {
pub fn check_pallet_number(input: TokenStream2, pallet_num: usize) -> Result<()> {
let max_pallet_num = {
if cfg!(feature = "tuples-96") {
96
Expand Down
8 changes: 4 additions & 4 deletions frame/support/procedural/src/construct_runtime/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ impl Parse for PalletPartKeyword {

impl PalletPartKeyword {
/// Returns the name of `Self`.
fn name(&self) -> &'static str {
pub fn name(&self) -> &'static str {
match self {
Self::Pallet(_) => "Pallet",
Self::Call(_) => "Call",
Expand All @@ -465,12 +465,12 @@ impl PalletPartKeyword {
}

/// Returns `true` if this pallet part is allowed to have generic arguments.
fn allows_generic(&self) -> bool {
pub fn allows_generic(&self) -> bool {
Self::all_generic_arg().iter().any(|n| *n == self.name())
}

/// Returns the names of all pallet parts that allow to have a generic argument.
fn all_generic_arg() -> &'static [&'static str] {
pub fn all_generic_arg() -> &'static [&'static str] {
&["Event", "Error", "Origin", "Config"]
}
}
Expand Down Expand Up @@ -552,7 +552,7 @@ fn remove_kind(
/// The declaration of a part without its generics
#[derive(Debug, Clone)]
pub struct PalletPartNoGeneric {
keyword: PalletPartKeyword,
pub keyword: PalletPartKeyword,
}

impl Parse for PalletPartNoGeneric {
Expand Down
Loading