From d9cf8d53005193f34b9edb0566c1e1eccb239fde Mon Sep 17 00:00:00 2001 From: noah Date: Tue, 22 Sep 2026 11:33:43 -0600 Subject: [PATCH] tuning: structured power + hashrate target dialogs (Round C) Round 17 C, first GUI increment. Adds "Set power target..." and "Set hashrate target..." to the right-click config menu, each a value prompt that shows the miner's current target and the firmware-advertised valid range, and validates the entry against it. - Power target routes through the existing set_power_limit path (LuxOS/Braiins/ WhatsMiner; VNish stays masked per operator guidance). Where the firmware advertises an envelope (Braiins: 944-6435 W) the prompt shows and enforces it. - Hashrate target routes through set_tuning_config for firmware that tunes by hashrate (ePIC). The apply path preserves the firmware's current tuning algorithm and scaling config (ePIC's set_tuning_config requires both), reading them back before writing the new target. Model gains: MinerRow.tuning_target_label + power/hashrate target min/max (from data.tuning_capabilities), and MinerCaps.hashrate_target (set when the miner actively tunes by hashrate via set_tuning_config). miner_probe's settune verb now mirrors the same algorithm+scaling-preserving apply path. Verified live (reversibly, restored after): ePIC S19j Pro (10.4.1.6) hashrate 94->92->94 TH via set_tuning_config Ok(true); LuxOS/Braiins power targets via set_power_limit (see the luxminer profile-name fix). Model tests + SELFTEST pass. Presets (G3) and per-board manual V/F (G7) are deferred: no firmware enumerates its presets through the standard tuning_capabilities API. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Djv3oncM4LxTS5tb61Ako6 --- crates/alkane-gui/src/bin/miner_probe.rs | 9 +- crates/alkane-gui/src/fixtures.rs | 1 + crates/alkane-gui/src/model.rs | 18 ++++ crates/alkane-gui/src/scan.rs | 76 ++++++++++++++++- crates/alkane-gui/src/ui.rs | 103 +++++++++++++++++++++-- 5 files changed, 199 insertions(+), 8 deletions(-) diff --git a/crates/alkane-gui/src/bin/miner_probe.rs b/crates/alkane-gui/src/bin/miner_probe.rs index f915f785..631757c7 100644 --- a/crates/alkane-gui/src/bin/miner_probe.rs +++ b/crates/alkane-gui/src/bin/miner_probe.rs @@ -570,7 +570,14 @@ async fn settune(ip_s: &str, kind: &str, value: f64) { // power-limit setter for a power target (LuxOS/Braiins tune by power // and expose no set_tuning_config). if m.supports_tuning_config() { - match m.set_tuning_config(TuningConfig::new(target), None).await { + // Mirror the GUI apply path: preserve the firmware's current tuning + // algorithm + scaling (ePIC requires both for set_tuning_config). + let mut cfg = TuningConfig::new(target); + if let Some(algo) = m.get_tuning_config().await.ok().and_then(|c| c.algorithm) { + cfg = cfg.with_algorithm(algo); + } + let scaling = m.get_scaling_config().await.ok(); + match m.set_tuning_config(cfg, scaling).await { Ok(v) => println!("set_tuning_config({kind} {value}) -> Ok({v})"), Err(e) => println!("set_tuning_config({kind} {value}) -> Err: {e:#}"), } diff --git a/crates/alkane-gui/src/fixtures.rs b/crates/alkane-gui/src/fixtures.rs index 4b0b9b7b..a8be8d42 100644 --- a/crates/alkane-gui/src/fixtures.rs +++ b/crates/alkane-gui/src/fixtures.rs @@ -165,6 +165,7 @@ impl Board { resume: self.mining, power_limit: self.mining, tuning: self.mining, + hashrate_target: self.mining, firmware_flash, pools: true, timezone: self.mining, diff --git a/crates/alkane-gui/src/model.rs b/crates/alkane-gui/src/model.rs index 0dbf5cf9..03ad2e2f 100644 --- a/crates/alkane-gui/src/model.rs +++ b/crates/alkane-gui/src/model.rs @@ -213,6 +213,10 @@ pub struct MinerCaps { pub resume: bool, pub power_limit: bool, pub tuning: bool, + /// Round 17 C: supports setting a structured hashrate target via + /// `set_tuning_config` (the firmware actively tunes by hashrate, e.g. ePIC). + /// Power targets are covered by `power_limit`. + pub hashrate_target: bool, /// Whether this miner's asic-rs driver supports `upgrade_firmware` /// (probed via `supports_upgrade_firmware()` at scan time). pub firmware_flash: bool, @@ -236,6 +240,7 @@ impl MinerCaps { resume: self.resume && other.resume, power_limit: self.power_limit && other.power_limit, tuning: self.tuning && other.tuning, + hashrate_target: self.hashrate_target && other.hashrate_target, firmware_flash: self.firmware_flash && other.firmware_flash, pools: self.pools && other.pools, timezone: self.timezone && other.timezone, @@ -268,6 +273,7 @@ impl MinerCaps { || self.resume || self.power_limit || self.tuning + || self.hashrate_target || self.firmware_flash || self.pools || self.timezone @@ -422,6 +428,17 @@ pub struct MinerRow { /// shows "V / A" for a healthy PSU instead of a bare "PSU OK". pub psu_out_voltage_v: Option, pub psu_out_current_a: Option, + /// Current structured tuning target, rendered for display (e.g. "2832 W", + /// "96 TH/s", "preset 3550"), or None (round 17 C). + pub tuning_target_label: Option, + /// Advertised power-target envelope in watts, when the firmware reports one + /// (round 17 C, e.g. Braiins 944-6435 W). Bounds + validate the power-target + /// prompt; `None` leaves it unbounded. + pub power_target_min_w: Option, + pub power_target_max_w: Option, + /// Advertised hashrate-target envelope in TH/s, when reported (round 17 C). + pub hashrate_target_min_ths: Option, + pub hashrate_target_max_ths: Option, pub tuning_percent: Option, // thermal / cooling /// Average chip temperature (used for sorting/colour banding of the @@ -2326,6 +2343,7 @@ mod tests { resume: true, power_limit: true, tuning: true, + hashrate_target: true, firmware_flash: true, pools: true, timezone: true, diff --git a/crates/alkane-gui/src/scan.rs b/crates/alkane-gui/src/scan.rs index c63d2390..5c58577f 100644 --- a/crates/alkane-gui/src/scan.rs +++ b/crates/alkane-gui/src/scan.rs @@ -675,6 +675,47 @@ async fn to_row(miner: &dyn Miner) -> MinerRow { // VNish; Braiins and the rest keep asic-rs's answer. let power_limit = miner.supports_set_power_limit() && !data.device_info.firmware.eq_ignore_ascii_case("VNish"); + // Structured tuning (round 17 C). Extract the current target + the advertised + // envelope so the "Set performance target" prompt can show/validate bounds. + use asic_rs::core::data::miner::TuningTarget; + let target_watts = |t: &TuningTarget| match t { + TuningTarget::Power(p) => Some(p.as_watts()), + _ => None, + }; + let target_ths = |t: &TuningTarget| match t { + TuningTarget::HashRate(h) => Some( + h.clone() + .as_unit(asic_rs::core::data::hashrate::HashRateUnit::TeraHash) + .value, + ), + _ => None, + }; + let (power_target_min_w, power_target_max_w, hashrate_target_min_ths, hashrate_target_max_ths) = + match &data.tuning_capabilities { + Some(c) => ( + c.power.as_ref().and_then(|p| p.minimum.as_ref()).and_then(&target_watts), + c.power.as_ref().and_then(|p| p.maximum.as_ref()).and_then(&target_watts), + c.hashrate.as_ref().and_then(|h| h.minimum.as_ref()).and_then(&target_ths), + c.hashrate.as_ref().and_then(|h| h.maximum.as_ref()).and_then(&target_ths), + ), + None => (None, None, None, None), + }; + let tuning_target_label = data.tuning_target.as_ref().map(|t| match t { + TuningTarget::Power(p) => format!("{:.0} W", p.as_watts()), + TuningTarget::HashRate(h) => format!( + "{:.0} TH/s", + h.clone().as_unit(asic_rs::core::data::hashrate::HashRateUnit::TeraHash).value + ), + TuningTarget::MiningMode(m) => format!("mode {m}"), + TuningTarget::Preset(s) => format!("preset {s}"), + TuningTarget::Manual { .. } => "manual".to_string(), + }); + // A hashrate target is offerable only where the firmware actively tunes by + // hashrate through set_tuning_config (ePIC); Braiins advertises a hashrate + // envelope but has no set_tuning_config wired, so it is excluded. + let tunes_by_hashrate = matches!(data.tuning_target, Some(TuningTarget::HashRate(_))) + || data.tuning_capabilities.as_ref().map(|c| c.hashrate.is_some()).unwrap_or(false); + let hashrate_target = miner.supports_tuning_config() && tunes_by_hashrate; // Probe what this miner supports being told to do (sync, no extra I/O). let caps = MinerCaps { fault_light: miner.supports_set_fault_light(), @@ -683,6 +724,7 @@ async fn to_row(miner: &dyn Miner) -> MinerRow { resume: miner.supports_resume(), power_limit, tuning: miner.supports_set_tuning_percent(), + hashrate_target, firmware_flash: miner.supports_upgrade_firmware(), pools: miner.supports_pools_config(), timezone: miner.supports_timezone_config(), @@ -773,6 +815,11 @@ async fn to_row(miner: &dyn Miner) -> MinerRow { // falls back to a status string until it is. psu_out_voltage_v: None, psu_out_current_a: None, + tuning_target_label, + power_target_min_w, + power_target_max_w, + hashrate_target_min_ths, + hashrate_target_max_ths, tuning_percent: data.tuning_percent, chip_temp_c, board_temps, @@ -810,7 +857,8 @@ pub enum ConfigAction { Restart, Pause, Resume, - PowerLimit(f64), // watts + PowerLimit(f64), // watts + HashRateTarget(f64), // TH/s -- structured hashrate target (round 17 C) TuningPercent(u8), Timezone(String), // IANA zone, e.g. "America/Edmonton" (round 17 B / G10) ChangePassword(String), // new web/API password (round 17 B / G11) @@ -826,7 +874,8 @@ impl ConfigAction { ConfigAction::Restart => "restart".into(), ConfigAction::Pause => "pause".into(), ConfigAction::Resume => "resume".into(), - ConfigAction::PowerLimit(w) => format!("power limit {w:.0} W"), + ConfigAction::PowerLimit(w) => format!("power target {w:.0} W"), + ConfigAction::HashRateTarget(t) => format!("hashrate target {t:.0} TH/s"), ConfigAction::TuningPercent(p) => format!("tuning {p}%"), ConfigAction::Timezone(tz) => format!("timezone {tz}"), ConfigAction::ChangePassword(_) => "change password".into(), @@ -844,6 +893,7 @@ impl ConfigAction { ConfigAction::Pause => "pausing…".into(), ConfigAction::Resume => "resuming…".into(), ConfigAction::PowerLimit(_) => "setting power…".into(), + ConfigAction::HashRateTarget(_) => "setting hashrate…".into(), ConfigAction::TuningPercent(_) => "tuning…".into(), ConfigAction::Timezone(_) => "setting timezone…".into(), ConfigAction::ChangePassword(_) => "changing password…".into(), @@ -878,6 +928,28 @@ async fn apply_action(miner: &dyn Miner, action: &ConfigAction) -> Result miner.pause(None).await, ConfigAction::Resume => miner.resume(None).await, ConfigAction::PowerLimit(w) => miner.set_power_limit(Power::from_watts(*w)).await, + ConfigAction::HashRateTarget(ths) => { + use asic_rs::core::config::tuning::TuningConfig; + use asic_rs::core::data::hashrate::HashRateUnit; + use asic_rs::core::data::miner::TuningTarget; + // Build a HashRate target by cloning the miner's current hashrate to + // inherit its algorithm (HashAlgorithm is not publicly nameable), + // overriding value + unit. + let data = miner.get_data().await; + let Some(mut hr) = data.hashrate.clone() else { + return Err("miner reports no current hashrate; cannot set a hashrate target".into()); + }; + hr.value = *ths; + hr.unit = HashRateUnit::TeraHash; + let mut cfg = TuningConfig::new(TuningTarget::HashRate(hr)); + // Preserve the firmware's current tuning algorithm + scaling (ePIC + // requires both for set_tuning_config; other firmware ignore them). + if let Some(algo) = miner.get_tuning_config().await.ok().and_then(|c| c.algorithm) { + cfg = cfg.with_algorithm(algo); + } + let scaling = miner.get_scaling_config().await.ok(); + miner.set_tuning_config(cfg, scaling).await + } ConfigAction::TuningPercent(p) => miner.set_tuning_percent(*p).await, ConfigAction::Timezone(tz) => { use asic_rs::core::config::timezone::{Tz, TimezoneConfig}; diff --git a/crates/alkane-gui/src/ui.rs b/crates/alkane-gui/src/ui.rs index 0d834b56..a0ab29a1 100644 --- a/crates/alkane-gui/src/ui.rs +++ b/crates/alkane-gui/src/ui.rs @@ -66,6 +66,7 @@ const ID_CTX_PAUSE: i32 = 725; const ID_CTX_RESUME: i32 = 726; const ID_CTX_TUNING: i32 = 727; const ID_CTX_POWER: i32 = 728; +const ID_CTX_HASHRATE: i32 = 740; // Set hashrate target (round 17 C) const ID_CTX_RESTART: i32 = 729; // Round 17 B: timezone / change-password / factory-reset config actions. const ID_CTX_TIMEZONE: i32 = 737; @@ -97,6 +98,7 @@ const ID_ACTION_CANCEL: i32 = 741; #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum PromptKind { Power, + HashRateTarget, Tuning, Timezone, Password, @@ -1483,7 +1485,10 @@ impl App { menu.menu_append(ID_CTX_TUNING, &format!("Set tuning %...{sfx}")); } if caps.power_limit { - menu.menu_append(ID_CTX_POWER, &format!("Set power limit...{sfx}")); + menu.menu_append(ID_CTX_POWER, &format!("Set power target...{sfx}")); + } + if caps.hashrate_target { + menu.menu_append(ID_CTX_HASHRATE, &format!("Set hashrate target...{sfx}")); } if caps.restart { menu.menu_append(ID_CTX_RESTART, &format!("Restart{sfx}")); @@ -2115,6 +2120,7 @@ impl App { ID_CTX_RESTART => return Some(self.build_confirm_dialog(scan::ConfigAction::Restart)), // Value entry is itself the confirmation. ID_CTX_POWER => return Some(self.build_action_prompt(PromptKind::Power)), + ID_CTX_HASHRATE => return Some(self.build_action_prompt(PromptKind::HashRateTarget)), ID_CTX_TUNING => return Some(self.build_action_prompt(PromptKind::Tuning)), ID_CTX_TIMEZONE => return Some(self.build_action_prompt(PromptKind::Timezone)), ID_CTX_PASSWORD => return Some(self.build_action_prompt(PromptKind::Password)), @@ -2165,21 +2171,81 @@ impl App { /// A small modal to enter a power limit (watts) or tuning percent for the /// selection. Built here, shown modally by `dispatch` outside the App borrow. + /// The tightest common tuning envelope (max of the mins .. min of the maxes) + /// across the captured-selection miners that advertise one, plus their shared + /// current-target label ("varies" if they differ), for the target prompts + /// (round 17 C). `get` picks the (min, max) pair for the target kind. + fn selected_envelope( + &self, + get: impl Fn(&MinerRow) -> (Option, Option), + ) -> (Option<(f64, f64)>, Option) { + let sel = self + .rows + .iter() + .filter(|r| self.action_ips.contains(&r.ip)); + let mut lo: Option = None; + let mut hi: Option = None; + let mut labels: std::collections::HashSet = std::collections::HashSet::new(); + for r in sel { + let (mn, mx) = get(r); + if let Some(m) = mn { + lo = Some(lo.map_or(m, |v: f64| v.max(m))); + } + if let Some(m) = mx { + hi = Some(hi.map_or(m, |v: f64| v.min(m))); + } + if let Some(l) = &r.tuning_target_label { + labels.insert(l.clone()); + } + } + let range = match (lo, hi) { + (Some(a), Some(b)) if a <= b => Some((a, b)), + _ => None, + }; + let label = match labels.len() { + 0 => None, + 1 => labels.into_iter().next(), + _ => Some("varies".to_string()), + }; + (range, label) + } + fn build_action_prompt(&mut self, kind: PromptKind) -> Widget { self.action_ips = self.selected_ip_list(); self.action_kind = kind; let n = self.action_ips.len(); let frame = Widget::main_frame(); let title = match kind { - PromptKind::Power => "Set power limit", + PromptKind::Power => "Set power target", + PromptKind::HashRateTarget => "Set hashrate target", PromptKind::Tuning => "Set tuning percent", PromptKind::Timezone => "Set timezone", PromptKind::Password => "Change password", }; let dlg = Widget::dialog(frame, title); let root = Widget::box_sizer(true); + // Append the current target and the advertised valid range to the target + // prompts (round 17 C), so the operator sees what the firmware will accept. + let target_hint = |range: Option<(f64, f64)>, cur: Option, unit: &str| { + let mut s = String::new(); + if let Some(c) = cur { + s.push_str(&format!("\nCurrent: {c}.")); + } + if let Some((a, b)) = range { + s.push_str(&format!(" Valid range: {a:.0}-{b:.0} {unit}.")); + } + s + }; let lbl = match kind { - PromptKind::Power => format!("Power limit in watts for {n} miner(s):"), + PromptKind::Power => { + let (range, cur) = self.selected_envelope(|r| (r.power_target_min_w, r.power_target_max_w)); + format!("Power target in watts for {n} miner(s):{}", target_hint(range, cur, "W")) + } + PromptKind::HashRateTarget => { + let (range, cur) = + self.selected_envelope(|r| (r.hashrate_target_min_ths, r.hashrate_target_max_ths)); + format!("Hashrate target in TH/s for {n} miner(s):{}", target_hint(range, cur, "TH/s")) + } PromptKind::Tuning => format!("Tuning percent (0-100) for {n} miner(s):"), PromptKind::Timezone => format!("IANA timezone (e.g. America/Edmonton) for {n} miner(s):"), PromptKind::Password => format!("New web/API password for {n} miner(s):"), @@ -2206,9 +2272,35 @@ impl App { /// captured selection) so the operator can correct it. fn apply_action_prompt(&mut self) { let val = self.action_input.get_value(); + // A target must be positive, finite, and within the advertised range when + // one exists (round 17 C). + let in_range = |v: f64, range: Option<(f64, f64)>| { + v > 0.0 && v.is_finite() && range.map_or(true, |(a, b)| v >= a && v <= b) + }; let action = match self.action_kind { PromptKind::Power => match val.trim().parse::() { - Ok(w) if w > 0.0 && w.is_finite() => Some(scan::ConfigAction::PowerLimit(w)), + Ok(w) + if in_range( + w, + self.selected_envelope(|r| (r.power_target_min_w, r.power_target_max_w)).0, + ) => + { + Some(scan::ConfigAction::PowerLimit(w)) + } + _ => None, + }, + PromptKind::HashRateTarget => match val.trim().parse::() { + Ok(t) + if in_range( + t, + self.selected_envelope(|r| { + (r.hashrate_target_min_ths, r.hashrate_target_max_ths) + }) + .0, + ) => + { + Some(scan::ConfigAction::HashRateTarget(t)) + } _ => None, }, PromptKind::Tuning => match val.trim().parse::() { @@ -2237,7 +2329,8 @@ impl App { } None => { let hint = match self.action_kind { - PromptKind::Power => "enter a positive number of watts", + PromptKind::Power => "enter a number of watts within the valid range", + PromptKind::HashRateTarget => "enter a hashrate in TH/s within the valid range", PromptKind::Tuning => "enter a percent from 0 to 100", PromptKind::Timezone => "enter a valid IANA zone, e.g. America/Edmonton", PromptKind::Password => "enter a non-empty password",