Skip to content

Commit e607de0

Browse files
lexnvEgorPopelyaev
andauthored
Backport/2412: Expose the unstable metadata v16 (#6676)
This PR is a backport for: - #5732 cc @paritytech/subxt-team --------- Signed-off-by: Alexandru Vasile <[email protected]> Co-authored-by: Egor_P <[email protected]>
1 parent 44990da commit e607de0

File tree

21 files changed

+360
-42
lines changed

21 files changed

+360
-42
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ frame-benchmarking-pallet-pov = { default-features = false, path = "substrate/fr
779779
frame-election-provider-solution-type = { path = "substrate/frame/election-provider-support/solution-type", default-features = false }
780780
frame-election-provider-support = { path = "substrate/frame/election-provider-support", default-features = false }
781781
frame-executive = { path = "substrate/frame/executive", default-features = false }
782-
frame-metadata = { version = "16.0.0", default-features = false }
782+
frame-metadata = { version = "18.0.0", default-features = false }
783783
frame-metadata-hash-extension = { path = "substrate/frame/metadata-hash-extension", default-features = false }
784784
frame-support = { path = "substrate/frame/support", default-features = false }
785785
frame-support-procedural = { path = "substrate/frame/support/procedural", default-features = false }
@@ -854,7 +854,7 @@ macro_magic = { version = "0.5.1" }
854854
maplit = { version = "1.0.2" }
855855
memmap2 = { version = "0.9.3" }
856856
memory-db = { version = "0.32.0", default-features = false }
857-
merkleized-metadata = { version = "0.1.0" }
857+
merkleized-metadata = { version = "0.1.2" }
858858
merlin = { version = "3.0", default-features = false }
859859
messages-relay = { path = "bridges/relays/messages" }
860860
metered = { version = "0.6.1", default-features = false, package = "prioritized-metered-channel" }

prdoc/pr_5732.prdoc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
title: Expose the unstable metadata v16
2+
doc:
3+
- audience: Node Dev
4+
description: |
5+
This PR exposes the *unstable* metadata V16. The metadata is exposed under the unstable u32::MAX number.
6+
Developers can start experimenting with the new features of the metadata v16. *Please note that this metadata is under development and expect breaking changes until stabilization.*
7+
The `ExtrinsicMetadata` trait receives a breaking change. Its associated type `VERSION` is rename to `VERSIONS` and now supports a constant static list of metadata versions.
8+
The versions implemented for `UncheckedExtrinsic` are v4 (legacy version) and v5 (new version).
9+
For metadata collection, it is assumed that all `TransactionExtensions` are under version 0.
10+
11+
crates:
12+
- name: sp-metadata-ir
13+
bump: major
14+
- name: frame-support-procedural
15+
bump: patch
16+
- name: frame-support
17+
bump: minor
18+
- name: frame-support-test
19+
bump: major
20+
- name: frame-metadata-hash-extension
21+
bump: patch
22+
- name: substrate-wasm-builder
23+
bump: minor
24+
- name: pallet-revive
25+
bump: minor
26+
- name: sp-runtime
27+
bump: major
28+
- name: frame-benchmarking-cli
29+
bump: patch

prdoc/pr_6676.prdoc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
title: Expose the unstable metadata v16
2+
doc:
3+
- audience: Node Dev
4+
description: |
5+
This PR exposes the *unstable* metadata V16. The metadata is exposed under the unstable u32::MAX number.
6+
Developers can start experimenting with the new features of the metadata v16. *Please note that this metadata is under development and expect breaking changes until stabilization.*
7+
The `ExtrinsicMetadata` trait receives a breaking change. Its associated type `VERSION` is rename to `VERSIONS` and now supports a constant static list of metadata versions.
8+
The versions implemented for `UncheckedExtrinsic` are v4 (legacy version) and v5 (new version).
9+
For metadata collection, it is assumed that all `TransactionExtensions` are under version 0.
10+
11+
crates:
12+
- name: sp-metadata-ir
13+
bump: major
14+
- name: frame-support-procedural
15+
bump: patch
16+
- name: frame-support
17+
bump: minor
18+
- name: frame-support-test
19+
bump: major
20+
- name: frame-metadata-hash-extension
21+
bump: patch
22+
- name: substrate-wasm-builder
23+
bump: minor
24+
- name: pallet-revive
25+
bump: minor
26+
- name: sp-runtime
27+
bump: major
28+
- name: frame-benchmarking-cli
29+
bump: patch

substrate/frame/metadata-hash-extension/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ substrate-test-runtime-client = { workspace = true }
2525
sp-api = { workspace = true, default-features = true }
2626
sp-transaction-pool = { workspace = true, default-features = true }
2727
merkleized-metadata = { workspace = true }
28-
frame-metadata = { features = ["current"], workspace = true, default-features = true }
28+
frame-metadata = { features = ["current", "unstable"], workspace = true, default-features = true }
2929
sp-tracing = { workspace = true, default-features = true }
3030

3131
[features]

substrate/frame/revive/src/evm/runtime.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,12 @@ impl<Address: TypeInfo, Signature: TypeInfo, E: EthExtra> ExtrinsicLike
9292
impl<Address, Signature, E: EthExtra> ExtrinsicMetadata
9393
for UncheckedExtrinsic<Address, Signature, E>
9494
{
95-
const VERSION: u8 =
96-
generic::UncheckedExtrinsic::<Address, CallOf<E::Config>, Signature, E::Extension>::VERSION;
95+
const VERSIONS: &'static [u8] = generic::UncheckedExtrinsic::<
96+
Address,
97+
CallOf<E::Config>,
98+
Signature,
99+
E::Extension,
100+
>::VERSIONS;
97101
type TransactionExtensions = E::Extension;
98102
}
99103

substrate/frame/support/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ scale-info = { features = [
2828
], workspace = true }
2929
frame-metadata = { features = [
3030
"current",
31+
"unstable",
3132
], workspace = true }
3233
sp-api = { features = [
3334
"frame-metadata",

substrate/frame/support/procedural/src/construct_runtime/expand/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub fn expand_runtime_metadata(
117117
pallets: #scrate::__private::vec![ #(#pallets),* ],
118118
extrinsic: #scrate::__private::metadata_ir::ExtrinsicMetadataIR {
119119
ty,
120-
version: <#extrinsic as #scrate::sp_runtime::traits::ExtrinsicMetadata>::VERSION,
120+
versions: <#extrinsic as #scrate::sp_runtime::traits::ExtrinsicMetadata>::VERSIONS.into_iter().map(|ref_version| *ref_version).collect(),
121121
address_ty,
122122
call_ty,
123123
signature_ty,

substrate/frame/support/test/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static_assertions = { workspace = true, default-features = true }
1919
serde = { features = ["derive"], workspace = true }
2020
codec = { features = ["derive"], workspace = true }
2121
scale-info = { features = ["derive"], workspace = true }
22-
frame-metadata = { features = ["current"], workspace = true }
22+
frame-metadata = { features = ["current", "unstable"], workspace = true }
2323
sp-api = { workspace = true }
2424
sp-arithmetic = { workspace = true }
2525
sp-io = { workspace = true }

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ parameter_types! {
5353
/// Latest stable metadata version used for testing.
5454
const LATEST_METADATA_VERSION: u32 = 15;
5555

56+
/// Unstable metadata version.
57+
const UNSTABLE_METADATA_VERSION: u32 = u32::MAX;
58+
5659
pub struct SomeType1;
5760
impl From<SomeType1> for u64 {
5861
fn from(_t: SomeType1) -> Self {
@@ -1944,7 +1947,10 @@ fn metadata_at_version() {
19441947

19451948
#[test]
19461949
fn metadata_versions() {
1947-
assert_eq!(vec![14, LATEST_METADATA_VERSION], Runtime::metadata_versions());
1950+
assert_eq!(
1951+
vec![14, LATEST_METADATA_VERSION, UNSTABLE_METADATA_VERSION],
1952+
Runtime::metadata_versions()
1953+
);
19481954
}
19491955

19501956
#[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"], workspace = true }
20+
frame-metadata = { features = ["current", "unstable"], workspace = true }
2121
scale-info = { features = ["derive"], workspace = true }
2222

2323
[features]

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

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

33+
mod unstable;
3334
mod v14;
3435
mod v15;
3536

@@ -39,23 +40,33 @@ const V14: u32 = 14;
3940
/// Metadata V15.
4041
const V15: u32 = 15;
4142

43+
/// Unstable metadata V16.
44+
const UNSTABLE_V16: u32 = u32::MAX;
45+
4246
/// Transform the IR to the specified version.
4347
///
4448
/// Use [`supported_versions`] to find supported versions.
4549
pub fn into_version(metadata: MetadataIR, version: u32) -> Option<RuntimeMetadataPrefixed> {
4650
// Note: Unstable metadata version is `u32::MAX` until stabilized.
4751
match version {
48-
// Latest stable version.
52+
// Version V14. This needs to be around until the
53+
// deprecation of the `Metadata_metadata` runtime call in favor of
54+
// `Metadata_metadata_at_version.
4955
V14 => Some(into_v14(metadata)),
50-
// Unstable metadata.
56+
57+
// Version V15 - latest stable.
5158
V15 => Some(into_latest(metadata)),
59+
60+
// Unstable metadata under `u32::MAX`.
61+
UNSTABLE_V16 => Some(into_unstable(metadata)),
62+
5263
_ => None,
5364
}
5465
}
5566

5667
/// Returns the supported metadata versions.
5768
pub fn supported_versions() -> alloc::vec::Vec<u32> {
58-
alloc::vec![V14, V15]
69+
alloc::vec![V14, V15, UNSTABLE_V16]
5970
}
6071

6172
/// Transform the IR to the latest stable metadata version.
@@ -70,6 +81,12 @@ pub fn into_v14(metadata: MetadataIR) -> RuntimeMetadataPrefixed {
7081
latest.into()
7182
}
7283

84+
/// Transform the IR to unstable metadata version 16.
85+
pub fn into_unstable(metadata: MetadataIR) -> RuntimeMetadataPrefixed {
86+
let latest: frame_metadata::v16::RuntimeMetadataV16 = metadata.into();
87+
latest.into()
88+
}
89+
7390
#[cfg(test)]
7491
mod test {
7592
use super::*;
@@ -81,7 +98,7 @@ mod test {
8198
pallets: vec![],
8299
extrinsic: ExtrinsicMetadataIR {
83100
ty: meta_type::<()>(),
84-
version: 0,
101+
versions: vec![0],
85102
address_ty: meta_type::<()>(),
86103
call_ty: meta_type::<()>(),
87104
signature_ty: meta_type::<()>(),

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ pub struct ExtrinsicMetadataIR<T: Form = MetaForm> {
170170
///
171171
/// Note: Field used for metadata V14 only.
172172
pub ty: T::Type,
173-
/// Extrinsic version.
174-
pub version: u8,
173+
/// Extrinsic versions.
174+
pub versions: Vec<u8>,
175175
/// The type of the address that signs the extrinsic
176176
pub address_ty: T::Type,
177177
/// The type of the outermost Call enum.
@@ -191,7 +191,7 @@ impl IntoPortable for ExtrinsicMetadataIR {
191191
fn into_portable(self, registry: &mut Registry) -> Self::Output {
192192
ExtrinsicMetadataIR {
193193
ty: registry.register_type(&self.ty),
194-
version: self.version,
194+
versions: self.versions,
195195
address_ty: registry.register_type(&self.address_ty),
196196
call_ty: registry.register_type(&self.call_ty),
197197
signature_ty: registry.register_type(&self.signature_ty),

0 commit comments

Comments
 (0)