Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 37e1407

Browse files
lexnvjsdw
andauthored
Stabilize V15 Metadata (#14481)
* Update frame-metadata to latest branch Signed-off-by: Alexandru Vasile <[email protected]> * Stabilize V15 Signed-off-by: Alexandru Vasile <[email protected]> * Update frame-metadata Signed-off-by: Alexandru Vasile <[email protected]> * Use frame-metadata from crates.io Signed-off-by: Alexandru Vasile <[email protected]> * Adjust testing Signed-off-by: Alexandru Vasile <[email protected]> * test: Adjust frame-support metadata docs Signed-off-by: Alexandru Vasile <[email protected]> * Update primitives/metadata-ir/src/lib.rs Co-authored-by: James Wilson <[email protected]> --------- Signed-off-by: Alexandru Vasile <[email protected]> Co-authored-by: James Wilson <[email protected]> Co-authored-by: parity-processbot <>
1 parent c14ff62 commit 37e1407

File tree

8 files changed

+64
-30
lines changed

8 files changed

+64
-30
lines changed

Diff for: Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: frame/support/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
1616
serde = { version = "1.0.163", default-features = false, features = ["alloc", "derive"] }
1717
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive", "max-encoded-len"] }
1818
scale-info = { version = "2.5.0", default-features = false, features = ["derive"] }
19-
frame-metadata = { version = "15.2.0", default-features = false, features = ["unstable"] }
19+
frame-metadata = { version = "16.0.0", default-features = false, features = ["current"] }
2020
sp-api = { version = "4.0.0-dev", default-features = false, path = "../../primitives/api" }
2121
sp-std = { version = "8.0.0", default-features = false, path = "../../primitives/std" }
2222
sp-io = { version = "23.0.0", default-features = false, path = "../../primitives/io" }

Diff for: frame/support/procedural/src/construct_runtime/expand/metadata.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ pub fn expand_runtime_metadata(
145145
}
146146

147147
pub fn metadata() -> #scrate::metadata::RuntimeMetadataPrefixed {
148-
#scrate::metadata_ir::into_latest(#runtime::metadata_ir())
148+
// Note: this always returns the V14 version. The runtime API function
149+
// must be deprecated.
150+
#scrate::metadata_ir::into_v14(#runtime::metadata_ir())
149151
}
150152

151153
pub fn metadata_at_version(version: u32) -> Option<#scrate::OpaqueMetadata> {

Diff for: frame/support/test/tests/construct_runtime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ fn call_subtype_conversion() {
631631

632632
#[test]
633633
fn test_metadata() {
634-
use frame_support::metadata::*;
634+
use frame_support::metadata::{v14::*, *};
635635
use scale_info::meta_type;
636636

637637
let pallets = vec![

Diff for: frame/support/test/tests/pallet.rs

+43-10
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ parameter_types! {
4747
}
4848

4949
/// Latest stable metadata version used for testing.
50-
const LATEST_METADATA_VERSION: u32 = 14;
50+
const LATEST_METADATA_VERSION: u32 = 15;
5151

5252
pub struct SomeType1;
5353
impl From<SomeType1> for u64 {
@@ -1300,7 +1300,8 @@ fn migrate_from_pallet_version_to_storage_version() {
13001300

13011301
#[test]
13021302
fn metadata() {
1303-
use frame_support::metadata::*;
1303+
use codec::Decode;
1304+
use frame_support::metadata::{v15::*, *};
13041305

13051306
fn maybe_docs(doc: Vec<&'static str>) -> Vec<&'static str> {
13061307
if cfg!(feature = "no-metadata-docs") {
@@ -1310,6 +1311,9 @@ fn metadata() {
13101311
}
13111312
}
13121313

1314+
let readme = "Support code for the runtime.\n\nLicense: Apache-2.0";
1315+
let expected_pallet_doc = vec![" Pallet documentation", readme, readme];
1316+
13131317
let pallets = vec![
13141318
PalletMetadata {
13151319
index: 1,
@@ -1570,6 +1574,7 @@ fn metadata() {
15701574
},
15711575
],
15721576
error: Some(PalletErrorMetadata { ty: meta_type::<pallet::Error<Runtime>>() }),
1577+
docs: expected_pallet_doc,
15731578
},
15741579
PalletMetadata {
15751580
index: 2,
@@ -1608,6 +1613,7 @@ fn metadata() {
16081613
event: Some(PalletEventMetadata { ty: meta_type::<pallet2::Event>() }),
16091614
constants: vec![],
16101615
error: None,
1616+
docs: vec![],
16111617
},
16121618
#[cfg(feature = "frame-feature-testing")]
16131619
PalletMetadata {
@@ -1618,6 +1624,7 @@ fn metadata() {
16181624
event: None,
16191625
constants: vec![],
16201626
error: None,
1627+
docs: vec![" Test that the supertrait check works when we pass some parameter to the `frame_system::Config`."],
16211628
},
16221629
#[cfg(feature = "frame-feature-testing-2")]
16231630
PalletMetadata {
@@ -1628,6 +1635,7 @@ fn metadata() {
16281635
event: None,
16291636
constants: vec![],
16301637
error: None,
1638+
docs: vec![" Test that the supertrait check works when we pass some parameter to the `frame_system::Config`."],
16311639
},
16321640
];
16331641

@@ -1642,24 +1650,48 @@ fn metadata() {
16421650
}
16431651

16441652
let extrinsic = ExtrinsicMetadata {
1645-
ty: meta_type::<UncheckedExtrinsic>(),
16461653
version: 4,
16471654
signed_extensions: vec![SignedExtensionMetadata {
16481655
identifier: "UnitSignedExtension",
16491656
ty: meta_type::<()>(),
16501657
additional_signed: meta_type::<()>(),
16511658
}],
1659+
address_ty: meta_type::<<<UncheckedExtrinsic as ExtrinsicT>::SignaturePayload as SignaturePayloadT>::SignatureAddress>(),
1660+
call_ty: meta_type::<<UncheckedExtrinsic as ExtrinsicT>::Call>(),
1661+
signature_ty: meta_type::<
1662+
<<UncheckedExtrinsic as ExtrinsicT>::SignaturePayload as SignaturePayloadT>::Signature
1663+
>(),
1664+
extra_ty: meta_type::<<<UncheckedExtrinsic as ExtrinsicT>::SignaturePayload as SignaturePayloadT>::SignatureExtra>(),
16521665
};
16531666

1654-
let expected_metadata: RuntimeMetadataPrefixed =
1655-
RuntimeMetadataLastVersion::new(pallets, extrinsic, meta_type::<Runtime>()).into();
1667+
let outer_enums = OuterEnums {
1668+
call_enum_ty: meta_type::<RuntimeCall>(),
1669+
event_enum_ty: meta_type::<RuntimeEvent>(),
1670+
error_enum_ty: meta_type::<RuntimeError>(),
1671+
};
1672+
1673+
let expected_metadata: RuntimeMetadataPrefixed = RuntimeMetadataLastVersion::new(
1674+
pallets,
1675+
extrinsic,
1676+
meta_type::<Runtime>(),
1677+
vec![],
1678+
outer_enums,
1679+
CustomMetadata { map: Default::default() },
1680+
)
1681+
.into();
16561682
let expected_metadata = match expected_metadata.1 {
1657-
RuntimeMetadata::V14(metadata) => metadata,
1683+
RuntimeMetadata::V15(metadata) => metadata,
16581684
_ => panic!("metadata has been bumped, test needs to be updated"),
16591685
};
16601686

1661-
let actual_metadata = match Runtime::metadata().1 {
1662-
RuntimeMetadata::V14(metadata) => metadata,
1687+
let bytes = &Runtime::metadata_at_version(LATEST_METADATA_VERSION)
1688+
.expect("Metadata must be present; qed");
1689+
1690+
let actual_metadata: RuntimeMetadataPrefixed =
1691+
Decode::decode(&mut &bytes[..]).expect("Metadata encoded properly; qed");
1692+
1693+
let actual_metadata = match actual_metadata.1 {
1694+
RuntimeMetadata::V15(metadata) => metadata,
16631695
_ => panic!("metadata has been bumped, test needs to be updated"),
16641696
};
16651697

@@ -1671,8 +1703,9 @@ fn metadata_at_version() {
16711703
use frame_support::metadata::*;
16721704
use sp_core::Decode;
16731705

1706+
// Metadata always returns the V14.3
16741707
let metadata = Runtime::metadata();
1675-
let at_metadata = match Runtime::metadata_at_version(LATEST_METADATA_VERSION) {
1708+
let at_metadata = match Runtime::metadata_at_version(14) {
16761709
Some(opaque) => {
16771710
let bytes = &*opaque;
16781711
let metadata: RuntimeMetadataPrefixed = Decode::decode(&mut &bytes[..]).unwrap();
@@ -1686,7 +1719,7 @@ fn metadata_at_version() {
16861719

16871720
#[test]
16881721
fn metadata_versions() {
1689-
assert_eq!(vec![LATEST_METADATA_VERSION, u32::MAX], Runtime::metadata_versions());
1722+
assert_eq!(vec![14, LATEST_METADATA_VERSION], Runtime::metadata_versions());
16901723
}
16911724

16921725
#[test]

Diff for: frame/support/test/tests/pallet_instance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ fn pallet_on_genesis() {
723723

724724
#[test]
725725
fn metadata() {
726-
use frame_support::metadata::*;
726+
use frame_support::metadata::{v14::*, *};
727727

728728
let system_pallet_metadata = PalletMetadata {
729729
index: 0,

Diff for: primitives/metadata-ir/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"]
1414

1515
[dependencies]
1616
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false }
17-
frame-metadata = { version = "15.2.0", default-features = false, features = ["unstable"] }
17+
frame-metadata = { version = "16.0.0", default-features = false, features = ["current"] }
1818
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
1919
sp-std = { version = "8.0.0", default-features = false, path = "../std" }
2020

Diff for: primitives/metadata-ir/src/lib.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
pub use frame_metadata;
2626

2727
mod types;
28-
use frame_metadata::{RuntimeMetadataPrefixed, RuntimeMetadataV14};
28+
use frame_metadata::RuntimeMetadataPrefixed;
2929
pub use types::*;
3030

3131
mod v14;
@@ -35,25 +35,18 @@ mod v15;
3535
const V14: u32 = 14;
3636

3737
/// Metadata V15.
38-
///
39-
/// Not yet stable, thus we set it to `u32::MAX`.
40-
const V15: u32 = u32::MAX;
38+
const V15: u32 = 15;
4139

4240
/// Transform the IR to the specified version.
4341
///
4442
/// Use [`supported_versions`] to find supported versions.
4543
pub fn into_version(metadata: MetadataIR, version: u32) -> Option<RuntimeMetadataPrefixed> {
44+
// Note: Unstable metadata version is `u32::MAX` until stabilized.
4645
match version {
4746
// Latest stable version.
48-
V14 => {
49-
let v14: frame_metadata::v14::RuntimeMetadataV14 = metadata.into();
50-
Some(v14.into())
51-
},
47+
V14 => Some(into_v14(metadata)),
5248
// Unstable metadata.
53-
V15 => {
54-
let v15: frame_metadata::v15::RuntimeMetadataV15 = metadata.into();
55-
Some(v15.into())
56-
},
49+
V15 => Some(into_latest(metadata)),
5750
_ => None,
5851
}
5952
}
@@ -65,7 +58,13 @@ pub fn supported_versions() -> sp_std::vec::Vec<u32> {
6558

6659
/// Transform the IR to the latest stable metadata version.
6760
pub fn into_latest(metadata: MetadataIR) -> RuntimeMetadataPrefixed {
68-
let latest: RuntimeMetadataV14 = metadata.into();
61+
let latest: frame_metadata::v15::RuntimeMetadataV15 = metadata.into();
62+
latest.into()
63+
}
64+
65+
/// Transform the IR to metadata version 14.
66+
pub fn into_v14(metadata: MetadataIR) -> RuntimeMetadataPrefixed {
67+
let latest: frame_metadata::v14::RuntimeMetadataV14 = metadata.into();
6968
latest.into()
7069
}
7170

0 commit comments

Comments
 (0)