Skip to content

Commit

Permalink
Add support for metadata hash extension (#2916)
Browse files Browse the repository at this point in the history
* add support for metadata hash extension

* use feature flag and update tx version

* build the metadata-hash for on-chain builds

* chore(ci): fix build for metadata-hash support

* test metadata hash feature

* add metadata-hash feature to moonbeam-service

* fix values in test-fee-multiplier-max.ts

---------

Co-authored-by: Rodrigo Quelhas <rodrigo_quelhas@outlook.pt>
  • Loading branch information
noandrea and RomarQ authored Sep 5, 2024
1 parent a8ca4d3 commit f6b69a8
Show file tree
Hide file tree
Showing 20 changed files with 942 additions and 308 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ jobs:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Cargo build
uses: ./.github/workflow-templates/cargo-build
with:
features: metadata-hash
- name: Upload runtimes
uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ jobs:
run: rustup component add llvm-tools-preview
- name: Cargo build
uses: ./.github/workflow-templates/cargo-build
with:
features: metadata-hash
- name: Enable coverage gathering
run: |
# Enable coverage when running tests
Expand Down
559 changes: 281 additions & 278 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ environmental = { version = "1.1.2", default-features = false }
frame-metadata = { version = "16.0.0", default-features = false, features = [
"current",
] }
frame-metadata-hash-extension = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0", default-features = false }
hex = { version = "0.4.3", default-features = false }
hex-literal = { version = "0.3.4" }
impl-serde = { version = "0.3.1", default-features = false }
Expand Down
2 changes: 2 additions & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ moonbase-native = [ "moonbeam-cli/moonbase-native", "moonbeam-service/moonbase-n
moonbeam-native = [ "moonbeam-cli/moonbeam-native", "moonbeam-service/moonbeam-native" ]
moonriver-native = [ "moonbeam-cli/moonriver-native", "moonbeam-service/moonriver-native" ]

metadata-hash = ["moonbeam-service/metadata-hash"]

test-spec = []

runtime-benchmarks = [
Expand Down
6 changes: 6 additions & 0 deletions node/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ moonbase-native = ["moonbase-runtime", "westend-native"]
moonbeam-native = ["moonbeam-runtime"]
moonriver-native = ["moonriver-runtime"]

metadata-hash = [
"moonbase-runtime/metadata-hash",
"moonriver-runtime/metadata-hash",
"moonbeam-runtime/metadata-hash",
]

test-spec = []

runtime-benchmarks = [
Expand Down
7 changes: 6 additions & 1 deletion runtime/moonbase/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ moonbeam-rpc-primitives-txpool = { workspace = true }

# Substrate
frame-executive = { workspace = true }
frame-metadata-hash-extension = { workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
frame-system-rpc-runtime-api = { workspace = true }
Expand Down Expand Up @@ -220,6 +221,7 @@ std = [
"fp-self-contained/std",
"frame-benchmarking/std",
"frame-executive/std",
"frame-metadata-hash-extension/std",
"frame-support/std",
"frame-system-rpc-runtime-api/std",
"frame-system/std",
Expand Down Expand Up @@ -331,10 +333,13 @@ force-debug = ["sp-debug-derive/force-debug"]
# Will be enabled by the `wasm-builder` when building the runtime for WASM.
runtime-wasm = []

# Enable the metadata hash generation in the wasm builder.
metadata-hash = ["substrate-wasm-builder/metadata-hash"]

# A feature that should be enabled when the runtime should be build for on-chain
# deployment. This will disable stuff that shouldn't be part of the on-chain wasm
# to make it smaller like logging for example.
on-chain-release-build = ["sp-api/disable-logging"]
on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"]

runtime-benchmarks = [
"cumulus-pallet-parachain-system/runtime-benchmarks",
Expand Down
11 changes: 11 additions & 0 deletions runtime/moonbase/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,21 @@

use substrate_wasm_builder::WasmBuilder;

#[cfg(not(feature = "metadata-hash"))]
fn main() {
WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.build()
}

#[cfg(feature = "metadata-hash")]
fn main() {
WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.enable_metadata_hash("UNIT", 18)
.build()
}
3 changes: 2 additions & 1 deletion runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_version: 3200,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
transaction_version: 3,
state_version: 0,
};

Expand Down Expand Up @@ -1475,6 +1475,7 @@ pub type SignedExtra = (
frame_system::CheckNonce<Runtime>,
frame_system::CheckWeight<Runtime>,
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim<Runtime>,
);
/// Unchecked extrinsic type as expected by this runtime.
Expand Down
7 changes: 6 additions & 1 deletion runtime/moonbeam/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ moonbeam-rpc-primitives-txpool = { workspace = true }

# Substrate
frame-executive = { workspace = true }
frame-metadata-hash-extension = { workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
frame-system-rpc-runtime-api = { workspace = true }
Expand Down Expand Up @@ -213,6 +214,7 @@ std = [
"fp-self-contained/std",
"frame-benchmarking/std",
"frame-executive/std",
"frame-metadata-hash-extension/std",
"frame-support/std",
"frame-system-rpc-runtime-api/std",
"frame-system/std",
Expand Down Expand Up @@ -316,10 +318,13 @@ evm-tracing = ["evm-tracing-events", "moonbeam-evm-tracer", "rlp", "sha3"]
# Will be enabled by the `wasm-builder` when building the runtime for WASM.
runtime-wasm = []

# Enable the metadata hash generation in the wasm builder.
metadata-hash = ["substrate-wasm-builder/metadata-hash"]

# A feature that should be enabled when the runtime should be build for on-chain
# deployment. This will disable stuff that shouldn't be part of the on-chain wasm
# to make it smaller like logging for example.
on-chain-release-build = ["sp-api/disable-logging"]
on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"]

runtime-benchmarks = [
"cumulus-pallet-parachain-system/runtime-benchmarks",
Expand Down
11 changes: 11 additions & 0 deletions runtime/moonbeam/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,21 @@

use substrate_wasm_builder::WasmBuilder;

#[cfg(not(feature = "metadata-hash"))]
fn main() {
WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.build()
}

#[cfg(feature = "metadata-hash")]
fn main() {
WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.enable_metadata_hash("GLMR", 18)
.build()
}
3 changes: 2 additions & 1 deletion runtime/moonbeam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_version: 3200,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
transaction_version: 3,
state_version: 0,
};

Expand Down Expand Up @@ -1524,6 +1524,7 @@ pub type SignedExtra = (
frame_system::CheckNonce<Runtime>,
frame_system::CheckWeight<Runtime>,
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim<Runtime>,
);
/// Unchecked extrinsic type as expected by this runtime.
Expand Down
7 changes: 6 additions & 1 deletion runtime/moonriver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ moonbeam-rpc-primitives-txpool = { workspace = true }

# Substrate
frame-executive = { workspace = true }
frame-metadata-hash-extension = { workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
frame-system-rpc-runtime-api = { workspace = true }
Expand Down Expand Up @@ -214,6 +215,7 @@ std = [
"fp-self-contained/std",
"frame-benchmarking/std",
"frame-executive/std",
"frame-metadata-hash-extension/std",
"frame-support/std",
"frame-system-rpc-runtime-api/std",
"frame-system/std",
Expand Down Expand Up @@ -321,10 +323,13 @@ force-debug = ["sp-debug-derive/force-debug"]
# Will be enabled by the `wasm-builder` when building the runtime for WASM.
runtime-wasm = []

# Enable the metadata hash generation in the wasm builder.
metadata-hash = ["substrate-wasm-builder/metadata-hash"]

# A feature that should be enabled when the runtime should be build for on-chain
# deployment. This will disable stuff that shouldn't be part of the on-chain wasm
# to make it smaller like logging for example.
on-chain-release-build = ["sp-api/disable-logging"]
on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"]

runtime-benchmarks = [
"cumulus-pallet-parachain-system/runtime-benchmarks",
Expand Down
11 changes: 11 additions & 0 deletions runtime/moonriver/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,21 @@

use substrate_wasm_builder::WasmBuilder;

#[cfg(not(feature = "metadata-hash"))]
fn main() {
WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.build()
}

#[cfg(feature = "metadata-hash")]
fn main() {
WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.enable_metadata_hash("MOVR", 18)
.build()
}
3 changes: 2 additions & 1 deletion runtime/moonriver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_version: 3200,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
transaction_version: 3,
state_version: 0,
};

Expand Down Expand Up @@ -1525,6 +1525,7 @@ pub type SignedExtra = (
frame_system::CheckNonce<Runtime>,
frame_system::CheckWeight<Runtime>,
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim<Runtime>,
);
/// Unchecked extrinsic type as expected by this runtime.
Expand Down
1 change: 1 addition & 0 deletions scripts/build-runtime-srtool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ CMD="docker run \
-e CARGO_NET_GIT_FETCH_WITH_CLI=true \
-e PACKAGE=${GH_WORKFLOW_MATRIX_CHAIN}-runtime \
-e RUNTIME_DIR=runtime/${GH_WORKFLOW_MATRIX_CHAIN} \
-e BUILD_OPTS=\"--features on-chain-release-build\" \
-e PROFILE=production \
-e WASM_BUILD_STD=0 \
-v ${PWD}:/build \
Expand Down
1 change: 1 addition & 0 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@polkadot/types-codec": "12.1.1",
"@polkadot/util": "12.6.2",
"@polkadot/util-crypto": "12.6.2",
"@polkadot-api/merkleize-metadata": "1.1.2",
"@substrate/txwrapper-core": "7.5.1",
"@substrate/txwrapper-substrate": "7.5.1",
"@vitest/ui": "2.0.1",
Expand Down
Loading

0 comments on commit f6b69a8

Please sign in to comment.