From c561f3573f5dae66b7378dc5c5168ae759434fb4 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Tue, 24 Dec 2024 21:06:29 +0800 Subject: [PATCH] Release `v0.1.2` --- Cargo.lock | 21 +++++++++++--- Cargo.toml | 5 ++-- README.md | 15 +++++++++- action/build/action.yml | 32 +++++++++++++++++---- action/override/action.yml | 40 +++++++++++++++++++++++---- action/try-runtime/action.yml | 26 +++++++++++++----- cli/src/cli/inspect.rs | 52 +++++++++++++++++++++-------------- cli/src/util.rs | 6 ++-- lib/Cargo.toml | 3 +- lib/src/error.rs | 4 +++ lib/src/runtime.rs | 2 +- lib/src/wasmer.rs | 20 ++++++++++++-- 12 files changed, 174 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b6130d9..f2a33f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1484,6 +1484,18 @@ dependencies = [ "serde", ] +[[package]] +name = "frame-metadata" +version = "18.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daaf440c68eb2c3d88e5760fe8c7af3f9fee9181fab6c2f2c4e7cc48dcc40bb8" +dependencies = [ + "cfg-if", + "parity-scale-codec", + "scale-info", + "serde", +] + [[package]] name = "fs-err" version = "2.11.0" @@ -2777,7 +2789,7 @@ checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" [[package]] name = "polkadot-runtime-releaser-cli" -version = "0.1.1" +version = "0.1.2" dependencies = [ "anyhow", "array-bytes 8.0.0", @@ -2795,20 +2807,21 @@ dependencies = [ [[package]] name = "polkadot-runtime-releaser-lib" -version = "0.1.1" +version = "0.1.2" dependencies = [ "blake2", + "frame-metadata 18.0.0", "md-5", "parity-scale-codec", "reqwew", "sc-executor", + "sc-executor-common", "serde", "serde_json", "sha2 0.10.8", "sp-core", "sp-maybe-compressed-blob", "sp-state-machine", - "sp-version", "thiserror 2.0.9", "tracing", ] @@ -4008,7 +4021,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a616fa51350b35326682a472ee8e6ba742fdacb18babac38ecd46b3e05ead869" dependencies = [ - "frame-metadata", + "frame-metadata 16.0.0", "parity-scale-codec", "scale-info", ] diff --git a/Cargo.toml b/Cargo.toml index 40cabfc..217e7fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ edition = "2021" homepage = "https://hack.ink/polkadot-runtime-releaser" license = "GPL-3.0" repository = "https://github.com/hack-ink/polkadot-runtime-releaser" -version = "0.1.1" +version = "0.1.2" [workspace.dependencies] # crates.io @@ -21,18 +21,19 @@ blake2 = { version = "0.10" } chrono = { version = "0.4" } clap = { version = "4.5" } color-eyre = { version = "0.6" } +frame-metadata = { version = "18.0" } ipfs-cid = { version = "2.0" } md-5 = { version = "0.10" } parity-scale-codec = { version = "3.6" } reqwew = { version = "0.6", default-features = false } sc-executor = { version = "0.40" } +sc-executor-common = { version = "0.35" } serde = { version = "1.0" } serde_json = { version = "1.0" } sha2 = { version = "0.10" } sp-core = { version = "34.0" } sp-maybe-compressed-blob = { version = "11.0" } sp-state-machine = { version = "0.43" } -sp-version = { version = "37.0" } thiserror = { version = "2.0" } tokio = { version = "1.42" } toml = { version = "0.8" } diff --git a/README.md b/README.md index 032ab78..cb6dbe2 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,20 @@ cargo install polkadot-runtime-releaser-cli #### Install from GitHub ```sh -curl -L .. +# macOS +curl -L https://github.com/hack-ink/polkadot-runtime-releaser/releases/latest/download/prr-aarch64-apple-darwin.zip \ + -o prr.zip && + unzip prr.zip && + chmod u+x prr && + rm prr.zip + +# Linux +curl -L https://github.com/hack-ink/polkadot-runtime-releaser/releases/latest/download/prr-x86_64-unknown-linux-gnu.tar.gz | + tar xz && + chmod u+x prr + +# If you like to move the binary to `~/.local/bin`. (OPTIONAL) +mkdir -p ~/.local/bin && mv prr ~/.local/bin ``` ### Rust Toolchain diff --git a/action/build/action.yml b/action/build/action.yml index 6243311..f517b74 100644 --- a/action/build/action.yml +++ b/action/build/action.yml @@ -11,18 +11,40 @@ inputs: features: description: "Features to enable for the runtime crate." required: false - default: "" - toolchain-version: + toolchain-ver: description: "Rust toolchain version to use." required: false - default: "stable" + workdir: + description: "Working directory for the runtime." + required: false + output-dir: + description: "Output directory for the runtime." + required: false runs: using: "composite" steps: - name: Setup Polkadot Runtime Releaser shell: bash - run: curl -L https://github.com/hack-ink/polkadot-runtime-releaser/releases/download/v0.1.0/polkadot-runtime-releaser.tar.gz | tar xz && chmod +x prr && mv prr /usr/local/bin/prr + run: curl \ + -L https://github.com/hack-ink/polkadot-runtime-releaser/releases/download/v0.1.2/polkadot-runtime-releaser.tar.gz | \ + tar xz && \ + chmod u+x prr && \ + mv prr /usr/local/bin/prr - name: Build shell: bash - run: prr build ${{ inputs.runtime }} -f ${{ inputs.features }} -t ${{ inputs.toolchain-version }} + run: | + CMD="prr build ${{ inputs.runtime }}" + if [ ! -z "${{ inputs.features }}" ]; then + CMD="$CMD -f ${{ inputs.features }}" + fi + if [ ! -z "${{ inputs.toolchain-ver }}" ]; then + CMD="$CMD -t ${{ inputs.toolchain-ver }}" + fi + if [ ! -z "${{ inputs.workdir }}" ]; then + CMD="$CMD -d ${{ inputs.workdir }}" + fi + if [ ! -z "${{ inputs.output-dir }}" ]; then + CMD="$CMD -o ${{ inputs.output-dir }}" + fi + eval "$CMD" diff --git a/action/override/action.yml b/action/override/action.yml index ee1eed5..8414490 100644 --- a/action/override/action.yml +++ b/action/override/action.yml @@ -5,26 +5,56 @@ branding: color: "blue" inputs: + repository: + description: "Repository to fetch the runtime code from." + required: true + ref: + description: "Branch, tag, or commit of the runtime repository to fetch." + required: true runtime: description: "Target runtime crate to build." required: true features: description: "Features to enable for the runtime crate." - required: false - default: "" - toolchain-version: + required: true + toolchain-ver: description: "Rust toolchain version to use." required: false - default: "stable" + token: + description: "GitHub token for authentication." + required: true + default: ${{ github.token }} runs: using: "composite" steps: - name: Fetch latest code uses: actions/checkout@v4 + with: + ref: ${{ inputs.runtime }} + path: override + - name: Fetch runtime code + uses: actions/checkout@v4 + with: + repository: ${{ inputs.repository }} + ref: ${{ inputs.ref }} + path: runtime - name: Build runtime uses: ../build/action.yml with: runtime: ${{ inputs.runtime }} features: ${{ inputs.features }} - toolchain-version: ${{ inputs.toolchain-version }} + toolchain-ver: ${{ inputs.toolchain-ver }} + workdir: runtime + output-dir: override/${{ inputs.features }} + - name: Commit changes + shell: bash + env: + GITHUB_TOKEN: ${{ inputs.token }} + run: | + cd override + git config --global user.name "github-actions[bot]" + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + git add . + git commit -m "Override `${{ inputs.ref }}`" + git push diff --git a/action/try-runtime/action.yml b/action/try-runtime/action.yml index 14f4636..45100fb 100644 --- a/action/try-runtime/action.yml +++ b/action/try-runtime/action.yml @@ -11,11 +11,9 @@ inputs: features: description: "Features to enable for the runtime crate." required: false - default: "" - toolchain-version: + toolchain-ver: description: "Rust toolchain version to use." required: false - default: "stable" try-runtime-version: description: "Try Runtime CLI version to use." required: false @@ -29,16 +27,30 @@ runs: steps: - name: Setup try runtime CLI shell: bash - run: curl -L https://github.com/paritytech/try-runtime-cli/releases/download/v${{ inputs.try-runtime-version }}/try-runtime-x86_64-unknown-linux-musl -o try-runtime && chmod +x try-runtime && mv try-runtime /usr/local/bin/try-runtime + run: curl \ + -L https://github.com/paritytech/try-runtime-cli/releases/download/v${{ inputs.try-runtime-version }}/try-runtime-x86_64-unknown-linux-musl \ + -o try-runtime && \ + chmod +x try-runtime && \ + mv try-runtime /usr/local/bin/try-runtime - name: Build runtime uses: ../build/action.yml with: runtime: ${{ inputs.runtime }} features: ${{ inputs.features }} - toolchain-version: ${{ inputs.toolchain-version }} + toolchain-ver: ${{ inputs.toolchain-ver }} - name: Try runtime + id: try_runtime shell: bash - run: try-runtime --runtime $(find polkadot-runtime-releaser-output -name "*.compact.compressed.wasm") on-runtime-upgrade live -u ${{ inputs.uri }} 2>&1 | tee output.log + run: | + echo "output<> $GITHUB_OUTPUT + try-runtime \ + --runtime $(find ./polkadot-runtime-releaser-output \ + -name "*.compact.compressed.wasm") \ + on-runtime-upgrade \ + live \ + -u ${{ inputs.uri }} \ + 2>&1 >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT - name: Comment uses: peter-evans/create-or-update-comment@v4 with: @@ -48,6 +60,6 @@ runs: Try Runtime Output for ${{ inputs.runtime }} ``` - ${{ cat output.log }} + ${{ steps.try_runtime.outputs.output }} ``` diff --git a/cli/src/cli/inspect.rs b/cli/src/cli/inspect.rs index ca4c928..d3a2ca8 100644 --- a/cli/src/cli/inspect.rs +++ b/cli/src/cli/inspect.rs @@ -24,25 +24,19 @@ impl Run for InspectCmd { let Self { path, check_version, verbose } = self; let wasmer = Wasmer::load(&path)?; let built_at = fs::metadata(&path)?.created()?; - let compressed_size = wasmer.compressed()?.len(); - let decompressed_size = wasmer.decompressed()?.len(); + let compressed = wasmer.compressed()?.len(); + let uncompressed = wasmer.decompressed()?.len(); + let size = Size { compressed, uncompressed }; let md5 = hasher::md5(&wasmer.code); let sha256 = hasher::sha256(&wasmer.code); let blake2_256 = hasher::blake2_256(&wasmer.code); let ipfs = ipfs_cid::generate_cid_v0(&wasmer.code)?; - let version = wasmer.runtime_version(verbose)?; - let call_hashes = CallHashes::of(&wasmer, check_version); - let json = serde_json::to_string(&Output { - built_at, - compressed_size, - decompressed_size, - md5, - sha256, - blake2_256, - ipfs, - version, - call_hashes, - })?; + let hash = Hash { md5, sha256, blake2_256, ipfs }; + let runtime = wasmer.runtime_version(verbose)?; + let metadata = wasmer.metadata()?.version(); + let version = Ver { runtime, metadata }; + let call_hash = CallHash::of(&wasmer, check_version); + let json = serde_json::to_string(&Output { built_at, size, hash, version, call_hash })?; println!("{json}"); @@ -55,10 +49,22 @@ impl Run for InspectCmd { struct Output { #[serde(serialize_with = "util::ser_system_time")] built_at: SystemTime, + size: Size, + hash: Hash, + version: Ver, + call_hash: CallHash, +} +#[derive(Debug, Serialize)] +#[serde(rename_all = "kebab-case")] +struct Size { #[serde(serialize_with = "util::ser_size_mb")] - compressed_size: usize, + compressed: usize, #[serde(serialize_with = "util::ser_size_mb")] - decompressed_size: usize, + uncompressed: usize, +} +#[derive(Debug, Serialize)] +#[serde(rename_all = "kebab-case")] +struct Hash { #[serde(serialize_with = "array_bytes::ser_hex")] md5: [u8; 16], #[serde(serialize_with = "array_bytes::ser_hex")] @@ -66,18 +72,22 @@ struct Output { #[serde(serialize_with = "array_bytes::ser_hex")] blake2_256: [u8; 32], ipfs: String, - version: Version, - call_hashes: CallHashes, } #[derive(Debug, Serialize)] #[serde(rename_all = "kebab-case")] -struct CallHashes { +struct Ver { + runtime: Version, + metadata: u32, +} +#[derive(Debug, Serialize)] +#[serde(rename_all = "kebab-case")] +struct CallHash { #[serde(serialize_with = "array_bytes::ser_hex")] set_code: [u8; 32], #[serde(serialize_with = "array_bytes::ser_hex")] authorized_upgrade: [u8; 32], } -impl CallHashes { +impl CallHash { fn of(wasmer: &Wasmer, check_version: bool) -> Self { let set_code = hasher::blake2_256( [ diff --git a/cli/src/util.rs b/cli/src/util.rs index 9c4b277..a356487 100644 --- a/cli/src/util.rs +++ b/cli/src/util.rs @@ -1,7 +1,7 @@ // std use std::time::SystemTime; // crates.io -use chrono::{DateTime, Utc}; +use chrono::{DateTime, SecondsFormat, Utc}; use serde::Serializer; pub fn ser_system_time(time: &SystemTime, serializer: S) -> Result @@ -10,7 +10,7 @@ where { let date = >::from(*time); - serializer.serialize_str(&date.to_rfc3339()) + serializer.serialize_str(&date.to_rfc3339_opts(SecondsFormat::Secs, true)) } pub fn ser_size_mb(size: &usize, serializer: S) -> Result @@ -50,6 +50,6 @@ fn ser_should_work() { size: 1024 * 1024 }) .unwrap(), - r#"{"time":"2021-08-01T00:00:00+00:00","size":"1.00 MB (1,048,576 bytes)"}"# + r#"{"time":"2021-08-01T00:00:00Z","size":"1.00 MB (1,048,576 bytes)"}"# ) } diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 76913a8..eaf0ffb 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -12,16 +12,17 @@ version.workspace = true [dependencies] # crates.io blake2 = { workspace = true } +frame-metadata = { workspace = true } md-5 = { workspace = true } parity-scale-codec = { workspace = true } reqwew = { workspace = true, features = ["blocking", "charset", "http2", "json", "reqwest", "rustls-tls"] } sc-executor = { workspace = true } +sc-executor-common = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } sha2 = { workspace = true } sp-core = { workspace = true } sp-maybe-compressed-blob = { workspace = true } sp-state-machine = { workspace = true } -sp-version = { workspace = true, features = ["serde"] } thiserror = { workspace = true } tracing = { workspace = true } diff --git a/lib/src/error.rs b/lib/src/error.rs index ecbf9a4..e31bb56 100644 --- a/lib/src/error.rs +++ b/lib/src/error.rs @@ -13,9 +13,13 @@ pub enum Error { #[error(transparent)] Compress(#[from] sp_maybe_compressed_blob::Error), #[error(transparent)] + Executor(#[from] sc_executor::error::Error), + #[error(transparent)] Reqwew(#[from] reqwew::error::Error), #[error(transparent)] SerdeJson(#[from] serde_json::Error), + #[error(transparent)] + Wasm(#[from] sc_executor_common::error::WasmError), #[error("{0}")] Custom(String), diff --git a/lib/src/runtime.rs b/lib/src/runtime.rs index 7f5d32e..f457ce2 100644 --- a/lib/src/runtime.rs +++ b/lib/src/runtime.rs @@ -2,7 +2,7 @@ // crates.io use serde::Serialize; -use sp_version::RuntimeVersion; +use sc_executor::RuntimeVersion; // self use crate::prelude::*; diff --git a/lib/src/wasmer.rs b/lib/src/wasmer.rs index a531952..675dee8 100644 --- a/lib/src/wasmer.rs +++ b/lib/src/wasmer.rs @@ -3,12 +3,13 @@ // std use std::{borrow::Cow, fs, path::Path}; // crates.io +use frame_metadata::{RuntimeMetadata, RuntimeMetadataPrefixed}; use parity_scale_codec::Decode; -use sc_executor::WasmExecutor; +use sc_executor::{RuntimeVersion, WasmExecutor}; +use sc_executor_common::runtime_blob::RuntimeBlob; use sp_core::traits::ReadRuntimeVersion; use sp_maybe_compressed_blob::CODE_BLOB_BOMB_LIMIT; use sp_state_machine::BasicExternalities; -use sp_version::RuntimeVersion; // self use crate::{prelude::*, runtime::Version}; @@ -57,4 +58,19 @@ impl Wasmer { Ok(ver) } + + /// Read the runtime metadata. + pub fn metadata(&self) -> Result { + let metadata_compressed = self.executor.uncached_call( + RuntimeBlob::uncompress_if_needed(&self.code)?, + &mut BasicExternalities::default(), + true, + "Metadata_metadata", + &[], + )?; + let metadata_encoded = >::decode(&mut &*metadata_compressed)?; + let metadata = RuntimeMetadataPrefixed::decode(&mut &*metadata_encoded)?; + + Ok(metadata.1) + } }