Add simulator mining command to Alkane OS
next-build / build (push) Canceled after 0s

This commit is contained in:
2026-10-15 18:22:49 -06:00
parent 3d63bbb3eb
commit 0e6fd9269b
2 changed files with 76 additions and 6 deletions
+10 -4
View File
@@ -1,6 +1,6 @@
# Alkane OS
[![CI](https://gitea.bluefla.re/blueflare/alkane-os/raw/branch/ci-badges/next.svg)](https://gitea.bluefla.re/blueflare/alkane-os/actions)
[![CI](https://gitea.bluefla.re/blueflare/alkane-os/raw/branch/ci-badges/main.svg)](https://gitea.bluefla.re/blueflare/alkane-os/actions)
![tests](https://gitea.bluefla.re/blueflare/alkane-os/raw/branch/ci-badges/badges/tests.svg)
![coverage](https://gitea.bluefla.re/blueflare/alkane-os/raw/branch/ci-badges/badges/coverage.svg)
![bench](https://gitea.bluefla.re/blueflare/alkane-os/raw/branch/ci-badges/badges/bench.svg)
@@ -17,9 +17,9 @@ board.
## Status
This is a library and an early CLI, not a complete mining daemon. The CLI
lists target obligations with `alkane-os --list-targets`; it does not mine or
serve a network API. No production board backend or run loop is installed.
The CLI lists target obligations with `alkane-os --list-targets`. It can also
mine through the SDK simulator HAL and a Stratum V1 pool. No production board
backend or network management API is installed.
The library has a versioned Unix-socket HAL client, BM1366 mining-session
logic, Stratum V1 job and share handling, SHA-256d share checks for BM1362 and
@@ -38,6 +38,12 @@ matches Litecoin's
[block 29255 vector](https://github.com/litecoin-project/litecoin/wiki/Scrypt-proof-of-work);
BM1489/BM1491 report handling and L7/L9 mining remain open.
For a simulator HAL socket and a Stratum V1 pool, set `ALKANE_POOL_PASSWORD`
and run `alkane-os --mine-simulator HAL_SOCKET POOL_ADDRESS WORKER`. The
optional fourth argument stops after that many accepted shares. The command
uses the simulator's 80 C temperature limit and exits on a pool or hardware
fault. The SDK HAL server must cut power when its client stalls or disconnects.
## Release gate
All 64 theoretical same-vendor control-board/chip pairings are required:
+66 -2
View File
@@ -1,7 +1,65 @@
// SPDX-License-Identifier: MIT
use alkane_os::hal_wire::HalClient;
use alkane_os::miner::Bm1366Miner;
use alkane_os::stratum_client::{PoolConnection, PoolEvent};
use alkane_os::target_matrix;
use std::error::Error;
use std::io;
use std::net::SocketAddr;
use std::time::Duration;
fn sim_mine(mut args: impl Iterator<Item = String>) -> Result<(), Box<dyn Error>> {
let socket = args.next().ok_or("missing HAL socket")?;
let address: SocketAddr = args.next().ok_or("missing pool address")?.parse()?;
let worker = args.next().ok_or("missing pool worker")?;
let max_accepts: Option<u64> = args.next().map(|value| value.parse()).transpose()?;
if args.next().is_some() || worker.is_empty() || max_accepts == Some(0) {
return Err("invalid simulator mining arguments".into());
}
let password = std::env::var("ALKANE_POOL_PASSWORD")
.map_err(|_| "set ALKANE_POOL_PASSWORD in the environment")?;
// Connect to the pool before enabling power. The SDK HAL server owns the
// power lease and cuts power if this process stalls or disconnects.
let mut pool = PoolConnection::connect(
address,
concat!("alkane-os/", env!("CARGO_PKG_VERSION")),
&worker,
&password,
Duration::from_secs(2),
Duration::from_secs(5),
)
.map_err(|error| io::Error::other(format!("pool handshake: {error:?}")))?;
let mut backend = HalClient::connect(socket)?;
let mut miner = Bm1366Miner::new(&mut backend, 0, 0, 0, 100, 80_000)
.ok_or("invalid simulator safety configuration")?;
miner.start()?;
let mut accepted = 0_u64;
loop {
let (event, reports) = pool
.cycle(&mut miner)
.map_err(|error| io::Error::other(format!("mining cycle: {error:?}")))?;
match event {
PoolEvent::ShareAccepted(_) => {
accepted += 1;
if max_accepts == Some(accepted) {
miner.stop()?;
println!("simulator shares accepted: {accepted}");
return Ok(());
}
}
PoolEvent::ShareRejected(id) => eprintln!("pool rejected share request {id}"),
_ => {}
}
if matches!(event, PoolEvent::Idle) && reports.is_empty() {
std::thread::sleep(Duration::from_millis(10));
}
}
}
fn main() {
match std::env::args().nth(1).as_deref() {
let mut args = std::env::args().skip(1);
match args.next().as_deref() {
Some("--list-targets") => {
println!("control_board,hash_chip,algorithm");
for target in target_matrix() {
@@ -12,8 +70,14 @@ fn main() {
}
}
Some("--version") => println!("alkane-os {}", env!("CARGO_PKG_VERSION")),
Some("--mine-simulator") => {
if let Err(error) = sim_mine(args) {
eprintln!("simulator mining failed: {error}");
std::process::exit(1);
}
}
_ => {
eprintln!("usage: alkane-os --list-targets | --version");
eprintln!("usage: alkane-os --list-targets | --version | --mine-simulator HAL_SOCKET POOL_ADDRESS WORKER [MAX_ACCEPTS]");
std::process::exit(2);
}
}