Metadata V16 (unstable): Enrich metadata with associated types of config traits (#5274)
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. ### API Design - There is nothing to collect from the associated types: ```rust #[pallet::config] pub trait Config: frame_system::Config { // Runtime events already propagated to the metadata. type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>; // Constants are already propagated. #[pallet::constant] type MyGetParam2: Get<u32>; } ``` - Default automatic collection of associated types that require TypeInfo or Parameter bounds: ```rust #[pallet::config] pub trait Config: frame_system::Config { // Runtime events already propagated to the metadata. type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>; // Constants are already propagated. #[pallet::constant] type MyGetParam2: Get<u32>; // 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<u8>; } ``` - Disable automatic collection ```rust // 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<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>; // Constants are already propagated. #[pallet::constant] type MyGetParam2: Get<u32>; // Explicitly include associated types. #[pallet::include_metadata] type Nonce: TypeInfo; type AccountData: Parameter; type NotIncluded: From<u8>; } ``` Builds on top of the PoC: https://github.com/paritytech/polkadot-sdk/pull/4358 Closes: https://github.com/paritytech/polkadot-sdk/issues/4519 cc @paritytech/subxt-team --------- Signed-off-by:Alexandru Vasile <alexandru.vasile@parity.io> Co-authored-by:
Bastian Köcher <git@kchr.de> Co-authored-by:
Guillaume Thiolliere <gui.thiolliere@gmail.com> Co-authored-by:
Shawn Tabrizi <shawntabrizi@gmail.com>
parent
2c41656c
Showing
- prdoc/pr_5274.prdoc 24 additions, 0 deletionsprdoc/pr_5274.prdoc
- substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs 11 additions, 0 deletions...pport/procedural/src/construct_runtime/expand/metadata.rs
- substrate/frame/support/procedural/src/lib.rs 9 additions, 0 deletionssubstrate/frame/support/procedural/src/lib.rs
- substrate/frame/support/procedural/src/pallet/expand/config.rs 48 additions, 0 deletions...rate/frame/support/procedural/src/pallet/expand/config.rs
- substrate/frame/support/procedural/src/pallet/expand/mod.rs 2 additions, 0 deletionssubstrate/frame/support/procedural/src/pallet/expand/mod.rs
- substrate/frame/support/procedural/src/pallet/parse/config.rs 110 additions, 3 deletions...trate/frame/support/procedural/src/pallet/parse/config.rs
- substrate/frame/support/procedural/src/pallet/parse/mod.rs 72 additions, 7 deletionssubstrate/frame/support/procedural/src/pallet/parse/mod.rs
- substrate/frame/support/procedural/tools/src/lib.rs 14 additions, 0 deletionssubstrate/frame/support/procedural/tools/src/lib.rs
- substrate/frame/support/src/lib.rs 58 additions, 0 deletionssubstrate/frame/support/src/lib.rs
- substrate/frame/support/test/tests/construct_runtime_ui/deprecated_where_block.stderr 25 additions, 0 deletions.../tests/construct_runtime_ui/deprecated_where_block.stderr
- substrate/frame/support/test/tests/pallet_associated_types_metadata.rs 269 additions, 0 deletions...me/support/test/tests/pallet_associated_types_metadata.rs
- substrate/frame/support/test/tests/pallet_ui/config_duplicate_attr.rs 39 additions, 0 deletions...ame/support/test/tests/pallet_ui/config_duplicate_attr.rs
- substrate/frame/support/test/tests/pallet_ui/config_duplicate_attr.stderr 5 additions, 0 deletions...support/test/tests/pallet_ui/config_duplicate_attr.stderr
- substrate/frame/support/test/tests/pallet_ui/config_metadata_non_type_info.rs 42 additions, 0 deletions...ort/test/tests/pallet_ui/config_metadata_non_type_info.rs
- substrate/frame/support/test/tests/pallet_ui/config_metadata_non_type_info.stderr 5 additions, 0 deletions...test/tests/pallet_ui/config_metadata_non_type_info.stderr
- substrate/frame/support/test/tests/pallet_ui/config_metadata_on_constants.rs 40 additions, 0 deletions...port/test/tests/pallet_ui/config_metadata_on_constants.rs
- substrate/frame/support/test/tests/pallet_ui/config_metadata_on_constants.stderr 5 additions, 0 deletions.../test/tests/pallet_ui/config_metadata_on_constants.stderr
- substrate/frame/support/test/tests/pallet_ui/config_metadata_on_events.rs 43 additions, 0 deletions...support/test/tests/pallet_ui/config_metadata_on_events.rs
- substrate/frame/support/test/tests/pallet_ui/config_metadata_on_events.stderr 5 additions, 0 deletions...ort/test/tests/pallet_ui/config_metadata_on_events.stderr
- substrate/frame/support/test/tests/pallet_ui/no_default_but_missing_with_default.stderr 1 addition, 1 deletion...ests/pallet_ui/no_default_but_missing_with_default.stderr
Please register or sign in to comment