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

[Enhancement] Throw an error when there are too many pallets #13763

Merged
merged 6 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
19 changes: 18 additions & 1 deletion frame/support/procedural/src/construct_runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ use proc_macro::TokenStream;
use proc_macro2::TokenStream as TokenStream2;
use quote::quote;
use std::{collections::HashSet, str::FromStr};
use syn::{Ident, Result};
use syn::{spanned::Spanned, Ident, Result};

/// The fixed name of the system pallet.
const SYSTEM_PALLET_NAME: &str = "System";
Expand All @@ -184,6 +184,23 @@ fn construct_runtime_intermediary_expansion(
input: TokenStream2,
definition: ImplicitRuntimeDeclaration,
) -> Result<TokenStream2> {
let max_pallet_num = {
if cfg!(feature = "tuples-96") {
96
} else if cfg!(feature = "tuples-128") {
128
} else {
64
}
};

if definition.pallets.len() > max_pallet_num {
return Err(syn::Error::new(
input.span(),
"The number of pallets exceeds the maximum number of tuple elements.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should include some information on how to fix this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah like an additional sentence like format!("To increase this limit, enable the tuples-{} feature of [crate]", next_highest_max).as_str()

))
}

let frame_support = generate_crate_access_2018("frame-support")?;
let mut expansion = quote::quote!(
#frame_support::construct_runtime! { #input }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use frame_support::construct_runtime;

construct_runtime! {
pub struct Runtime where
UncheckedExtrinsic = UncheckedExtrinsic,
Block = Block,
NodeBlock = Block,
{
System: system::{},
Pallet1: pallet2::{},
Pallet3: pallet4::{},
Pallet5: pallet6::{},
Pallet7: pallet8::{},
Pallet9: pallet10::{},
Pallet11: pallet12::{},
Pallet13: pallet14::{},
Pallet15: pallet16::{},
Pallet17: pallet18::{},
Pallet19: pallet20::{},
Pallet21: pallet22::{},
Pallet23: pallet24::{},
Pallet25: pallet26::{},
Pallet27: pallet28::{},
Pallet29: pallet30::{},
Pallet31: pallet32::{},
Pallet33: pallet34::{},
Pallet35: pallet36::{},
Pallet37: pallet38::{},
Pallet39: pallet40::{},
Pallet41: pallet42::{},
Pallet43: pallet44::{},
Pallet45: pallet46::{},
Pallet47: pallet48::{},
Pallet49: pallet50::{},
Pallet51: pallet52::{},
Pallet53: pallet54::{},
Pallet55: pallet56::{},
Pallet57: pallet58::{},
Pallet59: pallet60::{},
Pallet61: pallet62::{},
Pallet63: pallet64::{},
Pallet65: pallet66::{},
Pallet67: pallet68::{},
Pallet69: pallet70::{},
Pallet71: pallet72::{},
Pallet73: pallet74::{},
Pallet75: pallet76::{},
Pallet77: pallet78::{},
Pallet79: pallet80::{},
Pallet81: pallet82::{},
Pallet83: pallet84::{},
Pallet85: pallet86::{},
Pallet87: pallet88::{},
Pallet89: pallet90::{},
Pallet91: pallet92::{},
Pallet93: pallet94::{},
Pallet95: pallet96::{},
Pallet97: pallet98::{},
Pallet99: pallet100::{},
Pallet101: pallet102::{},
Pallet103: pallet104::{},
Pallet105: pallet106::{},
Pallet107: pallet108::{},
Pallet109: pallet110::{},
Pallet111: pallet112::{},
Pallet113: pallet114::{},
Pallet115: pallet116::{},
Pallet117: pallet118::{},
Pallet119: pallet120::{},
Pallet121: pallet122::{},
Pallet123: pallet124::{},
Pallet125: pallet126::{},
Pallet127: pallet128::{},
}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12344