From 6a741f972e2441c3520bbb748811974eff501bb8 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 28 Jun 2023 19:31:55 +0300 Subject: [PATCH 1/7] Update frame-metadata to latest branch Signed-off-by: Alexandru Vasile --- Cargo.lock | 3 +-- frame/support/Cargo.toml | 2 +- primitives/metadata-ir/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cb4cf877236b1..7d2f8adf6bc7e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2698,8 +2698,7 @@ dependencies = [ [[package]] name = "frame-metadata" version = "15.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2a893ede8dde2293e94dacf9c8f5db5d0506cd909257a8f0ac2b7d610baf50c" +source = "git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/stable_v15#e19a5873674457677cb978599f02783112231821" dependencies = [ "cfg-if", "parity-scale-codec", diff --git a/frame/support/Cargo.toml b/frame/support/Cargo.toml index 045f1169045c8..b4682f91c6c7c 100644 --- a/frame/support/Cargo.toml +++ b/frame/support/Cargo.toml @@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"] serde = { version = "1.0.163", default-features = false, features = ["alloc", "derive"] } codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive", "max-encoded-len"] } scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } -frame-metadata = { version = "15.2.0", default-features = false, features = ["unstable"] } +frame-metadata = { git = "https://github.com/paritytech/frame-metadata.git", branch = "lexnv/stable_v15", default-features = false, features = ["current"] } sp-api = { version = "4.0.0-dev", default-features = false, path = "../../primitives/api" } sp-std = { version = "8.0.0", default-features = false, path = "../../primitives/std" } sp-io = { version = "23.0.0", default-features = false, path = "../../primitives/io" } diff --git a/primitives/metadata-ir/Cargo.toml b/primitives/metadata-ir/Cargo.toml index 924fc08027563..f251df5847a03 100644 --- a/primitives/metadata-ir/Cargo.toml +++ b/primitives/metadata-ir/Cargo.toml @@ -14,7 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false } -frame-metadata = { version = "15.2.0", default-features = false, features = ["unstable"] } +frame-metadata = { git = "https://github.com/paritytech/frame-metadata.git", branch = "lexnv/stable_v15", default-features = false, features = ["current"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } sp-std = { version = "8.0.0", default-features = false, path = "../std" } From 2a59b169958fb8426fce9c8b0cc1cd0eca7addae Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 28 Jun 2023 19:36:04 +0300 Subject: [PATCH 2/7] Stabilize V15 Signed-off-by: Alexandru Vasile --- .../src/construct_runtime/expand/metadata.rs | 4 ++- frame/support/test/tests/pallet.rs | 4 +-- primitives/metadata-ir/src/lib.rs | 25 +++++++++---------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/frame/support/procedural/src/construct_runtime/expand/metadata.rs b/frame/support/procedural/src/construct_runtime/expand/metadata.rs index 7b99ecf6ad273..3f88d8c6d1353 100644 --- a/frame/support/procedural/src/construct_runtime/expand/metadata.rs +++ b/frame/support/procedural/src/construct_runtime/expand/metadata.rs @@ -145,7 +145,9 @@ pub fn expand_runtime_metadata( } pub fn metadata() -> #scrate::metadata::RuntimeMetadataPrefixed { - #scrate::metadata_ir::into_latest(#runtime::metadata_ir()) + // Note: this always returns the V14 version. The runtime API function + // must be deprecated. + #scrate::metadata_ir::into_v14(#runtime::metadata_ir()) } pub fn metadata_at_version(version: u32) -> Option<#scrate::OpaqueMetadata> { diff --git a/frame/support/test/tests/pallet.rs b/frame/support/test/tests/pallet.rs index b7a7e2a767a6e..46678945739d8 100644 --- a/frame/support/test/tests/pallet.rs +++ b/frame/support/test/tests/pallet.rs @@ -47,7 +47,7 @@ parameter_types! { } /// Latest stable metadata version used for testing. -const LATEST_METADATA_VERSION: u32 = 14; +const LATEST_METADATA_VERSION: u32 = 15; pub struct SomeType1; impl From for u64 { @@ -1686,7 +1686,7 @@ fn metadata_at_version() { #[test] fn metadata_versions() { - assert_eq!(vec![LATEST_METADATA_VERSION, u32::MAX], Runtime::metadata_versions()); + assert_eq!(vec![14, LATEST_METADATA_VERSION], Runtime::metadata_versions()); } #[test] diff --git a/primitives/metadata-ir/src/lib.rs b/primitives/metadata-ir/src/lib.rs index 9dc03f964a09e..1ff6ab80b7947 100644 --- a/primitives/metadata-ir/src/lib.rs +++ b/primitives/metadata-ir/src/lib.rs @@ -25,7 +25,7 @@ pub use frame_metadata; mod types; -use frame_metadata::{RuntimeMetadataPrefixed, RuntimeMetadataV14}; +use frame_metadata::RuntimeMetadataPrefixed; pub use types::*; mod v14; @@ -35,25 +35,18 @@ mod v15; const V14: u32 = 14; /// Metadata V15. -/// -/// Not yet stable, thus we set it to `u32::MAX`. -const V15: u32 = u32::MAX; +const V15: u32 = 15; /// Transform the IR to the specified version. /// /// Use [`supported_versions`] to find supported versions. pub fn into_version(metadata: MetadataIR, version: u32) -> Option { + // Note: Unstable metadata version is `u32::MAX` until stabilized. match version { // Latest stable version. - V14 => { - let v14: frame_metadata::v14::RuntimeMetadataV14 = metadata.into(); - Some(v14.into()) - }, + V14 => Some(into_v14(metadata)), // Unstable metadata. - V15 => { - let v15: frame_metadata::v15::RuntimeMetadataV15 = metadata.into(); - Some(v15.into()) - }, + V15 => Some(into_latest(metadata)), _ => None, } } @@ -65,7 +58,13 @@ pub fn supported_versions() -> sp_std::vec::Vec { /// Transform the IR to the latest stable metadata version. pub fn into_latest(metadata: MetadataIR) -> RuntimeMetadataPrefixed { - let latest: RuntimeMetadataV14 = metadata.into(); + let latest: frame_metadata::v15::RuntimeMetadataV15 = metadata.into(); + latest.into() +} + +/// Transform the IR to the latest stable metadata version. +pub fn into_v14(metadata: MetadataIR) -> RuntimeMetadataPrefixed { + let latest: frame_metadata::v14::RuntimeMetadataV14 = metadata.into(); latest.into() } From 13e32a300f78ae4251bea72e1268d4f2b48188bf Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 29 Jun 2023 17:50:28 +0300 Subject: [PATCH 3/7] Update frame-metadata Signed-off-by: Alexandru Vasile --- Cargo.lock | 2 +- frame/support/Cargo.toml | 2 +- primitives/metadata-ir/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7d2f8adf6bc7e..60c52f5086767 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2698,7 +2698,7 @@ dependencies = [ [[package]] name = "frame-metadata" version = "15.2.0" -source = "git+https://github.com/paritytech/frame-metadata.git?branch=lexnv/stable_v15#e19a5873674457677cb978599f02783112231821" +source = "git+https://github.com/paritytech/frame-metadata.git#62fb6340d412fd04afd1235ff21de4b29dc2aaae" dependencies = [ "cfg-if", "parity-scale-codec", diff --git a/frame/support/Cargo.toml b/frame/support/Cargo.toml index b4682f91c6c7c..80e5fcd09a05e 100644 --- a/frame/support/Cargo.toml +++ b/frame/support/Cargo.toml @@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"] serde = { version = "1.0.163", default-features = false, features = ["alloc", "derive"] } codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive", "max-encoded-len"] } scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } -frame-metadata = { git = "https://github.com/paritytech/frame-metadata.git", branch = "lexnv/stable_v15", default-features = false, features = ["current"] } +frame-metadata = { git = "https://github.com/paritytech/frame-metadata.git", default-features = false, features = ["current"] } sp-api = { version = "4.0.0-dev", default-features = false, path = "../../primitives/api" } sp-std = { version = "8.0.0", default-features = false, path = "../../primitives/std" } sp-io = { version = "23.0.0", default-features = false, path = "../../primitives/io" } diff --git a/primitives/metadata-ir/Cargo.toml b/primitives/metadata-ir/Cargo.toml index f251df5847a03..05d54d4a1dee8 100644 --- a/primitives/metadata-ir/Cargo.toml +++ b/primitives/metadata-ir/Cargo.toml @@ -14,7 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false } -frame-metadata = { git = "https://github.com/paritytech/frame-metadata.git", branch = "lexnv/stable_v15", default-features = false, features = ["current"] } +frame-metadata = { git = "https://github.com/paritytech/frame-metadata.git", default-features = false, features = ["current"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } sp-std = { version = "8.0.0", default-features = false, path = "../std" } From 7fe395791822d4548891cea8efe224bba1d7c1d8 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 29 Jun 2023 18:06:33 +0300 Subject: [PATCH 4/7] Use frame-metadata from crates.io Signed-off-by: Alexandru Vasile --- Cargo.lock | 5 +++-- frame/support/Cargo.toml | 2 +- primitives/metadata-ir/Cargo.toml | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 60c52f5086767..7a81f09d06563 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2697,8 +2697,9 @@ dependencies = [ [[package]] name = "frame-metadata" -version = "15.2.0" -source = "git+https://github.com/paritytech/frame-metadata.git#62fb6340d412fd04afd1235ff21de4b29dc2aaae" +version = "16.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cf1549fba25a6fcac22785b61698317d958e96cac72a59102ea45b9ae64692" dependencies = [ "cfg-if", "parity-scale-codec", diff --git a/frame/support/Cargo.toml b/frame/support/Cargo.toml index 80e5fcd09a05e..b9fd5e7e65549 100644 --- a/frame/support/Cargo.toml +++ b/frame/support/Cargo.toml @@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"] serde = { version = "1.0.163", default-features = false, features = ["alloc", "derive"] } codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive", "max-encoded-len"] } scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } -frame-metadata = { git = "https://github.com/paritytech/frame-metadata.git", default-features = false, features = ["current"] } +frame-metadata = { version = "16.0.0", default-features = false, features = ["current"] } sp-api = { version = "4.0.0-dev", default-features = false, path = "../../primitives/api" } sp-std = { version = "8.0.0", default-features = false, path = "../../primitives/std" } sp-io = { version = "23.0.0", default-features = false, path = "../../primitives/io" } diff --git a/primitives/metadata-ir/Cargo.toml b/primitives/metadata-ir/Cargo.toml index 05d54d4a1dee8..49fd23e208e41 100644 --- a/primitives/metadata-ir/Cargo.toml +++ b/primitives/metadata-ir/Cargo.toml @@ -14,7 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false } -frame-metadata = { git = "https://github.com/paritytech/frame-metadata.git", default-features = false, features = ["current"] } +frame-metadata = { version = "16.0.0", default-features = false, features = ["current"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } sp-std = { version = "8.0.0", default-features = false, path = "../std" } From a9f2a0d565249b8d947f0789b9023f123418eae6 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 29 Jun 2023 18:35:23 +0300 Subject: [PATCH 5/7] Adjust testing Signed-off-by: Alexandru Vasile --- frame/support/test/tests/construct_runtime.rs | 2 +- frame/support/test/tests/pallet.rs | 49 ++++++++++++++++--- frame/support/test/tests/pallet_instance.rs | 2 +- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/frame/support/test/tests/construct_runtime.rs b/frame/support/test/tests/construct_runtime.rs index 85e790095eb31..f91ea6cdf4127 100644 --- a/frame/support/test/tests/construct_runtime.rs +++ b/frame/support/test/tests/construct_runtime.rs @@ -631,7 +631,7 @@ fn call_subtype_conversion() { #[test] fn test_metadata() { - use frame_support::metadata::*; + use frame_support::metadata::{v14::*, *}; use scale_info::meta_type; let pallets = vec![ diff --git a/frame/support/test/tests/pallet.rs b/frame/support/test/tests/pallet.rs index 46678945739d8..1710673c7da06 100644 --- a/frame/support/test/tests/pallet.rs +++ b/frame/support/test/tests/pallet.rs @@ -1300,7 +1300,8 @@ fn migrate_from_pallet_version_to_storage_version() { #[test] fn metadata() { - use frame_support::metadata::*; + use codec::Decode; + use frame_support::metadata::{v15::*, *}; fn maybe_docs(doc: Vec<&'static str>) -> Vec<&'static str> { if cfg!(feature = "no-metadata-docs") { @@ -1310,6 +1311,9 @@ fn metadata() { } } + let readme = "Support code for the runtime.\n\nLicense: Apache-2.0"; + let expected_pallet_doc = vec![" Pallet documentation", readme, readme]; + let pallets = vec![ PalletMetadata { index: 1, @@ -1570,6 +1574,7 @@ fn metadata() { }, ], error: Some(PalletErrorMetadata { ty: meta_type::>() }), + docs: maybe_docs(expected_pallet_doc), }, PalletMetadata { index: 2, @@ -1608,6 +1613,7 @@ fn metadata() { event: Some(PalletEventMetadata { ty: meta_type::() }), constants: vec![], error: None, + docs: vec![], }, #[cfg(feature = "frame-feature-testing")] PalletMetadata { @@ -1618,6 +1624,7 @@ fn metadata() { event: None, constants: vec![], error: None, + docs: vec![], }, #[cfg(feature = "frame-feature-testing-2")] PalletMetadata { @@ -1628,6 +1635,7 @@ fn metadata() { event: None, constants: vec![], error: None, + docs: vec![], }, ]; @@ -1642,24 +1650,48 @@ fn metadata() { } let extrinsic = ExtrinsicMetadata { - ty: meta_type::(), version: 4, signed_extensions: vec![SignedExtensionMetadata { identifier: "UnitSignedExtension", ty: meta_type::<()>(), additional_signed: meta_type::<()>(), }], + address_ty: meta_type::<<::SignaturePayload as SignaturePayloadT>::SignatureAddress>(), + call_ty: meta_type::<::Call>(), + signature_ty: meta_type::< + <::SignaturePayload as SignaturePayloadT>::Signature + >(), + extra_ty: meta_type::<<::SignaturePayload as SignaturePayloadT>::SignatureExtra>(), }; - let expected_metadata: RuntimeMetadataPrefixed = - RuntimeMetadataLastVersion::new(pallets, extrinsic, meta_type::()).into(); + let outer_enums = OuterEnums { + call_enum_ty: meta_type::(), + event_enum_ty: meta_type::(), + error_enum_ty: meta_type::(), + }; + + let expected_metadata: RuntimeMetadataPrefixed = RuntimeMetadataLastVersion::new( + pallets, + extrinsic, + meta_type::(), + vec![], + outer_enums, + CustomMetadata { map: Default::default() }, + ) + .into(); let expected_metadata = match expected_metadata.1 { - RuntimeMetadata::V14(metadata) => metadata, + RuntimeMetadata::V15(metadata) => metadata, _ => panic!("metadata has been bumped, test needs to be updated"), }; - let actual_metadata = match Runtime::metadata().1 { - RuntimeMetadata::V14(metadata) => metadata, + let bytes = &Runtime::metadata_at_version(LATEST_METADATA_VERSION) + .expect("Metadata must be present; qed"); + + let actual_metadata: RuntimeMetadataPrefixed = + Decode::decode(&mut &bytes[..]).expect("Metadata encoded properly; qed"); + + let actual_metadata = match actual_metadata.1 { + RuntimeMetadata::V15(metadata) => metadata, _ => panic!("metadata has been bumped, test needs to be updated"), }; @@ -1671,8 +1703,9 @@ fn metadata_at_version() { use frame_support::metadata::*; use sp_core::Decode; + // Metadata always returns the V14.3 let metadata = Runtime::metadata(); - let at_metadata = match Runtime::metadata_at_version(LATEST_METADATA_VERSION) { + let at_metadata = match Runtime::metadata_at_version(14) { Some(opaque) => { let bytes = &*opaque; let metadata: RuntimeMetadataPrefixed = Decode::decode(&mut &bytes[..]).unwrap(); diff --git a/frame/support/test/tests/pallet_instance.rs b/frame/support/test/tests/pallet_instance.rs index 7918f93605e5c..03dcc455096e9 100644 --- a/frame/support/test/tests/pallet_instance.rs +++ b/frame/support/test/tests/pallet_instance.rs @@ -723,7 +723,7 @@ fn pallet_on_genesis() { #[test] fn metadata() { - use frame_support::metadata::*; + use frame_support::metadata::{v14::*, *}; let system_pallet_metadata = PalletMetadata { index: 0, From e0dfe5bbef266a46972c3bc88df5f4754f650964 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 29 Jun 2023 19:07:09 +0300 Subject: [PATCH 6/7] test: Adjust frame-support metadata docs Signed-off-by: Alexandru Vasile --- frame/support/test/tests/pallet.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frame/support/test/tests/pallet.rs b/frame/support/test/tests/pallet.rs index 1710673c7da06..5129346acea55 100644 --- a/frame/support/test/tests/pallet.rs +++ b/frame/support/test/tests/pallet.rs @@ -1574,7 +1574,7 @@ fn metadata() { }, ], error: Some(PalletErrorMetadata { ty: meta_type::>() }), - docs: maybe_docs(expected_pallet_doc), + docs: expected_pallet_doc, }, PalletMetadata { index: 2, @@ -1624,7 +1624,7 @@ fn metadata() { event: None, constants: vec![], error: None, - docs: vec![], + docs: vec![" Test that the supertrait check works when we pass some parameter to the `frame_system::Config`."], }, #[cfg(feature = "frame-feature-testing-2")] PalletMetadata { @@ -1635,7 +1635,7 @@ fn metadata() { event: None, constants: vec![], error: None, - docs: vec![], + docs: vec![" Test that the supertrait check works when we pass some parameter to the `frame_system::Config`."], }, ]; From 9a3007a3eb8ac79eef81bbc7edca8fd99f6c375e Mon Sep 17 00:00:00 2001 From: Alexandru Vasile <60601340+lexnv@users.noreply.github.com> Date: Thu, 29 Jun 2023 20:09:47 +0300 Subject: [PATCH 7/7] Update primitives/metadata-ir/src/lib.rs Co-authored-by: James Wilson --- primitives/metadata-ir/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primitives/metadata-ir/src/lib.rs b/primitives/metadata-ir/src/lib.rs index 1ff6ab80b7947..edfa58f861894 100644 --- a/primitives/metadata-ir/src/lib.rs +++ b/primitives/metadata-ir/src/lib.rs @@ -62,7 +62,7 @@ pub fn into_latest(metadata: MetadataIR) -> RuntimeMetadataPrefixed { latest.into() } -/// Transform the IR to the latest stable metadata version. +/// Transform the IR to metadata version 14. pub fn into_v14(metadata: MetadataIR) -> RuntimeMetadataPrefixed { let latest: frame_metadata::v14::RuntimeMetadataV14 = metadata.into(); latest.into()