-
Notifications
You must be signed in to change notification settings - Fork 729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Metadata V16: Enrich metadata with associated types of config traits #4519
Labels
I5-enhancement
An additional feature request.
T1-FRAME
This PR/Issue is related to core FRAME, the framework.
Comments
lexnv
added
I5-enhancement
An additional feature request.
T1-FRAME
This PR/Issue is related to core FRAME, the framework.
labels
May 20, 2024
Looks like a reasonable proposal to me! |
github-merge-queue bot
pushed a commit
that referenced
this issue
Oct 16, 2024
…fig 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: #4358 Closes: #4519 cc @paritytech/subxt-team --------- Signed-off-by: Alexandru Vasile <[email protected]> Co-authored-by: Bastian Köcher <[email protected]> Co-authored-by: Guillaume Thiolliere <[email protected]> Co-authored-by: Shawn Tabrizi <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
I5-enhancement
An additional feature request.
T1-FRAME
This PR/Issue is related to core FRAME, the framework.
Developers use associated types from pallet config traits to determine how to encode transactions (ie what hash is used by the node, the accountId, asset id etc). For example, subxt uses the following configs for Substrate and Polkadot to communicate with different chains.
This information can be exposed in the metadata V16, initially as unstable metadata (version u32::max).
Types included in the metadata must implement
scale_info::TypeInfo
.Default to include associated types to metadata
By default, all associated types from config traits are captured in the metadata:
polkadot-sdk/substrate/frame/system/src/lib.rs
Lines 481 to 518 in 313fe0f
Opt-out of associated types from metadata
Developers that do not want to include types into the metadata can specify it by the following attribute (name tbd):
Selectively include associated types
There might be scenarios where only a single associated type is needed to express the pallet in the metadata.
One such case is the AssetId:
polkadot-sdk/substrate/frame/assets/src/lib.rs
Lines 294 to 295 in 313fe0f
In this example, the
AssetId
is selectively included in the metadata, where theSecondType
is not included.PoC to capture associated types: #4358
PoC in subx to use associated metadata types: paritytech/subxt#1566
cc @jsdw @niklasad1 @bkchr @paritytech/subxt-team
The text was updated successfully, but these errors were encountered: