Skip to content

Commit bf9ad8f

Browse files
jsdwgithub-actions[bot]
authored andcommitted
Stabilize V16 metadata (#8443)
This PR bumps frame-metadata 23.0.0, which stabilizes V16 metadata. This was previously available as the "unstable" metadata. The main additions provided by V16 metadata are: - Information about the Pallet View Functions exposed by pallets. - Information about the Config associated types used by each pallet. - Support for V5 transactions, including support for a chain providing multiple transaction extension versions and multiple supported transaciton versions. - Support for deprecation information, so that mostly anything defined in a runtime can be marked as deprecated in order for runtime/pallet authors to communicate to consumers about deprecated items. To sanity check this, I've built a polkadot node with this change and checked that using Subxt (this PR paritytech/subxt#1999), v16 metadata is indeed available, downloads and decodes correctly. <!-- ✄ ----------------------------------------------------------------------------- Thank you for your Pull Request! 🙏 Please make sure it follows the contribution guidelines outlined in [this document](https://github.com/paritytech/polkadot-sdk/blob/master/docs/contributor/CONTRIBUTING.md) and fill out the sections below. Once you're ready to submit your PR for review, please delete this section and leave only the text under the "Description" heading. # Description *A concise description of what your PR is doing, and what potential issue it is solving. Use [Github semantic linking](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword) to link the PR to an issue that must be closed once this is merged.* ## Integration *In depth notes about how this PR should be integrated by downstream projects. This part is mandatory, and should be reviewed by reviewers, if the PR does NOT have the `R0-Silent` label. In case of a `R0-Silent`, it can be ignored.* ## Review Notes *In depth notes about the **implementation** details of your PR. This should be the main guide for reviewers to understand your approach and effectively review it. If too long, use [`<details>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details)*. *Imagine that someone who is depending on the old code wants to integrate your new code and the only information that they get is this section. It helps to include example usage and default value here, with a `diff` code-block to show possibly integration.* *Include your leftover TODOs, if any, here.* # Checklist * [ ] My PR includes a detailed description as outlined in the "Description" and its two subsections above. * [ ] My PR follows the [labeling requirements]( https://github.com/paritytech/polkadot-sdk/blob/master/docs/contributor/CONTRIBUTING.md#Process ) of this project (at minimum one label for `T` required) * External contributors: ask maintainers to put the right label on your PR. * [ ] I have made corresponding changes to the documentation (if applicable) * [ ] I have added tests that prove my fix is effective or that my feature works (if applicable) You can remove the "Checklist" section once all have been checked. Thank you for your contribution! ✄ ----------------------------------------------------------------------------- --. --------- Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 13a94ac commit bf9ad8f

9 files changed

Lines changed: 84 additions & 43 deletions

File tree

Cargo.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ frame-benchmarking-pallet-pov = { default-features = false, path = "substrate/fr
804804
frame-election-provider-solution-type = { path = "substrate/frame/election-provider-support/solution-type", default-features = false }
805805
frame-election-provider-support = { path = "substrate/frame/election-provider-support", default-features = false }
806806
frame-executive = { path = "substrate/frame/executive", default-features = false }
807-
frame-metadata = { version = "22.0.0", default-features = false }
807+
frame-metadata = { version = "23.0.0", default-features = false }
808808
frame-metadata-hash-extension = { path = "substrate/frame/metadata-hash-extension", default-features = false }
809809
frame-support = { path = "substrate/frame/support", default-features = false }
810810
frame-support-procedural = { path = "substrate/frame/support/procedural", default-features = false }

prdoc/pr_8443.prdoc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
2+
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json
3+
4+
title: Stabilize V16 metadata
5+
6+
doc:
7+
- audience: Node Dev
8+
description: |
9+
Metadata V16 is stabilized. V16 metadata exposes information about Pallet View Functions and V5 transactions,
10+
and can be obtained, where applicable, by using the Runtime APIs `Metadata_metadata_at_version(16)`.
11+
12+
crates:
13+
# Update to support frame-metadata 23. Changes pub interfaces:
14+
- name: sp-metadata-ir
15+
bump: major
16+
# Limit to fetching at latest v15 metadata:
17+
- name: sc-runtime-utilities
18+
bump: patch
19+
# Use newer frame-metadata; should be no observable change (CI wants minor):
20+
- name: substrate-wasm-builder
21+
bump: minor
22+
# frame-metadata bumped in this and exposed but via hidden docs. No code changes needed (CI wants minor):
23+
- name: frame-support
24+
bump: minor
25+
# Uses newer frame-support / metadata-ir but no code change needed (CI wants minor):
26+
- name: pallet-example-view-functions
27+
bump: minor
28+
# Avoid fetching V16 metadata:
29+
- name: frame-benchmarking-cli
30+
bump: minor

substrate/client/runtime-utilities/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ pub fn fetch_latest_metadata_from_code_blob<HF: HostFunctions>(
4848
let supported_versions = Vec::<u32>::decode(&mut supported_versions.as_slice())?;
4949
let latest_stable = supported_versions
5050
.into_iter()
51-
.filter(|v| *v != u32::MAX)
51+
// TODO: Subxt doesn't support V16 metadata until v0.42.0, so don't try
52+
// to fetch it here until we update to that version.
53+
.filter(|v| *v != u32::MAX && *v < 16)
5254
.max()
5355
.ok_or(Error::StableMetadataVersionNotFound)?;
5456

substrate/frame/support/test/tests/pallet.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ parameter_types! {
4949
storage UpdateStorageVersion: bool = false;
5050
}
5151

52-
/// Latest stable metadata version used for testing.
53-
const LATEST_METADATA_VERSION: u32 = 15;
54-
55-
/// Unstable metadata version.
56-
const UNSTABLE_METADATA_VERSION: u32 = u32::MAX;
57-
5852
pub struct SomeType1;
5953
impl From<SomeType1> for u64 {
6054
fn from(_t: SomeType1) -> Self {
@@ -1500,7 +1494,7 @@ fn pallet_item_docs_in_metadata() {
15001494

15011495
#[test]
15021496
#[allow(deprecated)]
1503-
fn metadata() {
1497+
fn metadata_v15() {
15041498
use codec::Decode;
15051499
use frame_metadata::{v15::*, *};
15061500

@@ -1975,8 +1969,7 @@ fn metadata() {
19751969
_ => panic!("metadata has been bumped, test needs to be updated"),
19761970
};
19771971

1978-
let bytes = &Runtime::metadata_at_version(LATEST_METADATA_VERSION)
1979-
.expect("Metadata must be present; qed");
1972+
let bytes = &Runtime::metadata_at_version(15).expect("Metadata must be present; qed");
19801973

19811974
let actual_metadata: RuntimeMetadataPrefixed =
19821975
Decode::decode(&mut &bytes[..]).expect("Metadata encoded properly; qed");
@@ -2010,10 +2003,7 @@ fn metadata_at_version() {
20102003

20112004
#[test]
20122005
fn metadata_versions() {
2013-
assert_eq!(
2014-
vec![14, LATEST_METADATA_VERSION, UNSTABLE_METADATA_VERSION],
2015-
Runtime::metadata_versions()
2016-
);
2006+
assert_eq!(vec![14, 15, 16], Runtime::metadata_versions());
20172007
}
20182008

20192009
#[test]

substrate/primitives/metadata-ir/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ targets = ["x86_64-unknown-linux-gnu"]
1717

1818
[dependencies]
1919
codec = { workspace = true }
20-
frame-metadata = { features = ["current", "unstable"], workspace = true }
20+
frame-metadata = { features = ["current"], workspace = true }
2121
scale-info = { features = ["derive"], workspace = true }
2222

2323
[features]

substrate/primitives/metadata-ir/src/lib.rs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ mod types;
3030
use frame_metadata::RuntimeMetadataPrefixed;
3131
pub use types::*;
3232

33-
mod unstable;
3433
mod v14;
3534
mod v15;
35+
mod v16;
3636

3737
/// Metadata V14.
3838
const V14: u32 = 14;
@@ -41,7 +41,7 @@ const V14: u32 = 14;
4141
const V15: u32 = 15;
4242

4343
/// Unstable metadata V16.
44-
const UNSTABLE_V16: u32 = u32::MAX;
44+
const V16: u32 = 16;
4545

4646
/// Transform the IR to the specified version.
4747
///
@@ -54,19 +54,19 @@ pub fn into_version(metadata: MetadataIR, version: u32) -> Option<RuntimeMetadat
5454
// `Metadata_metadata_at_version.
5555
V14 => Some(into_v14(metadata)),
5656

57-
// Version V15 - latest stable.
58-
V15 => Some(into_latest(metadata)),
57+
// Version V15
58+
V15 => Some(into_v15(metadata)),
5959

60-
// Unstable metadata under `u32::MAX`.
61-
UNSTABLE_V16 => Some(into_unstable(metadata)),
60+
// Version V16 - latest-stable.
61+
V16 => Some(into_v16(metadata)),
6262

6363
_ => None,
6464
}
6565
}
6666

6767
/// Returns the supported metadata versions.
6868
pub fn supported_versions() -> alloc::vec::Vec<u32> {
69-
alloc::vec![V14, V15, UNSTABLE_V16]
69+
alloc::vec![V14, V15, V16]
7070
}
7171

7272
/// Transform the IR to the latest stable metadata version.
@@ -81,8 +81,14 @@ pub fn into_v14(metadata: MetadataIR) -> RuntimeMetadataPrefixed {
8181
latest.into()
8282
}
8383

84-
/// Transform the IR to unstable metadata version 16.
85-
pub fn into_unstable(metadata: MetadataIR) -> RuntimeMetadataPrefixed {
84+
/// Transform the IR to metadata version 15.
85+
pub fn into_v15(metadata: MetadataIR) -> RuntimeMetadataPrefixed {
86+
let latest: frame_metadata::v15::RuntimeMetadataV15 = metadata.into();
87+
latest.into()
88+
}
89+
90+
/// Transform the IR to metadata version 16.
91+
pub fn into_v16(metadata: MetadataIR) -> RuntimeMetadataPrefixed {
8692
let latest: frame_metadata::v16::RuntimeMetadataV16 = metadata.into();
8793
latest.into()
8894
}
@@ -144,4 +150,14 @@ mod test {
144150

145151
assert!(matches!(metadata.1, RuntimeMetadata::V15(_)));
146152
}
153+
154+
#[test]
155+
fn into_version_16() {
156+
let ir = ir_metadata();
157+
let metadata = into_version(ir, V16).expect("Should return prefixed metadata");
158+
159+
assert_eq!(metadata.0, META_RESERVED);
160+
161+
assert!(matches!(metadata.1, RuntimeMetadata::V16(_)));
162+
}
147163
}

substrate/primitives/metadata-ir/src/unstable.rs renamed to substrate/primitives/metadata-ir/src/v16.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl From<MetadataIR> for RuntimeMetadataV16 {
4444
fn from(ir: MetadataIR) -> Self {
4545
RuntimeMetadataV16::new(
4646
ir.pallets.into_iter().map(Into::into).collect(),
47-
ir.extrinsic.into(),
47+
ir.extrinsic.into_v16_with_call_ty(ir.outer_enums.call_enum_ty),
4848
ir.apis.into_iter().map(Into::into).collect(),
4949
ir.outer_enums.into(),
5050
// Substrate does not collect yet the custom metadata fields.
@@ -179,18 +179,19 @@ impl From<TransactionExtensionMetadataIR> for TransactionExtensionMetadata {
179179
}
180180
}
181181

182-
impl From<ExtrinsicMetadataIR> for ExtrinsicMetadata {
183-
fn from(ir: ExtrinsicMetadataIR) -> Self {
182+
impl ExtrinsicMetadataIR {
183+
fn into_v16_with_call_ty(self, call_ty: scale_info::MetaType) -> ExtrinsicMetadata {
184184
// Assume version 0 for all extensions.
185-
let indexes = (0..ir.extensions.len()).map(|index| Compact(index as u32)).collect();
185+
let indexes = (0..self.extensions.len()).map(|index| Compact(index as u32)).collect();
186186
let transaction_extensions_by_version = [(0, indexes)].iter().cloned().collect();
187187

188188
ExtrinsicMetadata {
189-
versions: ir.versions,
190-
address_ty: ir.address_ty,
191-
signature_ty: ir.signature_ty,
189+
versions: self.versions,
190+
address_ty: self.address_ty,
191+
call_ty,
192+
signature_ty: self.signature_ty,
192193
transaction_extensions_by_version,
193-
transaction_extensions: ir.extensions.into_iter().map(Into::into).collect(),
194+
transaction_extensions: self.extensions.into_iter().map(Into::into).collect(),
194195
}
195196
}
196197
}

substrate/utils/frame/benchmarking-cli/src/overhead/remark_builder.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ impl<C: Config<Hash = subxt::utils::H256>> DynamicRemarkBuilder<C> {
6060

6161
let latest = supported_metadata_versions
6262
.into_iter()
63-
.filter(|v| *v != u32::MAX)
63+
// TODO: Subxt doesn't support V16 metadata until v0.42.0, so don't try
64+
// to fetch it here until we update to that version.
65+
.filter(|v| *v != u32::MAX && *v < 16)
6466
.max()
6567
.ok_or("No stable metadata versions supported".to_string())?;
6668

0 commit comments

Comments
 (0)