Fixes the Critical/High findings from the round-6 review (6 parallel dimension reviewers + adversarial verify), plus the cheap high-value non-blocking ones. Full write-up in code-review-report.md. Firmware-flash safety (the one irreversible, hardware-destroying action): - Critical: re-triggering an action no longer races the previous one. A flash now takes an exclusive lock (new App.flashing): it will not start while any scan / refresh / config action is running, and none of those (nor another flash) start while it runs. begin_scan, start_action, start_refresh and apply_flash_confirm all gate on it, and the context menu offers only the read-only "Open in browser" while flashing. This removes the two overlapping- network-operation paths that could interrupt/corrupt an upload and brick a miner (old.stop() never joined the in-flight upload). - High: the flash confirm dialog now lists every target IP + model and warns loudly when the batch spans more than one model (a single image is rarely valid for all), instead of showing only a bare count. Correctness: - High: combined columns no longer paint the "-" placeholder solid red when the actual is unknown but the expected is known (an idle/paused/booting miner of a recognised model looked like a 0% catastrophic failure). fill_rows now gates the ratio on the actual being known; unknown-actual falls to the plain, uncoloured segment. Was masked by the all-zero-expected fixtures. - compute_kpis buckets by status() instead of re-deriving the precedence from raw flags (KPI header can no longer disagree with a row's status; offline folds into not_hashing). Security: - credentials file is created at 0600 up front (OpenOptions::mode) and re-tightened while still empty, so the plaintext password is never on disk under a looser mode (was create-0644 then chmod-0600). - the "Set scan credentials" dialog no longer pre-fills the saved password in plaintext; a blank Password field keeps the stored one. Robustness / API: - the fake-scan branches of the config-action / refresh / flash background threads now honour the cancel flag (were ignored, so stop() was a no-op). - MinerRow.online -> offline (default false = online), removing the footgun where a struct-update literal that forgot `online: true` read back offline. Tests (the review's primary focus -- these paths had zero coverage): - scan.rs fake_mode_background_actions: start_scan offline-row emission, start_refresh (Row/Failed/Done), start_firmware_flash_action, and that a cancelled run still terminates with Done rather than hanging. - model.rs: flash_confirmed (exact/case/prefix/whitespace), compute_kpis vs status() consistency, Default-is-online. - new ui::tests: ratio_color/fan_color/tint_toward stops+clamping+blends, and the combined-cell unknown-actual and cooling-cell encodings. - credentials.rs: configured_factory smoke (both branches) + pre-existing-0644 re-tighten. - self-test: offline row (.199) spot-check, KPI quick-filter toggle on/off, and a numeric (not lexical) IP-sort assertion via model::ip_to_u32. Deferred (non-blocking, tracked in code-review-report.md): start_* boilerplate extraction; per-model firmware image-compatibility check; scoping saved credentials to a chosen backend; a masked password field (needs a wx-rs TE_PASSWORD binding); flash-specific status text; a segment-encode microbench. Verified: cargo check --release --tests is clean; unit tests + benches + the headless self-test run in CI (local release link is OOM-blocked on this desktop). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh
169 lines
8.3 KiB
Rust
169 lines
8.3 KiB
Rust
//! Bench-fleet fixtures: the expected hardware output of the 9 boards on
|
|
//! 10.255.1.0/24 (see ../../../HANDOFF.md section 7 and the parent project's
|
|
//! [removed]), plus one synthetic unreachable IP rendered via
|
|
//! `MinerRow::offline()` so the "offline" status/row shape is exercisable
|
|
//! offline too (10 rows total). These are the reference values the workflow
|
|
//! tests compare the application's actual output against, and the rows the
|
|
//! offline `ALKANE_FAKE_SCAN` demo mode renders.
|
|
//!
|
|
//! Hashrate/power/temp are representative per-model figures (the bench boards
|
|
//! are not always energised); the point of the fixtures is a fixed, known input
|
|
//! set so the transforms (formatting, KPI aggregation, sort, filter, the "slow"
|
|
//! band) can be checked deterministically. Update these if the bench inventory
|
|
//! changes.
|
|
|
|
use crate::model::{is_slow, MinerRow};
|
|
|
|
/// One fixture board, pre-transform. `expected` of 0.0 means "band unknown".
|
|
struct Board {
|
|
ip: &'static str,
|
|
model: &'static str,
|
|
firmware: &'static str,
|
|
hashrate: f64,
|
|
expected: f64,
|
|
power: f64,
|
|
temp: f64,
|
|
fan: f64,
|
|
worker: &'static str,
|
|
mining: bool,
|
|
/// True for the bench board deliberately rebucketed into the "paused"
|
|
/// status/KPI bucket (not-mining but operator-paused, distinct from a
|
|
/// unit that is simply idle/not-hashing).
|
|
paused: bool,
|
|
}
|
|
|
|
impl Board {
|
|
fn into_row(self) -> MinerRow {
|
|
let slow = is_slow(self.mining, self.hashrate, self.expected);
|
|
// A few extra metrics so the demo/offline mode shows non-empty values
|
|
// for some of the additional columns.
|
|
let last_octet: u8 = self.ip.rsplit('.').next().and_then(|s| s.parse().ok()).unwrap_or(0);
|
|
let (boards, chips, efficiency) = if self.mining {
|
|
(Some(3u32), Some(210u32), if self.hashrate > 0.0 { self.power / self.hashrate } else { 0.0 })
|
|
} else {
|
|
(None, None, 0.0)
|
|
};
|
|
let fan_rpms = if self.mining {
|
|
vec![self.fan, self.fan * 0.95, self.fan * 1.02]
|
|
} else {
|
|
vec![]
|
|
};
|
|
// Firmware-flash capability is modeled on the real Bitmain/Antminer
|
|
// upgrade path (S17/S19/S21 family); WhatsMiner boards in this fleet
|
|
// don't advertise it, so both true and false show up and the
|
|
// firmware menu item is testable.
|
|
let firmware_flash = self.model == "Antminer S17"
|
|
|| self.model.starts_with("Antminer S19")
|
|
|| self.model.starts_with("Antminer S21");
|
|
MinerRow {
|
|
ip: self.ip.to_string(),
|
|
selected: false,
|
|
model: self.model.to_string(),
|
|
firmware: self.firmware.to_string(),
|
|
hashrate_ths: self.hashrate,
|
|
expected_ths: self.expected,
|
|
efficiency,
|
|
power_w: self.power,
|
|
chip_temp_c: self.temp,
|
|
fan_rpms,
|
|
worker: self.worker.to_string(),
|
|
is_mining: self.mining,
|
|
slow,
|
|
paused: self.paused,
|
|
// offline defaults to false (online); these bench rows are reachable.
|
|
mac: format!("AA:BB:CC:00:{:02X}:{last_octet:02X}", last_octet.wrapping_mul(3)),
|
|
hostname: format!("miner-{last_octet}"),
|
|
hashboards: boards,
|
|
expected_hashboards: Some(3),
|
|
total_chips: chips,
|
|
psu_fan_rpm: if self.mining { self.fan * 0.9 } else { 0.0 },
|
|
uptime_secs: if self.mining { 3600 * 24 * 2 + 3600 * 5 } else { 0 },
|
|
light_flashing: Some(false),
|
|
pool_url: if self.worker.is_empty() { String::new() } else { "stratum+tcp://pool.blueflare:3333".to_string() },
|
|
pools: if self.worker.is_empty() {
|
|
Vec::new()
|
|
} else {
|
|
vec![
|
|
("stratum+tcp://pool.blueflare:3333".to_string(), self.worker.to_string()),
|
|
("stratum+tcp://backup.blueflare:3333".to_string(), format!("{}_bak", self.worker)),
|
|
]
|
|
},
|
|
operating_state: if self.paused {
|
|
"paused".to_string()
|
|
} else if self.mining {
|
|
"mining".to_string()
|
|
} else {
|
|
"idle".to_string()
|
|
},
|
|
// Synthetic capabilities so the right-click config menu is
|
|
// exercisable offline: mining units support everything, idle ones
|
|
// only the fault light + restart (to show the capability intersection).
|
|
caps: crate::model::MinerCaps {
|
|
fault_light: true,
|
|
restart: true,
|
|
pause: self.mining,
|
|
resume: self.mining,
|
|
power_limit: self.mining,
|
|
tuning: self.mining,
|
|
firmware_flash,
|
|
},
|
|
..Default::default()
|
|
}
|
|
}
|
|
}
|
|
|
|
/// The 9 bench boards plus one synthetic offline entry (10 rows total).
|
|
/// One is idle/not-hashing (S17 stock, .112); one is paused (WardenOS dev,
|
|
/// .115 - deliberately rebucketed from idle so the "paused" status/KPI
|
|
/// bucket is exercisable offline); one is slow (S21 Pro aml stock at ~30%
|
|
/// of expected); the other six hash normally; the last row is an
|
|
/// unreachable IP rendered via `MinerRow::offline()` (blank fields,
|
|
/// `offline: true`).
|
|
///
|
|
/// Derived totals (used by the workflow tests):
|
|
/// total = 10, hashing = 6, slow = 1, not hashing = 1, paused = 1, offline = 1,
|
|
/// total hashrate = 685.0 TH/s, total power = 21300 W (offline row is all zero).
|
|
///
|
|
/// Note: `compute_kpis` has no separate "offline" bucket - an offline row is
|
|
/// `!is_mining && !paused && !slow`, so it folds into the "not hashing" KPI
|
|
/// alongside the idle S17, giving `Kpis.not_hashing == 2`. The per-row
|
|
/// `status()` text still distinguishes them ("not hashing" for .112 vs.
|
|
/// "offline" for .199).
|
|
pub fn bench_fleet() -> Vec<MinerRow> {
|
|
let boards = [
|
|
Board { ip: "10.255.1.112", model: "Antminer S17", firmware: "Stock",
|
|
hashrate: 0.0, expected: 0.0, power: 0.0, temp: 0.0, fan: 0.0,
|
|
worker: "", mining: false, paused: false },
|
|
Board { ip: "10.255.1.166", model: "Antminer S19", firmware: "[removed] 1.2",
|
|
hashrate: 95.0, expected: 96.0, power: 3250.0, temp: 65.0, fan: 4200.0,
|
|
worker: "blueflare.s19", mining: true, paused: false },
|
|
Board { ip: "10.255.1.152", model: "Antminer S19j Pro", firmware: "[removed] 1.2",
|
|
hashrate: 100.0, expected: 104.0, power: 3100.0, temp: 62.0, fan: 3900.0,
|
|
worker: "blueflare.s19jpro", mining: true, paused: false },
|
|
Board { ip: "10.255.1.167", model: "Antminer S19k Pro", firmware: "[removed] 1.2",
|
|
hashrate: 120.0, expected: 128.0, power: 3300.0, temp: 68.0, fan: 4500.0,
|
|
worker: "blueflare.s19kpro", mining: true, paused: false },
|
|
Board { ip: "10.255.1.149", model: "Antminer S21 Pro", firmware: "Stock",
|
|
hashrate: 60.0, expected: 200.0, power: 1500.0, temp: 55.0, fan: 3000.0,
|
|
worker: "blueflare.s21pro", mining: true, paused: false }, // slow: 60/200 = 30%
|
|
Board { ip: "10.255.1.126", model: "WhatsMiner M30S", firmware: "WMOS H3",
|
|
hashrate: 92.0, expected: 96.0, power: 3400.0, temp: 70.0, fan: 4800.0,
|
|
worker: "blueflare.h3", mining: true, paused: false },
|
|
Board { ip: "10.255.1.131", model: "WhatsMiner M30S+", firmware: "WMOS H616",
|
|
hashrate: 100.0, expected: 100.0, power: 3450.0, temp: 71.0, fan: 4900.0,
|
|
worker: "blueflare.h616", mining: true, paused: false },
|
|
Board { ip: "10.255.1.148", model: "WhatsMiner M50", firmware: "WMOS CB4",
|
|
hashrate: 118.0, expected: 122.0, power: 3300.0, temp: 66.0, fan: 4600.0,
|
|
worker: "blueflare.m50", mining: true, paused: false },
|
|
// Rebucketed from idle/not-hashing to paused so the "paused"
|
|
// status/KPI bucket is exercisable in the fake-scan/offline demo.
|
|
Board { ip: "10.255.1.115", model: "Antminer S19", firmware: "WardenOS dev",
|
|
hashrate: 0.0, expected: 0.0, power: 0.0, temp: 0.0, fan: 0.0,
|
|
worker: "", mining: false, paused: true },
|
|
];
|
|
let mut rows: Vec<MinerRow> = boards.into_iter().map(Board::into_row).collect();
|
|
// Synthetic offline board: unreachable IP, blank/zeroed fields, offline: true.
|
|
rows.push(MinerRow::offline("10.255.1.199".into()));
|
|
rows
|
|
}
|