Skip to content
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

Open
Tracked by #4520
lexnv opened this issue May 20, 2024 · 1 comment
Open
Tracked by #4520

Metadata V16: Enrich metadata with associated types of config traits #4519

lexnv opened this issue May 20, 2024 · 1 comment
Labels
I5-enhancement An additional feature request. T1-FRAME This PR/Issue is related to core FRAME, the framework.

Comments

@lexnv
Copy link
Contributor

lexnv commented May 20, 2024

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:

type Nonce: Parameter
+ Member
+ MaybeSerializeDeserialize
+ Debug
+ Default
+ MaybeDisplay
+ AtLeast32Bit
+ Copy
+ MaxEncodedLen;
/// The output of the `Hashing` function.
type Hash: Parameter
+ Member
+ MaybeSerializeDeserialize
+ Debug
+ MaybeDisplay
+ SimpleBitOps
+ Ord
+ Default
+ Copy
+ CheckEqual
+ sp_std::hash::Hash
+ AsRef<[u8]>
+ AsMut<[u8]>
+ MaxEncodedLen;
/// The hashing system (algorithm) being used in the runtime (e.g. Blake2).
type Hashing: Hash<Output = Self::Hash> + TypeInfo;
/// The user account identifier type for the runtime.
type AccountId: Parameter
+ Member
+ MaybeSerializeDeserialize
+ Debug
+ MaybeDisplay
+ Ord
+ MaxEncodedLen;

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):

#[pallet::config(without_metadata)]
pub trait Config {
  type CustomParaType: ...
  
  type SecondType: ...
}

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:

/// Identifier for the class of asset.
type AssetId: Member + Parameter + Clone + MaybeSerializeDeserialize + MaxEncodedLen;

#[pallet::config(without_metadata)]
pub trait Config {
  
  #[pallet::include_metadata]
  type AssetId: ...
  
  type SecondType: ...
}

In this example, the AssetId is selectively included in the metadata, where the SecondType 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

@lexnv lexnv added I5-enhancement An additional feature request. T1-FRAME This PR/Issue is related to core FRAME, the framework. labels May 20, 2024
@bkchr
Copy link
Member

bkchr commented May 23, 2024

Looks like a reasonable proposal to me!

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.
Projects
None yet
Development

No branches or pull requests

2 participants