diff --git a/substrate/bin/node-template/runtime/src/lib.rs b/substrate/bin/node-template/runtime/src/lib.rs index 60d8b7485d..8580bfd895 100644 --- a/substrate/bin/node-template/runtime/src/lib.rs +++ b/substrate/bin/node-template/runtime/src/lib.rs @@ -251,7 +251,7 @@ construct_runtime!( Aura: aura::{Module, Config, Inherent(Timestamp)}, Grandpa: grandpa::{Module, Call, Storage, Config, Event}, Indices: indices, - Balances: balances::{default, Error}, + Balances: balances, TransactionPayment: transaction_payment::{Module, Storage}, Sudo: sudo, // Used for the module template in `./template.rs` diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 679bad2371..7a8ba7613b 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -527,14 +527,14 @@ construct_runtime!( UncheckedExtrinsic = UncheckedExtrinsic { System: frame_system::{Module, Call, Storage, Config, Event}, - Utility: pallet_utility::{Module, Call, Storage, Event, Error}, + Utility: pallet_utility::{Module, Call, Storage, Event}, Babe: pallet_babe::{Module, Call, Storage, Config, Inherent(Timestamp)}, Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent}, Authorship: pallet_authorship::{Module, Call, Storage, Inherent}, Indices: pallet_indices, - Balances: pallet_balances::{default, Error}, + Balances: pallet_balances, TransactionPayment: pallet_transaction_payment::{Module, Storage}, - Staking: pallet_staking::{default, OfflineWorker}, + Staking: pallet_staking, Session: pallet_session::{Module, Call, Storage, Event, Config}, Democracy: pallet_democracy::{Module, Call, Storage, Config, Event}, Council: pallet_collective::::{Module, Call, Storage, Origin, Event, Config}, diff --git a/substrate/frame/elections/src/mock.rs b/substrate/frame/elections/src/mock.rs index c53789f7ad..93efb71355 100644 --- a/substrate/frame/elections/src/mock.rs +++ b/substrate/frame/elections/src/mock.rs @@ -154,7 +154,7 @@ frame_support::construct_runtime!( UncheckedExtrinsic = UncheckedExtrinsic { System: system::{Module, Call, Event}, - Balances: pallet_balances::{Module, Call, Event, Config, Error}, + Balances: pallet_balances::{Module, Call, Event, Config}, Elections: elections::{Module, Call, Event, Config}, } ); diff --git a/substrate/frame/support/procedural/Cargo.toml b/substrate/frame/support/procedural/Cargo.toml index 9280289028..321002e08b 100644 --- a/substrate/frame/support/procedural/Cargo.toml +++ b/substrate/frame/support/procedural/Cargo.toml @@ -9,7 +9,6 @@ proc-macro = true [dependencies] frame-support-procedural-tools = { version = "2.0.0", path = "./tools" } - proc-macro2 = "1.0.6" quote = "1.0.2" syn = { version = "1.0.7", features = ["full"] } diff --git a/substrate/frame/support/procedural/src/construct_runtime/parse.rs b/substrate/frame/support/procedural/src/construct_runtime/parse.rs index 84ac6573c6..14dd18cb06 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/parse.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/parse.rs @@ -180,8 +180,8 @@ impl Parse for ModuleDeclaration { let has_default = parts.into_iter().any(|m| m.is_default()); for entry in parts { match entry { - ModuleEntry::Part(part) if has_default => { - if part.is_included_in_default() { + ModuleEntry::Part(part) => { + if has_default && part.is_included_in_default() { let msg = format!( "`{}` is already included in `default`. Either remove `default` or remove `{}`", part.name, @@ -189,8 +189,7 @@ impl Parse for ModuleDeclaration { ); return Err(Error::new(part.name.span(), msg)); } - } - ModuleEntry::Part(part) => { + if !resolved.insert(part.name.clone()) { let msg = format!( "`{}` was already declared before. Please remove the duplicate declaration", @@ -287,7 +286,18 @@ pub struct ModulePart { impl Parse for ModulePart { fn parse(input: ParseStream) -> Result { - let name = input.parse()?; + let name: Ident = input.parse()?; + + if !ModulePart::all_allowed().iter().any(|n| name == n) { + return Err(syn::Error::new( + name.span(), + format!( + "Only the following modules are allowed: {}", + ModulePart::format_names(ModulePart::all_allowed()), + ), + )) + } + let generics: syn::Generics = input.parse()?; if !generics.params.is_empty() && !Self::is_allowed_generic(&name) { let valid_generics = ModulePart::format_names(ModulePart::allowed_generics()); @@ -313,6 +323,7 @@ impl Parse for ModulePart { } else { None }; + Ok(Self { name, generics, @@ -330,15 +341,20 @@ impl ModulePart { Self::allowed_args().into_iter().any(|n| ident == n) } - pub fn allowed_generics() -> Vec<&'static str> { - vec!["Event", "Origin", "Config"] + pub fn allowed_generics() -> &'static [&'static str] { + &["Event", "Origin", "Config"] } - pub fn allowed_args() -> Vec<&'static str> { - vec!["Inherent"] + pub fn allowed_args() -> &'static [&'static str] { + &["Inherent"] } - pub fn format_names(names: Vec<&'static str>) -> String { + /// Returns all allowed names for module parts. + pub fn all_allowed() -> &'static [&'static str] { + &["Module", "Call", "Storage", "Event", "Config", "Origin", "Inherent", "ValidateUnsigned"] + } + + pub fn format_names(names: &[&'static str]) -> String { let res: Vec<_> = names.into_iter().map(|s| format!("`{}`", s)).collect(); res.join(", ") }