From f0ea7203fd32df8ee8562356e78ba1af245604f5 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 1 May 2024 15:24:53 +0000 Subject: [PATCH 01/24] metadata/ir: Extend IR with custom types Signed-off-by: Alexandru Vasile --- substrate/primitives/metadata-ir/src/types.rs | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/substrate/primitives/metadata-ir/src/types.rs b/substrate/primitives/metadata-ir/src/types.rs index b05f26ff55d4..6ecfeb1351fb 100644 --- a/substrate/primitives/metadata-ir/src/types.rs +++ b/substrate/primitives/metadata-ir/src/types.rs @@ -18,7 +18,7 @@ use codec::Encode; use scale_info::{ form::{Form, MetaForm, PortableForm}, - prelude::vec::Vec, + prelude::{collections::BTreeMap, vec::Vec}, IntoPortable, MetaType, Registry, }; @@ -41,6 +41,8 @@ pub struct MetadataIR { pub apis: Vec>, /// The outer enums types as found in the runtime. pub outer_enums: OuterEnumsIR, + /// The custom types collected by the runtime. + pub custom_types: CustomMetadataIR, } /// Metadata of a runtime trait. @@ -368,6 +370,27 @@ impl From for PalletEventMetadataIR { } } +/// Metadata for custom types. +#[derive(Clone, PartialEq, Eq, Encode, Debug)] +pub struct CustomMetadataIR { + /// The custom map. + pub map: BTreeMap, +} + +impl IntoPortable for CustomMetadataIR { + type Output = CustomMetadataIR; + + fn into_portable(self, registry: &mut Registry) -> Self::Output { + let map = self + .map + .into_iter() + .map(|(key, value)| (key.into_portable(registry), registry.register_type(&value))) + .collect(); + + CustomMetadataIR { map } + } +} + /// Metadata about one pallet constant. #[derive(Clone, PartialEq, Eq, Encode, Debug)] pub struct PalletConstantMetadataIR { From fecdd47fc3193bea03ce688f6bb8f076070a4f8d Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 1 May 2024 15:28:14 +0000 Subject: [PATCH 02/24] metadata/ir: Convert custom IR types to concrete metadata Signed-off-by: Alexandru Vasile --- substrate/primitives/metadata-ir/src/v15.rs | 28 ++++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/substrate/primitives/metadata-ir/src/v15.rs b/substrate/primitives/metadata-ir/src/v15.rs index a942eb73223b..41afd1ee9786 100644 --- a/substrate/primitives/metadata-ir/src/v15.rs +++ b/substrate/primitives/metadata-ir/src/v15.rs @@ -17,17 +17,16 @@ //! Convert the IR to V15 metadata. -use crate::OuterEnumsIR; - use super::types::{ - ExtrinsicMetadataIR, MetadataIR, PalletMetadataIR, RuntimeApiMetadataIR, - RuntimeApiMethodMetadataIR, RuntimeApiMethodParamMetadataIR, SignedExtensionMetadataIR, + CustomMetadataIR, ExtrinsicMetadataIR, MetadataIR, OuterEnumsIR, PalletMetadataIR, + RuntimeApiMetadataIR, RuntimeApiMethodMetadataIR, RuntimeApiMethodParamMetadataIR, + SignedExtensionMetadataIR, }; use frame_metadata::v15::{ - CustomMetadata, ExtrinsicMetadata, OuterEnums, PalletMetadata, RuntimeApiMetadata, - RuntimeApiMethodMetadata, RuntimeApiMethodParamMetadata, RuntimeMetadataV15, - SignedExtensionMetadata, + CustomMetadata, CustomValueMetadata, ExtrinsicMetadata, OuterEnums, PalletMetadata, + RuntimeApiMetadata, RuntimeApiMethodMetadata, RuntimeApiMethodParamMetadata, + RuntimeMetadataV15, SignedExtensionMetadata, }; impl From for RuntimeMetadataV15 { @@ -38,9 +37,8 @@ impl From for RuntimeMetadataV15 { ir.ty, ir.apis.into_iter().map(Into::into).collect(), ir.outer_enums.into(), - // Substrate does not collect yet the custom metadata fields. // This allows us to extend the V15 easily. - CustomMetadata { map: Default::default() }, + ir.custom_types.into(), ) } } @@ -119,3 +117,15 @@ impl From for OuterEnums { } } } + +impl From for CustomMetadata { + fn from(ir: CustomMetadataIR) -> Self { + CustomMetadata { + map: ir + .map + .into_iter() + .map(|(name, ty)| (name, CustomValueMetadata { ty, value: Default::default() })) + .collect(), + } + } +} From 12795940384678c3b8c26ff5a317f1b67bc63b6d Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 1 May 2024 15:49:52 +0000 Subject: [PATCH 03/24] frame/metadata: Populate custom types with runtime call of system config Signed-off-by: Alexandru Vasile --- .../src/construct_runtime/expand/metadata.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs index 0e76f9a92469..f14756c78283 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs @@ -140,6 +140,18 @@ pub fn expand_runtime_metadata( >(), event_enum_ty: #scrate::__private::scale_info::meta_type::(), error_enum_ty: #scrate::__private::scale_info::meta_type::(), + }, + custom_types: #scrate::__private::metadata_ir::CustomMetadataIR { + map: [ + ( + "CallEnumTy".into(), + #scrate::__private::scale_info::meta_type::< + <#runtime as #system_path::Config>::RuntimeCall + >(), + ), + ] + .into_iter() + .collect(), } } } From ab4f6ccff5bd6e2c7967dbf9a3422fc12a221e1f Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 1 May 2024 17:13:01 +0000 Subject: [PATCH 04/24] frame/metadata: Expose AccountId to metadata Signed-off-by: Alexandru Vasile --- .../procedural/src/construct_runtime/expand/metadata.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs index f14756c78283..3f5863525988 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs @@ -149,6 +149,12 @@ pub fn expand_runtime_metadata( <#runtime as #system_path::Config>::RuntimeCall >(), ), + ( + "AccountId".into(), + #scrate::__private::scale_info::meta_type::< + <#runtime as #system_path::Config>::AccountId + >(), + ), ] .into_iter() .collect(), From e7bee31990585888106cb668ee1e8f238e4ce919 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 1 May 2024 17:38:28 +0000 Subject: [PATCH 05/24] frame/metadata: Optionally expose the AssetId of the asset pallet Signed-off-by: Alexandru Vasile --- .../src/construct_runtime/expand/metadata.rs | 15 +++++++++++++++ .../procedural/src/construct_runtime/mod.rs | 11 +++++++++++ 2 files changed, 26 insertions(+) diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs index 3f5863525988..3ffafee1b8d6 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs @@ -27,6 +27,7 @@ pub fn expand_runtime_metadata( scrate: &TokenStream, extrinsic: &TokenStream, system_path: &PalletPath, + assets_path: Option, ) -> TokenStream { let pallets = pallet_declarations .iter() @@ -75,6 +76,19 @@ pub fn expand_runtime_metadata( }) .collect::>(); + let asset_id = if let Some(assets_path) = assets_path { + quote! { + ( + "AssetId".into(), + #scrate::__private::scale_info::meta_type::< + <#runtime as #assets_path::Config>::AssetId + >(), + ), + } + } else { + quote! {} + }; + quote! { impl #runtime { fn metadata_ir() -> #scrate::__private::metadata_ir::MetadataIR { @@ -155,6 +169,7 @@ pub fn expand_runtime_metadata( <#runtime as #system_path::Config>::AccountId >(), ), + #asset_id ] .into_iter() .collect(), diff --git a/substrate/frame/support/procedural/src/construct_runtime/mod.rs b/substrate/frame/support/procedural/src/construct_runtime/mod.rs index 1505d158895f..d784c1c8310c 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/mod.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/mod.rs @@ -226,6 +226,10 @@ use syn::{spanned::Spanned, Ident, Result}; /// The fixed name of the system pallet. const SYSTEM_PALLET_NAME: &str = "System"; +/// The fixed name of the ForeignAssets pallet. +const FOREIGN_ASSETS_PALLET_NAME: &str = "ForeignAssets"; +/// The fixed name of the Assets pallet. +const ASSETS_PALLET_NAME: &str = "Assets"; /// Implementation of `construct_runtime` macro. Either expand to some code which will call /// `construct_runtime` again, or expand to the final runtime definition. @@ -365,6 +369,12 @@ fn construct_runtime_final_expansion( )) } + // Find either the foreign assets pallet or the local assets pallet in this order. + let assets_pallet = pallets + .iter() + .find(|decl| decl.name == FOREIGN_ASSETS_PALLET_NAME) + .or_else(|| pallets.iter().find(|decl| decl.name == ASSETS_PALLET_NAME)); + let features = pallets .iter() .filter_map(|decl| { @@ -406,6 +416,7 @@ fn construct_runtime_final_expansion( &scrate, &unchecked_extrinsic, &system_pallet.path, + assets_pallet.map(|pallet| pallet.path.clone()), ); let outer_config = expand::expand_outer_config(&name, &pallets, &scrate); let inherent = From d0986cf4505d5c9f3a9f00fceb9ae1bef05ea7ca Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 2 May 2024 09:36:14 +0000 Subject: [PATCH 06/24] frame/metadata: Use runtime instance for extracting AssetId type Signed-off-by: Alexandru Vasile --- .../src/construct_runtime/expand/metadata.rs | 32 +++++++++++-------- .../procedural/src/construct_runtime/mod.rs | 2 +- .../procedural/src/runtime/expand/mod.rs | 11 +++++++ 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs index 3ffafee1b8d6..1bf70a3baba3 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs @@ -27,7 +27,7 @@ pub fn expand_runtime_metadata( scrate: &TokenStream, extrinsic: &TokenStream, system_path: &PalletPath, - assets_path: Option, + assets_pallet: Option<&Pallet>, ) -> TokenStream { let pallets = pallet_declarations .iter() @@ -76,18 +76,22 @@ pub fn expand_runtime_metadata( }) .collect::>(); - let asset_id = if let Some(assets_path) = assets_path { - quote! { - ( - "AssetId".into(), - #scrate::__private::scale_info::meta_type::< - <#runtime as #assets_path::Config>::AssetId - >(), - ), - } - } else { - quote! {} - }; + let maybe_asset_id = assets_pallet + .map(|pallet| { + let path = &pallet.path; + let instance = &pallet.instance; + let maybe_instance = instance.as_ref().map(|inst| quote! { <#inst> }); + + quote! { + ( + "AssetId".into(), + #scrate::__private::scale_info::meta_type::< + <#runtime as #path::Config #maybe_instance>::AssetId + >(), + ), + } + }) + .unwrap_or_default(); quote! { impl #runtime { @@ -169,7 +173,7 @@ pub fn expand_runtime_metadata( <#runtime as #system_path::Config>::AccountId >(), ), - #asset_id + #maybe_asset_id ] .into_iter() .collect(), diff --git a/substrate/frame/support/procedural/src/construct_runtime/mod.rs b/substrate/frame/support/procedural/src/construct_runtime/mod.rs index d784c1c8310c..e8b79e9b47e5 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/mod.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/mod.rs @@ -416,7 +416,7 @@ fn construct_runtime_final_expansion( &scrate, &unchecked_extrinsic, &system_pallet.path, - assets_pallet.map(|pallet| pallet.path.clone()), + assets_pallet, ); let outer_config = expand::expand_outer_config(&name, &pallets, &scrate); let inherent = diff --git a/substrate/frame/support/procedural/src/runtime/expand/mod.rs b/substrate/frame/support/procedural/src/runtime/expand/mod.rs index 43f11896808c..194b55e8acb1 100644 --- a/substrate/frame/support/procedural/src/runtime/expand/mod.rs +++ b/substrate/frame/support/procedural/src/runtime/expand/mod.rs @@ -39,6 +39,10 @@ use syn::{Ident, Result}; /// The fixed name of the system pallet. const SYSTEM_PALLET_NAME: &str = "System"; +/// The fixed name of the ForeignAssets pallet. +const FOREIGN_ASSETS_PALLET_NAME: &str = "ForeignAssets"; +/// The fixed name of the Assets pallet. +const ASSETS_PALLET_NAME: &str = "Assets"; pub fn expand(def: Def, legacy_ordering: bool) -> TokenStream2 { let input = def.input; @@ -143,6 +147,12 @@ fn construct_runtime_final_expansion( )) } + // Find either the foreign assets pallet or the local assets pallet in this order. + let assets_pallet = pallets + .iter() + .find(|decl| decl.name == FOREIGN_ASSETS_PALLET_NAME) + .or_else(|| pallets.iter().find(|decl| decl.name == ASSETS_PALLET_NAME)); + let features = pallets .iter() .filter_map(|decl| { @@ -230,6 +240,7 @@ fn construct_runtime_final_expansion( &scrate, &unchecked_extrinsic, &system_pallet.path, + assets_pallet, ); let outer_config = expand::expand_outer_config(&name, &pallets, &scrate); let inherent = From c8061aae49ad61a1d451b0cafb52beaa54493dc5 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 2 May 2024 10:35:44 +0000 Subject: [PATCH 07/24] frame/metadata: Extract address ty Signed-off-by: Alexandru Vasile --- .../procedural/src/construct_runtime/expand/metadata.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs index 1bf70a3baba3..27caf03d16f4 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs @@ -173,6 +173,10 @@ pub fn expand_runtime_metadata( <#runtime as #system_path::Config>::AccountId >(), ), + ( + "Address".into(), + address_ty, + ), #maybe_asset_id ] .into_iter() From e63dae6b7282f7fc0c33ab82719e0b8a73cb6da4 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 2 May 2024 10:48:35 +0000 Subject: [PATCH 08/24] frame/metadata: Extract signature ty Signed-off-by: Alexandru Vasile --- .../procedural/src/construct_runtime/expand/metadata.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs index 27caf03d16f4..084dc0aef4a0 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs @@ -177,6 +177,10 @@ pub fn expand_runtime_metadata( "Address".into(), address_ty, ), + ( + "Signature".into(), + signature_ty, + ), #maybe_asset_id ] .into_iter() From c666a6f47008e6040dae22695d0f4e2150b8c343 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 2 May 2024 10:57:35 +0000 Subject: [PATCH 09/24] frame/metadata: Extend with Hash and Hashing types Signed-off-by: Alexandru Vasile --- .../src/construct_runtime/expand/metadata.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs index 084dc0aef4a0..2959aed549bb 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs @@ -181,6 +181,18 @@ pub fn expand_runtime_metadata( "Signature".into(), signature_ty, ), + ( + "Hash".into(), + #scrate::__private::scale_info::meta_type::< + <#runtime as #system_path::Config>::Hash + >(), + ), + ( + "Hashing".into(), + #scrate::__private::scale_info::meta_type::< + <#runtime as #system_path::Config>::Hashing + >(), + ), #maybe_asset_id ] .into_iter() From fbd75b04a2fd87c503e5b437cc0031b671155fd4 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 2 May 2024 11:07:49 +0000 Subject: [PATCH 10/24] frame/metadata: Extract block header to custom types Signed-off-by: Alexandru Vasile --- .../procedural/src/construct_runtime/expand/metadata.rs | 5 +++++ .../frame/support/procedural/src/construct_runtime/mod.rs | 2 ++ substrate/frame/support/procedural/src/runtime/expand/mod.rs | 2 ++ 3 files changed, 9 insertions(+) diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs index 2959aed549bb..a3a57a4ec944 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs @@ -28,6 +28,7 @@ pub fn expand_runtime_metadata( extrinsic: &TokenStream, system_path: &PalletPath, assets_pallet: Option<&Pallet>, + header: &TokenStream, ) -> TokenStream { let pallets = pallet_declarations .iter() @@ -193,6 +194,10 @@ pub fn expand_runtime_metadata( <#runtime as #system_path::Config>::Hashing >(), ), + ( + "Header".into(), + #scrate::__private::scale_info::meta_type::<#header>(), + ), #maybe_asset_id ] .into_iter() diff --git a/substrate/frame/support/procedural/src/construct_runtime/mod.rs b/substrate/frame/support/procedural/src/construct_runtime/mod.rs index e8b79e9b47e5..d9565485eb5c 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/mod.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/mod.rs @@ -398,6 +398,7 @@ fn construct_runtime_final_expansion( let frame_system = generate_access_from_frame_or_crate("frame-system")?; let block = quote!(<#name as #frame_system::Config>::Block); let unchecked_extrinsic = quote!(<#block as #scrate::sp_runtime::traits::Block>::Extrinsic); + let header = quote!(<#block as #scrate::sp_runtime::traits::Block>::Header); let outer_event = expand::expand_outer_enum(&name, &pallets, &scrate, expand::OuterEnumType::Event)?; @@ -417,6 +418,7 @@ fn construct_runtime_final_expansion( &unchecked_extrinsic, &system_pallet.path, assets_pallet, + &header, ); let outer_config = expand::expand_outer_config(&name, &pallets, &scrate); let inherent = diff --git a/substrate/frame/support/procedural/src/runtime/expand/mod.rs b/substrate/frame/support/procedural/src/runtime/expand/mod.rs index 194b55e8acb1..3f4bab4a344c 100644 --- a/substrate/frame/support/procedural/src/runtime/expand/mod.rs +++ b/substrate/frame/support/procedural/src/runtime/expand/mod.rs @@ -176,6 +176,7 @@ fn construct_runtime_final_expansion( let frame_system = generate_access_from_frame_or_crate("frame-system")?; let block = quote!(<#name as #frame_system::Config>::Block); let unchecked_extrinsic = quote!(<#block as #scrate::sp_runtime::traits::Block>::Extrinsic); + let header = quote!(<#block as #scrate::sp_runtime::traits::Block>::Header); let mut dispatch = None; let mut outer_event = None; @@ -241,6 +242,7 @@ fn construct_runtime_final_expansion( &unchecked_extrinsic, &system_pallet.path, assets_pallet, + &header, ); let outer_config = expand::expand_outer_config(&name, &pallets, &scrate); let inherent = From 0fedb4dd008ee2adecdfa21b9362d568a9c64a48 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 2 May 2024 12:13:32 +0000 Subject: [PATCH 11/24] frame/metadata: Remove call enum ty from custom types Signed-off-by: Alexandru Vasile --- .../procedural/src/construct_runtime/expand/metadata.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs index a3a57a4ec944..30c975345447 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs @@ -162,12 +162,6 @@ pub fn expand_runtime_metadata( }, custom_types: #scrate::__private::metadata_ir::CustomMetadataIR { map: [ - ( - "CallEnumTy".into(), - #scrate::__private::scale_info::meta_type::< - <#runtime as #system_path::Config>::RuntimeCall - >(), - ), ( "AccountId".into(), #scrate::__private::scale_info::meta_type::< From 17ade2333e82dbed7ab68432031c55d3cab98290 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 16 May 2024 19:18:17 +0300 Subject: [PATCH 12/24] frame/proc: Refactor itemTrait extraction Signed-off-by: Alexandru Vasile --- substrate/frame/support/procedural/src/pallet/parse/config.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/config.rs b/substrate/frame/support/procedural/src/pallet/parse/config.rs index 406072df4b9d..d6add1fee291 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/config.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/config.rs @@ -334,9 +334,7 @@ impl ConfigDef { item: &mut syn::Item, enable_default: bool, ) -> syn::Result { - let item = if let syn::Item::Trait(item) = item { - item - } else { + let syn::Item::Trait(item) = item else { let msg = "Invalid pallet::config, expected trait definition"; return Err(syn::Error::new(item.span(), msg)) }; From 616e38d463b88119ac7b4c43a881b69ed214b2bc Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 16 May 2024 19:22:54 +0300 Subject: [PATCH 13/24] frame/proc: Refactor check_event_type Signed-off-by: Alexandru Vasile --- .../procedural/src/pallet/parse/config.rs | 84 +++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/config.rs b/substrate/frame/support/procedural/src/pallet/parse/config.rs index d6add1fee291..c98d7cf19164 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/config.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/config.rs @@ -223,55 +223,55 @@ fn check_event_type( trait_item: &syn::TraitItem, trait_has_instance: bool, ) -> syn::Result { - if let syn::TraitItem::Type(type_) = trait_item { - if type_.ident == "RuntimeEvent" { - // Check event has no generics - if !type_.generics.params.is_empty() || type_.generics.where_clause.is_some() { - let msg = "Invalid `type RuntimeEvent`, associated type `RuntimeEvent` is reserved and must have\ - no generics nor where_clause"; - return Err(syn::Error::new(trait_item.span(), msg)) - } + let syn::TraitItem::Type(type_) = trait_item else { return Ok(false) }; - // Check bound contains IsType and From - let has_is_type_bound = type_.bounds.iter().any(|s| { - syn::parse2::(s.to_token_stream()) - .map_or(false, |b| has_expected_system_config(b.0, frame_system)) - }); - - if !has_is_type_bound { - let msg = "Invalid `type RuntimeEvent`, associated type `RuntimeEvent` is reserved and must \ - bound: `IsType<::RuntimeEvent>`".to_string(); - return Err(syn::Error::new(type_.span(), msg)) - } + if type_.ident != "RuntimeEvent" { + return Ok(false) + } - let from_event_bound = type_ - .bounds - .iter() - .find_map(|s| syn::parse2::(s.to_token_stream()).ok()); + // Check event has no generics + if !type_.generics.params.is_empty() || type_.generics.where_clause.is_some() { + let msg = + "Invalid `type RuntimeEvent`, associated type `RuntimeEvent` is reserved and must have\ + no generics nor where_clause"; + return Err(syn::Error::new(trait_item.span(), msg)) + } - let from_event_bound = if let Some(b) = from_event_bound { - b - } else { - let msg = "Invalid `type RuntimeEvent`, associated type `RuntimeEvent` is reserved and must \ - bound: `From` or `From>` or `From>`"; - return Err(syn::Error::new(type_.span(), msg)) - }; + // Check bound contains IsType and From + let has_is_type_bound = type_.bounds.iter().any(|s| { + syn::parse2::(s.to_token_stream()) + .map_or(false, |b| has_expected_system_config(b.0, frame_system)) + }); + + if !has_is_type_bound { + let msg = + "Invalid `type RuntimeEvent`, associated type `RuntimeEvent` is reserved and must \ + bound: `IsType<::RuntimeEvent>`" + .to_string(); + return Err(syn::Error::new(type_.span(), msg)) + } - if from_event_bound.is_generic && (from_event_bound.has_instance != trait_has_instance) - { - let msg = "Invalid `type RuntimeEvent`, associated type `RuntimeEvent` bounds inconsistent \ + let from_event_bound = type_ + .bounds + .iter() + .find_map(|s| syn::parse2::(s.to_token_stream()).ok()); + + let Some(from_event_bound) = from_event_bound else { + let msg = + "Invalid `type RuntimeEvent`, associated type `RuntimeEvent` is reserved and must \ + bound: `From` or `From>` or `From>`"; + return Err(syn::Error::new(type_.span(), msg)) + }; + + if from_event_bound.is_generic && (from_event_bound.has_instance != trait_has_instance) { + let msg = + "Invalid `type RuntimeEvent`, associated type `RuntimeEvent` bounds inconsistent \ `From`. Config and generic Event must be both with instance or \ without instance"; - return Err(syn::Error::new(type_.span(), msg)) - } - - Ok(true) - } else { - Ok(false) - } - } else { - Ok(false) + return Err(syn::Error::new(type_.span(), msg)) } + + Ok(true) } /// Check that the path to `frame_system::Config` is valid, this is that the path is just From 482a5ed4cfd820f53ded2b186002cc4232b87a9c Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 16 May 2024 19:32:31 +0300 Subject: [PATCH 14/24] frame/proc: Refactor TraitItemType parsing Signed-off-by: Alexandru Vasile --- .../procedural/src/pallet/parse/config.rs | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/config.rs b/substrate/frame/support/procedural/src/pallet/parse/config.rs index c98d7cf19164..58047e1d25d8 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/config.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/config.rs @@ -94,30 +94,32 @@ impl TryFrom<&syn::TraitItemType> for ConstMetadataDef { let bound = trait_ty .bounds .iter() - .find_map(|b| { - if let syn::TypeParamBound::Trait(tb) = b { - tb.path - .segments - .last() - .and_then(|s| if s.ident == "Get" { Some(s) } else { None }) - } else { - None - } + .find_map(|param_bound| { + let syn::TypeParamBound::Trait(trait_bound) = param_bound else { return None }; + + trait_bound.path.segments.last().and_then(|s| { + if s.ident == "Get" { + Some(s) + } else { + None + } + }) }) .ok_or_else(|| err(trait_ty.span(), "`Get` trait bound not found"))?; - let type_arg = if let syn::PathArguments::AngleBracketed(ref ab) = bound.arguments { - if ab.args.len() == 1 { - if let syn::GenericArgument::Type(ref ty) = ab.args[0] { - Ok(ty) - } else { - Err(err(ab.args[0].span(), "Expected a type argument")) - } - } else { - Err(err(bound.span(), "Expected a single type argument")) - } - } else { - Err(err(bound.span(), "Expected trait generic args")) - }?; + + let syn::PathArguments::AngleBracketed(ref ab) = bound.arguments else { + return Err(err(bound.span(), "Expected trait generic args")) + }; + + // Only one type argument is expected. + if ab.args.len() != 1 { + return Err(err(bound.span(), "Expected a single type argument")) + } + + let syn::GenericArgument::Type(ref type_arg) = ab.args[0] else { + return Err(err(ab.args[0].span(), "Expected a type argument")) + }; + let type_ = syn::parse2::(replace_self_by_t(type_arg.to_token_stream())) .expect("Internal error: replacing `Self` by `T` should result in valid type"); From 785436ce98ce1bbd2973e6c5eb61ca9f2d18e993 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 17 May 2024 10:54:46 +0300 Subject: [PATCH 15/24] frame/constants: Improve documentation Signed-off-by: Alexandru Vasile --- .../frame/support/procedural/src/pallet/expand/constants.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/expand/constants.rs b/substrate/frame/support/procedural/src/pallet/expand/constants.rs index 57fa8b7f3cd9..d7fbb5a71897 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/constants.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/constants.rs @@ -30,8 +30,7 @@ struct ConstDef { pub metadata_name: Option, } -/// -/// * Impl fn module_constant_metadata for pallet. +/// Implement the `pallet_constants_metadata` function for the pallet. pub fn expand_constants(def: &mut Def) -> proc_macro2::TokenStream { let frame_support = &def.frame_support; let type_impl_gen = &def.type_impl_generics(proc_macro2::Span::call_site()); From a4d7ec7dba4867a6bfd318c2514ed2b30f5a6050 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 17 May 2024 11:02:39 +0300 Subject: [PATCH 16/24] frame/helpers: Refactor take_first_item_pallet_attr Signed-off-by: Alexandru Vasile --- .../procedural/src/pallet/parse/helper.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/helper.rs b/substrate/frame/support/procedural/src/pallet/parse/helper.rs index 3187c9139c8f..d4f58a4c56df 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/helper.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/helper.rs @@ -55,16 +55,16 @@ pub(crate) fn take_first_item_pallet_attr( where Attr: syn::parse::Parse, { - let attrs = if let Some(attrs) = item.mut_item_attrs() { attrs } else { return Ok(None) }; + let Some(attrs) = item.mut_item_attrs() else { return Ok(None) }; - if let Some(index) = attrs.iter().position(|attr| { + let Some(index) = attrs.iter().position(|attr| { attr.path().segments.first().map_or(false, |segment| segment.ident == "pallet") - }) { - let pallet_attr = attrs.remove(index); - Ok(Some(syn::parse2(pallet_attr.into_token_stream())?)) - } else { - Ok(None) - } + }) else { + return Ok(None) + }; + + let pallet_attr = attrs.remove(index); + Ok(Some(syn::parse2(pallet_attr.into_token_stream())?)) } /// Take all the pallet attributes (e.g. attribute like `#[pallet..]`) and decode them to `Attr` From c50d3643bb0bc69418da028805e3f2ffccfebf42 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 17 May 2024 11:10:32 +0300 Subject: [PATCH 17/24] frame/config: Add associated types to parsed config Signed-off-by: Alexandru Vasile --- .../procedural/src/pallet/parse/config.rs | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/config.rs b/substrate/frame/support/procedural/src/pallet/parse/config.rs index 58047e1d25d8..b09ac04b6415 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/config.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/config.rs @@ -55,6 +55,8 @@ pub struct ConfigDef { pub has_instance: bool, /// Const associated type. pub consts_metadata: Vec, + /// Associated types exposed to metadata. + pub associated_types_metadata: Vec, /// Whether the trait has the associated type `Event`, note that those bounds are /// checked: /// * `IsType::RuntimeEvent` @@ -127,6 +129,23 @@ impl TryFrom<&syn::TraitItemType> for ConstMetadataDef { } } +/// Input definition for an associated type in pallet config. +pub struct AssociatedTypeMetadataDef { + /// Name of the associated type. + pub ident: syn::Ident, + /// The doc associated + pub doc: Vec, +} + +impl From<&syn::TraitItemType> for AssociatedTypeMetadataDef { + fn from(trait_ty: &syn::TraitItemType) -> Self { + let ident = trait_ty.ident.clone(); + let doc = get_doc_literals(&trait_ty.attrs); + + Self { ident, doc } + } +} + /// Parse for `#[pallet::disable_frame_system_supertrait_check]` pub struct DisableFrameSystemSupertraitCheck; @@ -375,6 +394,7 @@ impl ConfigDef { let mut has_event_type = false; let mut consts_metadata = vec![]; + let mut associated_types_metadata = vec![]; let mut default_sub_trait = if enable_default { Some(DefaultTrait { items: Default::default(), @@ -414,7 +434,7 @@ impl ConfigDef { if !enable_default { return Err(syn::Error::new( pallet_attr._bracket.span.join(), - "`#[pallet:no_default]` can only be used if `#[pallet::config(with_default)]` \ + "`#[pallet::no_default]` can only be used if `#[pallet::config(with_default)]` \ has been specified" )) } @@ -446,6 +466,12 @@ impl ConfigDef { } } + if !is_event && !already_constant { + if let syn::TraitItem::Type(ref ty) = trait_item { + associated_types_metadata.push(AssociatedTypeMetadataDef::from(ty)); + } + } + if !already_no_default && enable_default { default_sub_trait .as_mut() @@ -488,6 +514,7 @@ impl ConfigDef { index, has_instance, consts_metadata, + associated_types_metadata, has_event_type, where_clause, attr_span, From f40acd4a514de7671b11700465ea71f71b6568db Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 17 May 2024 12:49:20 +0300 Subject: [PATCH 18/24] metadata-ir: Add type for PalletAssociatedTypesMetadataIR Signed-off-by: Alexandru Vasile --- substrate/primitives/metadata-ir/src/types.rs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/substrate/primitives/metadata-ir/src/types.rs b/substrate/primitives/metadata-ir/src/types.rs index 6ecfeb1351fb..646c7243ae86 100644 --- a/substrate/primitives/metadata-ir/src/types.rs +++ b/substrate/primitives/metadata-ir/src/types.rs @@ -417,6 +417,29 @@ impl IntoPortable for PalletConstantMetadataIR { } } +/// Metadata about one pallet associated type. +#[derive(Clone, PartialEq, Eq, Encode, Debug)] +pub struct PalletAssociatedTypesMetadataIR { + /// Name of the pallet associated type. + pub name: T::String, + /// Type of the pallet associated type. + pub ty: T::Type, + /// Documentation of the associated type. + pub docs: Vec, +} + +impl IntoPortable for PalletAssociatedTypesMetadataIR { + type Output = PalletAssociatedTypesMetadataIR; + + fn into_portable(self, registry: &mut Registry) -> Self::Output { + PalletAssociatedTypesMetadataIR { + name: self.name.into_portable(registry), + ty: registry.register_type(&self.ty), + docs: registry.map_into_portable(self.docs), + } + } +} + /// Metadata about a pallet error. #[derive(Clone, PartialEq, Eq, Encode, Debug)] pub struct PalletErrorMetadataIR { From 7659b19a9912042fa7ad878eccc24202972cba8e Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 17 May 2024 12:49:51 +0300 Subject: [PATCH 19/24] frame/config: Implement associated types metadata Signed-off-by: Alexandru Vasile --- .../procedural/src/pallet/expand/config.rs | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/substrate/frame/support/procedural/src/pallet/expand/config.rs b/substrate/frame/support/procedural/src/pallet/expand/config.rs index 5cf4035a8f8b..2e98ce6e6938 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/config.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/config.rs @@ -95,3 +95,48 @@ Consequently, a runtime that wants to include this pallet must implement this tr _ => Default::default(), } } + +/// Generate the metadata for the associated types of the config trait. +/// +/// Implements the `pallet_associated_types_metadata` function for the pallet. +pub fn expand_config_metadata(def: &mut Def) -> proc_macro2::TokenStream { + let frame_support = &def.frame_support; + let type_impl_gen = &def.type_impl_generics(proc_macro2::Span::call_site()); + let type_use_gen = &def.type_use_generics(proc_macro2::Span::call_site()); + let pallet_ident = &def.pallet_struct.pallet; + let trait_use_gen = &def.trait_use_generics(proc_macro2::Span::call_site()); + + let mut where_clauses = vec![&def.config.where_clause]; + where_clauses.extend(def.extra_constants.iter().map(|d| &d.where_clause)); + let completed_where_clause = super::merge_where_clauses(&where_clauses); + + let types = def.config.associated_types_metadata.iter().map(|metadata| { + let ident = &metadata.ident; + let ident_str = format!("{}", ident); + + let no_docs = vec![]; + let doc = if cfg!(feature = "no-metadata-docs") { &no_docs } else { &metadata.doc }; + + quote::quote!({ + #frame_support::__private::metadata_ir::PalletAssociatedTypesMetadataIR { + name: #ident_str, + ty: #frame_support::__private::scale_info::meta_type::< + <::#ident + >(), + docs: #frame_support::__private::sp_std::vec![ #( #doc ),* ], + } + }) + }); + + quote::quote!( + impl<#type_impl_gen> #pallet_ident<#type_use_gen> #completed_where_clause { + + #[doc(hidden)] + pub fn pallet_associated_types_metadata() + -> #frame_support::__private::sp_std::vec::Vec<#frame_support::__private::metadata_ir::PalletAssociatedTypesMetadataIR> + { + #frame_support::__private::sp_std::vec![ #( #types ),* ] + } + } + ) +} From ab0b1b18d46c0a9f451e3ee7eeab3df4ba3a4e7a Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 17 May 2024 13:04:14 +0300 Subject: [PATCH 20/24] frame/construct_runtime: Extract associated types from pallet config Signed-off-by: Alexandru Vasile --- .../src/construct_runtime/expand/metadata.rs | 11 +++++++++++ .../support/procedural/src/pallet/expand/config.rs | 4 ++-- .../frame/support/procedural/src/pallet/expand/mod.rs | 2 ++ substrate/primitives/metadata-ir/src/types.rs | 3 +++ substrate/primitives/metadata-ir/src/v14.rs | 2 +- substrate/primitives/metadata-ir/src/v15.rs | 1 + 6 files changed, 20 insertions(+), 3 deletions(-) diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs index 30c975345447..91c113234f0b 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs @@ -52,6 +52,7 @@ pub fn expand_runtime_metadata( let constants = expand_pallet_metadata_constants(runtime, decl); let errors = expand_pallet_metadata_errors(runtime, decl); let docs = expand_pallet_metadata_docs(runtime, decl); + let associated_types = expand_pallet_metadata_associated_types(runtime, decl); let attr = decl.cfg_pattern.iter().fold(TokenStream::new(), |acc, pattern| { let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) .expect("was successfully parsed before; qed"); @@ -72,6 +73,7 @@ pub fn expand_runtime_metadata( constants: #constants, error: #errors, docs: #docs, + associated_types: #associated_types, } } }) @@ -312,3 +314,12 @@ fn expand_pallet_metadata_docs(runtime: &Ident, decl: &Pallet) -> TokenStream { #path::Pallet::<#runtime #(, #path::#instance)*>::pallet_documentation_metadata() } } + +fn expand_pallet_metadata_associated_types(runtime: &Ident, decl: &Pallet) -> TokenStream { + let path = &decl.path; + let instance = decl.instance.as_ref().into_iter(); + + quote! { + #path::Pallet::<#runtime #(, #path::#instance)*>::pallet_associated_types_metadata() + } +} diff --git a/substrate/frame/support/procedural/src/pallet/expand/config.rs b/substrate/frame/support/procedural/src/pallet/expand/config.rs index 2e98ce6e6938..3478f6730803 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/config.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/config.rs @@ -99,7 +99,7 @@ Consequently, a runtime that wants to include this pallet must implement this tr /// Generate the metadata for the associated types of the config trait. /// /// Implements the `pallet_associated_types_metadata` function for the pallet. -pub fn expand_config_metadata(def: &mut Def) -> proc_macro2::TokenStream { +pub fn expand_config_metadata(def: &Def) -> proc_macro2::TokenStream { let frame_support = &def.frame_support; let type_impl_gen = &def.type_impl_generics(proc_macro2::Span::call_site()); let type_use_gen = &def.type_use_generics(proc_macro2::Span::call_site()); @@ -121,7 +121,7 @@ pub fn expand_config_metadata(def: &mut Def) -> proc_macro2::TokenStream { #frame_support::__private::metadata_ir::PalletAssociatedTypesMetadataIR { name: #ident_str, ty: #frame_support::__private::scale_info::meta_type::< - <::#ident + ::#ident >(), docs: #frame_support::__private::sp_std::vec![ #( #doc ),* ], } diff --git a/substrate/frame/support/procedural/src/pallet/expand/mod.rs b/substrate/frame/support/procedural/src/pallet/expand/mod.rs index 067839c28463..3f9b50f79c0c 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/mod.rs @@ -60,6 +60,7 @@ pub fn expand(mut def: Def) -> proc_macro2::TokenStream { let constants = constants::expand_constants(&mut def); let pallet_struct = pallet_struct::expand_pallet_struct(&mut def); let config = config::expand_config(&mut def); + let associated_types = config::expand_config_metadata(&def); let call = call::expand_call(&mut def); let tasks = tasks::expand_tasks(&mut def); let error = error::expand_error(&mut def); @@ -101,6 +102,7 @@ storage item. Otherwise, all storage items are listed among [*Type Definitions*] #constants #pallet_struct #config + #associated_types #call #tasks #error diff --git a/substrate/primitives/metadata-ir/src/types.rs b/substrate/primitives/metadata-ir/src/types.rs index 646c7243ae86..1d3bbce47bb0 100644 --- a/substrate/primitives/metadata-ir/src/types.rs +++ b/substrate/primitives/metadata-ir/src/types.rs @@ -134,6 +134,8 @@ pub struct PalletMetadataIR { pub index: u8, /// Pallet documentation. pub docs: Vec, + /// Pallet associated types metadata. + pub associated_types: Vec>, } impl IntoPortable for PalletMetadataIR { @@ -149,6 +151,7 @@ impl IntoPortable for PalletMetadataIR { error: self.error.map(|error| error.into_portable(registry)), index: self.index, docs: registry.map_into_portable(self.docs), + associated_types: registry.map_into_portable(self.associated_types), } } } diff --git a/substrate/primitives/metadata-ir/src/v14.rs b/substrate/primitives/metadata-ir/src/v14.rs index e1b7a24f7657..1915ba6daa58 100644 --- a/substrate/primitives/metadata-ir/src/v14.rs +++ b/substrate/primitives/metadata-ir/src/v14.rs @@ -51,7 +51,7 @@ impl From for PalletMetadata { constants: ir.constants.into_iter().map(Into::into).collect(), error: ir.error.map(Into::into), index: ir.index, - // Note: ir.docs not part of v14. + // Note: ir.docs and ir.associated_types are not part of v14. } } } diff --git a/substrate/primitives/metadata-ir/src/v15.rs b/substrate/primitives/metadata-ir/src/v15.rs index 41afd1ee9786..bdf14660c329 100644 --- a/substrate/primitives/metadata-ir/src/v15.rs +++ b/substrate/primitives/metadata-ir/src/v15.rs @@ -81,6 +81,7 @@ impl From for PalletMetadata { error: ir.error.map(Into::into), index: ir.index, docs: ir.docs, + // Note: ir.associated_types are not part of v15. } } } From b1d37e2cfe53c4b1ab3a0362f1333581ce0e57d5 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 17 May 2024 15:34:59 +0300 Subject: [PATCH 21/24] Add typeInfo to types and custom cargo patch Signed-off-by: Alexandru Vasile --- Cargo.lock | 2 -- cumulus/pallets/xcmp-queue/Cargo.toml | 2 +- polkadot/parachain/Cargo.toml | 3 ++- polkadot/xcm/Cargo.toml | 2 +- polkadot/xcm/pallet-xcm/Cargo.toml | 2 +- substrate/frame/executive/src/tests.rs | 1 + substrate/frame/multisig/src/tests.rs | 1 + substrate/frame/proxy/src/tests.rs | 2 ++ substrate/frame/referenda/src/mock.rs | 1 + substrate/frame/scheduler/src/mock.rs | 1 + .../procedural/src/pallet/parse/config.rs | 25 ++++++++++++++++--- .../procedural/src/pallet/parse/mod.rs | 1 + substrate/frame/support/src/dispatch.rs | 2 +- .../support/src/storage/generator/mod.rs | 2 +- substrate/frame/support/src/tests/mod.rs | 2 +- substrate/frame/support/src/traits/members.rs | 3 +++ substrate/frame/support/test/src/lib.rs | 3 ++- substrate/frame/support/test/tests/origin.rs | 1 + substrate/frame/system/src/lib.rs | 2 +- substrate/frame/utility/src/tests.rs | 1 + substrate/primitives/core/Cargo.toml | 2 +- substrate/primitives/runtime/src/traits.rs | 3 ++- substrate/primitives/weights/Cargo.toml | 2 +- 23 files changed, 49 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1fe4012070a0..287cdc4faa57 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1629,8 +1629,6 @@ dependencies = [ [[package]] name = "bounded-collections" version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d32385ecb91a31bddaf908e8dcf4a15aef1bcd3913cc03ebfad02ff6d568abc1" dependencies = [ "log", "parity-scale-codec", diff --git a/cumulus/pallets/xcmp-queue/Cargo.toml b/cumulus/pallets/xcmp-queue/Cargo.toml index ab196c6d3ec6..50e6841482e5 100644 --- a/cumulus/pallets/xcmp-queue/Cargo.toml +++ b/cumulus/pallets/xcmp-queue/Cargo.toml @@ -34,7 +34,7 @@ cumulus-primitives-core = { path = "../../primitives/core", default-features = f # Optional import for benchmarking frame-benchmarking = { path = "../../../substrate/frame/benchmarking", default-features = false, optional = true } -bounded-collections = { version = "0.2.0", default-features = false } +bounded-collections = { path = "/home/lexnv/workspace/parity-common/bounded-collections", default-features = false } # Bridges bp-xcm-bridge-hub-router = { path = "../../../bridges/primitives/xcm-bridge-hub-router", default-features = false, optional = true } diff --git a/polkadot/parachain/Cargo.toml b/polkadot/parachain/Cargo.toml index 15eea2addc89..78f4fe979783 100644 --- a/polkadot/parachain/Cargo.toml +++ b/polkadot/parachain/Cargo.toml @@ -21,7 +21,8 @@ sp-core = { path = "../../substrate/primitives/core", default-features = false, sp-weights = { path = "../../substrate/primitives/weights", default-features = false } polkadot-core-primitives = { path = "../core-primitives", default-features = false } derive_more = "0.99.11" -bounded-collections = { version = "0.2.0", default-features = false, features = ["serde"] } + +bounded-collections = { path = "/home/lexnv/workspace/parity-common/bounded-collections", default-features = false, features = ["serde"] } # all optional crates. serde = { features = ["alloc", "derive"], workspace = true } diff --git a/polkadot/xcm/Cargo.toml b/polkadot/xcm/Cargo.toml index b214342d2f48..c115019cd4e2 100644 --- a/polkadot/xcm/Cargo.toml +++ b/polkadot/xcm/Cargo.toml @@ -11,7 +11,7 @@ workspace = true [dependencies] array-bytes = "6.1" -bounded-collections = { version = "0.2.0", default-features = false, features = ["serde"] } +bounded-collections = { path = "/home/lexnv/workspace/parity-common/bounded-collections", default-features = false, features = ["serde"] } derivative = { version = "2.2.0", default-features = false, features = ["use_core"] } impl-trait-for-tuples = "0.2.2" log = { workspace = true } diff --git a/polkadot/xcm/pallet-xcm/Cargo.toml b/polkadot/xcm/pallet-xcm/Cargo.toml index 460597e6649a..49613ac26b95 100644 --- a/polkadot/xcm/pallet-xcm/Cargo.toml +++ b/polkadot/xcm/pallet-xcm/Cargo.toml @@ -10,7 +10,7 @@ license.workspace = true workspace = true [dependencies] -bounded-collections = { version = "0.2.0", default-features = false } +bounded-collections = { path = "/home/lexnv/workspace/parity-common/bounded-collections", default-features = false } codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive"] } scale-info = { version = "2.11.1", default-features = false, features = ["derive"] } serde = { optional = true, features = ["derive"], workspace = true, default-features = true } diff --git a/substrate/frame/executive/src/tests.rs b/substrate/frame/executive/src/tests.rs index e3721f7b6dcb..729e00ec0422 100644 --- a/substrate/frame/executive/src/tests.rs +++ b/substrate/frame/executive/src/tests.rs @@ -398,6 +398,7 @@ parameter_types! { pub static SystemCallbacksCalled: u32 = 0; } +#[derive(scale_info::TypeInfo)] pub struct MockedSystemCallbacks; impl PreInherents for MockedSystemCallbacks { fn pre_inherents() { diff --git a/substrate/frame/multisig/src/tests.rs b/substrate/frame/multisig/src/tests.rs index 0d73e3db6615..626d9c8ad829 100644 --- a/substrate/frame/multisig/src/tests.rs +++ b/substrate/frame/multisig/src/tests.rs @@ -53,6 +53,7 @@ impl pallet_balances::Config for Test { type AccountStore = System; } +#[derive(scale_info::TypeInfo)] pub struct TestBaseCallFilter; impl Contains for TestBaseCallFilter { fn contains(c: &RuntimeCall) -> bool { diff --git a/substrate/frame/proxy/src/tests.rs b/substrate/frame/proxy/src/tests.rs index 3ed61fbedaaa..e2bb1526c7e4 100644 --- a/substrate/frame/proxy/src/tests.rs +++ b/substrate/frame/proxy/src/tests.rs @@ -102,6 +102,8 @@ impl InstanceFilter for ProxyType { self == &ProxyType::Any || self == o } } + +#[derive(scale_info::TypeInfo)] pub struct BaseFilter; impl Contains for BaseFilter { fn contains(c: &RuntimeCall) -> bool { diff --git a/substrate/frame/referenda/src/mock.rs b/substrate/frame/referenda/src/mock.rs index 135476d7cb13..07ce204d99c4 100644 --- a/substrate/frame/referenda/src/mock.rs +++ b/substrate/frame/referenda/src/mock.rs @@ -48,6 +48,7 @@ frame_support::construct_runtime!( ); // Test that a fitlered call can be dispatched. +#[derive(scale_info::TypeInfo)] pub struct BaseFilter; impl Contains for BaseFilter { fn contains(call: &RuntimeCall) -> bool { diff --git a/substrate/frame/scheduler/src/mock.rs b/substrate/frame/scheduler/src/mock.rs index 8d36ca1c42e3..7fb27835f555 100644 --- a/substrate/frame/scheduler/src/mock.rs +++ b/substrate/frame/scheduler/src/mock.rs @@ -123,6 +123,7 @@ frame_support::construct_runtime!( ); // Scheduler must dispatch with root and no filter, this tests base filter is indeed not used. +#[derive(scale_info::TypeInfo)] pub struct BaseFilter; impl Contains for BaseFilter { fn contains(call: &RuntimeCall) -> bool { diff --git a/substrate/frame/support/procedural/src/pallet/parse/config.rs b/substrate/frame/support/procedural/src/pallet/parse/config.rs index b09ac04b6415..5bd494c8b3cf 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/config.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/config.rs @@ -137,8 +137,8 @@ pub struct AssociatedTypeMetadataDef { pub doc: Vec, } -impl From<&syn::TraitItemType> for AssociatedTypeMetadataDef { - fn from(trait_ty: &syn::TraitItemType) -> Self { +impl From<&mut syn::TraitItemType> for AssociatedTypeMetadataDef { + fn from(trait_ty: &mut syn::TraitItemType) -> Self { let ident = trait_ty.ident.clone(); let doc = get_doc_literals(&trait_ty.attrs); @@ -354,6 +354,7 @@ impl ConfigDef { index: usize, item: &mut syn::Item, enable_default: bool, + scrate: &syn::Path, ) -> syn::Result { let syn::Item::Trait(item) = item else { let msg = "Invalid pallet::config, expected trait definition"; @@ -467,7 +468,25 @@ impl ConfigDef { } if !is_event && !already_constant { - if let syn::TraitItem::Type(ref ty) = trait_item { + if let syn::TraitItem::Type(ty) = trait_item { + let has_type_info_bound = ty.bounds.iter().any(|b| { + syn::parse2::(b.to_token_stream()).map_or(false, |path| { + path.segments.iter().any(|s| s.ident == "TypeInfo") + }) + }); + + if !has_type_info_bound { + // Error here is one way to reason about type bounds: + // let msg = "Invalid pallet::config, expected associated type to have + // `TypeInfo` bound"; return Err(syn::Error::new(ty.span(), msg)) + + let extra_bound = syn::parse2::(quote::quote! { + #scrate::__private::scale_info::TypeInfo + }) + .expect("Valid TypeInfo path"); + ty.bounds.push(extra_bound); + } + associated_types_metadata.push(AssociatedTypeMetadataDef::from(ty)); } } diff --git a/substrate/frame/support/procedural/src/pallet/parse/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/mod.rs index 6e12774611dd..3d58d8e07462 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/mod.rs @@ -116,6 +116,7 @@ impl Def { index, item, with_default, + &frame_support, )?), Some(PalletAttr::Pallet(span)) if pallet_struct.is_none() => { let p = pallet_struct::PalletStructDef::try_from(span, index, item)?; diff --git a/substrate/frame/support/src/dispatch.rs b/substrate/frame/support/src/dispatch.rs index 4a313551aca6..473efe372b3b 100644 --- a/substrate/frame/support/src/dispatch.rs +++ b/substrate/frame/support/src/dispatch.rs @@ -692,7 +692,7 @@ mod weight_tests { type Block: Parameter + sp_runtime::traits::Block; type AccountId; type Balance; - type BaseCallFilter: crate::traits::Contains; + type BaseCallFilter: crate::traits::Contains + scale_info::TypeInfo; type RuntimeOrigin; type RuntimeCall; type RuntimeTask; diff --git a/substrate/frame/support/src/storage/generator/mod.rs b/substrate/frame/support/src/storage/generator/mod.rs index dd6d622852db..496784118364 100644 --- a/substrate/frame/support/src/storage/generator/mod.rs +++ b/substrate/frame/support/src/storage/generator/mod.rs @@ -60,7 +60,7 @@ mod tests { pub trait Config: 'static { type Block: sp_runtime::traits::Block; type AccountId; - type BaseCallFilter: crate::traits::Contains; + type BaseCallFilter: crate::traits::Contains + scale_info::TypeInfo; type RuntimeOrigin; type RuntimeCall; type RuntimeTask; diff --git a/substrate/frame/support/src/tests/mod.rs b/substrate/frame/support/src/tests/mod.rs index 88afa243f093..cec3e35255f3 100644 --- a/substrate/frame/support/src/tests/mod.rs +++ b/substrate/frame/support/src/tests/mod.rs @@ -68,7 +68,7 @@ pub mod frame_system { type Block: Parameter + sp_runtime::traits::Block; type AccountId; #[pallet::no_default_bounds] - type BaseCallFilter: crate::traits::Contains; + type BaseCallFilter: crate::traits::Contains + scale_info::TypeInfo; #[pallet::no_default_bounds] type RuntimeOrigin; #[pallet::no_default_bounds] diff --git a/substrate/frame/support/src/traits/members.rs b/substrate/frame/support/src/traits/members.rs index 53de84ab2245..4fc50e05b918 100644 --- a/substrate/frame/support/src/traits/members.rs +++ b/substrate/frame/support/src/traits/members.rs @@ -76,6 +76,7 @@ impl, CB: Contains> ContainsPair for FromContains } /// A [`Contains`] implementation that contains every value. +#[derive(scale_info::TypeInfo)] pub enum Everything {} impl Contains for Everything { fn contains(_: &T) -> bool { @@ -102,6 +103,7 @@ impl ContainsPair for Nothing { } /// A [`Contains`] implementation that contains everything except the values in `Exclude`. +#[derive(scale_info::TypeInfo)] pub struct EverythingBut(PhantomData); impl> Contains for EverythingBut { fn contains(t: &T) -> bool { @@ -132,6 +134,7 @@ impl, Except: ContainsPair> ContainsPair(PhantomData<(These, Those)>); impl, Those: Contains> Contains for InsideBoth { fn contains(t: &T) -> bool { diff --git a/substrate/frame/support/test/src/lib.rs b/substrate/frame/support/test/src/lib.rs index a8a723375033..4f9599427e0f 100644 --- a/substrate/frame/support/test/src/lib.rs +++ b/substrate/frame/support/test/src/lib.rs @@ -44,7 +44,8 @@ pub mod pallet { /// The account type. type AccountId: Parameter + Member + MaxEncodedLen; /// The basic call filter to use in Origin. - type BaseCallFilter: frame_support::traits::Contains; + type BaseCallFilter: frame_support::traits::Contains + + scale_info::TypeInfo; /// The runtime origin type. type RuntimeOrigin: Into, Self::RuntimeOrigin>> + From>; diff --git a/substrate/frame/support/test/tests/origin.rs b/substrate/frame/support/test/tests/origin.rs index a25c575cc517..a0ac1ef16215 100644 --- a/substrate/frame/support/test/tests/origin.rs +++ b/substrate/frame/support/test/tests/origin.rs @@ -145,6 +145,7 @@ pub mod module { } } +#[derive(scale_info::TypeInfo)] pub struct BaseCallFilter; impl Contains for BaseCallFilter { fn contains(c: &RuntimeCall) -> bool { diff --git a/substrate/frame/system/src/lib.rs b/substrate/frame/system/src/lib.rs index 30df4dcfd43e..a0fbdbbcfc7f 100644 --- a/substrate/frame/system/src/lib.rs +++ b/substrate/frame/system/src/lib.rs @@ -448,7 +448,7 @@ pub mod pallet { /// [`frame_support::traits::EverythingBut`] et al. The default would be /// [`frame_support::traits::Everything`]. #[pallet::no_default_bounds] - type BaseCallFilter: Contains; + type BaseCallFilter: Contains + scale_info::TypeInfo; /// Block & extrinsics weights: base values and limits. #[pallet::constant] diff --git a/substrate/frame/utility/src/tests.rs b/substrate/frame/utility/src/tests.rs index 9bcbec99f3b4..217b8a62ab8c 100644 --- a/substrate/frame/utility/src/tests.rs +++ b/substrate/frame/utility/src/tests.rs @@ -205,6 +205,7 @@ impl pallet_collective::Config for Test { impl example::Config for Test {} +#[derive(scale_info::TypeInfo)] pub struct TestBaseCallFilter; impl Contains for TestBaseCallFilter { fn contains(c: &RuntimeCall) -> bool { diff --git a/substrate/primitives/core/Cargo.toml b/substrate/primitives/core/Cargo.toml index 8437497b02bd..820cdf8b8a08 100644 --- a/substrate/primitives/core/Cargo.toml +++ b/substrate/primitives/core/Cargo.toml @@ -20,7 +20,7 @@ codec = { package = "parity-scale-codec", version = "3.6.1", default-features = scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } log = { workspace = true } serde = { optional = true, features = ["alloc", "derive"], workspace = true } -bounded-collections = { version = "0.2.0", default-features = false } +bounded-collections = { path = "/home/lexnv/workspace/parity-common/bounded-collections", default-features = false } primitive-types = { version = "0.12.0", default-features = false, features = ["codec", "scale-info"] } impl-serde = { version = "0.4.0", default-features = false, optional = true } hash-db = { version = "0.16.0", default-features = false } diff --git a/substrate/primitives/runtime/src/traits.rs b/substrate/primitives/runtime/src/traits.rs index d023aa045dbe..6c928313938b 100644 --- a/substrate/primitives/runtime/src/traits.rs +++ b/substrate/primitives/runtime/src/traits.rs @@ -226,7 +226,7 @@ pub trait StaticLookup { } /// A lookup implementation returning the input value. -#[derive(Default, Clone, Copy, PartialEq, Eq)] +#[derive(Default, Clone, Copy, PartialEq, Eq, scale_info::TypeInfo)] pub struct IdentityLookup(PhantomData); impl StaticLookup for IdentityLookup { type Source = T; @@ -248,6 +248,7 @@ impl Lookup for IdentityLookup { } /// A lookup implementation returning the `AccountId` from a `MultiAddress`. +#[derive(scale_info::TypeInfo)] pub struct AccountIdLookup(PhantomData<(AccountId, AccountIndex)>); impl StaticLookup for AccountIdLookup where diff --git a/substrate/primitives/weights/Cargo.toml b/substrate/primitives/weights/Cargo.toml index e73d4a702b42..14995d74c578 100644 --- a/substrate/primitives/weights/Cargo.toml +++ b/substrate/primitives/weights/Cargo.toml @@ -16,7 +16,7 @@ workspace = true targets = ["x86_64-unknown-linux-gnu"] [dependencies] -bounded-collections = { version = "0.2.0", default-features = false } +bounded-collections = { path = "/home/lexnv/workspace/parity-common/bounded-collections", default-features = false } codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive"] } scale-info = { version = "2.11.1", default-features = false, features = ["derive"] } serde = { optional = true, features = ["alloc", "derive"], workspace = true } From 97396d003a59bd5797458ce638233adb3a22fcd8 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 17 May 2024 15:57:10 +0300 Subject: [PATCH 22/24] frame/proc: Extract cfg attributes Signed-off-by: Alexandru Vasile --- .../support/procedural/src/pallet/expand/config.rs | 9 +++++++++ .../support/procedural/src/pallet/parse/config.rs | 7 +++++-- .../frame/support/procedural/tools/src/lib.rs | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/expand/config.rs b/substrate/frame/support/procedural/src/pallet/expand/config.rs index 3478f6730803..c39cacfb0642 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/config.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/config.rs @@ -113,11 +113,20 @@ pub fn expand_config_metadata(def: &Def) -> proc_macro2::TokenStream { let types = def.config.associated_types_metadata.iter().map(|metadata| { let ident = &metadata.ident; let ident_str = format!("{}", ident); + let cfgs = &metadata.cfg; + + if ident == "BenchmarkHelper" { + println!(); + println!(); + println!(); + println!(" cfg {:?}", cfgs); + } let no_docs = vec![]; let doc = if cfg!(feature = "no-metadata-docs") { &no_docs } else { &metadata.doc }; quote::quote!({ + #( #cfgs ) * #frame_support::__private::metadata_ir::PalletAssociatedTypesMetadataIR { name: #ident_str, ty: #frame_support::__private::scale_info::meta_type::< diff --git a/substrate/frame/support/procedural/src/pallet/parse/config.rs b/substrate/frame/support/procedural/src/pallet/parse/config.rs index 5bd494c8b3cf..9f92360cff7f 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/config.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/config.rs @@ -16,7 +16,7 @@ // limitations under the License. use super::helper; -use frame_support_procedural_tools::{get_doc_literals, is_using_frame_crate}; +use frame_support_procedural_tools::{get_cfg_attributes, get_doc_literals, is_using_frame_crate}; use quote::ToTokens; use syn::{spanned::Spanned, token, Token}; @@ -135,14 +135,17 @@ pub struct AssociatedTypeMetadataDef { pub ident: syn::Ident, /// The doc associated pub doc: Vec, + /// The cfg associated. + pub cfg: Vec, } impl From<&mut syn::TraitItemType> for AssociatedTypeMetadataDef { fn from(trait_ty: &mut syn::TraitItemType) -> Self { let ident = trait_ty.ident.clone(); let doc = get_doc_literals(&trait_ty.attrs); + let cfg = get_cfg_attributes(&trait_ty.attrs); - Self { ident, doc } + Self { ident, doc, cfg } } } diff --git a/substrate/frame/support/procedural/tools/src/lib.rs b/substrate/frame/support/procedural/tools/src/lib.rs index 8952cd6011ff..d7ba868db092 100644 --- a/substrate/frame/support/procedural/tools/src/lib.rs +++ b/substrate/frame/support/procedural/tools/src/lib.rs @@ -163,3 +163,17 @@ pub fn get_doc_literals(attrs: &[syn::Attribute]) -> Vec { }) .collect() } + +/// Return all cfg attributes literals found. +pub fn get_cfg_attributes(attrs: &[syn::Attribute]) -> Vec { + attrs + .iter() + .filter_map(|attr| { + if let syn::Meta::List(meta) = &attr.meta { + meta.path.get_ident().filter(|ident| *ident == "cfg").map(|_| attr.clone()) + } else { + None + } + }) + .collect() +} From 3f5597ecc7096566cd946a5de2f3267f60f095c3 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 17 May 2024 16:04:10 +0300 Subject: [PATCH 23/24] frame/config: Add type attributes to metadata expansion Signed-off-by: Alexandru Vasile --- .../procedural/src/pallet/expand/config.rs | 23 ++++++++++--------- substrate/frame/support/src/migrations.rs | 1 + 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/expand/config.rs b/substrate/frame/support/procedural/src/pallet/expand/config.rs index c39cacfb0642..95f6c2105309 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/config.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/config.rs @@ -125,16 +125,17 @@ pub fn expand_config_metadata(def: &Def) -> proc_macro2::TokenStream { let no_docs = vec![]; let doc = if cfg!(feature = "no-metadata-docs") { &no_docs } else { &metadata.doc }; - quote::quote!({ - #( #cfgs ) * - #frame_support::__private::metadata_ir::PalletAssociatedTypesMetadataIR { - name: #ident_str, - ty: #frame_support::__private::scale_info::meta_type::< - ::#ident - >(), - docs: #frame_support::__private::sp_std::vec![ #( #doc ),* ], - } - }) + quote::quote!( + #( #cfgs ) * { + #frame_support::__private::metadata_ir::PalletAssociatedTypesMetadataIR { + name: #ident_str, + ty: #frame_support::__private::scale_info::meta_type::< + ::#ident + >(), + docs: #frame_support::__private::sp_std::vec![ #( #doc ),* ], + } + }, + ) }); quote::quote!( @@ -144,7 +145,7 @@ pub fn expand_config_metadata(def: &Def) -> proc_macro2::TokenStream { pub fn pallet_associated_types_metadata() -> #frame_support::__private::sp_std::vec::Vec<#frame_support::__private::metadata_ir::PalletAssociatedTypesMetadataIR> { - #frame_support::__private::sp_std::vec![ #( #types ),* ] + #frame_support::__private::sp_std::vec![ #( #types )* ] } } ) diff --git a/substrate/frame/support/src/migrations.rs b/substrate/frame/support/src/migrations.rs index 968639e02d35..c2cb48b4ff0b 100644 --- a/substrate/frame/support/src/migrations.rs +++ b/substrate/frame/support/src/migrations.rs @@ -476,6 +476,7 @@ pub trait FailedMigrationHandler { /// Do now allow any transactions to be processed after a runtime upgrade failed. /// /// This is **not a sane default**, since it prevents governance intervention. +#[derive(scale_info::TypeInfo)] pub struct FreezeChainOnFailedMigration; impl FailedMigrationHandler for FreezeChainOnFailedMigration { From a6532ed7f126263367e1f2c274ac0fafdec2473e Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Mon, 20 May 2024 12:33:49 +0300 Subject: [PATCH 24/24] Add type info on other config types Signed-off-by: Alexandru Vasile --- .../pallets/collator-selection/src/weights.rs | 1 + .../assets/asset-hub-rococo/src/lib.rs | 5 +++++ .../collectives/collectives-westend/src/lib.rs | 1 + polkadot/runtime/rococo/src/lib.rs | 1 + polkadot/runtime/westend/src/lib.rs | 5 +++++ substrate/bin/node/runtime/src/impls.rs | 1 + substrate/bin/node/runtime/src/lib.rs | 18 ++++++++++++++++++ substrate/frame/alliance/src/mock.rs | 2 ++ substrate/frame/babe/src/equivocation.rs | 1 + substrate/frame/beefy/src/equivocation.rs | 1 + substrate/frame/contracts/src/lib.rs | 1 + substrate/frame/grandpa/src/equivocation.rs | 1 + substrate/frame/migrations/src/lib.rs | 1 + .../src/construct_runtime/expand/origin.rs | 1 + .../procedural/src/pallet/expand/config.rs | 12 ++++++------ substrate/frame/system/src/lib.rs | 1 + 16 files changed, 47 insertions(+), 6 deletions(-) diff --git a/cumulus/pallets/collator-selection/src/weights.rs b/cumulus/pallets/collator-selection/src/weights.rs index 1c01ad6cd6fe..a02c1789d451 100644 --- a/cumulus/pallets/collator-selection/src/weights.rs +++ b/cumulus/pallets/collator-selection/src/weights.rs @@ -40,6 +40,7 @@ pub trait WeightInfo { } /// Weights for pallet_collator_selection using the Substrate node and recommended hardware. +#[derive(scale_info::TypeInfo)] pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { fn set_invulnerables(b: u32) -> Weight { diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 151734804632..c8b0c0514dca 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -1678,8 +1678,13 @@ cumulus_pallet_parachain_system::register_validate_block! { parameter_types! { // The deposit configuration for the singed migration. Specially if you want to allow any signed account to do the migration (see `SignedFilter`, these deposits should be high) + #[derive(scale_info::TypeInfo)] pub const MigrationSignedDepositPerItem: Balance = CENTS; + + #[derive(scale_info::TypeInfo)] pub const MigrationSignedDepositBase: Balance = 2_000 * CENTS; + + #[derive(scale_info::TypeInfo)] pub const MigrationMaxKeyLen: u32 = 512; } diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index 7274e9acdcd6..5d7689bad25d 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -544,6 +544,7 @@ parameter_types! { pub WestendTreasuryAccount: AccountId = WESTEND_TREASURY_PALLET_ID.into_account_truncating(); // The number of blocks a member must wait between giving a retirement notice and retiring. // Supposed to be greater than time required to `kick_member` with alliance motion. + #[derive(scale_info::TypeInfo)] pub const AllianceRetirementPeriod: BlockNumber = (90 * DAYS) + ALLIANCE_MOTION_DURATION; } diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 287ae9937da4..b9465c9ec1f2 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -344,6 +344,7 @@ impl pallet_preimage::Config for Runtime { parameter_types! { pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK; + #[derive(scale_info::TypeInfo)] pub ReportLongevity: u64 = EpochDurationInBlocks::get() as u64 * 10; } diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 7125f5d34c40..67dd0f73de6b 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -1367,8 +1367,13 @@ impl pallet_root_testing::Config for Runtime { parameter_types! { // The deposit configuration for the singed migration. Specially if you want to allow any signed account to do the migration (see `SignedFilter`, these deposits should be high) + #[derive(scale_info::TypeInfo)] pub const MigrationSignedDepositPerItem: Balance = 1 * CENTS; + + #[derive(scale_info::TypeInfo)] pub const MigrationSignedDepositBase: Balance = 20 * CENTS * 100; + + #[derive(scale_info::TypeInfo)] pub const MigrationMaxKeyLen: u32 = 512; } diff --git a/substrate/bin/node/runtime/src/impls.rs b/substrate/bin/node/runtime/src/impls.rs index 34f043b33a4e..3c0c7c019cc4 100644 --- a/substrate/bin/node/runtime/src/impls.rs +++ b/substrate/bin/node/runtime/src/impls.rs @@ -55,6 +55,7 @@ impl HandleCredit for CreditToBlockAuthor { } } +#[derive(scale_info::TypeInfo)] pub struct AllianceIdentityVerifier; impl IdentityVerifier for AllianceIdentityVerifier { fn has_required_identities(who: &AccountId) -> bool { diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 18b0d0c31a4d..f0fcf6bfe890 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -489,6 +489,8 @@ parameter_types! { // Attempting to do so will brick block production. pub const EpochDuration: u64 = EPOCH_DURATION_IN_SLOTS; pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK; + + #[derive(scale_info::TypeInfo)] pub const ReportLongevity: u64 = BondingDuration::get() as u64 * SessionsPerEra::get() as u64 * EpochDuration::get(); } @@ -1954,8 +1956,13 @@ impl pallet_whitelist::Config for Runtime { } parameter_types! { + #[derive(scale_info::TypeInfo)] pub const MigrationSignedDepositPerItem: Balance = 1 * CENTS; + + #[derive(scale_info::TypeInfo)] pub const MigrationSignedDepositBase: Balance = 20 * DOLLARS; + + #[derive(scale_info::TypeInfo)] pub const MigrationMaxKeyLen: u32 = 512; } @@ -1978,8 +1985,13 @@ impl pallet_state_trie_migration::Config for Runtime { const ALLIANCE_MOTION_DURATION_IN_BLOCKS: BlockNumber = 5 * DAYS; parameter_types! { + #[derive(scale_info::TypeInfo)] pub const AllianceMotionDuration: BlockNumber = ALLIANCE_MOTION_DURATION_IN_BLOCKS; + + #[derive(scale_info::TypeInfo)] pub const AllianceMaxProposals: u32 = 100; + + #[derive(scale_info::TypeInfo)] pub const AllianceMaxMembers: u32 = 100; } @@ -1999,6 +2011,7 @@ impl pallet_collective::Config for Runtime { parameter_types! { pub const MaxFellows: u32 = AllianceMaxMembers::get(); + #[derive(scale_info::TypeInfo)] pub const MaxAllies: u32 = 100; pub const AllyDeposit: Balance = 10 * DOLLARS; pub const RetirementPeriod: BlockNumber = ALLIANCE_MOTION_DURATION_IN_BLOCKS + (1 * DAYS); @@ -2065,6 +2078,7 @@ impl pallet_statement::Config for Runtime { } parameter_types! { + #[derive(scale_info::TypeInfo)] pub MbmServiceWeight: Weight = Perbill::from_percent(80) * RuntimeBlockWeights::get().max_block; } @@ -2087,6 +2101,7 @@ parameter_types! { pub const BrokerPalletId: PalletId = PalletId(*b"py/broke"); } +#[derive(scale_info::TypeInfo)] pub struct IntoAuthor; impl OnUnbalanced> for IntoAuthor { fn on_nonzero_unbalanced(credit: Credit) { @@ -2100,6 +2115,7 @@ parameter_types! { pub storage CoretimeRevenue: Option<(BlockNumber, Balance)> = None; } +#[derive(scale_info::TypeInfo)] pub struct CoretimeProvider; impl CoretimeInterface for CoretimeProvider { type AccountId = AccountId; @@ -2206,6 +2222,7 @@ impl Default for RuntimeParameters { } } +#[derive(scale_info::TypeInfo)] pub struct DynamicParametersManagerOrigin; impl EnsureOriginWithArg for DynamicParametersManagerOrigin { type Success = (); @@ -2336,6 +2353,7 @@ mod runtime { pub type Offences = pallet_offences; #[runtime::pallet_index(26)] + #[derive(scale_info::TypeInfo)] pub type Historical = pallet_session_historical; #[runtime::pallet_index(27)] diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index 7116e69efa17..a48e9cf53ae7 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -154,6 +154,7 @@ impl Verify for AccountU64 { } } +#[derive(scale_info::TypeInfo)] pub struct AllianceIdentityVerifier; impl IdentityVerifier for AllianceIdentityVerifier { fn has_required_identities(who: &AccountId) -> bool { @@ -213,6 +214,7 @@ impl ProposalProvider for AllianceProposalProvider parameter_types! { pub const MaxFellows: u32 = MaxMembers::get(); + #[derive(scale_info::TypeInfo)] pub const MaxAllies: u32 = 100; pub const AllyDeposit: u64 = 25; pub const RetirementPeriod: BlockNumber = MOTION_DURATION_IN_BLOCKS + 1; diff --git a/substrate/frame/babe/src/equivocation.rs b/substrate/frame/babe/src/equivocation.rs index ed1df640583b..4073660490db 100644 --- a/substrate/frame/babe/src/equivocation.rs +++ b/substrate/frame/babe/src/equivocation.rs @@ -104,6 +104,7 @@ impl Offence for EquivocationOffence { /// - On-chain validity checks and processing are mostly delegated to the user provided generic /// types implementing `KeyOwnerProofSystem` and `ReportOffence` traits. /// - Offence reporter for unsigned transactions is fetched via the the authorship pallet. +#[derive(scale_info::TypeInfo)] pub struct EquivocationReportSystem(sp_std::marker::PhantomData<(T, R, P, L)>); impl diff --git a/substrate/frame/beefy/src/equivocation.rs b/substrate/frame/beefy/src/equivocation.rs index aecc9e721d5c..fd9caad593fb 100644 --- a/substrate/frame/beefy/src/equivocation.rs +++ b/substrate/frame/beefy/src/equivocation.rs @@ -119,6 +119,7 @@ where /// - On-chain validity checks and processing are mostly delegated to the user provided generic /// types implementing `KeyOwnerProofSystem` and `ReportOffence` traits. /// - Offence reporter for unsigned transactions is fetched via the the authorship pallet. +#[derive(scale_info::TypeInfo)] pub struct EquivocationReportSystem(sp_std::marker::PhantomData<(T, R, P, L)>); /// Equivocation evidence convenience alias. diff --git a/substrate/frame/contracts/src/lib.rs b/substrate/frame/contracts/src/lib.rs index 3e87eb9f37ea..2bdcf133ce32 100644 --- a/substrate/frame/contracts/src/lib.rs +++ b/substrate/frame/contracts/src/lib.rs @@ -508,6 +508,7 @@ pub mod pallet { } /// A type providing default configurations for this pallet in testing environment. + #[derive(scale_info::TypeInfo)] pub struct TestDefaultConfig; impl Randomness for TestDefaultConfig { diff --git a/substrate/frame/grandpa/src/equivocation.rs b/substrate/frame/grandpa/src/equivocation.rs index 16727f79a58d..986c49fa8e63 100644 --- a/substrate/frame/grandpa/src/equivocation.rs +++ b/substrate/frame/grandpa/src/equivocation.rs @@ -114,6 +114,7 @@ impl Offence for EquivocationOffence { /// - On-chain validity checks and processing are mostly delegated to the user provided generic /// types implementing `KeyOwnerProofSystem` and `ReportOffence` traits. /// - Offence reporter for unsigned transactions is fetched via the the authorship pallet. +#[derive(scale_info::TypeInfo)] pub struct EquivocationReportSystem(sp_std::marker::PhantomData<(T, R, P, L)>); impl diff --git a/substrate/frame/migrations/src/lib.rs b/substrate/frame/migrations/src/lib.rs index 649bc314a12b..7edc3e564535 100644 --- a/substrate/frame/migrations/src/lib.rs +++ b/substrate/frame/migrations/src/lib.rs @@ -346,6 +346,7 @@ pub mod pallet { frame_support::parameter_types! { /// Maximal weight per block that can be spent on migrations in tests. + #[derive(scale_info::TypeInfo)] pub TestMaxServiceWeight: Weight = <::BlockWeights as Get>::get().max_block.div(2); } diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/origin.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/origin.rs index 83049919d01c..f60eb1b4fff5 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/origin.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/origin.rs @@ -103,6 +103,7 @@ pub fn expand_outer_origin( /// #[doc = #doc_string] #[derive(Clone)] + #[derive(#scrate::__private::scale_info::TypeInfo)] pub struct RuntimeOrigin { pub caller: OriginCaller, filter: #scrate::__private::sp_std::rc::Rc::RuntimeCall) -> bool>>, diff --git a/substrate/frame/support/procedural/src/pallet/expand/config.rs b/substrate/frame/support/procedural/src/pallet/expand/config.rs index 95f6c2105309..2757ed6bab13 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/config.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/config.rs @@ -115,12 +115,12 @@ pub fn expand_config_metadata(def: &Def) -> proc_macro2::TokenStream { let ident_str = format!("{}", ident); let cfgs = &metadata.cfg; - if ident == "BenchmarkHelper" { - println!(); - println!(); - println!(); - println!(" cfg {:?}", cfgs); - } + // if ident == "BenchmarkHelper" { + // println!(); + // println!(); + // println!(); + // println!(" cfg {:?}", cfgs); + // } let no_docs = vec![]; let doc = if cfg!(feature = "no-metadata-docs") { &no_docs } else { &metadata.doc }; diff --git a/substrate/frame/system/src/lib.rs b/substrate/frame/system/src/lib.rs index a0fbdbbcfc7f..7fa264b9a7f6 100644 --- a/substrate/frame/system/src/lib.rs +++ b/substrate/frame/system/src/lib.rs @@ -1220,6 +1220,7 @@ impl< } /// Ensure the origin is any `Signed` origin. +#[derive(scale_info::TypeInfo)] pub struct EnsureSigned(sp_std::marker::PhantomData); impl, O>> + From>, AccountId: Decode> EnsureOrigin for EnsureSigned