Skip to content

SRLabs: Introduce fuzzing harness for pallet-domains #7736

SRLabs: Introduce fuzzing harness for pallet-domains

SRLabs: Introduce fuzzing harness for pallet-domains #7736

Workflow file for this run

name: Rust
on:
push:
branches:
- main
pull_request:
workflow_dispatch:
merge_group:
concurrency:
group: rust-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
# Not needed in CI, should make things a bit faster
CARGO_INCREMENTAL: 0
CARGO_TERM_COLOR: always
# Build smaller artifacts to avoid running out of space in CI and make it a bit faster
RUSTFLAGS: -C strip=symbols
RUST_BACKTRACE: full
# If a property test fails, we want to shrink it as much as possible to find the minimal failing
# case. This only happens on test failure, so it's not a big deal if it's slow.
PROPTEST_MAX_SHRINK_ITERS: 100000
# Default is 256, but we want PRs to check more cases, so they fail in CI before we merge them.
# For slow tests, this can be reduced using `#[property_test(config = "ProptestConfig { .. }")]`.
PROPTEST_CASES: 10000
PROPTEST_MAX_GLOBAL_REJECTS: 100000
# Disable spot instances in the GitHub merge queue. Otherwise, inherit the spot setting from the
# runner config. This environment variable helps us avoid nested strings inside complex actions
# expressions.
SPOT: ${{ contains(github.ref, 'gh-readonly-queue') && '/spot=false' || '' }}
jobs:
cargo-fmt:
name: cargo-fmt (Linux x86-64)
# Format checks do not require significant resources, so we use a free runner.
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: cargo fmt
run: cargo fmt --all -- --check
cargo-clippy:
name: cargo-clippy (${{ strategy.job-index == 0 && 'Linux x86-64' || (strategy.job-index == 1 && 'Windows x86-64' || 'macOS arm64') }})
strategy:
matrix:
# Disable spot instances in the GitHub merge queue, and disable runs-on entirely for forks
os: ${{ fromJson(github.repository_owner == 'autonomys' &&
'[
"runs-on=${{ github.run_id }}-${{ github.run_attempt }}/runner=self-hosted-ubuntu-22.04-x86-64/extras=s3-cache${{ env.SPOT }}",
["self-hosted", "windows-server-2022-x86-64"],
["self-hosted", "macos-14-arm64"]
]' ||
'["ubuntu-22.04", "windows-2022", "macos-14"]') }}
runs-on: ${{ matrix.os }}
steps:
# Enable the sccache runs-on S3 backend for Linux runners, to cache C/C++/CUDA and Rust.
# On GitHub-hosted or fork runners, the runs-on action is ignored.
- uses: runs-on/action@cd2b598b0515d39d78c38a02d529db87d2196d1e # v2.0.3
with:
sccache: ${{ runner.os == 'Linux' && 's3' || '' }}
- uses: mozilla-actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9
if: runner.os == 'Linux' && github.repository_owner == 'autonomys'
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
# On macOS, we need a proper Clang version, not Apple's custom version without wasm32 support
- name: Install LLVM and Clang for macOS
uses: KyleMayes/install-llvm-action@dec985c8d7b46a2f363ea1a78f660c946a3349ea # v2.0.1
with:
env: true
version: 17
if: runner.os == 'macOS'
# Because macOS, see https://andreasfertig.blog/2021/02/clang-and-gcc-on-macos-catalina-finding-the-include-paths/
- name: Configure C compiler macOS
run: |
echo "SDKROOT=$(xcrun --show-sdk-path)" >> $GITHUB_ENV
if: runner.os == 'macOS'
- name: Install glibtoolize (macOS)
run: brew install libtool
if: runner.os == 'macOS'
# We cache protoc because it sometimes fails to download, but cache is too slow on Windows.
- name: Configure tool cache
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
id: tool-cache
with:
path: '~/**/_tool'
# We don't have an easy way to clear old tool versions, but there aren't many tools
# (or versions), so just reset when we upgrade the compiler.
key: ${{ runner.os }}-tool-${{ hashFiles('./rust-toolchain.toml') }}
if: runner.os != 'Windows'
- name: Install Protoc
uses: arduino/setup-protoc@c65c819552d16ad3c9b72d9dfd5ba5237b9c906b # v3.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
# Needed for hwloc
- name: Install automake (macOS)
run: brew install automake
if: runner.os == 'macOS'
# TODO: cache CUDA from Program Files on Windows, because it takes 6+ minutes to install.
- name: CUDA toolchain
uses: Jimver/cuda-toolkit@4bd727d5619dc6fa323b1e76c3aa5dca94f5ec6d # v0.2.19
with:
cuda: '12.4.1'
method: network
sub-packages: '["nvcc", "cudart"]'
if: runner.os == 'Linux' || runner.os == 'Windows'
- name: Configure ROCm cache (Windows)
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
id: rocm-cache
with:
path: C:\Program Files\AMD\ROCm
key: ${{ runner.os }}-rocm
if: runner.os == 'Windows'
- name: ROCm toolchain
run: |
ROCM_VERSION=6.2.2
sudo mkdir -p --mode=0755 /etc/apt/keyrings
curl -L https://repo.radeon.com/rocm/rocm.gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/rocm.gpg > /dev/null
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/rocm/apt/$ROCM_VERSION jammy main" | sudo tee /etc/apt/sources.list.d/rocm.list > /dev/null
echo -e "Package: *\nPin: release o=repo.radeon.com\nPin-Priority: 600" | sudo tee /etc/apt/preferences.d/rocm-pin-600 > /dev/null
sudo apt-get update
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y --no-install-recommends rocm-hip-runtime-dev
echo "/opt/rocm/lib" | sudo tee /etc/ld.so.conf.d/rocm.conf > /dev/null
sudo ldconfig
if: runner.os == 'Linux'
- name: ROCm toolchain
run: |
$ErrorActionPreference = "Stop"
Invoke-WebRequest -Uri https://download.amd.com/developer/eula/rocm-hub/AMD-Software-PRO-Edition-24.Q3-WinSvr2022-For-HIP.exe -OutFile "${env:RUNNER_TEMP}\HIP-SDK-Installer.exe"
Start-Process "${env:RUNNER_TEMP}\HIP-SDK-Installer.exe" -ArgumentList '-install' -NoNewWindow -Wait
Remove-Item "${env:RUNNER_TEMP}\HIP-SDK-Installer.exe"
if: runner.os == 'Windows' && steps.rocm-cache.outputs.cache-hit != 'true'
- name: Configure source deps cache
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
# We don't need to cache anything more than the crate packages and bare git clones.
# <https://doc.rust-lang.org/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci>
path: |
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
# Reset stored crates when any direct dependency versions change, so we aren't storing
# outdated versions. Currently this happens every 1-3 weeks.
key: ${{ runner.os }}-cargo-${{ hashFiles('./Cargo.toml') }}
- name: Configure compiled deps cache
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
# Clippy has no build artifacts, so we can save the whole target directory
path: './target'
# There's no point in restoring deps from older compiler versions, because they won't be
# used. To stop the cache from growing too large, we also reset it whenever any direct
# dependency version changes.
# TODO: we might be able to share clippy and check-individually caches
key: ${{ runner.os }}-${{ github.job }}-target-${{ hashFiles('./Cargo.toml') }}-${{ hashFiles('./rust-toolchain.toml') }}
# Windows caching is very slow, and we already have sccache on Linux
if: runner.os == 'macOS'
# Checks benchmark code style and syntax (but clippy does not do code generation checks)
- name: cargo clippy
run: |
cargo -Zgitoxide -Zgit clippy --locked --all-targets --features runtime-benchmarks -- -D warnings
if: runner.os == 'macOS'
- name: cargo clippy
run: |
cargo -Zgitoxide -Zgit clippy --locked --all-targets --features runtime-benchmarks,cuda -- -D warnings
if: runner.os == 'Linux' || runner.os == 'Windows'
- name: cargo clippy (ROCm)
run: |
cargo -Zgitoxide -Zgit clippy --locked --all-targets --features rocm -- -D warnings
if: runner.os == 'Linux'
- name: cargo clippy (ROCm)
env:
# Why `PROGRA~1` instead of `Program Files`? Because Windows!
HIPCC: C:\PROGRA~1\AMD\ROCm\6.1\bin\hipcc.bin.exe
run: |
cargo -Zgitoxide -Zgit clippy --locked --all-targets --features rocm -- -D warnings
if: runner.os == 'Windows'
cargo-runtime-build:
name: cargo-runtime-build (Linux x86-64)
# If clippy and tests pass on all OSes, it is unlikely that a runtime build will pass on Linux, but fail on other OSes.
runs-on: ${{ fromJson(github.repository_owner == 'autonomys' &&
'"runs-on=${{ github.run_id }}-${{ github.run_attempt }}/runner=self-hosted-ubuntu-22.04-x86-64/extras=s3-cache${{ env.SPOT }}"' || '"ubuntu-22.04"') }}
steps:
- uses: runs-on/action@cd2b598b0515d39d78c38a02d529db87d2196d1e # v2.0.3
with:
sccache: 's3'
- uses: mozilla-actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9
if: github.repository_owner == 'autonomys'
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Configure tool cache
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
id: tool-cache
with:
path: '~/**/_tool'
key: ${{ runner.os }}-tool-${{ hashFiles('./rust-toolchain.toml') }}
- name: Install Protoc
uses: arduino/setup-protoc@c65c819552d16ad3c9b72d9dfd5ba5237b9c906b # v3.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure source deps cache
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: |
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
key: ${{ runner.os }}-cargo-${{ hashFiles('./Cargo.toml') }}
- name: build subspace-runtime
run: |
cargo -Zgitoxide -Zgit build --locked --package subspace-runtime
- name: build evm-domain-runtime
run: |
cargo -Zgitoxide -Zgit build --locked --package evm-domain-runtime
- name: build auto-id-domain-runtime
run: |
cargo -Zgitoxide -Zgit build --locked --package auto-id-domain-runtime
cargo-test:
name: cargo-test (${{ strategy.job-index == 0 && 'Linux x86-64' || (strategy.job-index == 1 && 'Windows x86-64' || 'macOS arm64') }})
strategy:
matrix:
os: ${{ fromJson(github.repository_owner == 'autonomys' &&
'[
"runs-on=${{ github.run_id }}-${{ github.run_attempt }}/runner=self-hosted-ubuntu-22.04-x86-64/extras=s3-cache${{ env.SPOT }}",
["self-hosted", "windows-server-2022-x86-64"],
["self-hosted", "macos-14-arm64"]
]' ||
'["ubuntu-22.04", "windows-2022", "macos-14"]') }}
runs-on: ${{ matrix.os }}
# Don't use the full 6 hours if a test hangs
timeout-minutes: 120
steps:
- uses: runs-on/action@cd2b598b0515d39d78c38a02d529db87d2196d1e # v2.0.3
with:
sccache: ${{ runner.os == 'Linux' && 's3' || '' }}
- uses: mozilla-actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9
if: runner.os == 'Linux' && github.repository_owner == 'autonomys'
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
# On macOS, we need a proper Clang version, not Apple's custom version without wasm32 support
- name: Install LLVM and Clang for macOS
uses: KyleMayes/install-llvm-action@dec985c8d7b46a2f363ea1a78f660c946a3349ea # v2.0.1
with:
env: true
version: 17
if: runner.os == 'macOS'
# Because macOS, see https://andreasfertig.blog/2021/02/clang-and-gcc-on-macos-catalina-finding-the-include-paths/
- name: Configure C compiler macOS
run: |
echo "SDKROOT=$(xcrun --show-sdk-path)" >> $GITHUB_ENV
if: runner.os == 'macOS'
- name: Install glibtoolize (macOS)
run: brew install libtool
if: runner.os == 'macOS'
- name: Configure tool cache
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
id: tool-cache
with:
path: '~/**/_tool'
key: ${{ runner.os }}-tool-${{ hashFiles('./rust-toolchain.toml') }}
if: runner.os != 'Windows'
- name: Install Protoc
uses: arduino/setup-protoc@c65c819552d16ad3c9b72d9dfd5ba5237b9c906b # v3.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
# Needed for hwloc
- name: Install automake (macOS)
run: brew install automake
if: runner.os == 'macOS'
- name: Install cargo-nextest
uses: taiki-e/install-action@21517c4e721ab8b872d9b8e90828e584dcabe8e2 # 2.56.3
with:
tool: cargo-nextest
- name: Configure source deps cache
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: |
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
key: ${{ runner.os }}-cargo-${{ hashFiles('./Cargo.toml') }}
- name: cargo nextest run --locked
run: |
cargo -Zgitoxide -Zgit nextest run --locked
# Checks benchmark code generation, and runs each benchmark once.
# Fails if code generation fails, benchmarks panic, or generated weights are not valid Rust.
check-runtime-benchmarks:
name: check-runtime-benchmarks (Linux x86-64)
# We always run benchmarks on our Linux reference machine
runs-on: ${{ fromJson(github.repository_owner == 'autonomys' &&
'"runs-on=${{ github.run_id }}-${{ github.run_attempt }}/runner=self-hosted-ubuntu-22.04-x86-64/extras=s3-cache${{ env.SPOT }}"' || '"ubuntu-22.04"') }}
# Don't use the full 6 hours if a benchmark hangs
timeout-minutes: 120
steps:
- uses: runs-on/action@cd2b598b0515d39d78c38a02d529db87d2196d1e # v2.0.3
with:
sccache: 's3'
- uses: mozilla-actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9
if: github.repository_owner == 'autonomys'
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Configure tool cache
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
id: tool-cache
with:
path: '~/**/_tool'
key: ${{ runner.os }}-tool-${{ hashFiles('./rust-toolchain.toml') }}
- name: Install Protoc
uses: arduino/setup-protoc@c65c819552d16ad3c9b72d9dfd5ba5237b9c906b # v3.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure source deps cache
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: |
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
key: ${{ runner.os }}-cargo-${{ hashFiles('./Cargo.toml') }}
- name: runtime-benchmark.sh check
run: |
scripts/runtime-benchmark.sh check
# This job checks all crates individually, including no_std and other featureless builds.
# We need to check crates individually for missing features, because cargo does feature
# unification, which hides missing features when crates are built together.
cargo-check-individually:
name: cargo-check-individually (Linux x86-64)
# If clippy and tests pass on all OSes, it is unlikely that a crate build will pass on Linux but fail on other OSes.
runs-on: ${{ fromJson(github.repository_owner == 'autonomys' &&
'"runs-on=${{ github.run_id }}-${{ github.run_attempt }}/runner=self-hosted-ubuntu-22.04-x86-64/extras=s3-cache${{ env.SPOT }}"' || '"ubuntu-22.04"') }}
steps:
- uses: runs-on/action@cd2b598b0515d39d78c38a02d529db87d2196d1e # v2.0.3
with:
sccache: 's3'
- uses: mozilla-actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9
if: github.repository_owner == 'autonomys'
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Configure tool cache
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
id: tool-cache
with:
path: '~/**/_tool'
key: ${{ runner.os }}-tool-${{ hashFiles('./rust-toolchain.toml') }}
- name: Install Protoc
uses: arduino/setup-protoc@c65c819552d16ad3c9b72d9dfd5ba5237b9c906b # v3.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure source deps cache
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: |
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
key: ${{ runner.os }}-cargo-${{ hashFiles('./Cargo.toml') }}
- name: check all crates individually
run: |
scripts/check-crates-individually.sh
# This job checks for incorrectly added dependencies, or dependencies that were made unused by code changes.
cargo-unused-deps:
name: cargo-unused-deps (Linux x86-64)
# We need to use Linux to check GPU dependencies (or Windows, but it's slow)
runs-on: ${{ fromJson(github.repository_owner == 'autonomys' &&
'"runs-on=${{ github.run_id }}-${{ github.run_attempt }}/runner=self-hosted-ubuntu-22.04-x86-64/extras=s3-cache${{ env.SPOT }}"' || '"ubuntu-22.04"') }}
steps:
- uses: runs-on/action@cd2b598b0515d39d78c38a02d529db87d2196d1e # v2.0.3
with:
sccache: 's3'
- uses: mozilla-actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9
if: github.repository_owner == 'autonomys'
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Configure tool cache
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
id: tool-cache
with:
path: '~/**/_tool'
key: ${{ runner.os }}-tool-${{ hashFiles('./rust-toolchain.toml') }}
- name: Install Protoc
uses: arduino/setup-protoc@c65c819552d16ad3c9b72d9dfd5ba5237b9c906b # v3.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: CUDA toolchain
uses: Jimver/cuda-toolkit@4bd727d5619dc6fa323b1e76c3aa5dca94f5ec6d # v0.2.19
with:
cuda: '12.4.1'
method: network
sub-packages: '["nvcc", "cudart"]'
- name: ROCm toolchain
run: |
ROCM_VERSION=6.2.2
sudo mkdir -p --mode=0755 /etc/apt/keyrings
curl -L https://repo.radeon.com/rocm/rocm.gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/rocm.gpg > /dev/null
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/rocm/apt/$ROCM_VERSION jammy main" | sudo tee /etc/apt/sources.list.d/rocm.list > /dev/null
echo -e "Package: *\nPin: release o=repo.radeon.com\nPin-Priority: 600" | sudo tee /etc/apt/preferences.d/rocm-pin-600 > /dev/null
sudo apt-get update
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y --no-install-recommends rocm-hip-runtime-dev
echo "/opt/rocm/lib" | sudo tee /etc/ld.so.conf.d/rocm.conf > /dev/null
sudo ldconfig
- name: Install cargo-udeps
uses: taiki-e/install-action@21517c4e721ab8b872d9b8e90828e584dcabe8e2 # 2.56.3
with:
tool: cargo-udeps
- name: Configure source deps cache
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: |
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
key: ${{ runner.os }}-cargo-${{ hashFiles('./Cargo.toml') }}
# If this check fails, check the new dependency is actually needed. If it is, try adding any
# new features to MOST_FEATURES in the script. If that doesn't work, add an exception to the
# crate:
# <https://github.com/est31/cargo-udeps?tab=readme-ov-file#ignoring-some-of-the-dependencies>
- name: check for unused dependencies
run: |
./scripts/find-unused-deps.sh
rust-all:
# Hack for buggy GitHub Actions behavior with skipped checks: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/troubleshooting-required-status-checks#handling-skipped-but-required-checks
if: ${{ always() }}
runs-on: ubuntu-24.04
needs:
- cargo-fmt
- cargo-clippy
- cargo-runtime-build
- cargo-test
- check-runtime-benchmarks
- cargo-check-individually
- cargo-unused-deps
steps:
- name: Check job statuses
# Another hack is to actually check the status of the dependencies or else it'll fall through
run: |
echo "Checking statuses..."
[[ "${{ needs.cargo-fmt.result }}" == "success" ]] || exit 1
[[ "${{ needs.cargo-clippy.result }}" == "success" ]] || exit 1
[[ "${{ needs.cargo-runtime-build.result }}" == "success" ]] || exit 1
[[ "${{ needs.cargo-test.result }}" == "success" ]] || exit 1
[[ "${{ needs.check-runtime-benchmarks.result }}" == "success" ]] || exit 1
[[ "${{ needs.cargo-check-individually.result }}" == "success" ]] || exit 1
[[ "${{ needs.cargo-unused-deps.result }}" == "success" ]] || exit 1