Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 9 additions & 9 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,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 = "22.0.0", default-features = false }
frame-metadata = { version = "23.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
30 changes: 30 additions & 0 deletions prdoc/pr_8512.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Stabilize V16 metadata

doc:
- audience: Node Dev
description: |
Metadata V16 is stabilized. V16 metadata exposes information about Pallet View Functions and V5 transactions,
and can be obtained, where applicable, by using the Runtime APIs `Metadata_metadata_at_version(16)`.

crates:
# Update to support frame-metadata 23. Changes pub interfaces:
- name: sp-metadata-ir
bump: major
# Limit to fetching at latest v15 metadata:
- name: sc-runtime-utilities
bump: patch
# Use newer frame-metadata; should be no observable change (CI wants minor):
- name: substrate-wasm-builder
bump: minor
# frame-metadata bumped in this and exposed but via hidden docs. No code changes needed (CI wants minor):
- name: frame-support
bump: minor
# Uses newer frame-support / metadata-ir but no code change needed (CI wants minor):
- name: pallet-example-view-functions
bump: minor
# Avoid fetching V16 metadata:
- name: frame-benchmarking-cli
bump: minor
4 changes: 3 additions & 1 deletion substrate/client/runtime-utilities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ pub fn fetch_latest_metadata_from_code_blob<HF: HostFunctions>(
let supported_versions = Vec::<u32>::decode(&mut supported_versions.as_slice())?;
let latest_stable = supported_versions
.into_iter()
.filter(|v| *v != u32::MAX)
// TODO: Subxt doesn't support V16 metadata until v0.42.0, so don't try
// to fetch it here until we update to that version.
.filter(|v| *v != u32::MAX && *v < 16)
.max()
.ok_or(Error::StableMetadataVersionNotFound)?;

Expand Down
2 changes: 1 addition & 1 deletion substrate/primitives/metadata-ir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { workspace = true }
frame-metadata = { features = ["current", "unstable"], workspace = true }
frame-metadata = { features = ["current"], workspace = true }
scale-info = { features = ["derive"], workspace = true }

[features]
Expand Down
34 changes: 25 additions & 9 deletions substrate/primitives/metadata-ir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ mod types;
use frame_metadata::RuntimeMetadataPrefixed;
pub use types::*;

mod unstable;
mod v14;
mod v15;
mod v16;

/// Metadata V14.
const V14: u32 = 14;
Expand All @@ -41,7 +41,7 @@ const V14: u32 = 14;
const V15: u32 = 15;

/// Unstable metadata V16.
const UNSTABLE_V16: u32 = u32::MAX;
const V16: u32 = 16;

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

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

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

_ => None,
}
}

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

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

/// Transform the IR to unstable metadata version 16.
pub fn into_unstable(metadata: MetadataIR) -> RuntimeMetadataPrefixed {
/// Transform the IR to metadata version 15.
pub fn into_v15(metadata: MetadataIR) -> RuntimeMetadataPrefixed {
let latest: frame_metadata::v15::RuntimeMetadataV15 = metadata.into();
latest.into()
}

/// Transform the IR to metadata version 16.
pub fn into_v16(metadata: MetadataIR) -> RuntimeMetadataPrefixed {
let latest: frame_metadata::v16::RuntimeMetadataV16 = metadata.into();
latest.into()
}
Expand Down Expand Up @@ -144,4 +150,14 @@ mod test {

assert!(matches!(metadata.1, RuntimeMetadata::V15(_)));
}

#[test]
fn into_version_16() {
let ir = ir_metadata();
let metadata = into_version(ir, V16).expect("Should return prefixed metadata");

assert_eq!(metadata.0, META_RESERVED);

assert!(matches!(metadata.1, RuntimeMetadata::V16(_)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl From<MetadataIR> for RuntimeMetadataV16 {
fn from(ir: MetadataIR) -> Self {
RuntimeMetadataV16::new(
ir.pallets.into_iter().map(Into::into).collect(),
ir.extrinsic.into(),
ir.extrinsic.into_v16_with_call_ty(ir.outer_enums.call_enum_ty),
ir.apis.into_iter().map(Into::into).collect(),
ir.outer_enums.into(),
// Substrate does not collect yet the custom metadata fields.
Expand Down Expand Up @@ -179,18 +179,19 @@ impl From<TransactionExtensionMetadataIR> for TransactionExtensionMetadata {
}
}

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

ExtrinsicMetadata {
versions: ir.versions,
address_ty: ir.address_ty,
signature_ty: ir.signature_ty,
versions: self.versions,
address_ty: self.address_ty,
call_ty,
signature_ty: self.signature_ty,
transaction_extensions_by_version,
transaction_extensions: ir.extensions.into_iter().map(Into::into).collect(),
transaction_extensions: self.extensions.into_iter().map(Into::into).collect(),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ impl<C: Config<Hash = subxt::utils::H256>> DynamicRemarkBuilder<C> {

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

Expand Down
Loading