From 3ab9d1a4bf3d360fbc02b4288d409e3ca8fc1cda Mon Sep 17 00:00:00 2001 From: noah Date: Tue, 13 Oct 2026 11:13:39 -0600 Subject: [PATCH] Initialize Alkane OS target matrix and release gates --- .gitea/workflows/main.yml | 42 +++ .gitea/workflows/next.yml | 30 ++ .gitignore | 4 + Cargo.lock | 7 + Cargo.toml | 14 + LICENSE | 22 ++ README.md | 36 ++ ci/check-conformance.py | 33 ++ ci/conformance.json | 763 ++++++++++++++++++++++++++++++++++++++ ci/release.py | 55 +++ ci/version-x.txt | 1 + ci/version.py | 56 +++ src/lib.rs | 225 +++++++++++ tests/bench.rs | 32 ++ 14 files changed, 1320 insertions(+) create mode 100644 .gitea/workflows/main.yml create mode 100644 .gitea/workflows/next.yml create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 ci/check-conformance.py create mode 100644 ci/conformance.json create mode 100644 ci/release.py create mode 100644 ci/version-x.txt create mode 100644 ci/version.py create mode 100644 src/lib.rs create mode 100644 tests/bench.rs diff --git a/.gitea/workflows/main.yml b/.gitea/workflows/main.yml new file mode 100644 index 0000000..08389c6 --- /dev/null +++ b/.gitea/workflows/main.yml @@ -0,0 +1,42 @@ +name: main-release-gate + +on: + push: + branches: [main] + +jobs: + verify-and-release: + runs-on: alkane-ci + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Formatting + run: cargo fmt --check + - name: Quality + run: cargo clippy --all-targets --locked -- -D warnings + - name: Build + run: cargo build --release --locked + - name: Unit and workflow tests + run: cargo test --locked + - name: Microbenchmarks + run: | + set -o pipefail + cargo test --release --locked -- --ignored --nocapture | tee bench-current.txt + - name: Pairing and simulator conformance + run: python3 ci/check-conformance.py + - name: Select release version + id: version + run: python3 ci/version.py main >> "$GITHUB_OUTPUT" + - name: Package source and benchmark result + if: steps.version.outputs.release == 'true' + run: | + mkdir -p dist + git archive --format=tar.gz --output="dist/alkane-os-${{ steps.version.outputs.version }}-source.tar.gz" HEAD + cp bench-current.txt dist/ + - name: Create private release + if: steps.version.outputs.release == 'true' + env: + GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: python3 ci/release.py "${{ steps.version.outputs.tag }}" false "dist/alkane-os-${{ steps.version.outputs.version }}-source.tar.gz" dist/bench-current.txt + diff --git a/.gitea/workflows/next.yml b/.gitea/workflows/next.yml new file mode 100644 index 0000000..9fc446d --- /dev/null +++ b/.gitea/workflows/next.yml @@ -0,0 +1,30 @@ +name: next-build + +on: + push: + branches: [next] + +jobs: + build: + runs-on: alkane-ci + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Build release candidate + run: cargo build --release --locked + - name: Select candidate version + id: version + run: python3 ci/version.py next >> "$GITHUB_OUTPUT" + - name: Package source and build output + if: steps.version.outputs.release == 'true' + run: | + mkdir -p dist + git archive --format=tar.gz --output="dist/alkane-os-${{ steps.version.outputs.version }}-source.tar.gz" HEAD + cp target/release/libalkane_os.rlib dist/ + - name: Create private prerelease + if: steps.version.outputs.release == 'true' + env: + GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: python3 ci/release.py "${{ steps.version.outputs.tag }}" true "dist/alkane-os-${{ steps.version.outputs.version }}-source.tar.gz" + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d28e7bb --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/target/ +/dist/ +/coverage/ +__pycache__/ diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..51393bb --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "alkane-os" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..5ade4d7 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "alkane-os" +version = "0.1.0" +edition = "2021" +license = "MIT" +description = "Portable mining and tuning core for Alkane control boards" + +[lib] +name = "alkane_os" + +[profile.release] +lto = true +codegen-units = 1 + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1fa324f --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) 2026 BlueFlare + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..7966027 --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +# Alkane OS + +Portable mining, tuning, and management logic for Alkane control boards. The +source is MIT licensed. `alkane-sdk` owns the board images and supplies the +hardware backend at build time. This repository has no on-board web frontend; +the intended management surfaces are SSH, cgminer-compatible port 4028, and a +minimal API. + +## Status + +This is the initial interface and release tooling. It does not mine yet. A +target in the matrix is an obligation to implement and validate, not a claim +of support. All 64 theoretical same-vendor controller/chip pairings are in +scope: 52 Bitmain and 12 WhatsMiner. For pairings a stock image rejects, the +simulator must record the first genuine rejection gate and Alkane OS must mine. +No live board is required by CI. Bench devices supply captures and independent +validation of the simulator. + +The `main` branch has full tests and a conformance gate; releases are created +only after every required cell passes. `next` runs a build check and produces +release candidates. `ci/version-x.txt` is the manually edited major version. +For this repository, Y changes when the mining protocol, HAL contract, tuning +policy or API changes; Z changes for compatible fixes and packaging updates. + +## Local checks + +```sh +cargo fmt --check +cargo clippy --all-targets -- -D warnings +cargo test +python3 ci/check-conformance.py +``` + +The last command currently fails because simulator and device evidence are +still pending. It is a release gate, not a unit test. + diff --git a/ci/check-conformance.py b/ci/check-conformance.py new file mode 100644 index 0000000..33798fa --- /dev/null +++ b/ci/check-conformance.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 +"""Fail the final release gate until every target has traceable evidence.""" + +import json +import pathlib +import sys + +manifest = json.loads(pathlib.Path("ci/conformance.json").read_text()) +rows = manifest["targets"] +expected = {(board, chip) for board in manifest["boards"] for chip in manifest["chips"] + if manifest["vendors"][board] == manifest["vendors"][chip]} +actual = {(row["board"], row["chip"]) for row in rows} +if actual != expected or len(rows) != len(expected): + sys.exit(f"matrix mismatch: {len(actual)} present, {len(expected)} expected") + +required = ("sdk_image_sha256", "stock_image_sha256", "stock_result", + "alkane_share_accept_capture", "simulator_trace_sha256", + "bench_validation") +incomplete = [] +for row in rows: + missing = [field for field in required if not row.get(field)] + if row.get("stock_result") not in (None, "mines", "rejects"): + missing.append("stock_result invalid") + if row.get("stock_result") == "rejects" and not row.get("stock_first_rejection"): + missing.append("stock_first_rejection") + if missing: + incomplete.append((row["board"], row["chip"], missing)) +if incomplete: + print(f"Conformance pending: {len(incomplete)}/{len(rows)} targets") + for board, chip, missing in incomplete[:8]: + print(f" {board} x {chip}: {', '.join(missing)}") + sys.exit(1) +print(f"Conformance complete: {len(rows)} targets") diff --git a/ci/conformance.json b/ci/conformance.json new file mode 100644 index 0000000..fb29f01 --- /dev/null +++ b/ci/conformance.json @@ -0,0 +1,763 @@ +{ + "schema": 1, + "boards": [ + "am335x-bb", + "zynq-7010", + "cv1835", + "a113d", + "allwinner-h3", + "allwinner-h6", + "allwinner-h616" + ], + "chips": [ + "BM1384", + "BM1387", + "BM1360", + "BM1362", + "BM1366", + "BM1368", + "BM1370", + "BM1396", + "BM1397", + "BM1398", + "BM1489", + "BM1491", + "BM1746", + "KF1950", + "ID-1968", + "ID-1980", + "ID-1990" + ], + "vendors": { + "am335x-bb": "bitmain", + "zynq-7010": "bitmain", + "cv1835": "bitmain", + "a113d": "bitmain", + "allwinner-h3": "whatsminer", + "allwinner-h6": "whatsminer", + "allwinner-h616": "whatsminer", + "BM1384": "bitmain", + "BM1387": "bitmain", + "BM1360": "bitmain", + "BM1362": "bitmain", + "BM1366": "bitmain", + "BM1368": "bitmain", + "BM1370": "bitmain", + "BM1396": "bitmain", + "BM1397": "bitmain", + "BM1398": "bitmain", + "BM1489": "bitmain", + "BM1491": "bitmain", + "BM1746": "bitmain", + "KF1950": "whatsminer", + "ID-1968": "whatsminer", + "ID-1980": "whatsminer", + "ID-1990": "whatsminer" + }, + "targets": [ + { + "board": "am335x-bb", + "chip": "BM1384", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "am335x-bb", + "chip": "BM1387", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "am335x-bb", + "chip": "BM1360", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "am335x-bb", + "chip": "BM1362", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "am335x-bb", + "chip": "BM1366", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "am335x-bb", + "chip": "BM1368", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "am335x-bb", + "chip": "BM1370", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "am335x-bb", + "chip": "BM1396", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "am335x-bb", + "chip": "BM1397", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "am335x-bb", + "chip": "BM1398", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "am335x-bb", + "chip": "BM1489", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "am335x-bb", + "chip": "BM1491", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "am335x-bb", + "chip": "BM1746", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "zynq-7010", + "chip": "BM1384", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "zynq-7010", + "chip": "BM1387", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "zynq-7010", + "chip": "BM1360", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "zynq-7010", + "chip": "BM1362", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "zynq-7010", + "chip": "BM1366", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "zynq-7010", + "chip": "BM1368", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "zynq-7010", + "chip": "BM1370", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "zynq-7010", + "chip": "BM1396", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "zynq-7010", + "chip": "BM1397", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "zynq-7010", + "chip": "BM1398", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "zynq-7010", + "chip": "BM1489", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "zynq-7010", + "chip": "BM1491", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "zynq-7010", + "chip": "BM1746", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "cv1835", + "chip": "BM1384", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "cv1835", + "chip": "BM1387", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "cv1835", + "chip": "BM1360", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "cv1835", + "chip": "BM1362", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "cv1835", + "chip": "BM1366", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "cv1835", + "chip": "BM1368", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "cv1835", + "chip": "BM1370", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "cv1835", + "chip": "BM1396", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "cv1835", + "chip": "BM1397", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "cv1835", + "chip": "BM1398", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "cv1835", + "chip": "BM1489", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "cv1835", + "chip": "BM1491", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "cv1835", + "chip": "BM1746", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "a113d", + "chip": "BM1384", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "a113d", + "chip": "BM1387", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "a113d", + "chip": "BM1360", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "a113d", + "chip": "BM1362", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "a113d", + "chip": "BM1366", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "a113d", + "chip": "BM1368", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "a113d", + "chip": "BM1370", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "a113d", + "chip": "BM1396", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "a113d", + "chip": "BM1397", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "a113d", + "chip": "BM1398", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "a113d", + "chip": "BM1489", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "a113d", + "chip": "BM1491", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "a113d", + "chip": "BM1746", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "allwinner-h3", + "chip": "KF1950", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "allwinner-h3", + "chip": "ID-1968", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "allwinner-h3", + "chip": "ID-1980", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "allwinner-h3", + "chip": "ID-1990", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "allwinner-h6", + "chip": "KF1950", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "allwinner-h6", + "chip": "ID-1968", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "allwinner-h6", + "chip": "ID-1980", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "allwinner-h6", + "chip": "ID-1990", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "allwinner-h616", + "chip": "KF1950", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "allwinner-h616", + "chip": "ID-1968", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "allwinner-h616", + "chip": "ID-1980", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + }, + { + "board": "allwinner-h616", + "chip": "ID-1990", + "sdk_image_sha256": null, + "stock_image_sha256": null, + "stock_result": null, + "stock_first_rejection": null, + "alkane_share_accept_capture": null, + "simulator_trace_sha256": null, + "bench_validation": null + } + ] +} diff --git a/ci/release.py b/ci/release.py new file mode 100644 index 0000000..5e324cd --- /dev/null +++ b/ci/release.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +"""Create one Gitea release and attach files using the runner's scoped token.""" + +import json +import os +import pathlib +import sys +import urllib.error +import urllib.parse +import urllib.request + + +def request(url, payload, content_type): + headers = { + "Authorization": "token " + os.environ["GITEA_TOKEN"], + "Content-Type": content_type, + } + req = urllib.request.Request(url, data=payload, headers=headers, method="POST") + with urllib.request.urlopen(req, timeout=60) as response: + return json.load(response) + + +def main(): + if len(sys.argv) < 4: + sys.exit("usage: release.py TAG PRERELEASE FILE [FILE ...]") + tag, prerelease, *files = sys.argv[1:] + api = os.environ.get("GITHUB_API_URL", "https://gitea.bluefla.re/api/v1").rstrip("/") + repo = os.environ["GITHUB_REPOSITORY"] + sha = os.environ["GITHUB_SHA"] + body = f"Automated Alkane OS build from {sha}. Conformance results are in the repository." + metadata = { + "tag_name": tag, + "target_commitish": sha, + "name": tag, + "body": body, + "prerelease": prerelease.lower() == "true", + } + try: + release = request(f"{api}/repos/{repo}/releases", json.dumps(metadata).encode(), "application/json") + except urllib.error.HTTPError as exc: + sys.exit(f"release creation failed: HTTP {exc.code}") + release_id = release["id"] + for name in files: + path = pathlib.Path(name) + query = urllib.parse.urlencode({"name": path.name}) + try: + request(f"{api}/repos/{repo}/releases/{release_id}/assets?{query}", + path.read_bytes(), "application/octet-stream") + except urllib.error.HTTPError as exc: + sys.exit(f"asset upload failed for {path.name}: HTTP {exc.code}") + print(f"Created {tag} with {len(files)} assets") + + +if __name__ == "__main__": + main() diff --git a/ci/version-x.txt b/ci/version-x.txt new file mode 100644 index 0000000..573541a --- /dev/null +++ b/ci/version-x.txt @@ -0,0 +1 @@ +0 diff --git a/ci/version.py b/ci/version.py new file mode 100644 index 0000000..4f66d5e --- /dev/null +++ b/ci/version.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +"""Select a release tag from Git history. The major version is manual.""" + +import argparse +import pathlib +import re +import subprocess + + +def git(*args): + return subprocess.check_output(["git", *args], text=True).strip() + + +def versions(branch): + suffix = r"" if branch == "main" else r"-rc\.(\d+)" + pattern = re.compile(r"^v(\d+)\.(\d+)\.(\d+)" + suffix + r"$") + result = [] + for tag in git("tag", "-l", "v*").splitlines(): + match = pattern.fullmatch(tag) + if match: + result.append((tuple(map(int, match.groups())), tag)) + return sorted(result) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("branch", choices=("main", "next")) + args = parser.parse_args() + major = int(pathlib.Path("ci/version-x.txt").read_text().strip()) + finals = versions("main") + previous = finals[-1] if finals else None + if previous and previous[0][0] > major: + raise SystemExit("manual major version is behind the latest release") + if previous and previous[0][0] == major: + _, minor, patch = previous[0] + changed = git("diff", "--name-only", previous[1], "HEAD").splitlines() + if not changed: + print("release=false") + return + feature = any(path.startswith("src/") or path == "Cargo.toml" for path in changed) + minor, patch = (minor + 1, 0) if feature else (minor, patch + 1) + else: + minor, patch = (1, 0) if major == 0 else (0, 0) + base = f"v{major}.{minor}.{patch}" + if args.branch == "next": + candidates = [parts[0][3] for parts in versions("next") if parts[0][:3] == (major, minor, patch)] + tag = f"{base}-rc.{max(candidates, default=0) + 1}" + else: + tag = base + print("release=true") + print(f"tag={tag}") + print(f"version={tag[1:]}") + + +if __name__ == "__main__": + main() diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..84a2315 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,225 @@ +//! Board independent policy and hardware interfaces for Alkane OS. +//! +//! An entry in the target matrix is a development obligation, not a claim that +//! the pairing already mines. Hardware backends are supplied by SDK images. + +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub enum Vendor { + Bitmain, + Whatsminer, +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub enum Algorithm { + Sha256, + Scrypt, + Equihash, +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub struct ControlBoard { + pub id: &'static str, + pub vendor: Vendor, +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub struct HashChip { + pub id: &'static str, + pub vendor: Vendor, + pub algorithm: Algorithm, +} + +pub const CONTROL_BOARDS: [ControlBoard; 7] = [ + ControlBoard { + id: "am335x-bb", + vendor: Vendor::Bitmain, + }, + ControlBoard { + id: "zynq-7010", + vendor: Vendor::Bitmain, + }, + ControlBoard { + id: "cv1835", + vendor: Vendor::Bitmain, + }, + ControlBoard { + id: "a113d", + vendor: Vendor::Bitmain, + }, + ControlBoard { + id: "allwinner-h3", + vendor: Vendor::Whatsminer, + }, + ControlBoard { + id: "allwinner-h6", + vendor: Vendor::Whatsminer, + }, + ControlBoard { + id: "allwinner-h616", + vendor: Vendor::Whatsminer, + }, +]; + +pub const HASH_CHIPS: [HashChip; 17] = [ + HashChip { + id: "BM1384", + vendor: Vendor::Bitmain, + algorithm: Algorithm::Sha256, + }, + HashChip { + id: "BM1387", + vendor: Vendor::Bitmain, + algorithm: Algorithm::Sha256, + }, + HashChip { + id: "BM1360", + vendor: Vendor::Bitmain, + algorithm: Algorithm::Sha256, + }, + HashChip { + id: "BM1362", + vendor: Vendor::Bitmain, + algorithm: Algorithm::Sha256, + }, + HashChip { + id: "BM1366", + vendor: Vendor::Bitmain, + algorithm: Algorithm::Sha256, + }, + HashChip { + id: "BM1368", + vendor: Vendor::Bitmain, + algorithm: Algorithm::Sha256, + }, + HashChip { + id: "BM1370", + vendor: Vendor::Bitmain, + algorithm: Algorithm::Sha256, + }, + HashChip { + id: "BM1396", + vendor: Vendor::Bitmain, + algorithm: Algorithm::Sha256, + }, + HashChip { + id: "BM1397", + vendor: Vendor::Bitmain, + algorithm: Algorithm::Sha256, + }, + HashChip { + id: "BM1398", + vendor: Vendor::Bitmain, + algorithm: Algorithm::Sha256, + }, + HashChip { + id: "BM1489", + vendor: Vendor::Bitmain, + algorithm: Algorithm::Scrypt, + }, + HashChip { + id: "BM1491", + vendor: Vendor::Bitmain, + algorithm: Algorithm::Scrypt, + }, + HashChip { + id: "BM1746", + vendor: Vendor::Bitmain, + algorithm: Algorithm::Equihash, + }, + HashChip { + id: "KF1950", + vendor: Vendor::Whatsminer, + algorithm: Algorithm::Sha256, + }, + HashChip { + id: "ID-1968", + vendor: Vendor::Whatsminer, + algorithm: Algorithm::Sha256, + }, + HashChip { + id: "ID-1980", + vendor: Vendor::Whatsminer, + algorithm: Algorithm::Sha256, + }, + HashChip { + id: "ID-1990", + vendor: Vendor::Whatsminer, + algorithm: Algorithm::Sha256, + }, +]; + +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub struct Target { + pub control: ControlBoard, + pub chip: HashChip, +} + +impl Target { + pub fn new(control: ControlBoard, chip: HashChip) -> Option { + (control.vendor == chip.vendor).then_some(Self { control, chip }) + } +} + +/// Every same-vendor theoretical pairing is in scope for Alkane OS. +pub fn target_matrix() -> impl Iterator { + CONTROL_BOARDS.into_iter().flat_map(|control| { + HASH_CHIPS + .into_iter() + .filter_map(move |chip| Target::new(control, chip)) + }) +} + +/// Hardware operations implemented by a board backend in the SDK image. +/// The methods deliberately expose no assumed UART, FPGA or Bitmicro layout. +pub trait HardwareBackend { + type Error; + + fn send_frame(&mut self, chain: u8, frame: &[u8]) -> Result<(), Self::Error>; + fn receive_frame(&mut self, chain: u8, frame: &mut [u8]) -> Result; + fn set_chain_reset(&mut self, chain: u8, asserted: bool) -> Result<(), Self::Error>; + fn set_fan_target(&mut self, fan: u8, percent: u8) -> Result<(), Self::Error>; + fn read_temperature_mc(&mut self, sensor: u8) -> Result; + fn set_psu_enabled(&mut self, enabled: bool) -> Result<(), Self::Error>; +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub enum PowerDecision { + Hold, + Stop, +} + +/// A safe starting policy: no hashing while temperature is unknown or unsafe. +/// Board-specific thresholds will come from measured, revision-specific data. +pub fn power_decision(temperature_mc: Option, max_mc: i32) -> PowerDecision { + match temperature_mc { + Some(value) if value < max_mc => PowerDecision::Hold, + _ => PowerDecision::Stop, + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn all_theoretical_same_vendor_targets_are_included() { + let targets: Vec<_> = target_matrix().collect(); + assert_eq!(targets.len(), 4 * 13 + 3 * 4); + assert!(targets.iter().all(|t| t.control.vendor == t.chip.vendor)); + for control in CONTROL_BOARDS { + for chip in HASH_CHIPS { + assert_eq!( + targets.contains(&Target { control, chip }), + control.vendor == chip.vendor + ); + } + } + } + + #[test] + fn unknown_or_hot_sensor_stops_power() { + assert_eq!(power_decision(None, 80_000), PowerDecision::Stop); + assert_eq!(power_decision(Some(80_000), 80_000), PowerDecision::Stop); + assert_eq!(power_decision(Some(79_999), 80_000), PowerDecision::Hold); + } +} diff --git a/tests/bench.rs b/tests/bench.rs new file mode 100644 index 0000000..2b8551b --- /dev/null +++ b/tests/bench.rs @@ -0,0 +1,32 @@ +use alkane_os::{power_decision, target_matrix}; +use std::hint::black_box; +use std::time::Instant; + +fn measure(name: &str, iterations: u64, mut f: impl FnMut()) { + let started = Instant::now(); + for _ in 0..iterations { + f(); + } + let ns = started.elapsed().as_nanos() as f64 / iterations as f64; + println!("BENCH {name} {ns:.3} ns/op"); +} + +#[test] +#[ignore = "microbenchmark"] +fn bench_target_matrix() { + measure("target_matrix", 20_000, || { + black_box( + target_matrix() + .filter(|target| black_box(target.chip.algorithm) == alkane_os::Algorithm::Sha256) + .count(), + ); + }); +} + +#[test] +#[ignore = "microbenchmark"] +fn bench_power_policy() { + measure("power_policy", 100_000, || { + black_box(power_decision(black_box(Some(64_000)), 80_000)); + }); +}