Skip to content

Commit

Permalink
add CheckMetadataHash signed extension (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
clangenb authored Jul 31, 2024
1 parent 4856525 commit 92b912c
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 10 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/check-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ on:
# Matches tags containing an arbitrary suffix starting with '-'.
- v[0-9]+.[0-9]+.[0-9]+-*

# Ensures only one build is run per branch, unless pushing to develop
# Cancel a currently running workflow from the same PR, branch or tag when a new workflow is
# triggered (ref https://stackoverflow.com/a/72408109)
concurrency:
group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/develop' && github.run_number || github.ref }}
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
Expand Down Expand Up @@ -105,6 +106,8 @@ jobs:
- name: Build ${{ matrix.runtime }}
id: srtool_build
uses: chevdor/srtool-actions@v0.9.2
env:
BUILD_OPTS: "--features on-chain-release-build"
with:
image: paritytech/srtool
chain: ${{ matrix.runtime }}
Expand Down
54 changes: 54 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ assets-common = { version = "0.14.0", default-featu
frame-benchmarking = { version = "35.0.0", default-features = false }
frame-benchmarking-cli = { version = "39.0.0" }
frame-executive = { version = "35.0.0", default-features = false }
frame-metadata-hash-extension = { version = "0.3.0", default-features = false }
frame-support = { version = "35.0.0", default-features = false }
frame-system = { version = "35.0.0", default-features = false }
frame-system-benchmarking = { version = "35.0.0", 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 @@ -23,6 +23,7 @@ parity-scale-codec = { workspace = true, features = ["std"] }
# Substrate
frame-benchmarking = { workspace = true, features = ["std"] }
frame-benchmarking-cli = { workspace = true }
frame-metadata-hash-extension = { workspace = true, features = ["std"] }
frame-support = { workspace = true, features = ["std"] }
frame-system-rpc-runtime-api = { workspace = true, features = ["std"] }
frame-try-runtime = { workspace = true, features = ["std"] }
Expand Down Expand Up @@ -116,3 +117,4 @@ try-runtime = [
"polkadot-cli/try-runtime",
"sp-runtime/try-runtime",
]
metadata-hash = ["ajuna-runtime/metadata-hash"]
15 changes: 14 additions & 1 deletion runtime/ajuna/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repository.workspace = true
version.workspace = true

[build-dependencies]
substrate-wasm-builder = { workspace = true }
substrate-wasm-builder = { workspace = true, optional = true }

[dependencies]
# General
Expand All @@ -25,6 +25,7 @@ scale-info = { workspace = true, features = [ "derive" ] }
assets-common = { workspace = true }
frame-benchmarking = { workspace = true, optional = true }
frame-executive = { workspace = true }
frame-metadata-hash-extension = { workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
frame-system-benchmarking = { workspace = true, optional = true }
Expand Down Expand Up @@ -118,6 +119,7 @@ std = [
"cumulus-primitives-utility/std",
"frame-benchmarking/std",
"frame-executive/std",
"frame-metadata-hash-extension/std",
"frame-support/std",
"frame-system-benchmarking/std",
"frame-system-rpc-runtime-api/std",
Expand Down Expand Up @@ -172,6 +174,7 @@ std = [
"staging-xcm/std",
"staging-xcm-builder/std",
"staging-xcm-executor/std",
"substrate-wasm-builder",
# integritee
"pallet-asset-registry/std",
"xcm-primitives/std",
Expand Down Expand Up @@ -258,3 +261,13 @@ try-runtime = [
# integritee
"pallet-asset-registry/try-runtime",
]

# Enable metadata hash generation at compile time for the `CheckMetadataHash` extension.
# This pulls in some dependencies and add compile time, this is why we only do it for
# production builds.
metadata-hash = ["substrate-wasm-builder?/metadata-hash"]

# A feature that should be enabled when the runtime should be built for on-chain
# deployment. Hence, the CI building the release artifact should always enable this
# feature.
on-chain-release-build = ["metadata-hash"]
15 changes: 8 additions & 7 deletions runtime/ajuna/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

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

#[cfg(all(feature = "std", feature = "metadata-hash"))]
fn main() {
substrate_wasm_builder::WasmBuilder::init_with_defaults()
.enable_metadata_hash("AJUN", 12)
.build()
}

/// The wasm builder is deactivated when compiling
/// this crate for wasm to speed up the compilation.
#[cfg(not(feature = "std"))]
fn main() {}
1 change: 1 addition & 0 deletions runtime/ajuna/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ pub type SignedExtra = (
frame_system::CheckNonce<Runtime>,
frame_system::CheckWeight<Runtime>,
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
);

/// Unchecked extrinsic type as expected by this runtime.
Expand Down

0 comments on commit 92b912c

Please sign in to comment.