Metadata V15: Expose API to fetch metadata for version (#13287)

* impl_runtime_apis: Generate getters for `metadata_at` functions

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* runtime: Implement new `Metadata` runtime trait

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* runtime: Move `metadata_at` functions to construct_runtime macro

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* contruct_runtime: Use `OpaqueMetadata` from hidden imports

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Adjust testing

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/tests: Add tests for the new API

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/tests: Adjust metdata naming

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Expose `metadata-v14` feature flag

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Expose metadata only under feature flags

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Expose v14 metadata by default

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Expose metadata feature for testing

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Test metadata under different feature flags

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update primitives/api/src/lib.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update primitives/api/src/lib.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* client/tests: Adjust testing to reflect trait Metadata change

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/metadata-ir: Add intermediate representation types for metadata

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/metadata-ir: Convert metadata to V14

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/metadata-ir: Add API to convert metadata to multiple versions

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/metadata-ir: Expose V14 under feature flag

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Adjust to metadata IR

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: More adjustments

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Guard v14 details under feature flag

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Adjust testing

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* CI: Ensure `quick-benchmarks` uses `metadata-v14`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Use `metadata-v14` for benchmarks

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Adjust cargo fmt

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* kitchensink-runtime: Add feature flag for `metadata-v14`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support/test: Adjust testing

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support/test: Check crates locally

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Activate metadata-v14 for pallets

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Remove metadata-v14 feature flag

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/metadata_ir: Move `api.rs` to `mod.rs`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Handle latest metadata conversion via IR

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/tests: Add constant for metadata version 14

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support/test: Fix merge conflict

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update frame/support/Cargo.toml

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update frame/support/src/metadata_ir/mod.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update frame/support/test/Cargo.toml

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update primitives/api/src/lib.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* frame/metadata: Collect pallet documentation for MetadataIR

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/tests: Check pallet documentation is propagated to MetadataIR

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Improve documentation

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: parity-processbot <>
Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
Alexandru Vasile
2023-03-15 19:49:28 +02:00
committed by GitHub
parent 8945c1bd42
commit 1a88833d73
31 changed files with 1002 additions and 316 deletions
+8 -8
View File
@@ -2977,7 +2977,7 @@ macro_rules! __dispatch_impl_metadata {
{
#[doc(hidden)]
#[allow(dead_code)]
pub fn call_functions() -> $crate::metadata::PalletCallMetadata {
pub fn call_functions() -> $crate::metadata_ir::PalletCallMetadataIR {
$crate::scale_info::meta_type::<$call_type<$trait_instance $(, $instance)?>>().into()
}
}
@@ -2998,7 +2998,7 @@ macro_rules! __impl_error_metadata {
{
#[doc(hidden)]
#[allow(dead_code)]
pub fn error_metadata() -> Option<$crate::metadata::PalletErrorMetadata> {
pub fn error_metadata() -> Option<$crate::metadata_ir::PalletErrorMetadataIR> {
None
}
}
@@ -3013,8 +3013,8 @@ macro_rules! __impl_error_metadata {
{
#[doc(hidden)]
#[allow(dead_code)]
pub fn error_metadata() -> Option<$crate::metadata::PalletErrorMetadata> {
Some($crate::metadata::PalletErrorMetadata {
pub fn error_metadata() -> Option<$crate::metadata_ir::PalletErrorMetadataIR> {
Some($crate::metadata_ir::PalletErrorMetadataIR {
ty: $crate::scale_info::meta_type::<$( $error_type )*>()
})
}
@@ -3109,7 +3109,7 @@ macro_rules! __impl_module_constants_metadata {
{
#[doc(hidden)]
#[allow(dead_code)]
pub fn pallet_constants_metadata() -> $crate::sp_std::vec::Vec<$crate::metadata::PalletConstantMetadata> {
pub fn pallet_constants_metadata() -> $crate::sp_std::vec::Vec<$crate::metadata_ir::PalletConstantMetadataIR> {
// Create the `ByteGetter`s
$(
#[allow(non_upper_case_types)]
@@ -3133,7 +3133,7 @@ macro_rules! __impl_module_constants_metadata {
)*
$crate::sp_std::vec![
$(
$crate::metadata::PalletConstantMetadata {
$crate::metadata_ir::PalletConstantMetadataIR {
name: stringify!($name),
ty: $crate::scale_info::meta_type::<$type>(),
value: $default_byte_name::<$const_trait_instance $(, $const_instance)?>(
@@ -3207,7 +3207,7 @@ mod tests {
use super::*;
use crate::{
dispatch::{DispatchClass, DispatchInfo, Pays},
metadata::*,
metadata_ir::*,
traits::{
CallerTrait, CrateVersion, Get, GetCallName, IntegrityTest, OnFinalize, OnIdle,
OnInitialize, OnRuntimeUpgrade, PalletInfo,
@@ -3405,7 +3405,7 @@ mod tests {
fn module_json_metadata() {
let metadata = Module::<TraitImpl>::call_functions();
let expected_metadata =
PalletCallMetadata { ty: scale_info::meta_type::<Call<TraitImpl>>() };
PalletCallMetadataIR { ty: scale_info::meta_type::<Call<TraitImpl>>() };
assert_eq!(expected_metadata, metadata);
}