Coauthored-by: Pavel Khrystenko pavel.khrystenko:parity.io
Hello everyone,
We are excited to share an update on the progress of the upcoming v16 metadata. This update builds on our previous discussion, which you can find here: Upcoming Metadata v16 Features. For those interested in the technical details, you can track the implementation progress on the Polkadot SDK in this issue.
Key Highlights
Enrich metadata with associated types of config traits
This feature is designed to simplify the configuration process for tools like Subxt and PAPI when interacting with chains. By including associated types of Config traits in the metadata, we aim to reduce the manual configuration needed for these tools.
For instance, in Subxt, our goal is to leverage this metadata to automatically provide configurations for interacting with various Substrate-based chains. Currently, we manually define configurations for substrate and polkadot. This new feature aims to reduce the amount of manual config definition by inferring or deriving more of it from the metadata.
#[pallet::config]
pub trait Config: frame_system::Config {
/// Associated type is now included in the metadata.
type AccountId: TypeInfo;
/// Associated type is now included in the metadata.
type Address: TypeInfo;
}
Developers can opt out of collecting metadata for associated types by using the without_metadata
optional attribute in #[pallet::config]
.
Additionally, the without_metadata attribute can be used alongside the new #[pallet::include_metadata]
attribute, allowing you to selectively include only certain associated types in the metadata collection.
For more details see PR: Metadata V16 (unstable): Enrich metadata with associated types of config traits
Extend metadata with deprecation information
To become aware of deprecated methods, developers must track a complex series of updates: from a Polkadot SDK release that deprecates a method, through various runtime upgrades and OpenGov referendums, and finally to the enactment of these changes
The feature aims to simplify this process by including deprecation information in the metadata. This will allow developers to easily identify deprecated methods and plan for their removal.
Parachain developers can include the deprecation information to the entire pallet, individual items, or even individual enum variants. This feature is particularly useful for dApp and tool developers.
#[frame_support::pallet]
/// Deprecate the entire pallet.
#[deprecated(note = "Reason for deprecation")]
pub mod pallet {
#[pallet::config]
pub trait Config: 'static {
#[pallet::constant]
/// Deprecate constants.
#[deprecated(note = "Reason for deprecation")]
type ExampleConstant: Get<()>;
}
#[pallet::event]
/// Deprecate events.
#[deprecated(note = "Reason for deprecation")]
pub enum Event<T: Config>
{
ExampleA,
/// Developers can also deprecate individual enum variants.
/// #[deprecated(note = "Reason for deprecation")]
ExampleB,
}
#[pallet::error]
/// Deprecate events.
#[deprecated(note = "Reason for deprecation")]
pub enum Error<T: Config>
{
ExampleA,
/// Developers can also deprecate individual enum variants.
/// #[deprecated(note = "Reason for deprecation")]
ExampleB,
}
#[pallet::call]
impl<T: Config> Pallet<T>
{
#[pallet::call_index(0)]
/// Deprecate calls.
#[deprecated(note = "Reason for deprecation")]
pub fn foo(
origin: OriginFor<T>,
) -> DispatchResultWithPostInfo { }
}
#[pallet::storage]
/// Deprecate storage items.
#[deprecated(note = "test")]
pub type OptionLinkedMap<T> = StorageMap<_, Blake2_128Concat, u32, u32, OptionQuery>;
}
sp_api::decl_runtime_apis! {
/// Deprecate runtime APIs.
#[deprecated]
pub trait Api {
#[deprecated(note = "example_method")]
fn example_method();
}
}
For more info see PR: Deprecation info support in RuntimeMetadataIR
Next Steps
We are currently working on the implementation of these features and will provide updates as we progress. We encourage developers to follow the issues on the Polkadot SDK repository for more details.
We plan to introduce an Unstable Metadata to the frame-metadata crate and expose the unstable metadata via RPC calls. This will allow developers to experiment with the new metadata features before they are stabilized.
We are also encouraging external developers to provide feedback on the proposed changes. If you have any questions or suggestions, please feel free to reach out to us on in this post or on github.
(cc Polkadot-api team @josep @voliva @carlosala)