From 9fd7b432fc201f05cb7a14d58771b2aa7f65bde1 Mon Sep 17 00:00:00 2001
From: James Wilson <james@jsdw.me>
Date: Wed, 10 Jul 2024 17:42:07 +0100
Subject: [PATCH] Expose metadata-hash feature from polkadot crate (#4886)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Enabling this feature when building the `polkadot ` crate will lead it
to being enabled for the builtin westend and rococo runtimes. The result
of that is that a merkleized metadata hash will be computed (at some
time cost) in those runtimes, which will allow transactions which
include a hash via the `CheckMetadataHash` extension to work.

The idea is that this is useful for being able to test/experiment with
the `CheckMetadataHash` extension against local nodes.

---------

Co-authored-by: command-bot <>
Co-authored-by: Bastian Köcher <git@kchr.de>
---
 Cargo.lock                       | 4 ++--
 polkadot/Cargo.toml              | 5 +++++
 polkadot/cli/Cargo.toml          | 1 +
 polkadot/node/service/Cargo.toml | 7 +++++++
 4 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index df96a2140ab..ab38930b1b0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -18528,9 +18528,9 @@ dependencies = [
 
 [[package]]
 name = "scale-decode"
-version = "0.13.0"
+version = "0.13.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b12ebca36cec2a3f983c46295b282b35e5f8496346fb859a8776dad5389e5389"
+checksum = "e98f3262c250d90e700bb802eb704e1f841e03331c2eb815e46516c4edbf5b27"
 dependencies = [
  "derive_more",
  "parity-scale-codec",
diff --git a/polkadot/Cargo.toml b/polkadot/Cargo.toml
index 512783de948..3a939464868 100644
--- a/polkadot/Cargo.toml
+++ b/polkadot/Cargo.toml
@@ -68,6 +68,11 @@ jemalloc-allocator = [
 	"polkadot-overseer/jemalloc-allocator",
 ]
 
+# Generate the metadata hash needed for CheckMetadataHash
+# in the builtin test runtimes (westend and rococo).
+metadata-hash = [
+	"polkadot-cli/metadata-hash",
+]
 
 # Enables timeout-based tests supposed to be run only in CI environment as they may be flaky
 # when run locally depending on system load
diff --git a/polkadot/cli/Cargo.toml b/polkadot/cli/Cargo.toml
index 9dcdb44ab64..da37f6062c5 100644
--- a/polkadot/cli/Cargo.toml
+++ b/polkadot/cli/Cargo.toml
@@ -49,6 +49,7 @@ substrate-build-script-utils = { workspace = true, default-features = true }
 [features]
 default = ["cli", "db", "full-node"]
 db = ["polkadot-service/db"]
+metadata-hash = ["polkadot-service/metadata-hash"]
 service = ["dep:polkadot-service"]
 cli = [
 	"clap",
diff --git a/polkadot/node/service/Cargo.toml b/polkadot/node/service/Cargo.toml
index 23cd51d8a04..c0ddbf7dcfc 100644
--- a/polkadot/node/service/Cargo.toml
+++ b/polkadot/node/service/Cargo.toml
@@ -201,6 +201,13 @@ rococo-native = [
 	"rococo-runtime-constants",
 ]
 
+# Generate the metadata hash needed for CheckMetadataHash
+# in the test runtimes.
+metadata-hash = [
+	"rococo-runtime?/metadata-hash",
+	"westend-runtime?/metadata-hash",
+]
+
 runtime-benchmarks = [
 	"frame-benchmarking-cli/runtime-benchmarks",
 	"frame-benchmarking/runtime-benchmarks",
-- 
GitLab