ant-node 0.24.0

Pure quantum-proof network node for the Autonomi decentralized network
Documentation
name: CI

on:
  pull_request:
    branches: [main, "rc-*"]

# A new push to a PR cancels the run still going for the previous push, so a
# superseded commit doesn't keep ~200 job-minutes of runners busy.
concurrency:
  group: ci-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

env:
  CARGO_TERM_COLOR: always
  RUSTFLAGS: "-D warnings"
  FOUNDRY_VERSION: v1.7.1

# Layout (V2-1811). Each piece of work runs once, in the job that needs that
# build, and `CI Gate` is the single "is this PR green" check:
#   quick-checks   fmt, clippy, docs, the no-default-features lib check
#   msrv           the declared minimum toolchain
#   notices        THIRD-PARTY-NOTICES.txt generation
#   test (3 OS)    every lib, bin and integration test target; Linux also runs
#                  the doc tests, the ignored five-node devnet test and the lib
#                  tests without default features
#   filesystems    the storage tests on ext4, XFS and btrfs
#   build-release  the shipped Linux binary, built exactly as release.yml does
jobs:
  quick-checks:
    name: Quick checks
    runs-on: ubuntu-latest
    timeout-minutes: 25
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy
      - uses: Swatinem/rust-cache@v2
      - name: Format
        run: cargo fmt --all -- --check
      - name: Clippy
        run: cargo clippy --all-targets --all-features -- -D warnings
      # Compile without cfg(test) too: browser unit tests can otherwise hide
      # unused helpers whose production callers require webrtc-direct.
      - name: Check library without default features
        run: cargo check --lib --no-default-features --locked
      - name: Documentation
        run: cargo doc --all-features --no-deps
        env:
          RUSTDOCFLAGS: "-D warnings"

  msrv:
    name: Rust 1.95 MSRV
    runs-on: ubuntu-latest
    timeout-minutes: 20
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@1.95.0
      - uses: Swatinem/rust-cache@v2
      - run: cargo check --all-targets --all-features --locked

  # The release workflow ships THIRD-PARTY-NOTICES.txt in every archive.
  # Generating it on each pull request catches a dependency that ships no
  # licence text, or a new crate that compiles bundled C code, before release.
  notices:
    name: Third-party notices
    runs-on: ubuntu-latest
    timeout-minutes: 20
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: actions/setup-python@v5
        with:
          python-version: "3.12"
      - name: Generate THIRD-PARTY-NOTICES.txt
        env:
          GITHUB_TOKEN: ${{ github.token }}
        run: >-
          python scripts/third_party_notices/generate.py
          --config scripts/third_party_notices/config.toml
          --output THIRD-PARTY-NOTICES.txt
          --target x86_64-unknown-linux-musl
          --target aarch64-unknown-linux-musl
          --target x86_64-apple-darwin
          --target aarch64-apple-darwin
          --target x86_64-pc-windows-msvc

  test:
    name: Test (${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    timeout-minutes: 90
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - name: Install Foundry
        uses: foundry-rs/foundry-toolchain@v1
        with:
          version: ${{ env.FOUNDRY_VERSION }}
      - name: Unit tests (lib and bins)
        run: cargo test --lib --bins --features test-utils
      # Build every integration test binary in one cargo invocation, so they compile
      # and link in parallel. When each target was built in its own step, each spent
      # 2-5 minutes building its binary for tests that finish in under a second.
      - name: Build integration test binaries
        shell: bash
        run: cargo test --test '*' --features test-utils --no-run
      # Every integration target Cargo knows about, read from `cargo metadata`,
      # so a new tests/*.rs runs without anyone editing this file. Each target
      # runs on its own, serially, and must pass at least one test: a target
      # whose required features are not passed is skipped with a warning and a
      # zero exit, and a cfg can compile a target down to nothing, so "exit 0"
      # alone doesn't show that anything ran. All targets run even after one
      # fails, and the step fails at the end listing them.
      - name: Integration tests (every target)
        shell: bash
        run: |
          # GitHub runs `shell: bash` with -e; turn it off so one failing target
          # doesn't stop the rest from running.
          set +e -uo pipefail
          targets=$(cargo metadata --no-deps --format-version 1 \
            | jq -r '.packages[] | select(.name == "ant-node") | .targets[] | select(.kind | index("test")) | .name' | tr -d '\r')
          echo "integration targets: $(echo $targets)"
          [ -n "$targets" ] || { echo "cargo metadata listed no integration targets"; exit 1; }
          failed=""
          for t in $targets; do
            extra=""
            if [ "$t" = devnet_lifecycle ] && [ "$RUNNER_OS" = Windows ]; then
              # It stops ant-devnet with SIGTERM and SIGKILL, so it is Unix
              # only, and compiles to nothing on Windows.
              echo "skipping $t on $RUNNER_OS (Unix only)"
              continue
            fi
            if [ "$t" = storage_scale ]; then
              # Its gates compare the store scan against timed directory walks, and
              # were measured on Linux; it has only ever run there.
              if [ "$RUNNER_OS" != Linux ]; then
                echo "skipping $t on $RUNNER_OS (Linux only)"
                continue
              fi
              # Prints the measured index memory and inode cost, which is the point of it.
              extra="--nocapture"
            fi
            echo "::group::$t"
            cargo test --test "$t" --features test-utils -- --test-threads=1 $extra 2>&1 | tee "/tmp/$t.log"
            status=${PIPESTATUS[0]}
            echo "::endgroup::"
            if [ "$status" -ne 0 ]; then
              failed="$failed $t"
            elif ! grep -qE 'test result: ok\. [1-9][0-9]* passed' "/tmp/$t.log"; then
              echo "::error::$t ran no tests"
              failed="$failed $t(ran-nothing)"
            fi
          done
          if [ -n "$failed" ]; then
            echo "::error::failing integration targets:$failed"
            exit 1
          fi
      - name: Doc tests
        if: runner.os == 'Linux'
        run: cargo test --doc --all-features
      - name: WebRTC Direct five-node devnet (ignored by default)
        if: runner.os == 'Linux'
        run: >-
          cargo test --test webrtc_direct_devnet --features test-utils
          -- --ignored --test-threads=1
      - name: Unit tests without default features (no logging, no webrtc-direct)
        if: runner.os == 'Linux'
        run: cargo test --lib --no-default-features
      # The run-directory tests that mount a tmpfs and bind mounts inside run
      # directories, make directories another user owns, or act as another
      # user. They need root, which the runner gives through sudo, so
      # `cargo test` alone skips them.
      - name: ant-devnet run directories against real mounts and other users
        if: runner.os == 'Linux'
        shell: bash
        run: |
          set -euo pipefail
          cargo test --lib --features test-utils with_sudo_ -- --ignored --test-threads=1 2>&1 | tee /tmp/run_dir_sudo.log
          grep -qE 'test result: ok\. [1-9]' /tmp/run_dir_sudo.log \
            || { echo 'the run-directory sudo tests ran nothing'; exit 1; }

  filesystems:
    name: Storage on ${{ matrix.fs }}
    runs-on: ubuntu-latest
    timeout-minutes: 25
    strategy:
      fail-fast: false
      matrix:
        fs: [ext4, xfs, btrfs]
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - name: Install the filesystem tools
        run: sudo apt-get update && sudo apt-get install -y xfsprogs btrfs-progs
      - name: Make a ${{ matrix.fs }} volume and mount it
        shell: bash
        run: |
          set -euo pipefail
          # A loopback image, so these run on a filesystem of the right kind rather than
          # on whatever the runner happens to give us. ext4 is what most of the fleet is
          # on; XFS and btrfs are the two the design reasons about separately, btrfs
          # because it has been observed reordering writes around a rename.
          # 3 GiB is ample: these tests use tens of MiB.
          truncate -s 3G /tmp/${{ matrix.fs }}.img
          mkfs.${{ matrix.fs }} -q /tmp/${{ matrix.fs }}.img
          sudo mkdir -p /mnt/antfs
          sudo mount -o loop /tmp/${{ matrix.fs }}.img /mnt/antfs
          sudo chown "$USER" /mnt/antfs
          df -hT /mnt/antfs
      # TMPDIR is what `TempDir::new` uses, so this puts every temporary store these tests
      # build on the mounted filesystem rather than on the runner's root.
      #
      # These used to be the migration harnesses. The migration is gone, and what is left
      # worth asking of a filesystem is what the store itself does on it: publish a chunk
      # through a temporary and a rename, flush the directory, unlink it again, and rebuild
      # an index from the names afterwards. The storage tests do all of that, and running
      # them here is what keeps ext4, XFS and btrfs covered now that the harnesses that used
      # to cover them have been deleted. They do not measure free space before and after;
      # the harness that did was about the migration and went with it.
      - name: Storage behaviour on ${{ matrix.fs }}
        env:
          TMPDIR: /mnt/antfs
        shell: bash
        run: |
          set -euo pipefail
          cargo test --lib --features test-utils storage:: 2>&1 | tee /tmp/storage.log
          grep -qE 'test result: ok\. [1-9]' /tmp/storage.log \
            || { echo 'the storage tests ran nothing'; exit 1; }

  # PR CI used to build `--release --no-default-features` on three OSes, a
  # configuration nobody ships. This builds the Linux x64 archive's binary the
  # way release.yml does (default features, musl, via cross), so a dependency
  # that breaks under musl or cross shows up on the PR rather than at the tag.
  # The test jobs already compile default features on macOS and Windows.
  build-release:
    name: Build release (x86_64-unknown-linux-musl)
    runs-on: ubuntu-22.04
    timeout-minutes: 45
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: x86_64-unknown-linux-musl
      - uses: Swatinem/rust-cache@v2
        with:
          key: x86_64-unknown-linux-musl
      - name: Install cross (as release.yml does)
        run: cargo install cross --git https://github.com/cross-rs/cross
      - name: Build
        run: cross build --release --target x86_64-unknown-linux-musl
      # The crash harness drives the store through a failpoint that parks the process
      # forever on an environment variable, and the store's own tests use the same one. It
      # is compiled only under `test-utils`, which is not a default feature and is not
      # passed by the release workflow, so a shipped binary does not contain it. This proves
      # that on the binary that ships rather than trusting it: the variable name is a string
      # literal, so it survives into the binary (stripping removes symbols, not string data)
      # whenever the code that reads it is compiled, and its absence is the absence of the
      # failpoint. The exact number is one per failpoint and is deliberately not asserted,
      # so that adding a failpoint does not fail this check.
      - name: The shipped binary carries no failpoint
        shell: bash
        run: |
          set -euo pipefail
          bin=target/x86_64-unknown-linux-musl/release/ant-node
          ls -la "$bin"
          found=$(strings -a "$bin" | grep -c 'ANT_HALT_' || true)
          if [ "$found" != "0" ]; then
            echo "the publish failpoint is compiled into the release build"
            exit 1
          fi
          echo "no failpoint in the release build"

  # Kept outside CI Gate until V2-1800 settles how advisories are handled: an
  # advisory comes from the RustSec database, not from the PR, so today this
  # reds every PR (RUSTSEC-2026-0387, V2-1743).
  security:
    name: Security Audit
    runs-on: ubuntu-latest
    timeout-minutes: 20
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - name: Install cargo-audit
        run: cargo install cargo-audit
      - name: Run security audit
        run: cargo audit

  # The single check that says whether a PR is green. It fails unless every job
  # it needs succeeded; a skipped or cancelled job counts as a failure.
  gate:
    name: CI Gate
    if: always()
    needs: [quick-checks, msrv, notices, test, filesystems, build-release]
    runs-on: ubuntu-latest
    timeout-minutes: 5
    steps:
      - name: Every required job succeeded
        env:
          NEEDS: ${{ toJSON(needs) }}
        run: |
          echo "$NEEDS" | jq -r 'to_entries[] | "\(.key): \(.value.result)"'
          echo "$NEEDS" | jq -e 'to_entries | all(.value.result == "success")' > /dev/null