From 7e8baee5bddb3e7f6f4b19b8ffd4ef2a1b8f45f0 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 7 Aug 2024 18:05:05 +0300 Subject: [PATCH 01/70] metadata-ir: Introduce PalletAssociatedTypeMetadata Signed-off-by: Alexandru Vasile --- substrate/primitives/metadata-ir/src/types.rs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/substrate/primitives/metadata-ir/src/types.rs b/substrate/primitives/metadata-ir/src/types.rs index b05f26ff55d4..9001d4c034e9 100644 --- a/substrate/primitives/metadata-ir/src/types.rs +++ b/substrate/primitives/metadata-ir/src/types.rs @@ -127,6 +127,8 @@ pub struct PalletMetadataIR { pub constants: Vec>, /// Pallet error metadata. pub error: Option>, + /// Config's trait associated types. + pub associated_types: Vec>, /// Define the index of the pallet, this index will be used for the encoding of pallet event, /// call and origin variants. pub index: u8, @@ -145,6 +147,7 @@ impl IntoPortable for PalletMetadataIR { event: self.event.map(|event| event.into_portable(registry)), constants: registry.map_into_portable(self.constants), error: self.error.map(|error| error.into_portable(registry)), + associated_types: registry.map_into_portable(self.associated_types), index: self.index, docs: registry.map_into_portable(self.docs), } @@ -188,6 +191,29 @@ impl IntoPortable for ExtrinsicMetadataIR { } } +/// Metadata of a pallet's associated type. +#[derive(Clone, PartialEq, Eq, Encode, Debug)] +pub struct PalletAssociatedTypeMetadataIR { + /// The name of the associated type. + pub name: T::String, + /// The type of the associated type. + pub ty: T::Type, + /// The documentation of the associated type. + pub docs: Vec, +} + +impl IntoPortable for PalletAssociatedTypeMetadataIR { + type Output = PalletAssociatedTypeMetadataIR; + + fn into_portable(self, registry: &mut Registry) -> Self::Output { + PalletAssociatedTypeMetadataIR { + name: self.name.into_portable(registry), + ty: registry.register_type(&self.ty), + docs: registry.map_into_portable(self.docs), + } + } +} + /// Metadata of an extrinsic's signed extension. #[derive(Clone, PartialEq, Eq, Encode, Debug)] pub struct SignedExtensionMetadataIR { From 1c12f1520605ae32454ca8ab6f480ce794285f65 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 7 Aug 2024 18:11:11 +0300 Subject: [PATCH 02/70] 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 6febaac9ffa3..d4b6169e018c 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 metadata. + pub associated_types_metadata: Vec, /// Whether the trait has the associated type `Event`, note that those bounds are /// checked: /// * `IsType::RuntimeEvent` @@ -70,6 +72,23 @@ pub struct ConfigDef { pub default_sub_trait: Option, } +/// 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 } + } +} + /// Input definition for a constant in pallet config. pub struct ConstMetadataDef { /// Name of the associated type. @@ -366,6 +385,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(), @@ -405,7 +425,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" )) } @@ -437,6 +457,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() @@ -479,6 +505,7 @@ impl ConfigDef { index, has_instance, consts_metadata, + associated_types_metadata, has_event_type, where_clause, default_sub_trait, From 20b22d8d314df7dfb6590f6d54857190231b77c2 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 7 Aug 2024 18:14:29 +0300 Subject: [PATCH 03/70] frame/expand: Implement associated types expansion 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..7e67aae93410 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::PalletAssociatedTypeMetadataIR { + 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::PalletAssociatedTypeMetadataIR> + { + #frame_support::__private::sp_std::vec![ #( #types ),* ] + } + } + ) +} From 350efce92491f6cb21e641526e45cba339d2fa35 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 7 Aug 2024 18:17:37 +0300 Subject: [PATCH 04/70] frame/expand: Use provided cfgs for the associated types Signed-off-by: Alexandru Vasile --- .../support/procedural/src/pallet/expand/config.rs | 2 ++ .../support/procedural/src/pallet/parse/config.rs | 7 +++++-- .../frame/support/procedural/tools/src/lib.rs | 14 ++++++++++++++ 3 files changed, 21 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 7e67aae93410..1921922781fe 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/config.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/config.rs @@ -113,11 +113,13 @@ pub fn expand_config_metadata(def: &mut 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; 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::PalletAssociatedTypeMetadataIR { 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 d4b6169e018c..f92f69c7a1d6 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}; @@ -78,14 +78,17 @@ pub struct AssociatedTypeMetadataDef { pub ident: syn::Ident, /// The doc associated. pub doc: Vec, + /// The cfg associated. + pub cfg: 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); + 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 ea53335a88fd..d1d7efaab01d 100644 --- a/substrate/frame/support/procedural/tools/src/lib.rs +++ b/substrate/frame/support/procedural/tools/src/lib.rs @@ -181,3 +181,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 3e97971d0b4840553dbc731d8f27737e130f4411 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 7 Aug 2024 18:33:25 +0300 Subject: [PATCH 05/70] 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 ++ 3 files changed, 15 insertions(+), 2 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 daef1b171617..cbefd9601701 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs @@ -49,6 +49,7 @@ pub fn expand_runtime_metadata( let event = expand_pallet_metadata_events(&filtered_names, runtime, scrate, decl); let constants = expand_pallet_metadata_constants(runtime, decl); let errors = expand_pallet_metadata_errors(runtime, decl); + let associated_types = expand_pallet_metadata_associated_types(runtime, decl); let docs = expand_pallet_metadata_docs(runtime, decl); let attr = decl.cfg_pattern.iter().fold(TokenStream::new(), |acc, pattern| { let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) @@ -70,6 +71,7 @@ pub fn expand_runtime_metadata( constants: #constants, error: #errors, docs: #docs, + associated_types: #associated_types, } } }) @@ -256,3 +258,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 1921922781fe..6b79c4b8b25a 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()); @@ -123,7 +123,7 @@ pub fn expand_config_metadata(def: &mut Def) -> proc_macro2::TokenStream { #frame_support::__private::metadata_ir::PalletAssociatedTypeMetadataIR { 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 From 5d8021eb1b58d605e77bb16427092933525092bb Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 7 Aug 2024 19:30:44 +0300 Subject: [PATCH 06/70] frame/pallet: Introduce `config(without_metadata)` Signed-off-by: Alexandru Vasile --- .../procedural/src/pallet/parse/config.rs | 4 +- .../procedural/src/pallet/parse/mod.rs | 60 ++++++++++++++++--- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/config.rs b/substrate/frame/support/procedural/src/pallet/parse/config.rs index f92f69c7a1d6..5c11bf8dbcaf 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/config.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/config.rs @@ -36,6 +36,7 @@ mod keyword { syn::custom_keyword!(no_default); syn::custom_keyword!(no_default_bounds); syn::custom_keyword!(constant); + syn::custom_keyword!(without_metadata); } #[derive(Default)] @@ -348,6 +349,7 @@ impl ConfigDef { index: usize, item: &mut syn::Item, enable_default: bool, + without_metadata: bool, ) -> syn::Result { let syn::Item::Trait(item) = item else { let msg = "Invalid pallet::config, expected trait definition"; @@ -460,7 +462,7 @@ impl ConfigDef { } } - if !is_event && !already_constant { + if !without_metadata && !is_event && !already_constant { if let syn::TraitItem::Type(ref ty) = trait_item { 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 f55b166c7917..fe709bf89ce8 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/mod.rs @@ -43,6 +43,7 @@ pub mod tests; use composite::{keyword::CompositeKeyword, CompositeDef}; use frame_support_procedural_tools::generate_access_from_frame_or_crate; use quote::ToTokens; +use std::collections::HashSet; use syn::spanned::Spanned; /// Parsed definition of a pallet. @@ -109,12 +110,13 @@ impl Def { let pallet_attr: Option = helper::take_first_item_pallet_attr(item)?; match pallet_attr { - Some(PalletAttr::Config(_, with_default)) if config.is_none() => + Some(PalletAttr::Config{ with_default, without_metadata, ..}) if config.is_none() => config = Some(config::ConfigDef::try_from( &frame_system, index, item, with_default, + without_metadata, )?), Some(PalletAttr::Pallet(span)) if pallet_struct.is_none() => { let p = pallet_struct::PalletStructDef::try_from(span, index, item)?; @@ -548,6 +550,7 @@ mod keyword { syn::custom_keyword!(event); syn::custom_keyword!(config); syn::custom_keyword!(with_default); + syn::custom_keyword!(without_metadata); syn::custom_keyword!(hooks); syn::custom_keyword!(inherent); syn::custom_keyword!(error); @@ -561,10 +564,35 @@ mod keyword { syn::custom_keyword!(composite_enum); } +/// The possible values for the `#[pallet::config]` attribute. +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +enum ConfigValue { + /// `#[pallet::config(with_default)]` + WithDefault(keyword::with_default), + /// `#[pallet::config(without_metadata)]` + WithoutMetadata(keyword::without_metadata), +} + +impl syn::parse::Parse for ConfigValue { + fn parse(input: syn::parse::ParseStream) -> syn::Result { + if input.peek(keyword::with_default) { + Ok(ConfigValue::WithDefault(input.parse()?)) + } else if input.peek(keyword::without_metadata) { + Ok(ConfigValue::WithoutMetadata(input.parse()?)) + } else { + Err(input.error("expected `with_default` or `without_metadata`")) + } + } +} + /// Parse attributes for item in pallet module /// syntax must be `pallet::` (e.g. `#[pallet::config]`) enum PalletAttr { - Config(proc_macro2::Span, bool), + Config { + span: proc_macro2::Span, + with_default: bool, + without_metadata: bool, + }, Pallet(proc_macro2::Span), Hooks(proc_macro2::Span), /// A `#[pallet::call]` with optional attributes to specialize the behaviour. @@ -626,7 +654,7 @@ enum PalletAttr { impl PalletAttr { fn span(&self) -> proc_macro2::Span { match self { - Self::Config(span, _) => *span, + Self::Config { span, .. } => *span, Self::Pallet(span) => *span, Self::Hooks(span) => *span, Self::Tasks(span) => *span, @@ -661,13 +689,31 @@ impl syn::parse::Parse for PalletAttr { let lookahead = content.lookahead1(); if lookahead.peek(keyword::config) { let span = content.parse::()?.span(); - let with_default = content.peek(syn::token::Paren); - if with_default { + if content.peek(syn::token::Paren) { let inside_config; + + // Parse (with_default, without_metadata) attributes. let _paren = syn::parenthesized!(inside_config in content); - inside_config.parse::()?; + + let fields: syn::punctuated::Punctuated = + inside_config.parse_terminated(ConfigValue::parse, syn::Token![,])?; + let config_values = fields.iter().collect::>(); + + let with_default = + config_values.iter().any(|v| matches!(v, ConfigValue::WithDefault(_))); + let without_metadata = + config_values.iter().any(|v| matches!(v, ConfigValue::WithoutMetadata(_))); + + // Check for duplicated attributes. + let config_set = config_values.iter().collect::>(); + if config_set.len() != config_values.len() { + return Err(syn::Error::new(span, "Invalid duplicated attribute")) + } + + Ok(PalletAttr::Config { span, with_default, without_metadata }) + } else { + Ok(PalletAttr::Config { span, with_default: false, without_metadata: false }) } - Ok(PalletAttr::Config(span, with_default)) } else if lookahead.peek(keyword::pallet) { Ok(PalletAttr::Pallet(content.parse::()?.span())) } else if lookahead.peek(keyword::hooks) { From 5679244aa99794ef415a17992f2c237ee1f40440 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 7 Aug 2024 19:42:50 +0300 Subject: [PATCH 07/70] frame/pallet: Introduce `#[pallet::include_metadata]` for associated types Signed-off-by: Alexandru Vasile --- .../procedural/src/pallet/parse/config.rs | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 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 5c11bf8dbcaf..65b2b195e94c 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/config.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/config.rs @@ -36,7 +36,7 @@ mod keyword { syn::custom_keyword!(no_default); syn::custom_keyword!(no_default_bounds); syn::custom_keyword!(constant); - syn::custom_keyword!(without_metadata); + syn::custom_keyword!(include_metadata); } #[derive(Default)] @@ -167,6 +167,8 @@ pub enum PalletAttrType { NoBounds(keyword::no_default_bounds), #[peek(keyword::constant, name = "constant")] Constant(keyword::constant), + #[peek(keyword::include_metadata, name = "include_metadata")] + IncludeMetadata(keyword::include_metadata), } /// Parsing for `#[pallet::X]` @@ -349,7 +351,7 @@ impl ConfigDef { index: usize, item: &mut syn::Item, enable_default: bool, - without_metadata: bool, + enable_associated_metadata: bool, ) -> syn::Result { let syn::Item::Trait(item) = item else { let msg = "Invalid pallet::config, expected trait definition"; @@ -406,6 +408,7 @@ impl ConfigDef { let mut already_no_default = false; let mut already_constant = false; let mut already_no_default_bounds = false; + let mut already_collected_associated_type = false; while let Ok(Some(pallet_attr)) = helper::take_first_item_pallet_attr::(trait_item) @@ -426,6 +429,31 @@ impl ConfigDef { trait_item.span(), "Invalid #[pallet::constant] in #[pallet::config], expected type item", )), + (PalletAttrType::IncludeMetadata(_), syn::TraitItem::Type(ref typ)) => { + if is_event { + return Err(syn::Error::new( + pallet_attr._bracket.span.join(), + "Invalid #[pallet::include_metadata] in `type RuntimeEvent`, \ + expected type item. The associated type `RuntimeEvent` is already collected.", + )) + } + + if already_constant { + return Err(syn::Error::new( + pallet_attr._bracket.span.join(), + "Invalid #[pallet::include_metadata] in #[pallet::constant], \ + expected type item. Pallet constant's metadata is already collected.", + )) + } + + already_collected_associated_type = true; + associated_types_metadata.push(AssociatedTypeMetadataDef::from(typ)); + } + (PalletAttrType::IncludeMetadata(_), _) => + return Err(syn::Error::new( + pallet_attr._bracket.span.join(), + "Invalid #[pallet::include_metadata] in #[pallet::config], expected type item", + )), (PalletAttrType::NoDefault(_), _) => { if !enable_default { return Err(syn::Error::new( @@ -462,7 +490,7 @@ impl ConfigDef { } } - if !without_metadata && !is_event && !already_constant { + if !already_collected_associated_type && enable_associated_metadata { if let syn::TraitItem::Type(ref ty) = trait_item { associated_types_metadata.push(AssociatedTypeMetadataDef::from(ty)); } From 958611ef5a5a5a73ca51878bce4a6e0b1b111740 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 7 Aug 2024 20:13:15 +0300 Subject: [PATCH 08/70] frame/pallet: Include associated type iff bounds contain TypeInfo Signed-off-by: Alexandru Vasile --- .../procedural/src/pallet/parse/config.rs | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 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 65b2b195e94c..2f8a0923b6c5 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/config.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/config.rs @@ -18,7 +18,7 @@ use super::helper; use frame_support_procedural_tools::{get_cfg_attributes, get_doc_literals, is_using_frame_crate}; use quote::ToTokens; -use syn::{spanned::Spanned, token, Token}; +use syn::{spanned::Spanned, token, Token, TraitItemType}; /// List of additional token to be used for parsing. mod keyword { @@ -345,6 +345,23 @@ pub fn replace_self_by_t(input: proc_macro2::TokenStream) -> proc_macro2::TokenS .collect() } +/// Check that the trait item requires the `TypeInfo` bound (or similar). +fn contains_type_info_bound(ty: &TraitItemType) -> bool { + const KNOWN_TYPE_INFO_BOUNDS: &[&str] = &[ + // Explicit TypeInfo trait. + "TypeInfo", + // Implicit known substrate traits that implement type info. + // Note: Aim to keep this list as small as possible. + "Parameter", + ]; + + ty.bounds.iter().any(|bound| { + let syn::TypeParamBound::Trait(bound) = bound else { return false }; + + KNOWN_TYPE_INFO_BOUNDS.iter().any(|known| bound.path.is_ident(known)) + }) +} + impl ConfigDef { pub fn try_from( frame_system: &syn::Path, @@ -429,6 +446,9 @@ impl ConfigDef { trait_item.span(), "Invalid #[pallet::constant] in #[pallet::config], expected type item", )), + // Pallet developer has explicitly requested to include metadata for this associated type. + // + // They must provide a type item that implements `TypeInfo`. (PalletAttrType::IncludeMetadata(_), syn::TraitItem::Type(ref typ)) => { if is_event { return Err(syn::Error::new( @@ -490,9 +510,17 @@ impl ConfigDef { } } - if !already_collected_associated_type && enable_associated_metadata { + // Metadata of associated types is collected by default, iff the associated type + // implements `TypeInfo`, or a similar trait that requires the `TypeInfo` bound. + if !already_collected_associated_type && + enable_associated_metadata && + !is_event && !already_constant + { if let syn::TraitItem::Type(ref ty) = trait_item { - associated_types_metadata.push(AssociatedTypeMetadataDef::from(ty)); + // Collect the metadata of the associated type if it implements `TypeInfo`. + if contains_type_info_bound(ty) { + associated_types_metadata.push(AssociatedTypeMetadataDef::from(ty)); + } } } From 7f26b67a7b33dc78c9fc2572a073e77bf14b2610 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 7 Aug 2024 20:13:37 +0300 Subject: [PATCH 09/70] frame/pallet: Proper flag for metdata collection Signed-off-by: Alexandru Vasile --- substrate/frame/support/procedural/src/pallet/parse/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/mod.rs index fe709bf89ce8..bf933bc820f3 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/mod.rs @@ -116,7 +116,7 @@ impl Def { index, item, with_default, - without_metadata, + !without_metadata, )?), Some(PalletAttr::Pallet(span)) if pallet_struct.is_none() => { let p = pallet_struct::PalletStructDef::try_from(span, index, item)?; From cc001f389f80abbdf511b911c2fd04007f1eedcb Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 8 Aug 2024 11:05:10 +0300 Subject: [PATCH 10/70] frame/tests/ui: Fix type in test Signed-off-by: Alexandru Vasile --- .../tests/pallet_ui/no_default_but_missing_with_default.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/support/test/tests/pallet_ui/no_default_but_missing_with_default.stderr b/substrate/frame/support/test/tests/pallet_ui/no_default_but_missing_with_default.stderr index e8df28a3046f..1b066bbe9fb8 100644 --- a/substrate/frame/support/test/tests/pallet_ui/no_default_but_missing_with_default.stderr +++ b/substrate/frame/support/test/tests/pallet_ui/no_default_but_missing_with_default.stderr @@ -1,4 +1,4 @@ -error: `#[pallet:no_default]` can only be used if `#[pallet::config(with_default)]` has been specified +error: `#[pallet::no_default]` can only be used if `#[pallet::config(with_default)]` has been specified --> tests/pallet_ui/no_default_but_missing_with_default.rs:26:4 | 26 | #[pallet::no_default] From b2803e2f2f785702de70e0825274eeffdd014d46 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 8 Aug 2024 11:12:19 +0300 Subject: [PATCH 11/70] frame/tests/ui: Check config without metadata Signed-off-by: Alexandru Vasile --- .../pallet_ui/pass/config_without_metadata.rs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 substrate/frame/support/test/tests/pallet_ui/pass/config_without_metadata.rs diff --git a/substrate/frame/support/test/tests/pallet_ui/pass/config_without_metadata.rs b/substrate/frame/support/test/tests/pallet_ui/pass/config_without_metadata.rs new file mode 100644 index 000000000000..9304b2ccc9bf --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/pass/config_without_metadata.rs @@ -0,0 +1,32 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[frame_support::pallet] +mod pallet { + use frame_support::pallet_prelude::*; + + #[pallet::config(without_metadata)] + pub trait Config: frame_system::Config { + #[pallet::constant] + type MyGetParam2: Get; + } + + #[pallet::pallet] + pub struct Pallet(_); +} + +fn main() {} From 94007d8c3189d5781db5ffe9d31d54cdc8a56cbd Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 8 Aug 2024 11:12:34 +0300 Subject: [PATCH 12/70] frame/tests/ui: Check config with multiple attributes Signed-off-by: Alexandru Vasile --- .../pallet_ui/pass/config_multiple_attr.rs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 substrate/frame/support/test/tests/pallet_ui/pass/config_multiple_attr.rs diff --git a/substrate/frame/support/test/tests/pallet_ui/pass/config_multiple_attr.rs b/substrate/frame/support/test/tests/pallet_ui/pass/config_multiple_attr.rs new file mode 100644 index 000000000000..1eee25b333e4 --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/pass/config_multiple_attr.rs @@ -0,0 +1,32 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[frame_support::pallet] +mod pallet { + use frame_support::pallet_prelude::*; + + #[pallet::config(with_default, without_metadata)] + pub trait Config: frame_system::Config { + #[pallet::constant] + type MyGetParam2: Get; + } + + #[pallet::pallet] + pub struct Pallet(_); +} + +fn main() {} From 75d26971b5e5520fbf8937a74665f1f1018e32c8 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 8 Aug 2024 11:50:00 +0300 Subject: [PATCH 13/70] frame/tests/ui: Add negative test for duplicate attributes in config Signed-off-by: Alexandru Vasile --- .../procedural/src/pallet/parse/mod.rs | 5 ++- .../tests/pallet_ui/config_duplicate_attr.rs | 39 +++++++++++++++++++ .../pallet_ui/config_duplicate_attr.stderr | 5 +++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 substrate/frame/support/test/tests/pallet_ui/config_duplicate_attr.rs create mode 100644 substrate/frame/support/test/tests/pallet_ui/config_duplicate_attr.stderr diff --git a/substrate/frame/support/procedural/src/pallet/parse/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/mod.rs index bf933bc820f3..6f5a599b08ee 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/mod.rs @@ -707,7 +707,10 @@ impl syn::parse::Parse for PalletAttr { // Check for duplicated attributes. let config_set = config_values.iter().collect::>(); if config_set.len() != config_values.len() { - return Err(syn::Error::new(span, "Invalid duplicated attribute")) + return Err(syn::Error::new( + span, + "Invalid duplicated attribute for `#[pallet::config]`. Please remove duplicates.", + )); } Ok(PalletAttr::Config { span, with_default, without_metadata }) diff --git a/substrate/frame/support/test/tests/pallet_ui/config_duplicate_attr.rs b/substrate/frame/support/test/tests/pallet_ui/config_duplicate_attr.rs new file mode 100644 index 000000000000..3d7b4f87d22c --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/config_duplicate_attr.rs @@ -0,0 +1,39 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[frame_support::pallet] +mod pallet { + use frame_support::pallet_prelude::*; + use frame_system::pallet_prelude::*; + + #[pallet::config(with_default, without_metadata, without_metadata)] + pub trait Config: frame_system::Config { + #[pallet::constant] + type MyGetParam2: Get; + } + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::hooks] + impl Hooks> for Pallet {} + + #[pallet::call] + impl Pallet {} +} + +fn main() {} diff --git a/substrate/frame/support/test/tests/pallet_ui/config_duplicate_attr.stderr b/substrate/frame/support/test/tests/pallet_ui/config_duplicate_attr.stderr new file mode 100644 index 000000000000..7217aa370ed5 --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/config_duplicate_attr.stderr @@ -0,0 +1,5 @@ +error: Invalid duplicated attribute for `#[pallet::config]`. Please remove duplicates. + --> tests/pallet_ui/config_duplicate_attr.rs:23:12 + | +23 | #[pallet::config(with_default, without_metadata, without_metadata)] + | ^^^^^^ From ebcb4a0aa5e6c65d17f15d49262bb4b4b3482964 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 8 Aug 2024 11:53:49 +0300 Subject: [PATCH 14/70] frame/tests/ui: Add negative test for collecting metadata from constants Signed-off-by: Alexandru Vasile --- .../pallet_ui/config_metadata_on_constants.rs | 40 +++++++++++++++++++ .../config_metadata_on_constants.stderr | 5 +++ 2 files changed, 45 insertions(+) create mode 100644 substrate/frame/support/test/tests/pallet_ui/config_metadata_on_constants.rs create mode 100644 substrate/frame/support/test/tests/pallet_ui/config_metadata_on_constants.stderr diff --git a/substrate/frame/support/test/tests/pallet_ui/config_metadata_on_constants.rs b/substrate/frame/support/test/tests/pallet_ui/config_metadata_on_constants.rs new file mode 100644 index 000000000000..a4ff02aeb1cd --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/config_metadata_on_constants.rs @@ -0,0 +1,40 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[frame_support::pallet] +mod pallet { + use frame_support::pallet_prelude::*; + use frame_system::pallet_prelude::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + #[pallet::constant] + #[pallet::include_metadata] + type MyGetParam2: Get; + } + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::hooks] + impl Hooks> for Pallet {} + + #[pallet::call] + impl Pallet {} +} + +fn main() {} diff --git a/substrate/frame/support/test/tests/pallet_ui/config_metadata_on_constants.stderr b/substrate/frame/support/test/tests/pallet_ui/config_metadata_on_constants.stderr new file mode 100644 index 000000000000..ac27bfe89a08 --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/config_metadata_on_constants.stderr @@ -0,0 +1,5 @@ +error: Invalid #[pallet::include_metadata] in #[pallet::constant], expected type item. Pallet constant's metadata is already collected. + --> tests/pallet_ui/config_metadata_on_constants.rs:26:10 + | +26 | #[pallet::include_metadata] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ From 51150217bf9cf8869a141e1cfe5f2dcd063e6594 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 8 Aug 2024 11:58:52 +0300 Subject: [PATCH 15/70] frame/tests/ui: Add negative test for metadata collection on events Signed-off-by: Alexandru Vasile --- .../pallet_ui/config_metadata_on_events.rs | 43 +++++++++++++++++++ .../config_metadata_on_events.stderr | 5 +++ 2 files changed, 48 insertions(+) create mode 100644 substrate/frame/support/test/tests/pallet_ui/config_metadata_on_events.rs create mode 100644 substrate/frame/support/test/tests/pallet_ui/config_metadata_on_events.stderr diff --git a/substrate/frame/support/test/tests/pallet_ui/config_metadata_on_events.rs b/substrate/frame/support/test/tests/pallet_ui/config_metadata_on_events.rs new file mode 100644 index 000000000000..d91f86771bf6 --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/config_metadata_on_events.rs @@ -0,0 +1,43 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[frame_support::pallet] +mod pallet { + use frame_support::pallet_prelude::*; + use frame_system::pallet_prelude::*; + + #[pallet::config(with_default)] + pub trait Config: frame_system::Config { + #[pallet::no_default_bounds] + #[pallet::include_metadata] + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + + #[pallet::constant] + type MyGetParam2: Get; + } + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::hooks] + impl Hooks> for Pallet {} + + #[pallet::call] + impl Pallet {} +} + +fn main() {} diff --git a/substrate/frame/support/test/tests/pallet_ui/config_metadata_on_events.stderr b/substrate/frame/support/test/tests/pallet_ui/config_metadata_on_events.stderr new file mode 100644 index 000000000000..0c79929bca37 --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/config_metadata_on_events.stderr @@ -0,0 +1,5 @@ +error: Invalid #[pallet::include_metadata] in `type RuntimeEvent`, expected type item. The associated type `RuntimeEvent` is already collected. + --> tests/pallet_ui/config_metadata_on_events.rs:26:4 + | +26 | #[pallet::include_metadata] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ From aba029a471f26dd5e1c4286104eb53029ceafd15 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 8 Aug 2024 13:07:25 +0300 Subject: [PATCH 16/70] frame/tests: Check PalletAssociatedTypeMetadataIR collection Signed-off-by: Alexandru Vasile --- .../tests/pallet_associated_types_metadata.rs | 269 ++++++++++++++++++ 1 file changed, 269 insertions(+) create mode 100644 substrate/frame/support/test/tests/pallet_associated_types_metadata.rs diff --git a/substrate/frame/support/test/tests/pallet_associated_types_metadata.rs b/substrate/frame/support/test/tests/pallet_associated_types_metadata.rs new file mode 100644 index 000000000000..9de5d79ad34c --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_associated_types_metadata.rs @@ -0,0 +1,269 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use frame_support::{derive_impl, traits::ConstU32}; +use scale_info::meta_type; +use sp_metadata_ir::PalletAssociatedTypeMetadataIR; + +pub type BlockNumber = u64; +pub type Header = sp_runtime::generic::Header; +pub type Block = sp_runtime::generic::Block; +pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic; + +/// Pallet without collectable associated types. +#[frame_support::pallet] +pub mod pallet { + use frame_support::pallet_prelude::*; + + #[pallet::pallet] + pub struct Pallet(_); + + #[pallet::config] + pub trait Config: frame_system::Config { + // Runtime events already propagated to the metadata. + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + + // Constants are already propagated. + #[pallet::constant] + type MyGetParam2: Get; + } + + #[pallet::event] + pub enum Event { + TestEvent, + } +} + +/// Pallet with default collectable associated types. +#[frame_support::pallet] +pub mod pallet2 { + use frame_support::pallet_prelude::*; + + #[pallet::pallet] + pub struct Pallet(_); + + #[pallet::config] + pub trait Config: frame_system::Config { + // Runtime events already propagated to the metadata. + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + + // Constants are already propagated. + #[pallet::constant] + type MyGetParam2: Get; + + // Associated type included by default, because it requires TypeInfo bound. + /// Nonce doc. + type Nonce: TypeInfo; + + // Associated type included by default, because it requires + // Parameter bound (indirect TypeInfo). + type AccountData: Parameter; + + // Associated type without metadata bounds, not included. + type NotIncluded: From; + } + + #[pallet::event] + pub enum Event { + TestEvent, + } +} + +/// Pallet with implicit collectable associated types. +#[frame_support::pallet] +pub mod pallet3 { + use frame_support::pallet_prelude::*; + + #[pallet::pallet] + pub struct Pallet(_); + + // Associated types are not collected by default. + #[pallet::config(without_metadata)] + pub trait Config: frame_system::Config { + // Runtime events already propagated to the metadata. + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + + // Constants are already propagated. + #[pallet::constant] + type MyGetParam2: Get; + + // Explicitly include associated types. + #[pallet::include_metadata] + type Nonce: TypeInfo; + + type AccountData: Parameter; + + type NotIncluded: From; + } + + #[pallet::event] + pub enum Event { + TestEvent, + } +} + +impl pallet::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type MyGetParam2 = ConstU32<10>; +} + +impl pallet2::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type MyGetParam2 = ConstU32<10>; + type Nonce = u64; + type AccountData = u16; + type NotIncluded = u8; +} + +impl pallet3::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type MyGetParam2 = ConstU32<10>; + type Nonce = u64; + type AccountData = u16; + type NotIncluded = u8; +} + +#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] +impl frame_system::Config for Runtime { + type BlockWeights = (); + type BlockLength = (); + type DbWeight = (); + type BaseCallFilter = frame_support::traits::Everything; + type RuntimeOrigin = RuntimeOrigin; + type Nonce = u64; + type RuntimeCall = RuntimeCall; + type Hash = sp_runtime::testing::H256; + type Hashing = sp_runtime::traits::BlakeTwo256; + type AccountId = u64; + type Lookup = sp_runtime::traits::IdentityLookup; + type Block = Block; + type RuntimeEvent = RuntimeEvent; + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = (); + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = ConstU32<16>; +} + +frame_support::construct_runtime!( + pub enum Runtime + { + System: frame_system, + Example: pallet, + DefaultInclusion: pallet2, + ExplicitInclusion: pallet3, + } +); + +#[test] +fn associated_types_metadata() { + fn maybe_docs(doc: Vec<&'static str>) -> Vec<&'static str> { + if cfg!(feature = "no-metadata-docs") { + vec![] + } else { + doc + } + } + + let ir = Runtime::metadata_ir(); + + // No associated types to collect. + let pallet = ir.pallets.iter().find(|pallet| pallet.name == "Example").unwrap(); + pretty_assertions::assert_eq!(pallet.associated_types, vec![]); + + // Collect by default types that implement TypeInfo or Parameter. + let pallet = ir.pallets.iter().find(|pallet| pallet.name == "DefaultInclusion").unwrap(); + pretty_assertions::assert_eq!( + pallet.associated_types, + vec![ + PalletAssociatedTypeMetadataIR { + name: "Nonce", + ty: meta_type::(), + docs: maybe_docs(vec![" Nonce doc."]), + }, + PalletAssociatedTypeMetadataIR { + name: "AccountData", + ty: meta_type::(), + docs: vec![], + } + ] + ); + + // Explicitly include associated types. + let pallet = ir.pallets.iter().find(|pallet| pallet.name == "ExplicitInclusion").unwrap(); + pretty_assertions::assert_eq!( + pallet.associated_types, + vec![PalletAssociatedTypeMetadataIR { + name: "Nonce", + ty: meta_type::(), + docs: vec![], + }] + ); + + // Check system pallet. + let pallet = ir.pallets.iter().find(|pallet| pallet.name == "System").unwrap(); + pretty_assertions::assert_eq!( + pallet.associated_types, + vec![ + PalletAssociatedTypeMetadataIR { + name: "RuntimeCall", + ty: meta_type::(), + docs: maybe_docs(vec![" The aggregated `RuntimeCall` type."]), + }, + PalletAssociatedTypeMetadataIR { + name: "Nonce", + ty: meta_type::(), + docs: maybe_docs(vec![" This stores the number of previous transactions associated with a sender account."]), + }, + PalletAssociatedTypeMetadataIR { + name: "Hash", + ty: meta_type::(), + docs: maybe_docs(vec![" The output of the `Hashing` function."]), + }, + PalletAssociatedTypeMetadataIR { + name: "Hashing", + ty: meta_type::(), + docs: maybe_docs(vec![" The hashing system (algorithm) being used in the runtime (e.g. Blake2)."]), + }, + PalletAssociatedTypeMetadataIR { + name: "AccountId", + ty: meta_type::(), + docs: maybe_docs(vec![" The user account identifier type for the runtime."]), + }, + PalletAssociatedTypeMetadataIR { + name: "Block", + ty: meta_type::(), + docs: maybe_docs(vec![ + " The Block type used by the runtime. This is used by `construct_runtime` to retrieve the", + " extrinsics or other block specific data as needed.", + ]), + }, + PalletAssociatedTypeMetadataIR { + name: "AccountData", + ty: meta_type::<()>(), + docs: maybe_docs(vec![ + " Data to be associated with an account (other than nonce/transaction counter, which this", + " pallet does regardless).", + ]), + }, + ] + ); +} From 6502c830889275418dc3392881aa52ce0da96dcf Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 8 Aug 2024 13:27:56 +0300 Subject: [PATCH 17/70] frame/support: Add documentation Signed-off-by: Alexandru Vasile --- substrate/frame/support/procedural/src/lib.rs | 9 +++ substrate/frame/support/src/lib.rs | 62 +++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/substrate/frame/support/procedural/src/lib.rs b/substrate/frame/support/procedural/src/lib.rs index ef99faee86ae..05f6333cd275 100644 --- a/substrate/frame/support/procedural/src/lib.rs +++ b/substrate/frame/support/procedural/src/lib.rs @@ -955,6 +955,15 @@ pub fn event(_: TokenStream, _: TokenStream) -> TokenStream { pallet_macro_stub() } +/// +/// --- +/// +/// Documentation for this macro can be found at `frame_support::pallet_macros::include_metadata`. +#[proc_macro_attribute] +pub fn include_metadata(_: TokenStream, _: TokenStream) -> TokenStream { + pallet_macro_stub() +} + /// /// --- /// diff --git a/substrate/frame/support/src/lib.rs b/substrate/frame/support/src/lib.rs index bd571571ee24..2d882dd224f5 100644 --- a/substrate/frame/support/src/lib.rs +++ b/substrate/frame/support/src/lib.rs @@ -1556,6 +1556,57 @@ pub mod pallet_macros { /// * [`frame_support::derive_impl`]. /// * [`#[pallet::no_default]`](`no_default`) /// * [`#[pallet::no_default_bounds]`](`no_default_bounds`) + /// + /// ## Optional: `without_metadata` + /// + /// By default, the associated types of the `Config` trait that require the `TypeInfo` or + /// `Parameter` bounds are included in the metadata of the pallet. Please note that the + /// `RuntimeEvent` and constants are already included in the metadata. + /// + /// The optional `without_metadata` argument can be used to exclude these associated types + /// from the metadata collection. + /// + /// Furthermore, the `without_metadata` argument can be used in combination with the + /// [`#[pallet::include_metadata]`](`include_metadata`) attribute to selectively include + /// only certain associated types in the metadata collection. + /// + /// ``` + /// #[frame_support::pallet] + /// mod pallet { + /// # use frame_support::pallet_prelude::*; + /// # use frame_system::pallet_prelude::*; + /// # use core::fmt::Debug; + /// # use frame_support::traits::Contains; + /// # + /// # pub trait SomeMoreComplexBound {} + /// # + /// #[pallet::pallet] + /// pub struct Pallet(_); + /// + /// #[pallet::config(with_default, without_metadata)] // <- with_default and without_metadata are optional + /// pub trait Config: frame_system::Config { + /// /// The overarching event type. + /// #[pallet::no_default_bounds] // Default with bounds is not supported for RuntimeEvent + /// type RuntimeEvent: From> + IsType<::RuntimeEvent>; + /// + /// /// A simple type. + /// // Type that would have been included in metadata, but is now excluded. + /// type SimpleType: From + TypeInfo; + /// + /// // The `pallet::include_metadata` is used to selectively include this type in metadata. + /// #[pallet::include_metadata] + /// type SelectivelyInclude: From + TypeInfo; + /// } + /// + /// #[pallet::event] + /// pub enum Event { + /// SomeEvent(u16, u32), + /// } + /// } + /// ``` + /// + /// For more information, see: + /// * [`#[pallet::include_metadata]`](`include_metadata`) pub use frame_support_procedural::config; /// Allows defining an enum that gets composed as an aggregate enum by `construct_runtime`. @@ -1935,6 +1986,17 @@ pub mod pallet_macros { /// `Member`, available in [`frame_support::pallet_prelude`]. pub use frame_support_procedural::event; + /// Selectively includes associated types in the metadata. + /// + /// The optional attribute allows you to selectively include associated types in the + /// metadata. This can be attached to trait items that implement `TypeInfo`. + /// + /// By default all collectable associated types are included in the metadata. + /// + /// This attribute can be used in combination with the + /// [`#[pallet::config(without_metadata)]`](`config`). + pub use frame_support_procedural::include_metadata; + /// Allows a pallet to declare a set of functions as a *dispatchable extrinsic*. /// /// In slightly simplified terms, this macro declares the set of "transactions" of a From e9571cbdd505ebfb57c567c988245c97413ae621 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 8 Aug 2024 13:33:52 +0300 Subject: [PATCH 18/70] Add PRdoc Signed-off-by: Alexandru Vasile --- prdoc/pr_5274.prdoc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 prdoc/pr_5274.prdoc diff --git a/prdoc/pr_5274.prdoc b/prdoc/pr_5274.prdoc new file mode 100644 index 000000000000..44c7085ef9d7 --- /dev/null +++ b/prdoc/pr_5274.prdoc @@ -0,0 +1,24 @@ +title: Enrich metadata IR with associated types of config traits + +doc: + - audience: Runtime Dev + description: | + This feature is part of the upcoming metadata V16. The associated types of the `Config` trait that require the `TypeInfo` + or `Parameter` bounds are included in the metadata of the pallet. The metadata is not yet exposed to the end-user, however + the metadata intermediate representation (IR) contains these types. + + Developers can opt out of metadata collection of the associated types by specifying `without_metadata` optional attribute + to the `#[pallet::config]`. + + Furthermore, the `without_metadata` argument can be used in combination with the newly added `#[pallet::include_metadata]` + attribute to selectively include only certain associated types in the metadata collection. + +crates: + - name: frame-support-procedural + bump: minor + - name: frame-support-procedural-tools + bump: minor + - name: sp-metadata-ir + bump: minor + - name: pallet-assets + bump: minor \ No newline at end of file From 7429eb7102518da7f74390b2b67ac5fa0d0c6a3f Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 8 Aug 2024 13:48:35 +0300 Subject: [PATCH 19/70] Update prdoc Signed-off-by: Alexandru Vasile --- prdoc/pr_5274.prdoc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/prdoc/pr_5274.prdoc b/prdoc/pr_5274.prdoc index 44c7085ef9d7..f3ec67da4a42 100644 --- a/prdoc/pr_5274.prdoc +++ b/prdoc/pr_5274.prdoc @@ -15,10 +15,10 @@ doc: crates: - name: frame-support-procedural - bump: minor + bump: patch - name: frame-support-procedural-tools - bump: minor + bump: patch - name: sp-metadata-ir - bump: minor + bump: patch - name: pallet-assets - bump: minor \ No newline at end of file + bump: patch From 8a0c138490971761e52b74bf729686b7c5eff84c Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 8 Aug 2024 13:48:51 +0300 Subject: [PATCH 20/70] prdoc: Remove unneeded crate Signed-off-by: Alexandru Vasile --- prdoc/pr_5274.prdoc | 2 -- 1 file changed, 2 deletions(-) diff --git a/prdoc/pr_5274.prdoc b/prdoc/pr_5274.prdoc index f3ec67da4a42..85f7d1cc2862 100644 --- a/prdoc/pr_5274.prdoc +++ b/prdoc/pr_5274.prdoc @@ -20,5 +20,3 @@ crates: bump: patch - name: sp-metadata-ir bump: patch - - name: pallet-assets - bump: patch From c6c1800fca82bb2003097f86811e9f53aefb5df2 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 8 Aug 2024 13:49:23 +0300 Subject: [PATCH 21/70] prdoc: Include frame-support Signed-off-by: Alexandru Vasile --- prdoc/pr_5274.prdoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/prdoc/pr_5274.prdoc b/prdoc/pr_5274.prdoc index 85f7d1cc2862..304e3e3f779e 100644 --- a/prdoc/pr_5274.prdoc +++ b/prdoc/pr_5274.prdoc @@ -14,6 +14,8 @@ doc: attribute to selectively include only certain associated types in the metadata collection. crates: + - name: frame-support + bump: patch - name: frame-support-procedural bump: patch - name: frame-support-procedural-tools From 90c100c0c67c0d273613292093f574040d923fcd Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 8 Aug 2024 13:57:45 +0300 Subject: [PATCH 22/70] Prupdate Signed-off-by: Alexandru Vasile --- prdoc/pr_5274.prdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prdoc/pr_5274.prdoc b/prdoc/pr_5274.prdoc index 304e3e3f779e..fb76ce661b4e 100644 --- a/prdoc/pr_5274.prdoc +++ b/prdoc/pr_5274.prdoc @@ -21,4 +21,4 @@ crates: - name: frame-support-procedural-tools bump: patch - name: sp-metadata-ir - bump: patch + bump: major From fc87031e5ac9a07fa09c7793963906ddf59d146a Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 13 Sep 2024 17:07:05 +0300 Subject: [PATCH 23/70] metadata-ir: Add v16 wrappers in preparation for frame-md release Signed-off-by: Alexandru Vasile --- substrate/primitives/metadata-ir/src/lib.rs | 21 +++++++++++++++++-- .../primitives/metadata-ir/src/unstable.rs | 0 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 substrate/primitives/metadata-ir/src/unstable.rs diff --git a/substrate/primitives/metadata-ir/src/lib.rs b/substrate/primitives/metadata-ir/src/lib.rs index 18b20f2ccaac..0051bd7b58fb 100644 --- a/substrate/primitives/metadata-ir/src/lib.rs +++ b/substrate/primitives/metadata-ir/src/lib.rs @@ -30,6 +30,7 @@ mod types; use frame_metadata::RuntimeMetadataPrefixed; pub use types::*; +mod unstable; mod v14; mod v15; @@ -39,16 +40,26 @@ const V14: u32 = 14; /// Metadata V15. const V15: u32 = 15; +/// Unstable metadata V16. +const UNSTABLE_V16: u32 = u32::MAX; + /// Transform the IR to the specified version. /// /// Use [`supported_versions`] to find supported versions. pub fn into_version(metadata: MetadataIR, version: u32) -> Option { // Note: Unstable metadata version is `u32::MAX` until stabilized. match version { - // Latest stable version. + // Version V14. This needs to be around until the + // deprecation of the `Metadata_metadata` runtime call in favor of + // `Metadata_metadata_at_version. V14 => Some(into_v14(metadata)), - // Unstable metadata. + + // Version V15 - latest stable. V15 => Some(into_latest(metadata)), + + // Unstable metadata under `u32::MAX`.s + UNSTABLE_V16 => Some(into_unstable(metadata)), + _ => None, } } @@ -70,6 +81,12 @@ pub fn into_v14(metadata: MetadataIR) -> RuntimeMetadataPrefixed { latest.into() } +/// Transform the IR to unstable metadata version 16. +pub fn into_unstable(metadata: MetadataIR) -> RuntimeMetadataPrefixed { + let latest: frame_metadata::v14::RuntimeMetadataV14 = metadata.into(); + latest.into() +} + #[cfg(test)] mod test { use super::*; diff --git a/substrate/primitives/metadata-ir/src/unstable.rs b/substrate/primitives/metadata-ir/src/unstable.rs new file mode 100644 index 000000000000..e69de29bb2d1 From b533f600af55b7d257e67b327954be0a17758dc1 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 13 Sep 2024 18:18:21 +0300 Subject: [PATCH 24/70] metadata-ir: Add conversion methods Signed-off-by: Alexandru Vasile --- Cargo.lock | 23 +- Cargo.toml | 2 +- .../frame/metadata-hash-extension/Cargo.toml | 2 +- substrate/frame/support/Cargo.toml | 1 + substrate/frame/support/test/Cargo.toml | 2 +- substrate/primitives/metadata-ir/Cargo.toml | 2 +- substrate/primitives/metadata-ir/src/lib.rs | 2 +- .../primitives/metadata-ir/src/unstable.rs | 213 ++++++++++++++++++ substrate/utils/wasm-builder/Cargo.toml | 2 +- 9 files changed, 236 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 85b0699fff7f..16863993ffd7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5941,6 +5941,16 @@ dependencies = [ "sp-version", ] +[[package]] +name = "frame-metadata" +version = "16.0.0" +dependencies = [ + "cfg-if", + "parity-scale-codec", + "scale-info", + "serde", +] + [[package]] name = "frame-metadata" version = "16.0.0" @@ -5950,7 +5960,6 @@ dependencies = [ "cfg-if", "parity-scale-codec", "scale-info", - "serde", ] [[package]] @@ -5959,7 +5968,7 @@ version = "0.1.0" dependencies = [ "array-bytes", "docify", - "frame-metadata", + "frame-metadata 16.0.0", "frame-support", "frame-system", "log", @@ -6020,7 +6029,7 @@ dependencies = [ "bitflags 1.3.2", "docify", "environmental", - "frame-metadata", + "frame-metadata 16.0.0", "frame-support-procedural", "frame-system", "impl-trait-for-tuples", @@ -6111,7 +6120,7 @@ version = "3.0.0" dependencies = [ "frame-benchmarking", "frame-executive", - "frame-metadata", + "frame-metadata 16.0.0", "frame-support", "frame-support-test-pallet", "frame-system", @@ -8733,7 +8742,7 @@ checksum = "f313fcff1d2a4bcaa2deeaa00bf7530d77d5f7bd0467a117dde2e29a75a7a17a" dependencies = [ "array-bytes", "blake3", - "frame-metadata", + "frame-metadata 16.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec", "scale-decode", "scale-info", @@ -20537,7 +20546,7 @@ dependencies = [ name = "sp-metadata-ir" version = "0.6.0" dependencies = [ - "frame-metadata", + "frame-metadata 16.0.0", "parity-scale-codec", "scale-info", ] @@ -21703,7 +21712,7 @@ dependencies = [ "cargo_metadata", "console", "filetime", - "frame-metadata", + "frame-metadata 16.0.0", "jobserver", "merkleized-metadata", "parity-scale-codec", diff --git a/Cargo.toml b/Cargo.toml index 7e48fa14ccc2..8f6b63df6a76 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -760,7 +760,7 @@ frame-benchmarking-pallet-pov = { default-features = false, path = "substrate/fr frame-election-provider-solution-type = { path = "substrate/frame/election-provider-support/solution-type", default-features = false } frame-election-provider-support = { path = "substrate/frame/election-provider-support", default-features = false } frame-executive = { path = "substrate/frame/executive", default-features = false } -frame-metadata = { version = "16.0.0", default-features = false } +frame-metadata = { path = "/home/lexnv/workspace/frame-metadata/frame-metadata", default-features = false } frame-metadata-hash-extension = { path = "substrate/frame/metadata-hash-extension", default-features = false } frame-support = { path = "substrate/frame/support", default-features = false } frame-support-procedural = { path = "substrate/frame/support/procedural", default-features = false } diff --git a/substrate/frame/metadata-hash-extension/Cargo.toml b/substrate/frame/metadata-hash-extension/Cargo.toml index 10d90bba0911..d9dffb8b0592 100644 --- a/substrate/frame/metadata-hash-extension/Cargo.toml +++ b/substrate/frame/metadata-hash-extension/Cargo.toml @@ -24,7 +24,7 @@ substrate-test-runtime-client = { workspace = true } sp-api = { workspace = true, default-features = true } sp-transaction-pool = { workspace = true, default-features = true } merkleized-metadata = { workspace = true } -frame-metadata = { features = ["current"], workspace = true, default-features = true } +frame-metadata = { features = ["current","unstable"], workspace = true, default-features = true } sp-tracing = { workspace = true, default-features = true } [features] diff --git a/substrate/frame/support/Cargo.toml b/substrate/frame/support/Cargo.toml index 549059e261cc..b2d577f19599 100644 --- a/substrate/frame/support/Cargo.toml +++ b/substrate/frame/support/Cargo.toml @@ -27,6 +27,7 @@ scale-info = { features = [ ], workspace = true } frame-metadata = { features = [ "current", + "unstable", ], workspace = true } sp-api = { features = [ "frame-metadata", diff --git a/substrate/frame/support/test/Cargo.toml b/substrate/frame/support/test/Cargo.toml index 5c12c082305f..5ac853c25880 100644 --- a/substrate/frame/support/test/Cargo.toml +++ b/substrate/frame/support/test/Cargo.toml @@ -19,7 +19,7 @@ static_assertions = { workspace = true, default-features = true } serde = { features = ["derive"], workspace = true } codec = { features = ["derive"], workspace = true } scale-info = { features = ["derive"], workspace = true } -frame-metadata = { features = ["current"], workspace = true } +frame-metadata = { features = ["current","unstable"], workspace = true } sp-api = { workspace = true } sp-arithmetic = { workspace = true } sp-io = { workspace = true } diff --git a/substrate/primitives/metadata-ir/Cargo.toml b/substrate/primitives/metadata-ir/Cargo.toml index d7786347dd02..fcbf7889f6d0 100644 --- a/substrate/primitives/metadata-ir/Cargo.toml +++ b/substrate/primitives/metadata-ir/Cargo.toml @@ -17,7 +17,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { workspace = true } -frame-metadata = { features = ["current"], workspace = true } +frame-metadata = { features = ["current","unstable"], workspace = true } scale-info = { features = ["derive"], workspace = true } [features] diff --git a/substrate/primitives/metadata-ir/src/lib.rs b/substrate/primitives/metadata-ir/src/lib.rs index 0051bd7b58fb..6255ccdfd70f 100644 --- a/substrate/primitives/metadata-ir/src/lib.rs +++ b/substrate/primitives/metadata-ir/src/lib.rs @@ -57,7 +57,7 @@ pub fn into_version(metadata: MetadataIR, version: u32) -> Option Some(into_latest(metadata)), - // Unstable metadata under `u32::MAX`.s + // Unstable metadata under `u32::MAX`. UNSTABLE_V16 => Some(into_unstable(metadata)), _ => None, diff --git a/substrate/primitives/metadata-ir/src/unstable.rs b/substrate/primitives/metadata-ir/src/unstable.rs index e69de29bb2d1..cd462448d241 100644 --- a/substrate/primitives/metadata-ir/src/unstable.rs +++ b/substrate/primitives/metadata-ir/src/unstable.rs @@ -0,0 +1,213 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Convert the IR to V16 metadata. + +use crate::{ + DeprecationInfoIR, DeprecationStatusIR, OuterEnumsIR, PalletAssociatedTypeMetadataIR, + PalletCallMetadataIR, PalletConstantMetadataIR, PalletErrorMetadataIR, PalletEventMetadataIR, + PalletStorageMetadataIR, StorageEntryMetadataIR, +}; + +use super::types::{ + ExtrinsicMetadataIR, MetadataIR, PalletMetadataIR, RuntimeApiMetadataIR, + RuntimeApiMethodMetadataIR, RuntimeApiMethodParamMetadataIR, SignedExtensionMetadataIR, +}; + +use frame_metadata::v16::{ + CustomMetadata, DeprecationInfo, DeprecationStatus, ExtrinsicMetadata, OuterEnums, + PalletAssociatedTypeMetadata, PalletCallMetadata, PalletConstantMetadata, PalletErrorMetadata, + PalletEventMetadata, PalletMetadata, PalletStorageMetadata, RuntimeApiMetadata, + RuntimeApiMethodMetadata, RuntimeApiMethodParamMetadata, RuntimeMetadataV16, + SignedExtensionMetadata, StorageEntryMetadata, +}; + +impl From for RuntimeMetadataV16 { + fn from(ir: MetadataIR) -> Self { + RuntimeMetadataV16::new( + ir.pallets.into_iter().map(Into::into).collect(), + ir.extrinsic.into(), + 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() }, + ) + } +} + +impl From for RuntimeApiMetadata { + fn from(ir: RuntimeApiMetadataIR) -> Self { + RuntimeApiMetadata { + name: ir.name, + methods: ir.methods.into_iter().map(Into::into).collect(), + docs: ir.docs, + deprecation_info: ir.deprecation_info.into(), + } + } +} + +impl From for RuntimeApiMethodMetadata { + fn from(ir: RuntimeApiMethodMetadataIR) -> Self { + RuntimeApiMethodMetadata { + name: ir.name, + inputs: ir.inputs.into_iter().map(Into::into).collect(), + output: ir.output, + docs: ir.docs, + deprecation_info: ir.deprecation_info.into(), + } + } +} + +impl From for RuntimeApiMethodParamMetadata { + fn from(ir: RuntimeApiMethodParamMetadataIR) -> Self { + RuntimeApiMethodParamMetadata { name: ir.name, ty: ir.ty } + } +} + +impl From for PalletMetadata { + fn from(ir: PalletMetadataIR) -> Self { + PalletMetadata { + name: ir.name, + storage: ir.storage.map(Into::into), + calls: ir.calls.map(Into::into), + event: ir.event.map(Into::into), + constants: ir.constants.into_iter().map(Into::into).collect(), + error: ir.error.map(Into::into), + index: ir.index, + docs: ir.docs, + associated_types: ir.associated_types.into_iter().map(Into::into).collect(), + deprecation_info: ir.deprecation_info.into(), + } + } +} + +impl From for PalletStorageMetadata { + fn from(ir: PalletStorageMetadataIR) -> Self { + PalletStorageMetadata { + prefix: ir.prefix, + entries: ir.entries.into_iter().map(Into::into).collect(), + } + } +} + +impl From for StorageEntryMetadata { + fn from(ir: StorageEntryMetadataIR) -> Self { + StorageEntryMetadata { + name: ir.name, + modifier: ir.modifier.into(), + ty: ir.ty.into(), + default: ir.default, + docs: ir.docs, + deprecation_info: ir.deprecation_info.into(), + } + } +} + +impl From for PalletAssociatedTypeMetadata { + fn from(ir: PalletAssociatedTypeMetadataIR) -> Self { + PalletAssociatedTypeMetadata { name: ir.name, ty: ir.ty, docs: ir.docs } + } +} + +impl From for PalletErrorMetadata { + fn from(ir: PalletErrorMetadataIR) -> Self { + PalletErrorMetadata { ty: ir.ty, deprecation_info: ir.deprecation_info.into() } + } +} + +impl From for PalletEventMetadata { + fn from(ir: PalletEventMetadataIR) -> Self { + PalletEventMetadata { ty: ir.ty, deprecation_info: ir.deprecation_info.into() } + } +} + +impl From for PalletCallMetadata { + fn from(ir: PalletCallMetadataIR) -> Self { + PalletCallMetadata { ty: ir.ty, deprecation_info: ir.deprecation_info.into() } + } +} + +impl From for PalletConstantMetadata { + fn from(ir: PalletConstantMetadataIR) -> Self { + PalletConstantMetadata { + name: ir.name, + ty: ir.ty, + value: ir.value, + docs: ir.docs, + deprecation_info: ir.deprecation_info.into(), + } + } +} + +impl From for SignedExtensionMetadata { + fn from(ir: SignedExtensionMetadataIR) -> Self { + SignedExtensionMetadata { + identifier: ir.identifier, + ty: ir.ty, + additional_signed: ir.additional_signed, + } + } +} + +impl From for ExtrinsicMetadata { + fn from(ir: ExtrinsicMetadataIR) -> Self { + ExtrinsicMetadata { + version: ir.version, + address_ty: ir.address_ty, + call_ty: ir.call_ty, + signature_ty: ir.signature_ty, + extra_ty: ir.extra_ty, + signed_extensions: ir.signed_extensions.into_iter().map(Into::into).collect(), + } + } +} + +impl From for OuterEnums { + fn from(ir: OuterEnumsIR) -> Self { + OuterEnums { + call_enum_ty: ir.call_enum_ty, + event_enum_ty: ir.event_enum_ty, + error_enum_ty: ir.error_enum_ty, + } + } +} + +impl From for DeprecationStatus { + fn from(ir: DeprecationStatusIR) -> Self { + match ir { + DeprecationStatusIR::NotDeprecated => DeprecationStatus::NotDeprecated, + DeprecationStatusIR::DeprecatedWithoutNote => DeprecationStatus::DeprecatedWithoutNote, + DeprecationStatusIR::Deprecated { since, note } => + DeprecationStatus::Deprecated { since, note }, + } + } +} + +impl From for DeprecationInfo { + fn from(ir: DeprecationInfoIR) -> Self { + match ir { + DeprecationInfoIR::NotDeprecated => DeprecationInfo::NotDeprecated, + DeprecationInfoIR::ItemDeprecated(status) => + DeprecationInfo::ItemDeprecated(status.into()), + DeprecationInfoIR::VariantsDeprecated(btree) => DeprecationInfo::VariantsDeprecated( + btree.into_iter().map(|(key, value)| (key, value.into())).collect(), + ), + } + } +} diff --git a/substrate/utils/wasm-builder/Cargo.toml b/substrate/utils/wasm-builder/Cargo.toml index 15a1fd007ca2..c9df6bd39e6a 100644 --- a/substrate/utils/wasm-builder/Cargo.toml +++ b/substrate/utils/wasm-builder/Cargo.toml @@ -35,7 +35,7 @@ sc-executor = { optional = true, workspace = true, default-features = true } sp-core = { optional = true, workspace = true, default-features = true } sp-io = { optional = true, workspace = true, default-features = true } sp-version = { optional = true, workspace = true, default-features = true } -frame-metadata = { features = ["current"], optional = true, workspace = true, default-features = true } +frame-metadata = { features = ["current","unstable"], optional = true, workspace = true, default-features = true } codec = { optional = true, workspace = true, default-features = true } array-bytes = { optional = true, workspace = true, default-features = true } sp-tracing = { optional = true, workspace = true, default-features = true } From e298259103a69269c9e0cfed85996dfa14d44a2a Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 13 Sep 2024 18:20:23 +0300 Subject: [PATCH 25/70] metadata-ir: Enable v16 version as unstable Signed-off-by: Alexandru Vasile --- substrate/primitives/metadata-ir/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/primitives/metadata-ir/src/lib.rs b/substrate/primitives/metadata-ir/src/lib.rs index 6255ccdfd70f..c24c6492710f 100644 --- a/substrate/primitives/metadata-ir/src/lib.rs +++ b/substrate/primitives/metadata-ir/src/lib.rs @@ -66,7 +66,7 @@ pub fn into_version(metadata: MetadataIR, version: u32) -> Option alloc::vec::Vec { - alloc::vec![V14, V15] + alloc::vec![V14, V15, UNSTABLE_V16] } /// Transform the IR to the latest stable metadata version. From d0ff8f4df91078be207f78dbd4cb8436172a7957 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 13 Sep 2024 19:45:11 +0300 Subject: [PATCH 26/70] metadata-ir: Fix into stable conversion Signed-off-by: Alexandru Vasile --- substrate/primitives/metadata-ir/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/primitives/metadata-ir/src/lib.rs b/substrate/primitives/metadata-ir/src/lib.rs index c24c6492710f..06639fc227dd 100644 --- a/substrate/primitives/metadata-ir/src/lib.rs +++ b/substrate/primitives/metadata-ir/src/lib.rs @@ -83,7 +83,7 @@ pub fn into_v14(metadata: MetadataIR) -> RuntimeMetadataPrefixed { /// Transform the IR to unstable metadata version 16. pub fn into_unstable(metadata: MetadataIR) -> RuntimeMetadataPrefixed { - let latest: frame_metadata::v14::RuntimeMetadataV14 = metadata.into(); + let latest: frame_metadata::v16::RuntimeMetadataV16 = metadata.into(); latest.into() } From 4060637574c56a255988d75e24daf5bd6593fc28 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Mon, 16 Sep 2024 18:27:36 +0300 Subject: [PATCH 27/70] frame-md: Use git dependency instead Signed-off-by: Alexandru Vasile --- Cargo.lock | 17 +++++++++-------- Cargo.toml | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 16863993ffd7..bcffc103b368 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5944,22 +5944,23 @@ dependencies = [ [[package]] name = "frame-metadata" version = "16.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cf1549fba25a6fcac22785b61698317d958e96cac72a59102ea45b9ae64692" dependencies = [ "cfg-if", "parity-scale-codec", "scale-info", - "serde", ] [[package]] name = "frame-metadata" version = "16.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cf1549fba25a6fcac22785b61698317d958e96cac72a59102ea45b9ae64692" +source = "git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/metadata-v16-associated-types#ede6a4dda012a101e46eea7a44a410a13b46867f" dependencies = [ "cfg-if", "parity-scale-codec", "scale-info", + "serde", ] [[package]] @@ -5968,7 +5969,7 @@ version = "0.1.0" dependencies = [ "array-bytes", "docify", - "frame-metadata 16.0.0", + "frame-metadata 16.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/metadata-v16-associated-types)", "frame-support", "frame-system", "log", @@ -6029,7 +6030,7 @@ dependencies = [ "bitflags 1.3.2", "docify", "environmental", - "frame-metadata 16.0.0", + "frame-metadata 16.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/metadata-v16-associated-types)", "frame-support-procedural", "frame-system", "impl-trait-for-tuples", @@ -6120,7 +6121,7 @@ version = "3.0.0" dependencies = [ "frame-benchmarking", "frame-executive", - "frame-metadata 16.0.0", + "frame-metadata 16.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/metadata-v16-associated-types)", "frame-support", "frame-support-test-pallet", "frame-system", @@ -20546,7 +20547,7 @@ dependencies = [ name = "sp-metadata-ir" version = "0.6.0" dependencies = [ - "frame-metadata 16.0.0", + "frame-metadata 16.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/metadata-v16-associated-types)", "parity-scale-codec", "scale-info", ] @@ -21712,7 +21713,7 @@ dependencies = [ "cargo_metadata", "console", "filetime", - "frame-metadata 16.0.0", + "frame-metadata 16.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/metadata-v16-associated-types)", "jobserver", "merkleized-metadata", "parity-scale-codec", diff --git a/Cargo.toml b/Cargo.toml index 8f6b63df6a76..42851b3d0855 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -760,7 +760,7 @@ frame-benchmarking-pallet-pov = { default-features = false, path = "substrate/fr frame-election-provider-solution-type = { path = "substrate/frame/election-provider-support/solution-type", default-features = false } frame-election-provider-support = { path = "substrate/frame/election-provider-support", default-features = false } frame-executive = { path = "substrate/frame/executive", default-features = false } -frame-metadata = { path = "/home/lexnv/workspace/frame-metadata/frame-metadata", default-features = false } +frame-metadata = { git = "https://github.com/paritytech/frame-metadata.git", branch = "lexnv/metadata-v16-associated-types", default-features = false } frame-metadata-hash-extension = { path = "substrate/frame/metadata-hash-extension", default-features = false } frame-support = { path = "substrate/frame/support", default-features = false } frame-support-procedural = { path = "substrate/frame/support/procedural", default-features = false } From adf7508f093660d6c1859b8ffd8e3f2d8453fdb8 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Mon, 16 Sep 2024 19:02:19 +0300 Subject: [PATCH 28/70] metadata-ir: Adjust for new transaction format Signed-off-by: Alexandru Vasile --- substrate/primitives/metadata-ir/src/unstable.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/substrate/primitives/metadata-ir/src/unstable.rs b/substrate/primitives/metadata-ir/src/unstable.rs index cd462448d241..01aadc918852 100644 --- a/substrate/primitives/metadata-ir/src/unstable.rs +++ b/substrate/primitives/metadata-ir/src/unstable.rs @@ -33,7 +33,7 @@ use frame_metadata::v16::{ PalletAssociatedTypeMetadata, PalletCallMetadata, PalletConstantMetadata, PalletErrorMetadata, PalletEventMetadata, PalletMetadata, PalletStorageMetadata, RuntimeApiMetadata, RuntimeApiMethodMetadata, RuntimeApiMethodParamMetadata, RuntimeMetadataV16, - SignedExtensionMetadata, StorageEntryMetadata, + StorageEntryMetadata, TransactionExtensionMetadata, }; impl From for RuntimeMetadataV16 { @@ -41,7 +41,6 @@ impl From for RuntimeMetadataV16 { RuntimeMetadataV16::new( ir.pallets.into_iter().map(Into::into).collect(), ir.extrinsic.into(), - ir.ty, ir.apis.into_iter().map(Into::into).collect(), ir.outer_enums.into(), // Substrate does not collect yet the custom metadata fields. @@ -155,9 +154,9 @@ impl From for PalletConstantMetadata { } } -impl From for SignedExtensionMetadata { +impl From for TransactionExtensionMetadata { fn from(ir: SignedExtensionMetadataIR) -> Self { - SignedExtensionMetadata { + TransactionExtensionMetadata { identifier: ir.identifier, ty: ir.ty, additional_signed: ir.additional_signed, @@ -168,12 +167,12 @@ impl From for SignedExtensionMetadata { impl From for ExtrinsicMetadata { fn from(ir: ExtrinsicMetadataIR) -> Self { ExtrinsicMetadata { - version: ir.version, + versions: alloc::vec![ir.version], address_ty: ir.address_ty, call_ty: ir.call_ty, signature_ty: ir.signature_ty, extra_ty: ir.extra_ty, - signed_extensions: ir.signed_extensions.into_iter().map(Into::into).collect(), + transaction_extensions: ir.signed_extensions.into_iter().map(Into::into).collect(), } } } @@ -206,7 +205,7 @@ impl From for DeprecationInfo { DeprecationInfoIR::ItemDeprecated(status) => DeprecationInfo::ItemDeprecated(status.into()), DeprecationInfoIR::VariantsDeprecated(btree) => DeprecationInfo::VariantsDeprecated( - btree.into_iter().map(|(key, value)| (key, value.into())).collect(), + btree.into_iter().map(|(key, value)| (key.0, value.into())).collect(), ), } } From 97eb703c54771fe8fe158e0705fa24fc3b75a162 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 25 Oct 2024 12:46:36 +0300 Subject: [PATCH 29/70] cargo: Use frame-metadata 17 Signed-off-by: Alexandru Vasile --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 42851b3d0855..d7515069b8e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -760,7 +760,7 @@ frame-benchmarking-pallet-pov = { default-features = false, path = "substrate/fr frame-election-provider-solution-type = { path = "substrate/frame/election-provider-support/solution-type", default-features = false } frame-election-provider-support = { path = "substrate/frame/election-provider-support", default-features = false } frame-executive = { path = "substrate/frame/executive", default-features = false } -frame-metadata = { git = "https://github.com/paritytech/frame-metadata.git", branch = "lexnv/metadata-v16-associated-types", default-features = false } +frame-metadata = { version = "17.0.0", default-features = false } frame-metadata-hash-extension = { path = "substrate/frame/metadata-hash-extension", default-features = false } frame-support = { path = "substrate/frame/support", default-features = false } frame-support-procedural = { path = "substrate/frame/support/procedural", default-features = false } From 6ff6f37b8721229072414690af0c168c7a8247e2 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 25 Oct 2024 13:00:05 +0300 Subject: [PATCH 30/70] metadata-ir: Adjust metadata Signed-off-by: Alexandru Vasile --- substrate/primitives/metadata-ir/src/types.rs | 23 ------------------- .../primitives/metadata-ir/src/unstable.rs | 10 ++++---- 2 files changed, 5 insertions(+), 28 deletions(-) diff --git a/substrate/primitives/metadata-ir/src/types.rs b/substrate/primitives/metadata-ir/src/types.rs index 698e91fa11c6..199b692fbd8c 100644 --- a/substrate/primitives/metadata-ir/src/types.rs +++ b/substrate/primitives/metadata-ir/src/types.rs @@ -224,29 +224,6 @@ impl IntoPortable for PalletAssociatedTypeMetadataIR { } } -/// Metadata of a pallet's associated type. -#[derive(Clone, PartialEq, Eq, Encode, Debug)] -pub struct PalletAssociatedTypeMetadataIR { - /// The name of the associated type. - pub name: T::String, - /// The type of the associated type. - pub ty: T::Type, - /// The documentation of the associated type. - pub docs: Vec, -} - -impl IntoPortable for PalletAssociatedTypeMetadataIR { - type Output = PalletAssociatedTypeMetadataIR; - - fn into_portable(self, registry: &mut Registry) -> Self::Output { - PalletAssociatedTypeMetadataIR { - name: self.name.into_portable(registry), - ty: registry.register_type(&self.ty), - docs: registry.map_into_portable(self.docs), - } - } -} - /// Metadata of an extrinsic's signed extension. #[derive(Clone, PartialEq, Eq, Encode, Debug)] pub struct TransactionExtensionMetadataIR { diff --git a/substrate/primitives/metadata-ir/src/unstable.rs b/substrate/primitives/metadata-ir/src/unstable.rs index 01aadc918852..c50064a5a4d7 100644 --- a/substrate/primitives/metadata-ir/src/unstable.rs +++ b/substrate/primitives/metadata-ir/src/unstable.rs @@ -25,7 +25,7 @@ use crate::{ use super::types::{ ExtrinsicMetadataIR, MetadataIR, PalletMetadataIR, RuntimeApiMetadataIR, - RuntimeApiMethodMetadataIR, RuntimeApiMethodParamMetadataIR, SignedExtensionMetadataIR, + RuntimeApiMethodMetadataIR, RuntimeApiMethodParamMetadataIR, TransactionExtensionMetadataIR, }; use frame_metadata::v16::{ @@ -154,12 +154,12 @@ impl From for PalletConstantMetadata { } } -impl From for TransactionExtensionMetadata { - fn from(ir: SignedExtensionMetadataIR) -> Self { +impl From for TransactionExtensionMetadata { + fn from(ir: TransactionExtensionMetadataIR) -> Self { TransactionExtensionMetadata { identifier: ir.identifier, ty: ir.ty, - additional_signed: ir.additional_signed, + additional_signed: ir.implicit, } } } @@ -172,7 +172,7 @@ impl From for ExtrinsicMetadata { call_ty: ir.call_ty, signature_ty: ir.signature_ty, extra_ty: ir.extra_ty, - transaction_extensions: ir.signed_extensions.into_iter().map(Into::into).collect(), + transaction_extensions: ir.extensions.into_iter().map(Into::into).collect(), } } } From fba350219c1e9f3503079842e22ee6003b232fdd Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 25 Oct 2024 13:05:17 +0300 Subject: [PATCH 31/70] metadata-ir: Prepare metadataIR for multiple version collection Signed-off-by: Alexandru Vasile --- .../procedural/src/construct_runtime/expand/metadata.rs | 2 +- substrate/primitives/metadata-ir/src/lib.rs | 2 +- substrate/primitives/metadata-ir/src/types.rs | 6 +++--- substrate/primitives/metadata-ir/src/unstable.rs | 2 +- substrate/primitives/metadata-ir/src/v14.rs | 2 +- substrate/primitives/metadata-ir/src/v15.rs | 2 +- 6 files changed, 8 insertions(+), 8 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 c12fc20bc8b8..e0c35ebae9ab 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs @@ -117,7 +117,7 @@ pub fn expand_runtime_metadata( pallets: #scrate::__private::vec![ #(#pallets),* ], extrinsic: #scrate::__private::metadata_ir::ExtrinsicMetadataIR { ty, - version: <#extrinsic as #scrate::sp_runtime::traits::ExtrinsicMetadata>::VERSION, + versions: #scrate::__private::vec![ <#extrinsic as #scrate::sp_runtime::traits::ExtrinsicMetadata>::VERSION ], address_ty, call_ty, signature_ty, diff --git a/substrate/primitives/metadata-ir/src/lib.rs b/substrate/primitives/metadata-ir/src/lib.rs index d2012cabf187..bf234432a1a6 100644 --- a/substrate/primitives/metadata-ir/src/lib.rs +++ b/substrate/primitives/metadata-ir/src/lib.rs @@ -98,7 +98,7 @@ mod test { pallets: vec![], extrinsic: ExtrinsicMetadataIR { ty: meta_type::<()>(), - version: 0, + versions: vec![0], address_ty: meta_type::<()>(), call_ty: meta_type::<()>(), signature_ty: meta_type::<()>(), diff --git a/substrate/primitives/metadata-ir/src/types.rs b/substrate/primitives/metadata-ir/src/types.rs index 199b692fbd8c..af217ffe16ee 100644 --- a/substrate/primitives/metadata-ir/src/types.rs +++ b/substrate/primitives/metadata-ir/src/types.rs @@ -170,8 +170,8 @@ pub struct ExtrinsicMetadataIR { /// /// Note: Field used for metadata V14 only. pub ty: T::Type, - /// Extrinsic version. - pub version: u8, + /// Extrinsic versions. + pub versions: Vec, /// The type of the address that signs the extrinsic pub address_ty: T::Type, /// The type of the outermost Call enum. @@ -191,7 +191,7 @@ impl IntoPortable for ExtrinsicMetadataIR { fn into_portable(self, registry: &mut Registry) -> Self::Output { ExtrinsicMetadataIR { ty: registry.register_type(&self.ty), - version: self.version, + versions: self.versions, address_ty: registry.register_type(&self.address_ty), call_ty: registry.register_type(&self.call_ty), signature_ty: registry.register_type(&self.signature_ty), diff --git a/substrate/primitives/metadata-ir/src/unstable.rs b/substrate/primitives/metadata-ir/src/unstable.rs index c50064a5a4d7..64835337f3b1 100644 --- a/substrate/primitives/metadata-ir/src/unstable.rs +++ b/substrate/primitives/metadata-ir/src/unstable.rs @@ -167,7 +167,7 @@ impl From for TransactionExtensionMetadata { impl From for ExtrinsicMetadata { fn from(ir: ExtrinsicMetadataIR) -> Self { ExtrinsicMetadata { - versions: alloc::vec![ir.version], + versions: ir.versions.into_iter().map(Into::into).collect(), address_ty: ir.address_ty, call_ty: ir.call_ty, signature_ty: ir.signature_ty, diff --git a/substrate/primitives/metadata-ir/src/v14.rs b/substrate/primitives/metadata-ir/src/v14.rs index 70e84532add9..683effcedbb1 100644 --- a/substrate/primitives/metadata-ir/src/v14.rs +++ b/substrate/primitives/metadata-ir/src/v14.rs @@ -151,7 +151,7 @@ impl From for ExtrinsicMetadata { fn from(ir: ExtrinsicMetadataIR) -> Self { ExtrinsicMetadata { ty: ir.ty, - version: ir.version, + version: *ir.versions.get(0).expect("Metadata V14 supports only one version"), signed_extensions: ir.extensions.into_iter().map(Into::into).collect(), } } diff --git a/substrate/primitives/metadata-ir/src/v15.rs b/substrate/primitives/metadata-ir/src/v15.rs index 4b3b6106d27f..850de0b702d7 100644 --- a/substrate/primitives/metadata-ir/src/v15.rs +++ b/substrate/primitives/metadata-ir/src/v15.rs @@ -100,7 +100,7 @@ impl From for SignedExtensionMetadata { impl From for ExtrinsicMetadata { fn from(ir: ExtrinsicMetadataIR) -> Self { ExtrinsicMetadata { - version: ir.version, + version: *ir.versions.get(0).expect("Metadata V15 supports only one version"), address_ty: ir.address_ty, call_ty: ir.call_ty, signature_ty: ir.signature_ty, From ca2b0f0f095c917209f2a285412bfba78d22e64c Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 25 Oct 2024 13:10:05 +0300 Subject: [PATCH 32/70] Add prdoc Signed-off-by: Alexandru Vasile --- prdoc/pr_5732.prdoc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 prdoc/pr_5732.prdoc diff --git a/prdoc/pr_5732.prdoc b/prdoc/pr_5732.prdoc new file mode 100644 index 000000000000..a22caf3af3e8 --- /dev/null +++ b/prdoc/pr_5732.prdoc @@ -0,0 +1,17 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: Expose the unstable metadata v16 + +doc: + - audience: + - Runtime Dev + - Runtime User + description: | + This PR exposes the *unstable* metadata V16. The metadata is exposed under the unstable u32::MAX number. + Developers can start experimenting with the new features of the metadata v16. Please note that + this metadata is under development and expect breaking changes until stabilization. + +crates: + - name: sp-metadata-ir + bump: patch From 379ec83842d3da9d580e44806a8210386e5e654b Mon Sep 17 00:00:00 2001 From: Alexandru Vasile <60601340+lexnv@users.noreply.github.com> Date: Wed, 30 Oct 2024 18:06:51 +0200 Subject: [PATCH 33/70] Update substrate/frame/metadata-hash-extension/Cargo.toml Co-authored-by: Niklas Adolfsson --- substrate/frame/metadata-hash-extension/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/metadata-hash-extension/Cargo.toml b/substrate/frame/metadata-hash-extension/Cargo.toml index 441305ffe69f..8f4ba922984c 100644 --- a/substrate/frame/metadata-hash-extension/Cargo.toml +++ b/substrate/frame/metadata-hash-extension/Cargo.toml @@ -25,7 +25,7 @@ substrate-test-runtime-client = { workspace = true } sp-api = { workspace = true, default-features = true } sp-transaction-pool = { workspace = true, default-features = true } merkleized-metadata = { workspace = true } -frame-metadata = { features = ["current","unstable"], workspace = true, default-features = true } +frame-metadata = { features = ["current", "unstable"], workspace = true, default-features = true } sp-tracing = { workspace = true, default-features = true } [features] From 475288c83a4bd064392a59e2386b985e6958cd1f Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 7 Nov 2024 15:38:44 +0200 Subject: [PATCH 34/70] Update cargo lock with pending branches Signed-off-by: Alexandru Vasile --- Cargo.lock | 25 +++++++++++++++++-------- Cargo.toml | 4 ++-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1f8c97659e2e..88f6fd423a4f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6386,6 +6386,16 @@ name = "frame-metadata" version = "17.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "701bac17e9b55e0f95067c428ebcb46496587f08e8cf4ccc0fe5903bea10dbb8" +dependencies = [ + "cfg-if", + "parity-scale-codec", + "scale-info", +] + +[[package]] +name = "frame-metadata" +version = "17.0.0" +source = "git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16#743b690162edae12e35bdfff027858480fdf4ad9" dependencies = [ "cfg-if", "parity-scale-codec", @@ -6400,7 +6410,7 @@ dependencies = [ "array-bytes", "const-hex", "docify", - "frame-metadata 17.0.0", + "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", "frame-support", "frame-system", "log", @@ -6463,7 +6473,7 @@ dependencies = [ "bitflags 1.3.2", "docify", "environmental", - "frame-metadata 17.0.0", + "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", "frame-support-procedural", "frame-system", "impl-trait-for-tuples", @@ -6555,7 +6565,7 @@ version = "3.0.0" dependencies = [ "frame-benchmarking", "frame-executive", - "frame-metadata 17.0.0", + "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", "frame-support", "frame-support-test-pallet", "frame-system", @@ -9648,12 +9658,11 @@ dependencies = [ [[package]] name = "merkleized-metadata" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f313fcff1d2a4bcaa2deeaa00bf7530d77d5f7bd0467a117dde2e29a75a7a17a" +source = "git+https://github.com/lexnv/merkleized-metadata.git?branch=lexnv/update-frame-md#c72164a029302dd6ecfec365b8fafc3759891953" dependencies = [ "array-bytes", "blake3", - "frame-metadata 16.0.0", + "frame-metadata 17.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec", "scale-decode", "scale-info", @@ -22433,7 +22442,7 @@ dependencies = [ name = "sp-metadata-ir" version = "0.6.0" dependencies = [ - "frame-metadata 17.0.0", + "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", "parity-scale-codec", "scale-info", ] @@ -24106,7 +24115,7 @@ dependencies = [ "cargo_metadata", "console", "filetime", - "frame-metadata 17.0.0", + "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", "jobserver", "merkleized-metadata", "parity-scale-codec", diff --git a/Cargo.toml b/Cargo.toml index 95304689aa87..fbb6c839cae5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -771,7 +771,7 @@ frame-benchmarking-pallet-pov = { default-features = false, path = "substrate/fr frame-election-provider-solution-type = { path = "substrate/frame/election-provider-support/solution-type", default-features = false } frame-election-provider-support = { path = "substrate/frame/election-provider-support", default-features = false } frame-executive = { path = "substrate/frame/executive", default-features = false } -frame-metadata = { version = "17.0.0", default-features = false } +frame-metadata = { git = "https://github.com/paritytech/frame-metadata.git", branch = "lexnv/extensions-v16", default-features = false } frame-metadata-hash-extension = { path = "substrate/frame/metadata-hash-extension", default-features = false } frame-support = { path = "substrate/frame/support", default-features = false } frame-support-procedural = { path = "substrate/frame/support/procedural", default-features = false } @@ -846,7 +846,7 @@ macro_magic = { version = "0.5.1" } maplit = { version = "1.0.2" } memmap2 = { version = "0.9.3" } memory-db = { version = "0.32.0", default-features = false } -merkleized-metadata = { version = "0.1.0" } +merkleized-metadata = { git = "https://github.com/lexnv/merkleized-metadata.git", branch = "lexnv/update-frame-md" } merlin = { version = "3.0", default-features = false } messages-relay = { path = "bridges/relays/messages" } metered = { version = "0.6.1", default-features = false, package = "prioritized-metered-channel" } From 195e51488ba7a7a09fe00d76efb78dfe8f23610b Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 7 Nov 2024 15:39:44 +0200 Subject: [PATCH 35/70] Update prdoc Signed-off-by: Alexandru Vasile --- prdoc/pr_5732.prdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prdoc/pr_5732.prdoc b/prdoc/pr_5732.prdoc index a22caf3af3e8..14777065268d 100644 --- a/prdoc/pr_5732.prdoc +++ b/prdoc/pr_5732.prdoc @@ -14,4 +14,4 @@ doc: crates: - name: sp-metadata-ir - bump: patch + bump: minor From 332a900ddf9bdd73e7f475298c69bd8a9b3820ea Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 7 Nov 2024 15:40:33 +0200 Subject: [PATCH 36/70] metadata-ir/v14: Populate with lowest supported version Signed-off-by: Alexandru Vasile --- substrate/primitives/metadata-ir/src/v14.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/substrate/primitives/metadata-ir/src/v14.rs b/substrate/primitives/metadata-ir/src/v14.rs index 683effcedbb1..f3cb5973f5bd 100644 --- a/substrate/primitives/metadata-ir/src/v14.rs +++ b/substrate/primitives/metadata-ir/src/v14.rs @@ -149,9 +149,12 @@ impl From for SignedExtensionMetadata { impl From for ExtrinsicMetadata { fn from(ir: ExtrinsicMetadataIR) -> Self { + let lowest_supported_version = + ir.versions.iter().min().expect("Metadata V14 supports one version; qed"); + ExtrinsicMetadata { ty: ir.ty, - version: *ir.versions.get(0).expect("Metadata V14 supports only one version"), + version: *lowest_supported_version, signed_extensions: ir.extensions.into_iter().map(Into::into).collect(), } } From f9b635d7e06f61ea22993ef389c3d05c171fce51 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 7 Nov 2024 16:13:20 +0200 Subject: [PATCH 37/70] metadata-ir/unstable: Adjust for new frame-md version Signed-off-by: Alexandru Vasile --- .../primitives/metadata-ir/src/unstable.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/substrate/primitives/metadata-ir/src/unstable.rs b/substrate/primitives/metadata-ir/src/unstable.rs index 64835337f3b1..e2a2cc412b17 100644 --- a/substrate/primitives/metadata-ir/src/unstable.rs +++ b/substrate/primitives/metadata-ir/src/unstable.rs @@ -156,22 +156,23 @@ impl From for PalletConstantMetadata { impl From for TransactionExtensionMetadata { fn from(ir: TransactionExtensionMetadataIR) -> Self { - TransactionExtensionMetadata { - identifier: ir.identifier, - ty: ir.ty, - additional_signed: ir.implicit, - } + TransactionExtensionMetadata { identifier: ir.identifier, ty: ir.ty, implicit: ir.implicit } } } impl From for ExtrinsicMetadata { fn from(ir: ExtrinsicMetadataIR) -> Self { + let versions = &[4, 5]; + + let transaction_extensions_by_version = versions + .iter() + .map(|version| (*version, (0..ir.extensions.len()).map(|index| index as u32).collect())) + .collect(); + ExtrinsicMetadata { - versions: ir.versions.into_iter().map(Into::into).collect(), address_ty: ir.address_ty, - call_ty: ir.call_ty, signature_ty: ir.signature_ty, - extra_ty: ir.extra_ty, + transaction_extensions_by_version, transaction_extensions: ir.extensions.into_iter().map(Into::into).collect(), } } From ce4281302693ce12436713f4b2038c907775167a Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 7 Nov 2024 19:05:09 +0200 Subject: [PATCH 38/70] extrinsic: Modify ExtrinsicMetadata to return a Vec of versions Signed-off-by: Alexandru Vasile --- substrate/frame/revive/src/evm/runtime.rs | 8 ++++++-- .../procedural/src/construct_runtime/expand/metadata.rs | 2 +- .../primitives/runtime/src/generic/unchecked_extrinsic.rs | 3 +-- substrate/primitives/runtime/src/traits/mod.rs | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/substrate/frame/revive/src/evm/runtime.rs b/substrate/frame/revive/src/evm/runtime.rs index 4c3fdeca720c..f9dbf5dd3ead 100644 --- a/substrate/frame/revive/src/evm/runtime.rs +++ b/substrate/frame/revive/src/evm/runtime.rs @@ -80,8 +80,12 @@ impl ExtrinsicLike impl ExtrinsicMetadata for UncheckedExtrinsic { - const VERSION: u8 = - generic::UncheckedExtrinsic::, Signature, E::Extension>::VERSION; + const VERSIONS: &'static [u8] = generic::UncheckedExtrinsic::< + Address, + CallOf, + Signature, + E::Extension, + >::VERSIONS; type TransactionExtensions = E::Extension; } 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 e0c35ebae9ab..4590a3a7f490 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs @@ -117,7 +117,7 @@ pub fn expand_runtime_metadata( pallets: #scrate::__private::vec![ #(#pallets),* ], extrinsic: #scrate::__private::metadata_ir::ExtrinsicMetadataIR { ty, - versions: #scrate::__private::vec![ <#extrinsic as #scrate::sp_runtime::traits::ExtrinsicMetadata>::VERSION ], + versions: <#extrinsic as #scrate::sp_runtime::traits::ExtrinsicMetadata>::VERSIONS.into_iter().map(|ref_version| *ref_version).collect(), address_ty, call_ty, signature_ty, diff --git a/substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs b/substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs index 8c44e147f90b..4636df0ca53e 100644 --- a/substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs +++ b/substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs @@ -390,8 +390,7 @@ where impl> ExtrinsicMetadata for UncheckedExtrinsic { - // TODO: Expose both version 4 and version 5 in metadata v16. - const VERSION: u8 = LEGACY_EXTRINSIC_FORMAT_VERSION; + const VERSIONS: &'static [u8] = &[LEGACY_EXTRINSIC_FORMAT_VERSION, EXTRINSIC_FORMAT_VERSION]; type TransactionExtensions = Extension; } diff --git a/substrate/primitives/runtime/src/traits/mod.rs b/substrate/primitives/runtime/src/traits/mod.rs index e6906cdb3877..8597f8e36440 100644 --- a/substrate/primitives/runtime/src/traits/mod.rs +++ b/substrate/primitives/runtime/src/traits/mod.rs @@ -1409,10 +1409,10 @@ impl SignaturePayload for () { /// Implementor is an [`Extrinsic`] and provides metadata about this extrinsic. pub trait ExtrinsicMetadata { - /// The format version of the `Extrinsic`. + /// The format versions of the `Extrinsic`. /// /// By format is meant the encoded representation of the `Extrinsic`. - const VERSION: u8; + const VERSIONS: &'static [u8]; /// Transaction extensions attached to this `Extrinsic`. type TransactionExtensions; From bdf9e7e1e029af4613b2be73ad9563c178f51b55 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 7 Nov 2024 19:07:59 +0200 Subject: [PATCH 39/70] metadata-ir: Use IR versions instead of hardcoding Signed-off-by: Alexandru Vasile --- substrate/primitives/metadata-ir/src/unstable.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/substrate/primitives/metadata-ir/src/unstable.rs b/substrate/primitives/metadata-ir/src/unstable.rs index e2a2cc412b17..d678db44e3d6 100644 --- a/substrate/primitives/metadata-ir/src/unstable.rs +++ b/substrate/primitives/metadata-ir/src/unstable.rs @@ -162,9 +162,10 @@ impl From for TransactionExtensionMetadata { impl From for ExtrinsicMetadata { fn from(ir: ExtrinsicMetadataIR) -> Self { - let versions = &[4, 5]; - - let transaction_extensions_by_version = versions + // Presume all extensions work for all versions. + // This is true for now. + let transaction_extensions_by_version = ir + .versions .iter() .map(|version| (*version, (0..ir.extensions.len()).map(|index| index as u32).collect())) .collect(); From 7ed95ff20e31238f5e1600a87d5432fdf46b479f Mon Sep 17 00:00:00 2001 From: Alexandru Vasile <60601340+lexnv@users.noreply.github.com> Date: Mon, 11 Nov 2024 18:32:07 +0200 Subject: [PATCH 40/70] Update substrate/primitives/metadata-ir/src/v15.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- substrate/primitives/metadata-ir/src/v15.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/primitives/metadata-ir/src/v15.rs b/substrate/primitives/metadata-ir/src/v15.rs index 850de0b702d7..ed315a31e6dc 100644 --- a/substrate/primitives/metadata-ir/src/v15.rs +++ b/substrate/primitives/metadata-ir/src/v15.rs @@ -100,7 +100,7 @@ impl From for SignedExtensionMetadata { impl From for ExtrinsicMetadata { fn from(ir: ExtrinsicMetadataIR) -> Self { ExtrinsicMetadata { - version: *ir.versions.get(0).expect("Metadata V15 supports only one version"), + version: *ir.versions.iter().min().expect("Metadata V15 supports only one version"), address_ty: ir.address_ty, call_ty: ir.call_ty, signature_ty: ir.signature_ty, From b81abd882ef2674e10ca0d42f4d5c1fd4c7217dd Mon Sep 17 00:00:00 2001 From: Alexandru Vasile <60601340+lexnv@users.noreply.github.com> Date: Mon, 11 Nov 2024 18:34:05 +0200 Subject: [PATCH 41/70] Update substrate/primitives/runtime/src/traits/mod.rs Co-authored-by: James Wilson --- substrate/primitives/runtime/src/traits/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/primitives/runtime/src/traits/mod.rs b/substrate/primitives/runtime/src/traits/mod.rs index 8597f8e36440..3abe60ae7a1b 100644 --- a/substrate/primitives/runtime/src/traits/mod.rs +++ b/substrate/primitives/runtime/src/traits/mod.rs @@ -1411,7 +1411,7 @@ impl SignaturePayload for () { pub trait ExtrinsicMetadata { /// The format versions of the `Extrinsic`. /// - /// By format is meant the encoded representation of the `Extrinsic`. + /// By format we mean the encoded representation of the `Extrinsic`. const VERSIONS: &'static [u8]; /// Transaction extensions attached to this `Extrinsic`. From 138467472df549d5c606c494ee8fbf63c5f85e5d Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Mon, 11 Nov 2024 18:48:00 +0200 Subject: [PATCH 42/70] metadata-ir: Assume version 0 for transaction_extensions Signed-off-by: Alexandru Vasile --- substrate/primitives/metadata-ir/src/unstable.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/substrate/primitives/metadata-ir/src/unstable.rs b/substrate/primitives/metadata-ir/src/unstable.rs index d678db44e3d6..3e623ce001ac 100644 --- a/substrate/primitives/metadata-ir/src/unstable.rs +++ b/substrate/primitives/metadata-ir/src/unstable.rs @@ -44,7 +44,7 @@ impl From for RuntimeMetadataV16 { 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. + // This allows us to extend the V16 easily. CustomMetadata { map: Default::default() }, ) } @@ -162,15 +162,12 @@ impl From for TransactionExtensionMetadata { impl From for ExtrinsicMetadata { fn from(ir: ExtrinsicMetadataIR) -> Self { - // Presume all extensions work for all versions. - // This is true for now. - let transaction_extensions_by_version = ir - .versions - .iter() - .map(|version| (*version, (0..ir.extensions.len()).map(|index| index as u32).collect())) - .collect(); + // Assume version 0 for all extensions. + let indexes = (0..ir.extensions.len()).map(|index| index as u32).collect::>(); + let transaction_extensions_by_version = [(0, indexes)].iter().cloned().collect(); ExtrinsicMetadata { + versions: ir.versions, address_ty: ir.address_ty, signature_ty: ir.signature_ty, transaction_extensions_by_version, From aef4a5c1cb52483e70fb1d1e7bd891d647fefb46 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Mon, 11 Nov 2024 18:48:31 +0200 Subject: [PATCH 43/70] Update cargo to latest Signed-off-by: Alexandru Vasile --- Cargo.lock | 29 +++++++++-------------------- Cargo.toml | 2 +- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 88f6fd423a4f..eab139e43fbc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6384,18 +6384,7 @@ dependencies = [ [[package]] name = "frame-metadata" version = "17.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "701bac17e9b55e0f95067c428ebcb46496587f08e8cf4ccc0fe5903bea10dbb8" -dependencies = [ - "cfg-if", - "parity-scale-codec", - "scale-info", -] - -[[package]] -name = "frame-metadata" -version = "17.0.0" -source = "git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16#743b690162edae12e35bdfff027858480fdf4ad9" +source = "git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16#2c2ffa63f7f04b5b8795a0bedb98f7c5dc388fe2" dependencies = [ "cfg-if", "parity-scale-codec", @@ -6410,7 +6399,7 @@ dependencies = [ "array-bytes", "const-hex", "docify", - "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", + "frame-metadata 17.0.0", "frame-support", "frame-system", "log", @@ -6473,7 +6462,7 @@ dependencies = [ "bitflags 1.3.2", "docify", "environmental", - "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", + "frame-metadata 17.0.0", "frame-support-procedural", "frame-system", "impl-trait-for-tuples", @@ -6565,7 +6554,7 @@ version = "3.0.0" dependencies = [ "frame-benchmarking", "frame-executive", - "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", + "frame-metadata 17.0.0", "frame-support", "frame-support-test-pallet", "frame-system", @@ -9657,12 +9646,12 @@ dependencies = [ [[package]] name = "merkleized-metadata" -version = "0.1.0" -source = "git+https://github.com/lexnv/merkleized-metadata.git?branch=lexnv/update-frame-md#c72164a029302dd6ecfec365b8fafc3759891953" +version = "0.1.1" +source = "git+https://github.com/lexnv/merkleized-metadata.git?branch=lexnv/latest-frame-update#bdacb9314fbd08137813c2af213f86c08e57b128" dependencies = [ "array-bytes", "blake3", - "frame-metadata 17.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "frame-metadata 17.0.0", "parity-scale-codec", "scale-decode", "scale-info", @@ -22442,7 +22431,7 @@ dependencies = [ name = "sp-metadata-ir" version = "0.6.0" dependencies = [ - "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", + "frame-metadata 17.0.0", "parity-scale-codec", "scale-info", ] @@ -24115,7 +24104,7 @@ dependencies = [ "cargo_metadata", "console", "filetime", - "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", + "frame-metadata 17.0.0", "jobserver", "merkleized-metadata", "parity-scale-codec", diff --git a/Cargo.toml b/Cargo.toml index fbb6c839cae5..5f6923db37e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -846,7 +846,7 @@ macro_magic = { version = "0.5.1" } maplit = { version = "1.0.2" } memmap2 = { version = "0.9.3" } memory-db = { version = "0.32.0", default-features = false } -merkleized-metadata = { git = "https://github.com/lexnv/merkleized-metadata.git", branch = "lexnv/update-frame-md" } +merkleized-metadata = { git = "https://github.com/lexnv/merkleized-metadata.git", branch = "lexnv/latest-frame-update" } merlin = { version = "3.0", default-features = false } messages-relay = { path = "bridges/relays/messages" } metered = { version = "0.6.1", default-features = false, package = "prioritized-metered-channel" } From 628616e6f292c7bb967c95f167d88e11e90f93fb Mon Sep 17 00:00:00 2001 From: Alexandru Vasile <60601340+lexnv@users.noreply.github.com> Date: Mon, 11 Nov 2024 18:49:38 +0200 Subject: [PATCH 44/70] Update Cargo.toml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index fbb6c839cae5..e663f0988740 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -846,7 +846,7 @@ macro_magic = { version = "0.5.1" } maplit = { version = "1.0.2" } memmap2 = { version = "0.9.3" } memory-db = { version = "0.32.0", default-features = false } -merkleized-metadata = { git = "https://github.com/lexnv/merkleized-metadata.git", branch = "lexnv/update-frame-md" } +merkleized-metadata = "0.1.1" merlin = { version = "3.0", default-features = false } messages-relay = { path = "bridges/relays/messages" } metered = { version = "0.6.1", default-features = false, package = "prioritized-metered-channel" } From 2390a7b5cd9180cedf24af3471a58cfc79600ed7 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Mon, 11 Nov 2024 18:51:24 +0200 Subject: [PATCH 45/70] Update cargo lock with unreleased branch Signed-off-by: Alexandru Vasile --- Cargo.lock | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eab139e43fbc..ad71796ff77d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6381,6 +6381,17 @@ dependencies = [ "serde", ] +[[package]] +name = "frame-metadata" +version = "17.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "701bac17e9b55e0f95067c428ebcb46496587f08e8cf4ccc0fe5903bea10dbb8" +dependencies = [ + "cfg-if", + "parity-scale-codec", + "scale-info", +] + [[package]] name = "frame-metadata" version = "17.0.0" @@ -6399,7 +6410,7 @@ dependencies = [ "array-bytes", "const-hex", "docify", - "frame-metadata 17.0.0", + "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", "frame-support", "frame-system", "log", @@ -6462,7 +6473,7 @@ dependencies = [ "bitflags 1.3.2", "docify", "environmental", - "frame-metadata 17.0.0", + "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", "frame-support-procedural", "frame-system", "impl-trait-for-tuples", @@ -6554,7 +6565,7 @@ version = "3.0.0" dependencies = [ "frame-benchmarking", "frame-executive", - "frame-metadata 17.0.0", + "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", "frame-support", "frame-support-test-pallet", "frame-system", @@ -9647,11 +9658,12 @@ dependencies = [ [[package]] name = "merkleized-metadata" version = "0.1.1" -source = "git+https://github.com/lexnv/merkleized-metadata.git?branch=lexnv/latest-frame-update#bdacb9314fbd08137813c2af213f86c08e57b128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8eb81785630905a22bb31c5703114c0f4e17b12d116b9569154d1639e184c29" dependencies = [ "array-bytes", "blake3", - "frame-metadata 17.0.0", + "frame-metadata 17.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec", "scale-decode", "scale-info", @@ -22431,7 +22443,7 @@ dependencies = [ name = "sp-metadata-ir" version = "0.6.0" dependencies = [ - "frame-metadata 17.0.0", + "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", "parity-scale-codec", "scale-info", ] @@ -24104,7 +24116,7 @@ dependencies = [ "cargo_metadata", "console", "filetime", - "frame-metadata 17.0.0", + "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", "jobserver", "merkleized-metadata", "parity-scale-codec", From eeb7e4ac70e9692c951f459ab28eb6d0989a26ce Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Tue, 12 Nov 2024 10:45:42 +0200 Subject: [PATCH 46/70] metadata-ir: Do not specify vec Signed-off-by: Alexandru Vasile --- substrate/primitives/metadata-ir/src/unstable.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/primitives/metadata-ir/src/unstable.rs b/substrate/primitives/metadata-ir/src/unstable.rs index 3e623ce001ac..d46ce3ec6a7d 100644 --- a/substrate/primitives/metadata-ir/src/unstable.rs +++ b/substrate/primitives/metadata-ir/src/unstable.rs @@ -163,7 +163,7 @@ impl From for TransactionExtensionMetadata { impl From for ExtrinsicMetadata { fn from(ir: ExtrinsicMetadataIR) -> Self { // Assume version 0 for all extensions. - let indexes = (0..ir.extensions.len()).map(|index| index as u32).collect::>(); + let indexes = (0..ir.extensions.len()).map(|index| index as u32).collect(); let transaction_extensions_by_version = [(0, indexes)].iter().cloned().collect(); ExtrinsicMetadata { From 06c0eb33b2ba28bacc23fb009ac3cb8b14ee398f Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Tue, 12 Nov 2024 10:56:58 +0200 Subject: [PATCH 47/70] Update PRdoc Signed-off-by: Alexandru Vasile --- prdoc/pr_5732.prdoc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/prdoc/pr_5732.prdoc b/prdoc/pr_5732.prdoc index 14777065268d..8a5df85cd08c 100644 --- a/prdoc/pr_5732.prdoc +++ b/prdoc/pr_5732.prdoc @@ -12,6 +12,16 @@ doc: Developers can start experimenting with the new features of the metadata v16. Please note that this metadata is under development and expect breaking changes until stabilization. + The `ExtrinsicMetadata` trait receives a breaking change. Its associated type `VERSION` is rename to `VERSIONS` + and now supports a constant static list of metadata versions. The versions implemented for `UncheckedExtrinsic` + are v4 (legacy version) and v5 (new version). + crates: - name: sp-metadata-ir - bump: minor + bump: major + - name: sp-runtime + bump: major + - name: frame-support-procedural + bump: patch + - name: pallet-revive + bump: patch From e0b9c32f59eeb0b9144d32304b50c54654355b99 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Tue, 12 Nov 2024 10:58:53 +0200 Subject: [PATCH 48/70] cargo: Update merkleized-metadata to unreleased branch Signed-off-by: Alexandru Vasile --- Cargo.lock | 26 +++++++------------------- Cargo.toml | 2 +- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3564697f9098..6289f21c04fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6438,17 +6438,6 @@ dependencies = [ "serde", ] -[[package]] -name = "frame-metadata" -version = "17.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "701bac17e9b55e0f95067c428ebcb46496587f08e8cf4ccc0fe5903bea10dbb8" -dependencies = [ - "cfg-if", - "parity-scale-codec", - "scale-info", -] - [[package]] name = "frame-metadata" version = "17.0.0" @@ -6467,7 +6456,7 @@ dependencies = [ "array-bytes", "const-hex", "docify", - "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", + "frame-metadata 17.0.0", "frame-support", "frame-system", "log", @@ -6536,7 +6525,7 @@ dependencies = [ "bitflags 1.3.2", "docify", "environmental", - "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", + "frame-metadata 17.0.0", "frame-support-procedural", "frame-system", "impl-trait-for-tuples", @@ -6628,7 +6617,7 @@ version = "3.0.0" dependencies = [ "frame-benchmarking", "frame-executive", - "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", + "frame-metadata 17.0.0", "frame-support", "frame-support-test-pallet", "frame-system", @@ -9731,12 +9720,11 @@ dependencies = [ [[package]] name = "merkleized-metadata" version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8eb81785630905a22bb31c5703114c0f4e17b12d116b9569154d1639e184c29" +source = "git+https://github.com/lexnv/merkleized-metadata.git?branch=lexnv/latest-frame-update#bdacb9314fbd08137813c2af213f86c08e57b128" dependencies = [ "array-bytes", "blake3", - "frame-metadata 17.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "frame-metadata 17.0.0", "parity-scale-codec", "scale-decode", "scale-info", @@ -22563,7 +22551,7 @@ dependencies = [ name = "sp-metadata-ir" version = "0.6.0" dependencies = [ - "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", + "frame-metadata 17.0.0", "parity-scale-codec", "scale-info", ] @@ -24239,7 +24227,7 @@ dependencies = [ "cargo_metadata", "console", "filetime", - "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", + "frame-metadata 17.0.0", "jobserver", "merkleized-metadata", "parity-scale-codec", diff --git a/Cargo.toml b/Cargo.toml index 65472d8044fa..76881099ea02 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -854,7 +854,7 @@ macro_magic = { version = "0.5.1" } maplit = { version = "1.0.2" } memmap2 = { version = "0.9.3" } memory-db = { version = "0.32.0", default-features = false } -merkleized-metadata = "0.1.1" +merkleized-metadata = { git = "https://github.com/lexnv/merkleized-metadata.git", branch = "lexnv/latest-frame-update" } merlin = { version = "3.0", default-features = false } messages-relay = { path = "bridges/relays/messages" } metered = { version = "0.6.1", default-features = false, package = "prioritized-metered-channel" } From d05af730abb6fe8db515a46b1b5169f39db39894 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 15 Nov 2024 17:36:34 +0200 Subject: [PATCH 49/70] cargo: Update dependencies Signed-off-by: Alexandru Vasile --- Cargo.lock | 30 ++++++++++++++++-------------- Cargo.toml | 4 ++-- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8c354f5aa0f8..a8e817a4bd28 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7058,7 +7058,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02d3379df61ff3dd871e2dde7d1bcdc0263e613c21c7579b149fd4f0ad9b1dc2" dependencies = [ - "frame-metadata 17.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "frame-metadata 17.0.0", "parity-scale-codec", "scale-decode 0.14.0", "scale-info", @@ -7212,8 +7212,9 @@ dependencies = [ [[package]] name = "frame-metadata" -version = "17.0.0" -source = "git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16#2c2ffa63f7f04b5b8795a0bedb98f7c5dc388fe2" +version = "18.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daaf440c68eb2c3d88e5760fe8c7af3f9fee9181fab6c2f2c4e7cc48dcc40bb8" dependencies = [ "cfg-if", "parity-scale-codec", @@ -7228,7 +7229,7 @@ dependencies = [ "array-bytes", "const-hex", "docify", - "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", + "frame-metadata 18.0.0", "frame-support 28.0.0", "frame-system 28.0.0", "log", @@ -7313,7 +7314,7 @@ dependencies = [ "bitflags 1.3.2", "docify", "environmental", - "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", + "frame-metadata 18.0.0", "frame-support-procedural 23.0.0", "frame-system 28.0.0", "impl-trait-for-tuples", @@ -7491,7 +7492,7 @@ version = "3.0.0" dependencies = [ "frame-benchmarking 28.0.0", "frame-executive 28.0.0", - "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", + "frame-metadata 18.0.0", "frame-support 28.0.0", "frame-support-test-pallet", "frame-system 28.0.0", @@ -10517,12 +10518,13 @@ dependencies = [ [[package]] name = "merkleized-metadata" -version = "0.1.1" -source = "git+https://github.com/lexnv/merkleized-metadata.git?branch=lexnv/latest-frame-update#bdacb9314fbd08137813c2af213f86c08e57b128" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "943f6d92804ed0100803d51fa9b21fd9432b5d122ba4c713dc26fe6d2f619cf6" dependencies = [ "array-bytes", "blake3", - "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", + "frame-metadata 18.0.0", "parity-scale-codec", "scale-decode 0.13.1", "scale-info", @@ -26651,7 +26653,7 @@ dependencies = [ name = "sp-metadata-ir" version = "0.6.0" dependencies = [ - "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", + "frame-metadata 18.0.0", "parity-scale-codec", "scale-info", ] @@ -28588,7 +28590,7 @@ dependencies = [ "cargo_metadata", "console", "filetime", - "frame-metadata 17.0.0 (git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/extensions-v16)", + "frame-metadata 18.0.0", "jobserver", "merkleized-metadata", "parity-scale-codec", @@ -28683,7 +28685,7 @@ dependencies = [ "derive-where", "either", "finito", - "frame-metadata 17.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "frame-metadata 17.0.0", "futures", "hex", "impl-serde 0.5.0", @@ -28738,7 +28740,7 @@ dependencies = [ "blake2 0.10.6", "derive-where", "frame-decode", - "frame-metadata 17.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "frame-metadata 17.0.0", "hashbrown 0.14.5", "hex", "impl-serde 0.5.0", @@ -28797,7 +28799,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee13e6862eda035557d9a2871955306aff540d2b89c06e0a62a1136a700aed28" dependencies = [ "frame-decode", - "frame-metadata 17.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "frame-metadata 17.0.0", "hashbrown 0.14.5", "parity-scale-codec", "polkadot-sdk 0.7.0", diff --git a/Cargo.toml b/Cargo.toml index 5bc0caceaac5..b255e94a3fea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -779,7 +779,7 @@ frame-benchmarking-pallet-pov = { default-features = false, path = "substrate/fr frame-election-provider-solution-type = { path = "substrate/frame/election-provider-support/solution-type", default-features = false } frame-election-provider-support = { path = "substrate/frame/election-provider-support", default-features = false } frame-executive = { path = "substrate/frame/executive", default-features = false } -frame-metadata = { git = "https://github.com/paritytech/frame-metadata.git", branch = "lexnv/extensions-v16", default-features = false } +frame-metadata = { version = "18.0.0", default-features = false } frame-metadata-hash-extension = { path = "substrate/frame/metadata-hash-extension", default-features = false } frame-support = { path = "substrate/frame/support", default-features = false } frame-support-procedural = { path = "substrate/frame/support/procedural", default-features = false } @@ -854,7 +854,7 @@ macro_magic = { version = "0.5.1" } maplit = { version = "1.0.2" } memmap2 = { version = "0.9.3" } memory-db = { version = "0.32.0", default-features = false } -merkleized-metadata = { git = "https://github.com/lexnv/merkleized-metadata.git", branch = "lexnv/latest-frame-update" } +merkleized-metadata = { version = "0.1.2" } merlin = { version = "3.0", default-features = false } messages-relay = { path = "bridges/relays/messages" } metered = { version = "0.6.1", default-features = false, package = "prioritized-metered-channel" } From 0979d1a5d68d999c7c28750ac8c41a550e44b881 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Mon, 18 Nov 2024 11:24:56 +0200 Subject: [PATCH 50/70] benchmark-cli/overhead: Select latest stable version for metadata Subxt cannot support unstable metadata until this is released in polkadot-sdk. Until then, select the latest stable metadata for testing by omni-node / benchmark-cli Signed-off-by: Alexandru Vasile --- .../src/overhead/runtime_utilities.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/substrate/utils/frame/benchmarking-cli/src/overhead/runtime_utilities.rs b/substrate/utils/frame/benchmarking-cli/src/overhead/runtime_utilities.rs index c498da38afb0..3081197dc033 100644 --- a/substrate/utils/frame/benchmarking-cli/src/overhead/runtime_utilities.rs +++ b/substrate/utils/frame/benchmarking-cli/src/overhead/runtime_utilities.rs @@ -35,14 +35,19 @@ pub fn fetch_latest_metadata_from_code_blob( let opaque_metadata: OpaqueMetadata = match version_result { Ok(supported_versions) => { - let latest_version = Vec::::decode(&mut supported_versions.as_slice()) - .map_err(|e| format!("Unable to decode version list: {e}"))? - .pop() - .ok_or("No metadata versions supported".to_string())?; + let supported_versions = Vec::::decode(&mut supported_versions.as_slice()) + .map_err(|e| format!("Unable to decode version list: {e}"))?; + + let latest_stable = supported_versions + .into_iter() + .filter(|v| *v != u32::MAX) + .max() + .ok_or("No stable metadata versions supported".to_string())?; let encoded = runtime_caller - .call("Metadata_metadata_at_version", latest_version) + .call("Metadata_metadata_at_version", latest_stable) .map_err(|_| "Unable to fetch metadata from blob".to_string())?; + Option::::decode(&mut encoded.as_slice())? .ok_or_else(|| "Metadata not found".to_string())? }, From f7dfa0dfaed10ee4d06bb650cd56e170982cc5de Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Mon, 18 Nov 2024 11:50:27 +0200 Subject: [PATCH 51/70] Add space to cargo.toml features Signed-off-by: Alexandru Vasile --- substrate/frame/support/test/Cargo.toml | 2 +- substrate/primitives/metadata-ir/Cargo.toml | 2 +- substrate/utils/wasm-builder/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/substrate/frame/support/test/Cargo.toml b/substrate/frame/support/test/Cargo.toml index 3e98c3987c89..17ee3130b741 100644 --- a/substrate/frame/support/test/Cargo.toml +++ b/substrate/frame/support/test/Cargo.toml @@ -19,7 +19,7 @@ static_assertions = { workspace = true, default-features = true } serde = { features = ["derive"], workspace = true } codec = { features = ["derive"], workspace = true } scale-info = { features = ["derive"], workspace = true } -frame-metadata = { features = ["current","unstable"], workspace = true } +frame-metadata = { features = ["current", "unstable"], workspace = true } sp-api = { workspace = true } sp-arithmetic = { workspace = true } sp-io = { workspace = true } diff --git a/substrate/primitives/metadata-ir/Cargo.toml b/substrate/primitives/metadata-ir/Cargo.toml index fcbf7889f6d0..046441104b88 100644 --- a/substrate/primitives/metadata-ir/Cargo.toml +++ b/substrate/primitives/metadata-ir/Cargo.toml @@ -17,7 +17,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { workspace = true } -frame-metadata = { features = ["current","unstable"], workspace = true } +frame-metadata = { features = ["current", "unstable"], workspace = true } scale-info = { features = ["derive"], workspace = true } [features] diff --git a/substrate/utils/wasm-builder/Cargo.toml b/substrate/utils/wasm-builder/Cargo.toml index 0216414fdf6a..fb15e8619a38 100644 --- a/substrate/utils/wasm-builder/Cargo.toml +++ b/substrate/utils/wasm-builder/Cargo.toml @@ -35,7 +35,7 @@ sc-executor = { optional = true, workspace = true, default-features = true } sp-core = { optional = true, workspace = true, default-features = true } sp-io = { optional = true, workspace = true, default-features = true } sp-version = { optional = true, workspace = true, default-features = true } -frame-metadata = { features = ["current","unstable"], optional = true, workspace = true, default-features = true } +frame-metadata = { features = ["current", "unstable"], optional = true, workspace = true, default-features = true } codec = { optional = true, workspace = true, default-features = true } array-bytes = { optional = true, workspace = true, default-features = true } sp-tracing = { optional = true, workspace = true, default-features = true } From bb682dd1aa2aee960956f14e44b051424c1a2133 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Mon, 18 Nov 2024 12:53:28 +0200 Subject: [PATCH 52/70] utils/cli: Use latest stable metadata for tests Signed-off-by: Alexandru Vasile --- .../frame/benchmarking-cli/src/overhead/remark_builder.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/substrate/utils/frame/benchmarking-cli/src/overhead/remark_builder.rs b/substrate/utils/frame/benchmarking-cli/src/overhead/remark_builder.rs index a1d5f282d9f8..3a2d8776d1e1 100644 --- a/substrate/utils/frame/benchmarking-cli/src/overhead/remark_builder.rs +++ b/substrate/utils/frame/benchmarking-cli/src/overhead/remark_builder.rs @@ -54,13 +54,15 @@ impl> DynamicRemarkBuilder { log::debug!("Found metadata API version {}.", metadata_api_version); let opaque_metadata = if metadata_api_version > 1 { - let Ok(mut supported_metadata_versions) = api.metadata_versions(genesis) else { + let Ok(supported_metadata_versions) = api.metadata_versions(genesis) else { return Err("Unable to fetch metadata versions".to_string().into()); }; let latest = supported_metadata_versions - .pop() - .ok_or("No metadata version supported".to_string())?; + .into_iter() + .filter(|v| *v != u32::MAX) + .max() + .ok_or("No stable metadata versions supported".to_string())?; api.metadata_at_version(genesis, latest) .map_err(|e| format!("Unable to fetch metadata: {:?}", e))? From 15b361ccfdd01c1f50f42517be1d614d8c83c822 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Mon, 18 Nov 2024 14:28:53 +0200 Subject: [PATCH 53/70] frame/support: Check unstable metadata is propagated Signed-off-by: Alexandru Vasile --- substrate/frame/support/test/tests/pallet.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/substrate/frame/support/test/tests/pallet.rs b/substrate/frame/support/test/tests/pallet.rs index b0b83f772499..fd3f73474f54 100644 --- a/substrate/frame/support/test/tests/pallet.rs +++ b/substrate/frame/support/test/tests/pallet.rs @@ -53,6 +53,9 @@ parameter_types! { /// Latest stable metadata version used for testing. const LATEST_METADATA_VERSION: u32 = 15; +/// Unstable metadata version. +const UNSTABLE_METADATA_VERSION: u32 = u32::MAX; + pub struct SomeType1; impl From for u64 { fn from(_t: SomeType1) -> Self { @@ -1944,7 +1947,10 @@ fn metadata_at_version() { #[test] fn metadata_versions() { - assert_eq!(vec![14, LATEST_METADATA_VERSION], Runtime::metadata_versions()); + assert_eq!( + vec![14, LATEST_METADATA_VERSION, UNSTABLE_METADATA_VERSION], + Runtime::metadata_versions() + ); } #[test] From 8747a92f217d843bb85b55726f132a85fe4629b5 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Mon, 18 Nov 2024 17:39:15 +0200 Subject: [PATCH 54/70] Update PRdoc Signed-off-by: Alexandru Vasile --- prdoc/pr_5732.prdoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/prdoc/pr_5732.prdoc b/prdoc/pr_5732.prdoc index 8a5df85cd08c..a089ebbeda28 100644 --- a/prdoc/pr_5732.prdoc +++ b/prdoc/pr_5732.prdoc @@ -25,3 +25,5 @@ crates: bump: patch - name: pallet-revive bump: patch + - name: frame-benchmarking-cli + bump: patch From 75d2f94619404ea809fe417fe95ec68bfba78a52 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Mon, 18 Nov 2024 16:29:45 +0000 Subject: [PATCH 55/70] Update from lexnv running command 'prdoc --audience node_dev --bump patch --force' --- prdoc/pr_5732.prdoc | 58 ++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/prdoc/pr_5732.prdoc b/prdoc/pr_5732.prdoc index a089ebbeda28..99d160b2706a 100644 --- a/prdoc/pr_5732.prdoc +++ b/prdoc/pr_5732.prdoc @@ -1,29 +1,39 @@ -# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 -# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json +title: 'v16: Expose the unstable metadata v16' +doc: +- audience: Node Dev + description: |- + This PR exposes the *unstable* metadata V16. The metadata is exposed under the unstable u32::MAX number. -title: Expose the unstable metadata v16 + Developers can start experimenting with the new features of the metadata v16. *Please note that this metadata is under development and expect breaking changes until stabilization.* -doc: - - audience: - - Runtime Dev - - Runtime User - description: | - This PR exposes the *unstable* metadata V16. The metadata is exposed under the unstable u32::MAX number. - Developers can start experimenting with the new features of the metadata v16. Please note that - this metadata is under development and expect breaking changes until stabilization. + The `ExtrinsicMetadata` trait receives a breaking change. Its associated type `VERSION` is rename to `VERSIONS` and now supports a constant static list of metadata versions. + The versions implemented for `UncheckedExtrinsic` are v4 (legacy version) and v5 (new version). + + For metadata collection, it is assumed that all `TransactionExtensions` are under version 0. + + Builds on top of: https://github.com/paritytech/polkadot-sdk/pull/5274 - The `ExtrinsicMetadata` trait receives a breaking change. Its associated type `VERSION` is rename to `VERSIONS` - and now supports a constant static list of metadata versions. The versions implemented for `UncheckedExtrinsic` - are v4 (legacy version) and v5 (new version). + Closes: https://github.com/paritytech/polkadot-sdk/issues/5980 + Closes: https://github.com/paritytech/polkadot-sdk/issues/5347 + Closes: https://github.com/paritytech/polkadot-sdk/issues/5285 + cc @paritytech/subxt-team crates: - - name: sp-metadata-ir - bump: major - - name: sp-runtime - bump: major - - name: frame-support-procedural - bump: patch - - name: pallet-revive - bump: patch - - name: frame-benchmarking-cli - bump: patch +- name: sp-metadata-ir + bump: patch +- name: frame-support-procedural + bump: patch +- name: frame-support-procedural-tools + bump: patch +- name: frame-support + bump: patch +- name: frame-metadata-hash-extension + bump: patch +- name: substrate-wasm-builder + bump: patch +- name: pallet-revive + bump: patch +- name: sp-runtime + bump: patch +- name: frame-benchmarking-cli + bump: patch From cae9c1eb48f86d1ca6838da355751a94adcad803 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Mon, 18 Nov 2024 18:35:21 +0200 Subject: [PATCH 56/70] Update PRdoc Signed-off-by: Alexandru Vasile --- prdoc/pr_5732.prdoc | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/prdoc/pr_5732.prdoc b/prdoc/pr_5732.prdoc index 99d160b2706a..5ba1f581f938 100644 --- a/prdoc/pr_5732.prdoc +++ b/prdoc/pr_5732.prdoc @@ -11,16 +11,9 @@ doc: For metadata collection, it is assumed that all `TransactionExtensions` are under version 0. - Builds on top of: https://github.com/paritytech/polkadot-sdk/pull/5274 - - Closes: https://github.com/paritytech/polkadot-sdk/issues/5980 - Closes: https://github.com/paritytech/polkadot-sdk/issues/5347 - Closes: https://github.com/paritytech/polkadot-sdk/issues/5285 - - cc @paritytech/subxt-team crates: - name: sp-metadata-ir - bump: patch + bump: major - name: frame-support-procedural bump: patch - name: frame-support-procedural-tools @@ -34,6 +27,6 @@ crates: - name: pallet-revive bump: patch - name: sp-runtime - bump: patch + bump: major - name: frame-benchmarking-cli bump: patch From 9b251c481dc0f29b72a58e503c57526021bdc9f0 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Tue, 19 Nov 2024 13:36:02 +0200 Subject: [PATCH 57/70] ci: Check-semver update CI to stable Signed-off-by: Alexandru Vasile --- .github/workflows/check-semver.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-semver.yml b/.github/workflows/check-semver.yml index 78602410cdf6..c8d054d1ddc3 100644 --- a/.github/workflows/check-semver.yml +++ b/.github/workflows/check-semver.yml @@ -11,7 +11,7 @@ concurrency: cancel-in-progress: true env: - TOOLCHAIN: nightly-2024-06-01 + TOOLCHAIN: stable jobs: preflight: From 1f4ae8c61fe77c9c0332e02403750fd2204cdc80 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Tue, 19 Nov 2024 13:43:21 +0200 Subject: [PATCH 58/70] ci: Update to nightly as toolchain for semvercheck Signed-off-by: Alexandru Vasile --- .github/workflows/check-semver.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-semver.yml b/.github/workflows/check-semver.yml index c8d054d1ddc3..13fc3c187f4a 100644 --- a/.github/workflows/check-semver.yml +++ b/.github/workflows/check-semver.yml @@ -11,7 +11,7 @@ concurrency: cancel-in-progress: true env: - TOOLCHAIN: stable + TOOLCHAIN: nightly-2024-11-19 jobs: preflight: From 4a23b69bb6937135dcf2c8e8b5837522f5829cfe Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Tue, 19 Nov 2024 14:07:09 +0200 Subject: [PATCH 59/70] ci: Use an older nightly version Signed-off-by: Alexandru Vasile --- .github/workflows/check-semver.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-semver.yml b/.github/workflows/check-semver.yml index 13fc3c187f4a..e0d43e87d93a 100644 --- a/.github/workflows/check-semver.yml +++ b/.github/workflows/check-semver.yml @@ -11,7 +11,7 @@ concurrency: cancel-in-progress: true env: - TOOLCHAIN: nightly-2024-11-19 + TOOLCHAIN: nightly-2024-10-19 jobs: preflight: From f6b9aa3ad6baf58607370baef2d0d06ab1a1389e Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Tue, 19 Nov 2024 14:19:11 +0200 Subject: [PATCH 60/70] ci: Switch to v0.9 instead Signed-off-by: Alexandru Vasile --- .github/workflows/check-semver.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-semver.yml b/.github/workflows/check-semver.yml index e0d43e87d93a..ad07c696a64e 100644 --- a/.github/workflows/check-semver.yml +++ b/.github/workflows/check-semver.yml @@ -74,7 +74,7 @@ jobs: - name: install parity-publish # Set the target dir to cache the build. - run: CARGO_TARGET_DIR=./target/ cargo install parity-publish@0.8.0 --locked -q + run: CARGO_TARGET_DIR=./target/ cargo install parity-publish@0.9.0 --locked -q - name: check semver run: | From d64fd330f37838bb44f3d6507a401cf7760c09b4 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Tue, 19 Nov 2024 15:20:12 +0200 Subject: [PATCH 61/70] Revert CI changes for a followup Signed-off-by: Alexandru Vasile --- .github/workflows/check-semver.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-semver.yml b/.github/workflows/check-semver.yml index ad07c696a64e..78602410cdf6 100644 --- a/.github/workflows/check-semver.yml +++ b/.github/workflows/check-semver.yml @@ -11,7 +11,7 @@ concurrency: cancel-in-progress: true env: - TOOLCHAIN: nightly-2024-10-19 + TOOLCHAIN: nightly-2024-06-01 jobs: preflight: @@ -74,7 +74,7 @@ jobs: - name: install parity-publish # Set the target dir to cache the build. - run: CARGO_TARGET_DIR=./target/ cargo install parity-publish@0.9.0 --locked -q + run: CARGO_TARGET_DIR=./target/ cargo install parity-publish@0.8.0 --locked -q - name: check semver run: | From 61bf04fb0efbbf07fb42bd08b90bf0b1ca83e6f2 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 20 Nov 2024 11:40:11 +0200 Subject: [PATCH 62/70] Include semver-fix Signed-off-by: Alexandru Vasile --- .github/workflows/check-semver.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-semver.yml b/.github/workflows/check-semver.yml index 78602410cdf6..dd955ab0a4fd 100644 --- a/.github/workflows/check-semver.yml +++ b/.github/workflows/check-semver.yml @@ -11,7 +11,7 @@ concurrency: cancel-in-progress: true env: - TOOLCHAIN: nightly-2024-06-01 + TOOLCHAIN: nightly-2024-11-19 jobs: preflight: @@ -74,7 +74,7 @@ jobs: - name: install parity-publish # Set the target dir to cache the build. - run: CARGO_TARGET_DIR=./target/ cargo install parity-publish@0.8.0 --locked -q + run: CARGO_TARGET_DIR=./target/ cargo install parity-publish@0.10.0 --locked -q - name: check semver run: | From 9293fcab72da722f6e3f69703327d4f1cf1088da Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 20 Nov 2024 12:38:00 +0200 Subject: [PATCH 63/70] Adjust PRdoc Signed-off-by: Alexandru Vasile --- prdoc/pr_5732.prdoc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/prdoc/pr_5732.prdoc b/prdoc/pr_5732.prdoc index 5ba1f581f938..fe8df4e2a1a8 100644 --- a/prdoc/pr_5732.prdoc +++ b/prdoc/pr_5732.prdoc @@ -16,16 +16,14 @@ crates: bump: major - name: frame-support-procedural bump: patch -- name: frame-support-procedural-tools - bump: patch - name: frame-support - bump: patch + bump: minor - name: frame-metadata-hash-extension bump: patch - name: substrate-wasm-builder - bump: patch + bump: minor - name: pallet-revive - bump: patch + bump: minor - name: sp-runtime bump: major - name: frame-benchmarking-cli From 10d6bcb9749a5c44976c3d08f1c4e45ee459016e Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 20 Nov 2024 13:21:31 +0200 Subject: [PATCH 64/70] Bump none for frame tests support crate Signed-off-by: Alexandru Vasile --- prdoc/pr_5732.prdoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/prdoc/pr_5732.prdoc b/prdoc/pr_5732.prdoc index fe8df4e2a1a8..c3480783d17a 100644 --- a/prdoc/pr_5732.prdoc +++ b/prdoc/pr_5732.prdoc @@ -16,6 +16,8 @@ crates: bump: major - name: frame-support-procedural bump: patch +- name: frame-support-test + bump: none - name: frame-support bump: minor - name: frame-metadata-hash-extension From 6cf31bc5147a04e5cd80705ca059450dd2127f1a Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 20 Nov 2024 15:41:48 +0200 Subject: [PATCH 65/70] prdoc: Make frame-support-test a patch again Signed-off-by: Alexandru Vasile --- prdoc/pr_5732.prdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prdoc/pr_5732.prdoc b/prdoc/pr_5732.prdoc index c3480783d17a..f6ca343f8273 100644 --- a/prdoc/pr_5732.prdoc +++ b/prdoc/pr_5732.prdoc @@ -17,7 +17,7 @@ crates: - name: frame-support-procedural bump: patch - name: frame-support-test - bump: none + bump: patch - name: frame-support bump: minor - name: frame-metadata-hash-extension From c52b80c706f0bc17345686a372882187c6d1bca3 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 20 Nov 2024 17:59:48 +0200 Subject: [PATCH 66/70] prdoc: Remove frame-support-test Signed-off-by: Alexandru Vasile --- prdoc/pr_5732.prdoc | 2 -- 1 file changed, 2 deletions(-) diff --git a/prdoc/pr_5732.prdoc b/prdoc/pr_5732.prdoc index f6ca343f8273..fe8df4e2a1a8 100644 --- a/prdoc/pr_5732.prdoc +++ b/prdoc/pr_5732.prdoc @@ -16,8 +16,6 @@ crates: bump: major - name: frame-support-procedural bump: patch -- name: frame-support-test - bump: patch - name: frame-support bump: minor - name: frame-metadata-hash-extension From 3f61d31c8e85668efae4c90776e3a7192cd61c2a Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 20 Nov 2024 19:03:13 +0200 Subject: [PATCH 67/70] prdoc: Add frame-support-test as Minor bump Signed-off-by: Alexandru Vasile --- prdoc/pr_5732.prdoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/prdoc/pr_5732.prdoc b/prdoc/pr_5732.prdoc index fe8df4e2a1a8..df61cb53344e 100644 --- a/prdoc/pr_5732.prdoc +++ b/prdoc/pr_5732.prdoc @@ -18,6 +18,8 @@ crates: bump: patch - name: frame-support bump: minor +- name: frame-support-test + bump: minor - name: frame-metadata-hash-extension bump: patch - name: substrate-wasm-builder From bc98d08a7c47a38175fad8ee0df4ff267f76ca1f Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 20 Nov 2024 21:04:36 +0200 Subject: [PATCH 68/70] prdoc: Bump as major Signed-off-by: Alexandru Vasile --- prdoc/pr_5732.prdoc | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/prdoc/pr_5732.prdoc b/prdoc/pr_5732.prdoc index df61cb53344e..6f1d6e1410d8 100644 --- a/prdoc/pr_5732.prdoc +++ b/prdoc/pr_5732.prdoc @@ -12,21 +12,21 @@ doc: For metadata collection, it is assumed that all `TransactionExtensions` are under version 0. crates: -- name: sp-metadata-ir - bump: major -- name: frame-support-procedural - bump: patch -- name: frame-support - bump: minor -- name: frame-support-test - bump: minor -- name: frame-metadata-hash-extension - bump: patch -- name: substrate-wasm-builder - bump: minor -- name: pallet-revive - bump: minor -- name: sp-runtime - bump: major -- name: frame-benchmarking-cli - bump: patch + - name: sp-metadata-ir + bump: major + - name: frame-support-procedural + bump: patch + - name: frame-support + bump: minor + - name: frame-support-test + bump: major + - name: frame-metadata-hash-extension + bump: patch + - name: substrate-wasm-builder + bump: minor + - name: pallet-revive + bump: minor + - name: sp-runtime + bump: major + - name: frame-benchmarking-cli + bump: patch From 60cf5fe6ecba5e9750534b35e46a7dd3cdb35a98 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile <60601340+lexnv@users.noreply.github.com> Date: Thu, 21 Nov 2024 09:11:51 +0200 Subject: [PATCH 69/70] Update .github/workflows/check-semver.yml --- .github/workflows/check-semver.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-semver.yml b/.github/workflows/check-semver.yml index dd955ab0a4fd..716b9b2a07c0 100644 --- a/.github/workflows/check-semver.yml +++ b/.github/workflows/check-semver.yml @@ -74,7 +74,7 @@ jobs: - name: install parity-publish # Set the target dir to cache the build. - run: CARGO_TARGET_DIR=./target/ cargo install parity-publish@0.10.0 --locked -q + run: CARGO_TARGET_DIR=./target/ cargo install parity-publish@0.10.1 --locked -q - name: check semver run: | From e68ecbd4902a2c72268325d401ffd59191cad3fa Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 27 Nov 2024 12:36:23 +0200 Subject: [PATCH 70/70] prdoc: Replace description |- with | Signed-off-by: Alexandru Vasile --- prdoc/pr_5732.prdoc | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/prdoc/pr_5732.prdoc b/prdoc/pr_5732.prdoc index 6f1d6e1410d8..6f3f9b8a1668 100644 --- a/prdoc/pr_5732.prdoc +++ b/prdoc/pr_5732.prdoc @@ -1,14 +1,11 @@ -title: 'v16: Expose the unstable metadata v16' +title: Expose the unstable metadata v16 doc: - audience: Node Dev - description: |- + description: | This PR exposes the *unstable* metadata V16. The metadata is exposed under the unstable u32::MAX number. - Developers can start experimenting with the new features of the metadata v16. *Please note that this metadata is under development and expect breaking changes until stabilization.* - The `ExtrinsicMetadata` trait receives a breaking change. Its associated type `VERSION` is rename to `VERSIONS` and now supports a constant static list of metadata versions. The versions implemented for `UncheckedExtrinsic` are v4 (legacy version) and v5 (new version). - For metadata collection, it is assumed that all `TransactionExtensions` are under version 0. crates: