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

Add Runtime Api version to metadata #7607

Merged
merged 24 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
baa61fd
add Runtime Api version to runtime metadata
re-gius Feb 18, 2025
4d4c59a
Merge branch 'master' into re-gius/runtime-api-metadata-version
re-gius Feb 18, 2025
a165fbc
Add TODO for v16 integration
re-gius Feb 18, 2025
da85e8a
Merge branch 'master' into re-gius/runtime-api-metadata-version
re-gius Feb 18, 2025
a9c74f6
Update from re-gius running command 'prdoc --audience runtime_dev --b…
github-actions[bot] Feb 18, 2025
9fe6988
fix prdoc
re-gius Feb 18, 2025
c4b0ba7
convert `Compact<u32>` into `u32`
re-gius Feb 18, 2025
0f6f919
Merge branch 'master' into re-gius/runtime-api-metadata-version
re-gius Feb 18, 2025
4c7a507
Merge branch 'master' into re-gius/runtime-api-metadata-version
re-gius Feb 21, 2025
84b227b
Bump `frame-metadata` and `merkleized-metadata`
re-gius Feb 21, 2025
83fb666
Merge branch 'master' into re-gius/runtime-api-metadata-version
re-gius Feb 24, 2025
c793453
fix prdoc
re-gius Feb 24, 2025
945c363
Replate `ViewFunctionMethod` with `ViewFunction` everywhere in metada…
re-gius Feb 24, 2025
c331fe1
fix prdoc
re-gius Feb 24, 2025
84e76d1
Merge branch 'master' into re-gius/runtime-api-metadata-version
re-gius Feb 24, 2025
2fb9db2
Merge branch 'master' into re-gius/runtime-api-metadata-version
re-gius Feb 24, 2025
cc0b1a3
Merge branch 'master' into re-gius/runtime-api-metadata-version
re-gius Feb 24, 2025
f9c37b6
Merge branch 'master' into re-gius/runtime-api-metadata-version
re-gius Feb 25, 2025
3662a92
Try to fix semver CI
re-gius Feb 25, 2025
e353eb6
undo nightly change
re-gius Feb 25, 2025
ef3e8af
use same nightly version as rust version in `check-semver` CI
re-gius Feb 25, 2025
c252bf4
undo change
re-gius Feb 25, 2025
ff5d2a6
undo change
re-gius Feb 25, 2025
2964fb0
Cargo.lock fix
re-gius Feb 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ frame-benchmarking-pallet-pov = { default-features = false, path = "substrate/fr
frame-election-provider-solution-type = { path = "substrate/frame/election-provider-support/solution-type", default-features = false }
frame-election-provider-support = { path = "substrate/frame/election-provider-support", default-features = false }
frame-executive = { path = "substrate/frame/executive", default-features = false }
frame-metadata = { version = "19.0.0", default-features = false }
frame-metadata = { version = "20.0.0", default-features = false }
frame-metadata-hash-extension = { path = "substrate/frame/metadata-hash-extension", default-features = false }
frame-support = { path = "substrate/frame/support", default-features = false }
frame-support-procedural = { path = "substrate/frame/support/procedural", default-features = false }
Expand Down Expand Up @@ -862,7 +862,7 @@ macro_magic = { version = "0.5.1" }
maplit = { version = "1.0.2" }
memmap2 = { version = "0.9.3" }
memory-db = { version = "0.32.0", default-features = false }
merkleized-metadata = { version = "0.3.0" }
merkleized-metadata = { version = "0.4.0" }
merlin = { version = "3.0", default-features = false }
messages-relay = { path = "bridges/relays/messages" }
metered = { version = "0.6.1", default-features = false, package = "prioritized-metered-channel" }
Expand Down
20 changes: 20 additions & 0 deletions prdoc/pr_7607.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
title: Add Runtime Api version to metadata
doc:
- audience: Runtime Dev
description: |-
The runtime API implemented version is not explicitly shown in metadata, so here we add it to improve developer experience.

This closes #7352 .
crates:
- name: sp-api-proc-macro
bump: patch
- name: sp-metadata-ir
bump: major
- name: frame-support
bump: minor
- name: frame-support-procedural
bump: patch
- name: substrate-wasm-builder
bump: minor
- name: pallet-example-view-functions
bump: minor
9 changes: 4 additions & 5 deletions substrate/frame/examples/view-functions/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ use scale_info::meta_type;
use frame_support::{derive_impl, pallet_prelude::PalletInfoAccess, view_functions::ViewFunction};
use sp_io::hashing::twox_128;
use sp_metadata_ir::{
DeprecationStatusIR, PalletViewFunctionMethodMetadataIR,
PalletViewFunctionMethodParamMetadataIR,
DeprecationStatusIR, PalletViewFunctionMetadataIR, PalletViewFunctionParamMetadataIR,
};
use sp_runtime::testing::TestXt;

Expand Down Expand Up @@ -139,18 +138,18 @@ fn metadata_ir_definitions() {
pretty_assertions::assert_eq!(
pallet1.view_functions,
vec![
PalletViewFunctionMethodMetadataIR {
PalletViewFunctionMetadataIR {
name: "get_value",
id: get_value_id,
inputs: vec![],
output: meta_type::<Option<u32>>(),
docs: vec![" Query value with no input args."],
deprecation_info: DeprecationStatusIR::NotDeprecated,
},
PalletViewFunctionMethodMetadataIR {
PalletViewFunctionMetadataIR {
name: "get_value_with_arg",
id: get_value_with_arg_id,
inputs: vec![PalletViewFunctionMethodParamMetadataIR {
inputs: vec![PalletViewFunctionParamMetadataIR {
name: "key",
ty: meta_type::<u32>()
},],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ fn impl_view_function_metadata(
let pat = &typed.pat;
let ty = &typed.ty;
Some(quote::quote! {
#frame_support::__private::metadata_ir::PalletViewFunctionMethodParamMetadataIR {
#frame_support::__private::metadata_ir::PalletViewFunctionParamMetadataIR {
name: ::core::stringify!(#pat),
ty: #frame_support::__private::scale_info::meta_type::<#ty>(),
}
Expand All @@ -235,7 +235,7 @@ fn impl_view_function_metadata(
};

quote::quote! {
#frame_support::__private::metadata_ir::PalletViewFunctionMethodMetadataIR {
#frame_support::__private::metadata_ir::PalletViewFunctionMetadataIR {
name: ::core::stringify!(#name),
id: <#view_function_struct_ident<#type_use_gen> as #frame_support::view_functions::ViewFunction>::id().into(),
inputs: #frame_support::__private::sp_std::vec![ #( #inputs ),* ],
Expand All @@ -252,7 +252,7 @@ fn impl_view_function_metadata(
impl<#type_impl_gen> #pallet_ident<#type_use_gen> #where_clause {
#[doc(hidden)]
pub fn pallet_view_functions_metadata()
-> #frame_support::__private::Vec<#frame_support::__private::metadata_ir::PalletViewFunctionMethodMetadataIR> {
-> #frame_support::__private::Vec<#frame_support::__private::metadata_ir::PalletViewFunctionMetadataIR> {
#frame_support::__private::vec![ #( #view_functions ),* ]
}
}
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/support/test/tests/runtime_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ fn runtime_metadata() {
" Documentation on multiline.",
]),
deprecation_info: DeprecationStatusIR::DeprecatedWithoutNote,
version: codec::Compact(1),

},
RuntimeApiMetadataIR {
Expand Down Expand Up @@ -238,6 +239,7 @@ fn runtime_metadata() {
" The `Core` runtime api that every Substrate runtime needs to implement.",
]),
deprecation_info: DeprecationStatusIR::NotDeprecated,
version: codec::Compact(5),
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ pub fn generate_decl_runtime_metadata<'a>(
.collect(),
docs: #docs,
deprecation_info: #deprecation,
version: impl_version.into(),
}
}
}
Expand Down
25 changes: 14 additions & 11 deletions substrate/primitives/metadata-ir/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ pub struct RuntimeApiMetadataIR<T: Form = MetaForm> {
pub methods: Vec<RuntimeApiMethodMetadataIR<T>>,
/// Trait documentation.
pub docs: Vec<T::String>,
/// Deprecation info
/// Deprecation info.
pub deprecation_info: DeprecationStatusIR<T>,
/// Runtime API version.
pub version: Compact<u32>,
}

impl IntoPortable for RuntimeApiMetadataIR {
Expand All @@ -65,6 +67,7 @@ impl IntoPortable for RuntimeApiMetadataIR {
methods: registry.map_into_portable(self.methods),
docs: registry.map_into_portable(self.docs),
deprecation_info: self.deprecation_info.into_portable(registry),
version: self.version,
}
}
}
Expand Down Expand Up @@ -120,13 +123,13 @@ impl IntoPortable for RuntimeApiMethodParamMetadataIR {

/// Metadata of a pallet view function method.
#[derive(Clone, PartialEq, Eq, Encode, Decode, Debug)]
pub struct PalletViewFunctionMethodMetadataIR<T: Form = MetaForm> {
pub struct PalletViewFunctionMetadataIR<T: Form = MetaForm> {
/// Method name.
pub name: T::String,
/// Method id.
pub id: [u8; 32],
/// Method parameters.
pub inputs: Vec<PalletViewFunctionMethodParamMetadataIR<T>>,
pub inputs: Vec<PalletViewFunctionParamMetadataIR<T>>,
/// Method output.
pub output: T::Type,
/// Method documentation.
Expand All @@ -135,11 +138,11 @@ pub struct PalletViewFunctionMethodMetadataIR<T: Form = MetaForm> {
pub deprecation_info: DeprecationStatusIR<T>,
}

impl IntoPortable for PalletViewFunctionMethodMetadataIR {
type Output = PalletViewFunctionMethodMetadataIR<PortableForm>;
impl IntoPortable for PalletViewFunctionMetadataIR {
type Output = PalletViewFunctionMetadataIR<PortableForm>;

fn into_portable(self, registry: &mut Registry) -> Self::Output {
PalletViewFunctionMethodMetadataIR {
PalletViewFunctionMetadataIR {
name: self.name.into_portable(registry),
id: self.id,
inputs: registry.map_into_portable(self.inputs),
Expand All @@ -152,18 +155,18 @@ impl IntoPortable for PalletViewFunctionMethodMetadataIR {

/// Metadata of a pallet view function method argument.
#[derive(Clone, PartialEq, Eq, Encode, Decode, Debug)]
pub struct PalletViewFunctionMethodParamMetadataIR<T: Form = MetaForm> {
pub struct PalletViewFunctionParamMetadataIR<T: Form = MetaForm> {
/// Parameter name.
pub name: T::String,
/// Parameter type.
pub ty: T::Type,
}

impl IntoPortable for PalletViewFunctionMethodParamMetadataIR {
type Output = PalletViewFunctionMethodParamMetadataIR<PortableForm>;
impl IntoPortable for PalletViewFunctionParamMetadataIR {
type Output = PalletViewFunctionParamMetadataIR<PortableForm>;

fn into_portable(self, registry: &mut Registry) -> Self::Output {
PalletViewFunctionMethodParamMetadataIR {
PalletViewFunctionParamMetadataIR {
name: self.name.into_portable(registry),
ty: registry.register_type(&self.ty),
}
Expand All @@ -180,7 +183,7 @@ pub struct PalletMetadataIR<T: Form = MetaForm> {
/// Pallet calls metadata.
pub calls: Option<PalletCallMetadataIR<T>>,
/// Pallet view functions metadata.
pub view_functions: Vec<PalletViewFunctionMethodMetadataIR<T>>,
pub view_functions: Vec<PalletViewFunctionMetadataIR<T>>,
/// Pallet event metadata.
pub event: Option<PalletEventMetadataIR<T>>,
/// Pallet constants metadata.
Expand Down
13 changes: 7 additions & 6 deletions substrate/primitives/metadata-ir/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
use crate::{
DeprecationInfoIR, DeprecationStatusIR, OuterEnumsIR, PalletAssociatedTypeMetadataIR,
PalletCallMetadataIR, PalletConstantMetadataIR, PalletErrorMetadataIR, PalletEventMetadataIR,
PalletStorageMetadataIR, PalletViewFunctionMethodMetadataIR,
PalletViewFunctionMethodParamMetadataIR, StorageEntryMetadataIR,
PalletStorageMetadataIR, PalletViewFunctionMetadataIR, PalletViewFunctionParamMetadataIR,
StorageEntryMetadataIR,
};

use super::types::{
Expand Down Expand Up @@ -59,6 +59,7 @@ impl From<RuntimeApiMetadataIR> for RuntimeApiMetadata {
methods: ir.methods.into_iter().map(Into::into).collect(),
docs: ir.docs,
deprecation_info: ir.deprecation_info.into(),
version: ir.version.into(),
}
}
}
Expand Down Expand Up @@ -145,8 +146,8 @@ impl From<PalletCallMetadataIR> for PalletCallMetadata {
}
}

impl From<PalletViewFunctionMethodMetadataIR> for PalletViewFunctionMetadata {
fn from(ir: PalletViewFunctionMethodMetadataIR) -> Self {
impl From<PalletViewFunctionMetadataIR> for PalletViewFunctionMetadata {
fn from(ir: PalletViewFunctionMetadataIR) -> Self {
PalletViewFunctionMetadata {
name: ir.name,
id: ir.id,
Expand All @@ -158,8 +159,8 @@ impl From<PalletViewFunctionMethodMetadataIR> for PalletViewFunctionMetadata {
}
}

impl From<PalletViewFunctionMethodParamMetadataIR> for PalletViewFunctionParamMetadata {
fn from(ir: PalletViewFunctionMethodParamMetadataIR) -> Self {
impl From<PalletViewFunctionParamMetadataIR> for PalletViewFunctionParamMetadata {
fn from(ir: PalletViewFunctionParamMetadataIR) -> Self {
PalletViewFunctionParamMetadata { name: ir.name, ty: ir.ty }
}
}
Expand Down
Loading