From ccbd1e422cbaf14ba4b399639fb44fbe9a6489fa Mon Sep 17 00:00:00 2001 From: Honza Date: Sat, 28 Dec 2024 18:41:34 +0100 Subject: [PATCH] feat: adding metadata hash --- Cargo.lock | 68 ++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + runtime/Cargo.toml | 2 ++ runtime/build.rs | 11 +++++++- runtime/src/lib.rs | 7 +++-- 5 files changed, 85 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index acc027aa4..ac365b520 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2730,6 +2730,21 @@ dependencies = [ "serde", ] +[[package]] +name = "frame-metadata-hash-extension" +version = "0.6.0" +source = "git+https://github.com/paritytech/polkadot-sdk?tag=polkadot-stable2409#87971b3e92721bdf10bf40b410eaae779d494ca0" +dependencies = [ + "array-bytes", + "docify", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-runtime", +] + [[package]] name = "frame-remote-externalities" version = "0.46.0" @@ -5251,6 +5266,20 @@ dependencies = [ "hash-db", ] +[[package]] +name = "merkleized-metadata" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f313fcff1d2a4bcaa2deeaa00bf7530d77d5f7bd0467a117dde2e29a75a7a17a" +dependencies = [ + "array-bytes", + "blake3", + "frame-metadata", + "parity-scale-codec", + "scale-decode", + "scale-info", +] + [[package]] name = "merlin" version = "3.0.0" @@ -5717,6 +5746,7 @@ dependencies = [ "fp-self-contained", "frame-benchmarking", "frame-executive", + "frame-metadata-hash-extension", "frame-support", "frame-system", "frame-system-benchmarking", @@ -9158,6 +9188,29 @@ dependencies = [ "sp-arithmetic", ] +[[package]] +name = "scale-bits" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e57b1e7f6b65ed1f04e79a85a57d755ad56d76fdf1e9bddcc9ae14f71fcdcf54" +dependencies = [ + "parity-scale-codec", + "scale-type-resolver", +] + +[[package]] +name = "scale-decode" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e98f3262c250d90e700bb802eb704e1f841e03331c2eb815e46516c4edbf5b27" +dependencies = [ + "derive_more 0.99.18", + "parity-scale-codec", + "scale-bits", + "scale-type-resolver", + "smallvec", +] + [[package]] name = "scale-info" version = "2.11.6" @@ -9184,6 +9237,12 @@ dependencies = [ "syn 2.0.90", ] +[[package]] +name = "scale-type-resolver" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0cded6518aa0bd6c1be2b88ac81bf7044992f0f154bfbabd5ad34f43512abcb" + [[package]] name = "schannel" version = "0.1.27" @@ -10763,14 +10822,23 @@ name = "substrate-wasm-builder" version = "24.0.1" source = "git+https://github.com/paritytech/polkadot-sdk?tag=polkadot-stable2409#87971b3e92721bdf10bf40b410eaae779d494ca0" dependencies = [ + "array-bytes", "build-helper", "cargo_metadata", "console", "filetime", + "frame-metadata", "jobserver", + "merkleized-metadata", + "parity-scale-codec", "parity-wasm", "polkavm-linker", + "sc-executor", + "sp-core", + "sp-io", "sp-maybe-compressed-blob", + "sp-tracing", + "sp-version", "strum 0.26.3", "tempfile", "toml 0.8.19", diff --git a/Cargo.toml b/Cargo.toml index 54c1c6f23..acd68a3e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -115,6 +115,7 @@ frame-system = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polk frame-system-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2409", default-features = false } frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2409", default-features = false } frame-try-runtime = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2409", default-features = false } +frame-metadata-hash-extension = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2409", default-features = false } pallet-aura = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2409", default-features = false } pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2409", default-features = false } pallet-grandpa = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2409", default-features = false } diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 07ef45baa..52a8d46a6 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -32,6 +32,7 @@ frame-executive.workspace = true frame-support.workspace = true frame-system.workspace = true frame-try-runtime = { workspace = true, optional = true } +frame-metadata-hash-extension.workspace = true pallet-aura.workspace = true pallet-balances.workspace = true pallet-grandpa.workspace = true @@ -187,3 +188,4 @@ try-runtime = [ "pallet-evm-chain-id/try-runtime", "fp-self-contained/try-runtime", ] +metadata-hash = ["substrate-wasm-builder/metadata-hash"] diff --git a/runtime/build.rs b/runtime/build.rs index 8f021e838..84acf296f 100644 --- a/runtime/build.rs +++ b/runtime/build.rs @@ -1,5 +1,5 @@ fn main() { - #[cfg(feature = "std")] + #[cfg(all(feature = "std", not(feature = "metadata-hash")))] { substrate_wasm_builder::WasmBuilder::new() .with_current_project() @@ -7,4 +7,13 @@ fn main() { .import_memory() .build(); } + #[cfg(all(feature = "std", feature = "metadata-hash"))] + { + substrate_wasm_builder::WasmBuilder::new() + .with_current_project() + .export_heap_base() + .import_memory() + .enable_metadata_hash("COMAI", 9) + .build(); + } } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 878af560b..d1403f483 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -204,7 +204,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("node-subspace"), impl_name: create_runtime_str!("node-subspace"), authoring_version: 1, - spec_version: 514, + spec_version: 515, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, @@ -217,7 +217,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("node-subspace"), impl_name: create_runtime_str!("node-subspace"), authoring_version: 1, - spec_version: 127, + spec_version: 128, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, @@ -756,6 +756,7 @@ pub type SignedExtra = ( frame_system::CheckNonce, frame_system::CheckWeight, pallet_transaction_payment::ChargeTransactionPayment, + frame_metadata_hash_extension::CheckMetadataHash, ); // Unchecked extrinsic type as expected by this runtime. @@ -1531,7 +1532,7 @@ where frame_system::CheckNonce::::from(nonce), frame_system::CheckWeight::::new(), pallet_transaction_payment::ChargeTransactionPayment::::from(tip), - // frame_metadata_hash_extension::CheckMetadataHash::new(true), TODO + frame_metadata_hash_extension::CheckMetadataHash::::new(true), ); let raw_payload = SignedPayload::new(call, extra)