From 95b8428c12f594d7b561c6fde754eb5075c7b4cc Mon Sep 17 00:00:00 2001 From: noah Date: Tue, 22 Sep 2026 17:34:26 -0600 Subject: [PATCH] Round C G3: named firmware presets (LuxOS) end to end The flagship structured-tuning parity item: list and select a firmware's named profiles/presets, not just map a watts number onto one. Backend (vendored asic-rs, patch 0022): LuxOS now implements SupportsPresets (get_presets reads the live `profiles` RPC) and a real SupportsTuningConfig (set_tuning_config routes Preset(name) -> profileset, Power -> set_power_limit). Unit-tested (parse_profiles_to_presets); verified live-read on two production LuxOS S19j Pro (10.4.1.60/.67). VNish already exposed presets. GUI: MinerCaps.supports_presets + MinerRow.presets (read live at scan time for preset-capable miners; ~1 RPC per such miner per 300 s rescan). New "Set profile..." right-click item opens a selector populated from the profiles common to the whole selection (so the chosen name is valid on every target), applied via the new ConfigAction::Preset. Offline fixtures seed demo presets. CLI: `miner_probe presets ` (list) and `setpreset ` (select). Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Djv3oncM4LxTS5tb61Ako6 --- crates/alkane-gui/src/bin/miner_probe.rs | 75 +++++++++ crates/alkane-gui/src/fixtures.rs | 12 ++ crates/alkane-gui/src/model.rs | 19 +++ crates/alkane-gui/src/scan.rs | 25 +++ crates/alkane-gui/src/ui.rs | 103 ++++++++++++ ...2-luxminer-presets-and-tuning-config.patch | 159 ++++++++++++++++++ .../.cargo-checksum.json | 2 +- .../src/backends/v1/mod.rs | 99 ++++++++++- 8 files changed, 491 insertions(+), 3 deletions(-) create mode 100644 thirdparty/asic-rs/patches/0022-luxminer-presets-and-tuning-config.patch diff --git a/crates/alkane-gui/src/bin/miner_probe.rs b/crates/alkane-gui/src/bin/miner_probe.rs index 42152351..f511ace2 100644 --- a/crates/alkane-gui/src/bin/miner_probe.rs +++ b/crates/alkane-gui/src/bin/miner_probe.rs @@ -598,6 +598,77 @@ async fn settune(ip_s: &str, kind: &str, value: f64) { } } +/// READ: list the firmware's selectable profiles/presets (roadmap G3). +async fn presets(ip_s: &str) { + let ip: std::net::IpAddr = match ip_s.parse() { + Ok(ip) => ip, + Err(e) => { + eprintln!("bad ip {ip_s}: {e}"); + return; + } + }; + let f = factory(); + match f.scan_miner(ip).await { + Ok(Some(m)) => { + if !m.supports_presets() { + println!("{ip}: firmware does not expose named presets"); + return; + } + let list = m.get_presets().await; + if list.is_empty() { + println!("{ip}: no presets reported"); + return; + } + for p in list { + match (p.pretty, p.status) { + (Some(pretty), Some(status)) => println!("{}\t{pretty}\t[{status}]", p.name), + (Some(pretty), None) => println!("{}\t{pretty}", p.name), + (None, _) => println!("{}", p.name), + } + } + } + Ok(None) => eprintln!("no miner at {ip}"), + Err(e) => eprintln!("scan_miner {ip}: {e}"), + } +} + +/// WRITE (reversible): select a named firmware profile/preset (roadmap G3). +/// `setpreset `. Prints the prior target so it can be restored. +async fn setpreset(ip_s: &str, name: &str) { + use asic_rs::core::config::tuning::TuningConfig; + use asic_rs::core::data::miner::TuningTarget; + let ip: std::net::IpAddr = match ip_s.parse() { + Ok(ip) => ip, + Err(e) => { + eprintln!("bad ip {ip_s}: {e}"); + return; + } + }; + let f = factory(); + match f.scan_miner(ip).await { + Ok(Some(m)) => { + let before = m.get_data().await; + eprintln!( + "target {ip}: {} {} {} (supports_presets={}); prior target = {:?}", + before.device_info.make, + before.device_info.firmware, + before.device_info.model, + m.supports_presets(), + before.tuning_target, + ); + let cfg = TuningConfig::new(TuningTarget::Preset(name.to_string())); + match m.set_tuning_config(cfg, None).await { + Ok(v) => println!("set_tuning_config(preset {name}) -> Ok({v})"), + Err(e) => println!("set_tuning_config(preset {name}) -> Err: {e:#}"), + } + let after = m.get_data().await; + println!(" target now = {:?}", after.tuning_target); + } + Ok(None) => eprintln!("no miner at {ip}"), + Err(e) => eprintln!("scan_miner {ip}: {e}"), + } +} + fn main() { let args: Vec = std::env::args().collect(); let rt = match tokio::runtime::Builder::new_current_thread().enable_all().build() { @@ -630,6 +701,8 @@ fn main() { } Some("msgs") if args.len() == 3 => rt.block_on(msgs(&args[2])), Some("tune") if args.len() == 3 => rt.block_on(tune(&args[2])), + Some("presets") if args.len() == 3 => rt.block_on(presets(&args[2])), + Some("setpreset") if args.len() == 4 => rt.block_on(setpreset(&args[2], &args[3])), Some("settune") if args.len() == 5 && matches!(args[3].as_str(), "power" | "hashrate") => { let value: f64 = args[4].parse().unwrap_or(-1.0); if value <= 0.0 { @@ -651,6 +724,7 @@ fn main() { \x20 hashrate [...] raw hashrate/algo dump\n\ \x20 msgs structured faults + per-board data\n\ \x20 tune structured-tuning support + capability envelope\n\ + \x20 presets list selectable firmware profiles/presets\n\ \n\ WRITE (MUTATES the miner -- use the test-bed miners, not production):\n\ \x20 light set the locate light\n\ @@ -660,6 +734,7 @@ fn main() { \x20 restart restart/reboot\n\ \x20 setpl set power limit\n\ \x20 settune set a structured tuning target (prints prior)\n\ + \x20 setpreset select a named firmware profile/preset (prints prior)\n\ \x20 setpools set the default pool group\n\ \x20 timezone [] read (no arg) or set the timezone\n\ \x20 passwd change the web/API password (DANGEROUS)\n\ diff --git a/crates/alkane-gui/src/fixtures.rs b/crates/alkane-gui/src/fixtures.rs index dc071d13..1e103581 100644 --- a/crates/alkane-gui/src/fixtures.rs +++ b/crates/alkane-gui/src/fixtures.rs @@ -173,6 +173,7 @@ impl Board { power_limit: self.mining, tuning: self.mining, hashrate_target: self.mining, + supports_presets: self.mining, firmware_flash, pools: true, timezone: self.mining, @@ -203,6 +204,17 @@ impl Board { } else { Vec::new() }, + // Demo firmware presets (round 18 / G3) so the "Set profile..." dialog + // is exercisable offline on units that advertise preset support. + presets: if self.mining { + vec![ + crate::model::MinerPreset { name: "default".into(), pretty: Some("2794 W ~ 121.8 TH @ 590 MHz".into()) }, + crate::model::MinerPreset { name: "540MHz".into(), pretty: Some("2485 W ~ 111.5 TH @ 540 MHz".into()) }, + crate::model::MinerPreset { name: "490MHz".into(), pretty: Some("2192 W ~ 101.1 TH @ 490 MHz".into()) }, + ] + } else { + Vec::new() + }, ..Default::default() } } diff --git a/crates/alkane-gui/src/model.rs b/crates/alkane-gui/src/model.rs index f55018b3..18204dbb 100644 --- a/crates/alkane-gui/src/model.rs +++ b/crates/alkane-gui/src/model.rs @@ -234,6 +234,10 @@ pub struct MinerCaps { /// `set_tuning_config` (the firmware actively tunes by hashrate, e.g. ePIC). /// Power targets are covered by `power_limit`. pub hashrate_target: bool, + /// Round 18 / roadmap G3: supports selecting a named firmware preset/profile + /// via `set_tuning_config(TuningTarget::Preset)` (LuxOS profiles, VNish presets). + /// The available presets are read live into `MinerRow::presets` at scan time. + pub supports_presets: bool, /// Whether this miner's asic-rs driver supports `upgrade_firmware` /// (probed via `supports_upgrade_firmware()` at scan time). pub firmware_flash: bool, @@ -258,6 +262,7 @@ impl MinerCaps { power_limit: self.power_limit && other.power_limit, tuning: self.tuning && other.tuning, hashrate_target: self.hashrate_target && other.hashrate_target, + supports_presets: self.supports_presets && other.supports_presets, firmware_flash: self.firmware_flash && other.firmware_flash, pools: self.pools && other.pools, timezone: self.timezone && other.timezone, @@ -291,6 +296,7 @@ impl MinerCaps { || self.power_limit || self.tuning || self.hashrate_target + || self.supports_presets || self.firmware_flash || self.pools || self.timezone @@ -382,6 +388,15 @@ pub enum HealthFacet { Boards, } +/// One selectable firmware preset/profile (round 18 / roadmap G3). `name` is the +/// identifier the firmware expects (e.g. LuxOS "540MHz", VNish "5560"); `pretty` +/// is an optional human summary (e.g. "2485 W ~ 111.5 TH @ 540 MHz"). +#[derive(Debug, Clone, Default, PartialEq, Eq)] +pub struct MinerPreset { + pub name: String, + pub pretty: Option, +} + /// One miner's telemetry snapshot, flattened from asic-rs `MinerData` into the /// scalar fields the table can display. Absent metrics are `None` / empty / /// 0.0 and render as a blank cell. @@ -457,6 +472,9 @@ pub struct MinerRow { /// 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, + /// The firmware's selectable named presets/profiles, read live at scan time + /// when `caps.supports_presets` (round 18 / roadmap G3). Empty otherwise. + pub presets: Vec, /// 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. @@ -2436,6 +2454,7 @@ mod tests { power_limit: true, tuning: true, hashrate_target: true, + supports_presets: 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 441574da..9cd85deb 100644 --- a/crates/alkane-gui/src/scan.rs +++ b/crates/alkane-gui/src/scan.rs @@ -828,12 +828,26 @@ async fn to_row(miner: &dyn Miner) -> MinerRow { power_limit, tuning: miner.supports_set_tuning_percent(), hashrate_target, + supports_presets: miner.supports_presets(), firmware_flash: miner.supports_upgrade_firmware(), pools: miner.supports_pools_config(), timezone: miner.supports_timezone_config(), change_password: miner.supports_change_password(), factory_reset: miner.supports_factory_reset(), }; + // The firmware's selectable named presets/profiles (round 18 / roadmap G3), + // read live only for miners that advertise them (LuxOS/VNish). One extra RPC + // at scan time for those miners; the default 300 s rescan makes it negligible. + let presets: Vec = if caps.supports_presets { + miner + .get_presets() + .await + .into_iter() + .map(|p| crate::model::MinerPreset { name: p.name, pretty: p.pretty }) + .collect() + } else { + Vec::new() + }; // PIC vs noPIC (round 14 #2 rework). No firmware exposes a PIC flag over the // network -- it's a fixed hardware property of the hashboard type -- so infer // it from the model, which every API reports. See `infer_pic`. @@ -885,6 +899,7 @@ async fn to_row(miner: &dyn Miner) -> MinerRow { model, brand, submodel, + presets, mac: data.mac.map(|m| m.to_string()).unwrap_or_default(), hostname: data.hostname.clone().unwrap_or_default(), serial: { @@ -976,6 +991,7 @@ pub enum ConfigAction { Resume, PowerLimit(f64), // watts HashRateTarget(f64), // TH/s -- structured hashrate target (round 17 C) + Preset(String), // named firmware profile/preset (round 18 / G3) TuningPercent(u8), Timezone(String), // IANA zone, e.g. "America/Edmonton" (round 17 B / G10) ChangePassword(String), // new web/API password (round 17 B / G11) @@ -993,6 +1009,7 @@ impl ConfigAction { ConfigAction::Resume => "resume".into(), ConfigAction::PowerLimit(w) => format!("power target {w:.0} W"), ConfigAction::HashRateTarget(t) => format!("hashrate target {t:.0} TH/s"), + ConfigAction::Preset(name) => format!("preset {name}"), ConfigAction::TuningPercent(p) => format!("tuning {p}%"), ConfigAction::Timezone(tz) => format!("timezone {tz}"), ConfigAction::ChangePassword(_) => "change password".into(), @@ -1011,6 +1028,7 @@ impl ConfigAction { ConfigAction::Resume => "resuming…".into(), ConfigAction::PowerLimit(_) => "setting power…".into(), ConfigAction::HashRateTarget(_) => "setting hashrate…".into(), + ConfigAction::Preset(_) => "setting preset…".into(), ConfigAction::TuningPercent(_) => "tuning…".into(), ConfigAction::Timezone(_) => "setting timezone…".into(), ConfigAction::ChangePassword(_) => "changing password…".into(), @@ -1067,6 +1085,13 @@ async fn apply_action(miner: &dyn Miner, action: &ConfigAction) -> Result { + use asic_rs::core::config::tuning::TuningConfig; + use asic_rs::core::data::miner::TuningTarget; + miner + .set_tuning_config(TuningConfig::new(TuningTarget::Preset(name.clone())), None) + .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 4e88f1a4..f09c28ce 100644 --- a/crates/alkane-gui/src/ui.rs +++ b/crates/alkane-gui/src/ui.rs @@ -67,6 +67,7 @@ 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_PRESET: i32 = 741; // Set firmware profile/preset (round 18 / G3) const ID_CTX_RESTART: i32 = 729; // Round 17 B: timezone / change-password / factory-reset config actions. const ID_CTX_TIMEZONE: i32 = 737; @@ -87,6 +88,10 @@ const ID_POOLS_CANCEL: i32 = 789; // Pool-preset manager dialog (round 18 #8b): edit the whole saved list at once. const ID_POOL_PRESETS_SAVE: i32 = 790; const ID_POOL_PRESETS_CANCEL: i32 = 791; +// Firmware profile/preset selector dialog (round 18 / roadmap G3). +const ID_FWPRESET_OK: i32 = 792; +const ID_FWPRESET_CANCEL: i32 = 793; +const ID_FWPRESET_CHOICE: i32 = 794; // Pool-field "+" dropdown buttons (round 15 #1): 12 buttons (3 rows x 4 fields), // id = base + row*4 + field. The dropdown menu items use their own id range. const ID_POOL_PLUS_BASE: i32 = 800; @@ -749,6 +754,13 @@ pub struct App { pool_presets_dialog: Widget, pool_presets_input: Widget, pool_presets_field: crate::pool_prefs::PoolField, + // Firmware profile/preset selector (round 18 / roadmap G3): a Choice of the + // selected miner's presets, the names behind each entry, and the target IPs + // captured when the dialog opened. + fw_preset_dialog: Widget, + fw_preset_choice: Widget, + fw_preset_names: Vec, + fw_preset_ips: Vec, // Saved view presets + the Presets dialog widgets. presets: Vec, presets_dialog: Widget, @@ -1052,6 +1064,10 @@ pub fn build(frame: Widget) -> App { pool_presets_dialog: frame, pool_presets_input: frame, pool_presets_field: crate::pool_prefs::PoolField::Address, + fw_preset_dialog: frame, + fw_preset_choice: frame, + fw_preset_names: Vec::new(), + fw_preset_ips: Vec::new(), presets: crate::presets::load_presets(), presets_dialog: frame, presets_choice: frame, @@ -1528,6 +1544,9 @@ impl App { if caps.hashrate_target { menu.menu_append(ID_CTX_HASHRATE, &format!("Set hashrate target...{sfx}")); } + if caps.supports_presets { + menu.menu_append(ID_CTX_PRESET, &format!("Set profile...{sfx}")); + } if caps.restart { menu.menu_append(ID_CTX_RESTART, &format!("Restart{sfx}")); } @@ -2210,6 +2229,7 @@ impl App { // 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_PRESET => return self.build_fw_preset_dialog(), 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)), @@ -2429,6 +2449,86 @@ impl App { } } + /// Build (but do not show) the firmware profile/preset selector (round 18 / + /// roadmap G3). Populated live from the presets read at scan time; only the + /// profiles common (by name) to every selected preset-capable miner are + /// offered, so the chosen profile is valid on all of them. Returns None (with + /// a status hint) when there is nothing to offer. + fn build_fw_preset_dialog(&mut self) -> Option { + let supporting: Vec<&MinerRow> = self + .selected_rows() + .into_iter() + .filter(|r| r.caps.supports_presets && !r.presets.is_empty()) + .collect(); + if supporting.is_empty() { + wx_rs::set_status_text("no firmware profiles available for the selection yet"); + return None; + } + // Intersect the profile names across the selection so the chosen name is + // valid on every target; keep the first miner's pretty labels. + let mut common: Vec = supporting[0].presets.clone(); + for r in &supporting[1..] { + let names: std::collections::HashSet<&str> = + r.presets.iter().map(|p| p.name.as_str()).collect(); + common.retain(|p| names.contains(p.name.as_str())); + } + if common.is_empty() { + wx_rs::set_status_text("selected miners share no common firmware profile"); + return None; + } + self.fw_preset_ips = supporting.iter().map(|r| r.ip.clone()).collect(); + self.fw_preset_names = common.iter().map(|p| p.name.clone()).collect(); + let n = self.fw_preset_ips.len(); + + let frame = Widget::main_frame(); + let dlg = Widget::dialog(frame, "Set profile"); + let root = Widget::box_sizer(true); + root.add( + Widget::static_text(dlg, &format!("Firmware profile for {n} miner(s):")), + 0, + sf::BORDER_ALL, + 8, + ); + let choice = Widget::choice(dlg, ID_FWPRESET_CHOICE); + for p in &common { + let label = match &p.pretty { + Some(pretty) => format!("{} -- {pretty}", p.name), + None => p.name.clone(), + }; + choice.choice_append(&label); + } + choice.choice_set_selection(0); + choice.set_min_size(340, -1); + root.add(choice, 0, sf::EXPAND | sf::BORDER_LEFT | sf::BORDER_RIGHT, 8); + let btns = Widget::box_sizer(false); + btns.add_stretch(1); + btns.add(Widget::button(dlg, "Apply", ID_FWPRESET_OK), 0, sf::BORDER_ALL, 6); + btns.add(Widget::button(dlg, "Cancel", ID_FWPRESET_CANCEL), 0, sf::BORDER_ALL, 6); + root.add_sizer(btns, 0, sf::EXPAND | sf::BORDER_ALL, 6); + root.set_sizer_on(dlg); + dlg.set_min_size(420, -1); + dlg.fit(dlg); + self.fw_preset_dialog = dlg; + self.fw_preset_choice = choice; + Some(dlg) + } + + /// Apply the selected firmware profile to the captured targets (round 18 / G3). + fn apply_fw_preset(&mut self) { + let sel = self.fw_preset_choice.choice_get_selection(); + let Some(name) = usize::try_from(sel) + .ok() + .and_then(|i| self.fw_preset_names.get(i)) + .cloned() + else { + wx_rs::set_status_text("select a profile"); + return; + }; + let ips = std::mem::take(&mut self.fw_preset_ips); + self.fw_preset_dialog.close(1); + self.start_action(ips, scan::ConfigAction::Preset(name)); + } + /// Strong typed confirmation before flashing firmware to hardware: the /// operator must type FLASH exactly, on top of seeing the image's file /// name and how many of the selected miners actually support it. Built @@ -3939,6 +4039,9 @@ impl App { // Pool-preset manager buttons (round 18 #8b). ID_POOL_PRESETS_SAVE => self.apply_pool_presets(), ID_POOL_PRESETS_CANCEL => self.pool_presets_dialog.close(0), + // Firmware profile/preset selector buttons (round 18 / G3). + ID_FWPRESET_OK => self.apply_fw_preset(), + ID_FWPRESET_CANCEL => self.fw_preset_dialog.close(0), // Pool-field "+" dropdown buttons (round 15 #1). id if (ID_POOL_PLUS_BASE..ID_POOL_PLUS_BASE + 12).contains(&id) => { self.open_pool_dropdown((id - ID_POOL_PLUS_BASE) as usize); diff --git a/thirdparty/asic-rs/patches/0022-luxminer-presets-and-tuning-config.patch b/thirdparty/asic-rs/patches/0022-luxminer-presets-and-tuning-config.patch new file mode 100644 index 00000000..b627fda5 --- /dev/null +++ b/thirdparty/asic-rs/patches/0022-luxminer-presets-and-tuning-config.patch @@ -0,0 +1,159 @@ +Subject: [PATCH 0022] luxminer: named presets + set_tuning_config (roadmap G3) + +LuxOS tunes by discrete named profiles. This exposes them as first-class +presets and wires the structured tuning-config setter, so the toolkit can list +and select a profile (not only map a watts number onto one via SetPowerLimit). + +- SupportsPresets: supports_presets()=true and get_presets() reads the live + `profiles` RPC into PresetInfo{name, pretty=" W ~ TH @ MHz", + status=IsTuned?tuned:untuned}. Never hardcoded -- the step list varies by + model and tune state. New helper parse_profiles_to_presets + unit test. +- SupportsTuningConfig: supports_tuning_config()=true and set_tuning_config + handles Preset(name) -> profileset(name) (the same privileged RPC set_power_limit + already uses, proven in patch 0017) and Power(w) -> set_power_limit; hashrate / + mining-mode / manual targets are refused with clear messages. + +Verified live (read) on two production LuxOS S19j Pro (10.4.1.60 / .67): the +profile ladders and supports_tuning_config=true are reported correctly. The +write path reuses the already-proven profileset(name) call; per the parity +roadmap, LuxOS profile writes are bench-only (never on the .60/.67 production +units), so the setter is not exercised against them here. + +diff --git a/vendor/asic-rs-firmwares-luxminer/src/backends/v1/mod.rs b/vendor/asic-rs-firmwares-luxminer/src/backends/v1/mod.rs +index a4db1e03..b5a5a73c 100644 +--- a/vendor/asic-rs-firmwares-luxminer/src/backends/v1/mod.rs ++++ b/vendor/asic-rs-firmwares-luxminer/src/backends/v1/mod.rs +@@ -5,6 +5,8 @@ use asic_rs_core::{ + config::{ + collector::{ConfigCollector, ConfigExtractor, ConfigField, ConfigLocation}, + pools::{PoolConfig, PoolGroupConfig}, ++ preset::PresetInfo, ++ tuning::TuningConfig, + }, + data::{ + board::{BoardData, ChipData, MinerControlBoard}, +@@ -1102,6 +1104,38 @@ fn parse_profile_watts(profiles: &Value) -> Vec<(String, f64)> { + .unwrap_or_default() + } + ++/// Parse a LuxOS `profiles` RPC reply into the firmware's tunable presets, one ++/// per dynamic profile (round 18 / roadmap G3). The `Profile Name` is the ++/// identifier `profileset` expects; the pretty string summarises the profile's ++/// watt / hashrate / frequency operating point, and `status` reflects `IsTuned`. ++fn parse_profiles_to_presets(profiles: &Value) -> Vec { ++ profiles ++ .get("PROFILES") ++ .and_then(Value::as_array) ++ .map(|arr| { ++ arr.iter() ++ .filter_map(|p| { ++ let name = p.get("Profile Name").and_then(Value::as_str)?.to_string(); ++ let watts = p.get("Watts").and_then(Value::as_f64); ++ let hashrate = p.get("Hashrate").and_then(Value::as_f64); ++ let freq = p.get("Frequency").and_then(Value::as_f64); ++ let pretty = match (watts, hashrate, freq) { ++ (Some(w), Some(h), Some(f)) => Some(format!("{w:.0} W ~ {h:.1} TH @ {f:.0} MHz")), ++ (Some(w), Some(h), None) => Some(format!("{w:.0} W ~ {h:.1} TH")), ++ (Some(w), None, _) => Some(format!("{w:.0} W")), ++ _ => None, ++ }; ++ let status = p ++ .get("IsTuned") ++ .and_then(Value::as_bool) ++ .map(|t| if t { "tuned" } else { "untuned" }.to_string()); ++ Some(PresetInfo { name, pretty, status }) ++ }) ++ .collect() ++ }) ++ .unwrap_or_default() ++} ++ + /// Choose the LuxOS profile name to satisfy a watts power limit: the highest-watt + /// profile that does not exceed `target_w`, or -- when the target is below every + /// profile -- the lowest-watt profile. Returns None only when there are no +@@ -1284,7 +1318,38 @@ impl Validate for LuxMinerV1 { + #[async_trait] + impl SupportsTuningConfig for LuxMinerV1 { + fn supports_tuning_config(&self) -> bool { +- false ++ true ++ } ++ ++ /// LuxOS tunes by named profile (roadmap G3). A `Preset` target is applied ++ /// straight through `profileset`; a `Power` target reuses the watts->profile ++ /// mapping in `set_power_limit`. LuxOS has no hashrate/mining-mode targets and ++ /// per-board manual tuning is not wired, so those targets are refused. ++ async fn set_tuning_config( ++ &self, ++ config: TuningConfig, ++ _scaling_config: Option, ++ ) -> anyhow::Result { ++ match config.target { ++ TuningTarget::Preset(name) => { ++ let resp = self.rpc.profileset(&name).await?; ++ Ok(resp ++ .pointer("/STATUS/0/STATUS") ++ .and_then(Value::as_str) ++ .map(|s| matches!(s, "S" | "I")) ++ .unwrap_or(true)) ++ } ++ TuningTarget::Power(p) => self.set_power_limit(p).await, ++ TuningTarget::HashRate(_) => { ++ anyhow::bail!("LuxOS does not tune by hashrate target; select a named profile") ++ } ++ TuningTarget::MiningMode(_) => { ++ anyhow::bail!("LuxOS has no mining modes; select a named profile") ++ } ++ TuningTarget::Manual { .. } => { ++ anyhow::bail!("Per-board manual tuning is not wired for LuxOS") ++ } ++ } + } + } + +@@ -1299,7 +1364,21 @@ impl SupportsTemperatureConfig for LuxMinerV1 {} + impl GetTuningPercent for LuxMinerV1 {} + impl SetTuningPercent for LuxMinerV1 {} + +-impl SupportsPresets for LuxMinerV1 {} ++#[async_trait] ++impl SupportsPresets for LuxMinerV1 { ++ fn supports_presets(&self) -> bool { ++ true ++ } ++ ++ /// The firmware's tunable profiles, read live from the `profiles` RPC (roadmap ++ /// G3). Never hardcoded -- the step list varies by model and tune state. ++ async fn get_presets(&self) -> Vec { ++ match self.rpc.profiles().await { ++ Ok(profiles) => parse_profiles_to_presets(&profiles), ++ Err(_) => Vec::new(), ++ } ++ } ++} + #[cfg(test)] + mod tests { + use std::sync::{Arc, Mutex}; +@@ -1361,6 +1440,22 @@ mod tests { + assert!(select_profile_at_or_below(&parsed, 2500.0).is_some()); + } + ++ #[test] ++ fn profiles_parse_to_presets() { ++ // The `profiles` reply becomes one PresetInfo per profile (roadmap G3). ++ let profiles: Value = serde_json::from_str(PROFILES).unwrap(); ++ let presets = parse_profiles_to_presets(&profiles); ++ assert_eq!(presets.len(), 25, "one preset per fixture profile"); ++ // The factory point is named "default"; its pretty string carries the ++ // watt / hashrate / frequency operating point. ++ let default = presets.iter().find(|p| p.name == "default").unwrap(); ++ assert_eq!(default.pretty.as_deref(), Some("2794 W ~ 121.8 TH @ 590 MHz")); ++ // IsTuned maps to the status string. ++ let tuned = presets.iter().find(|p| p.name == "290MHz").unwrap(); ++ assert_eq!(tuned.status.as_deref(), Some("tuned")); ++ assert_eq!(default.status.as_deref(), Some("untuned")); ++ } ++ + #[tokio::test] + + async fn test_luxminer_v1() -> anyhow::Result<()> { diff --git a/vendor/asic-rs-firmwares-luxminer/.cargo-checksum.json b/vendor/asic-rs-firmwares-luxminer/.cargo-checksum.json index daebdb42..78bb3f05 100644 --- a/vendor/asic-rs-firmwares-luxminer/.cargo-checksum.json +++ b/vendor/asic-rs-firmwares-luxminer/.cargo-checksum.json @@ -1 +1 @@ -{"$comment":"This file only protects against accidental modifications. It is not a security mechanism and does not protect against malicious changes.","files":{".cargo_vcs_info.json":"fe8effe2bfdda5d4c390656c016729f531a2b1c60033228557659c0befdde9f2","Cargo.lock":"a2b2cb45bb8b574e4f29ffdcdb5ebafd1dd87a0e6e11b47383973a99be367784","Cargo.toml":"503efa00123f8567f5fe40bf6a93e9e453d13094df0e0e1b7e98bdacdfbd2595","Cargo.toml.orig":"1c4ba0315fb491c086fc22a5c9bafaf7288c6b1fd48679c3d03dbd9df156a8b5","src/backends/mod.rs":"548d988b877410e330a55e275f64b2adad95ca5f1a0f085fe144957c96b8906f","src/backends/v1/mod.rs":"0c12f7714b8486372054261afd263b61f432a446cef8ae9e6cd72550a0cf4f8f","src/backends/v1/rpc.rs":"25b0b9d56fbf113d5b8c3d3bc8eb7a0d67967b1f90f6d855da0b9f6ff24ae335","src/firmware.rs":"d95345295ae5043dfc357e69ae56c564b261fdb3b19b5c0ad1765267ff05ab3f","src/lib.rs":"53f7acddeff8f7d82f80d09e0a9f91962011f9ccf2e441c4ca05cd7fc4eb292e","src/test/json/mod.rs":"24191681066d5cf6a3022ad59c1baa92b57e3ce7717bb78d6a682af9e19a38c4","src/test/json/v1/config.json":"6ca9e6217d853d4bf1e75d69159630e9c9184ede96751706b88dfb699b5d59ad","src/test/json/v1/devs.json":"8f746dc6a02953eee5ee96dcf53be8dc7880a8ffc2c6e303f0284bcf6a97f42d","src/test/json/v1/events.json":"913683ff97af3333018807e1cc6e43467ea8a55925e5964dc402616615e2a5e3","src/test/json/v1/fans.json":"f8a9a1234d651055c80f4ebb1380bbb4e6d19eb33012902c55fff1385e592447","src/test/json/v1/healthchipget_0.json":"10619460049333ca016b2beec59ecc514ed9077fb19bdf7d0ed697201f8cb96c","src/test/json/v1/healthchipget_1.json":"80927fb1480c95be7f3a4e155d63f68f97720530ff7cf5d5ade06f2a3e810bf0","src/test/json/v1/healthchipget_2.json":"1e93ee2ab472ee7af58add08b4251e3ce0ad4f986d4325abbf43fd4c9b3dd28f","src/test/json/v1/mod.rs":"5a050f07455e622e35ad79ab1c8a6daf2ea38c4198472e49c6bbfe80538a9e48","src/test/json/v1/pools.json":"0068745327e31853fec051172abb7337f18a4cf9972c51967113d63f4f31f504","src/test/json/v1/power.json":"80534bb4581de7c8b747bf33b5d629b909c6e16a531d18ecb4afd7ffad3f014f","src/test/json/v1/profiles.json":"1f00429036e270daa08f12cd2d7357135070c57acd7a899a3c0af6167fe82abb","src/test/json/v1/stats.json":"2b105f0eb927046c9d2389bde978a43e3d54d12a420dfbe400786bb2f0ae31ca","src/test/json/v1/summary.json":"aaea3378eb7040952037e2f1ef7bd5f20a1b242bf93d4ba0501c46104b0b31a0","src/test/json/v1/temps.json":"1ee781cd2be3ed6a6a07e23be930248735fb51348c160453ba10f6ef71fcb7f1","src/test/json/v1/version.json":"4beb6ca5c0ebf359cee0434fdcc4d0a1a0607436634e46be3fd951e2256595df","src/test/json/v1/voltageget_0.json":"c445fa8674c2542b2d296fbafdd3166c53008dfbd9da8095327217989d37f1da","src/test/json/v1/voltageget_1.json":"96b91c3447dd66e7f1f575ed3b99611062e8b1d516d31422b74e425c46b2f49c","src/test/json/v1/voltageget_2.json":"7d40544021b2e32401135ae333067b770d2d736ada9e60deaca8fd8f5a79a1e3","src/test/mod.rs":"ed52c3d613eabc4a0346bb38bcfdf7a94933d61e368d3c9094821edeab92f81b"},"package":"513792d93a2a21d5258d9e6ac0e6dc9e0a6365118934514b4e656792add78066"} \ No newline at end of file +{"$comment":"This file only protects against accidental modifications. It is not a security mechanism and does not protect against malicious changes.","files":{".cargo_vcs_info.json":"fe8effe2bfdda5d4c390656c016729f531a2b1c60033228557659c0befdde9f2","Cargo.lock":"a2b2cb45bb8b574e4f29ffdcdb5ebafd1dd87a0e6e11b47383973a99be367784","Cargo.toml":"503efa00123f8567f5fe40bf6a93e9e453d13094df0e0e1b7e98bdacdfbd2595","Cargo.toml.orig":"1c4ba0315fb491c086fc22a5c9bafaf7288c6b1fd48679c3d03dbd9df156a8b5","src/backends/mod.rs":"548d988b877410e330a55e275f64b2adad95ca5f1a0f085fe144957c96b8906f","src/backends/v1/mod.rs":"abcf1ffb8443efa70838489b026730ac19de774ba9e6f7c9a9800e3ba03c06a4","src/backends/v1/rpc.rs":"25b0b9d56fbf113d5b8c3d3bc8eb7a0d67967b1f90f6d855da0b9f6ff24ae335","src/firmware.rs":"d95345295ae5043dfc357e69ae56c564b261fdb3b19b5c0ad1765267ff05ab3f","src/lib.rs":"53f7acddeff8f7d82f80d09e0a9f91962011f9ccf2e441c4ca05cd7fc4eb292e","src/test/json/mod.rs":"24191681066d5cf6a3022ad59c1baa92b57e3ce7717bb78d6a682af9e19a38c4","src/test/json/v1/config.json":"6ca9e6217d853d4bf1e75d69159630e9c9184ede96751706b88dfb699b5d59ad","src/test/json/v1/devs.json":"8f746dc6a02953eee5ee96dcf53be8dc7880a8ffc2c6e303f0284bcf6a97f42d","src/test/json/v1/events.json":"913683ff97af3333018807e1cc6e43467ea8a55925e5964dc402616615e2a5e3","src/test/json/v1/fans.json":"f8a9a1234d651055c80f4ebb1380bbb4e6d19eb33012902c55fff1385e592447","src/test/json/v1/healthchipget_0.json":"10619460049333ca016b2beec59ecc514ed9077fb19bdf7d0ed697201f8cb96c","src/test/json/v1/healthchipget_1.json":"80927fb1480c95be7f3a4e155d63f68f97720530ff7cf5d5ade06f2a3e810bf0","src/test/json/v1/healthchipget_2.json":"1e93ee2ab472ee7af58add08b4251e3ce0ad4f986d4325abbf43fd4c9b3dd28f","src/test/json/v1/mod.rs":"5a050f07455e622e35ad79ab1c8a6daf2ea38c4198472e49c6bbfe80538a9e48","src/test/json/v1/pools.json":"0068745327e31853fec051172abb7337f18a4cf9972c51967113d63f4f31f504","src/test/json/v1/power.json":"80534bb4581de7c8b747bf33b5d629b909c6e16a531d18ecb4afd7ffad3f014f","src/test/json/v1/profiles.json":"1f00429036e270daa08f12cd2d7357135070c57acd7a899a3c0af6167fe82abb","src/test/json/v1/stats.json":"2b105f0eb927046c9d2389bde978a43e3d54d12a420dfbe400786bb2f0ae31ca","src/test/json/v1/summary.json":"aaea3378eb7040952037e2f1ef7bd5f20a1b242bf93d4ba0501c46104b0b31a0","src/test/json/v1/temps.json":"1ee781cd2be3ed6a6a07e23be930248735fb51348c160453ba10f6ef71fcb7f1","src/test/json/v1/version.json":"4beb6ca5c0ebf359cee0434fdcc4d0a1a0607436634e46be3fd951e2256595df","src/test/json/v1/voltageget_0.json":"c445fa8674c2542b2d296fbafdd3166c53008dfbd9da8095327217989d37f1da","src/test/json/v1/voltageget_1.json":"96b91c3447dd66e7f1f575ed3b99611062e8b1d516d31422b74e425c46b2f49c","src/test/json/v1/voltageget_2.json":"7d40544021b2e32401135ae333067b770d2d736ada9e60deaca8fd8f5a79a1e3","src/test/mod.rs":"ed52c3d613eabc4a0346bb38bcfdf7a94933d61e368d3c9094821edeab92f81b"},"package":"513792d93a2a21d5258d9e6ac0e6dc9e0a6365118934514b4e656792add78066"} \ No newline at end of file diff --git a/vendor/asic-rs-firmwares-luxminer/src/backends/v1/mod.rs b/vendor/asic-rs-firmwares-luxminer/src/backends/v1/mod.rs index a4db1e03..b5a5a73c 100644 --- a/vendor/asic-rs-firmwares-luxminer/src/backends/v1/mod.rs +++ b/vendor/asic-rs-firmwares-luxminer/src/backends/v1/mod.rs @@ -5,6 +5,8 @@ use asic_rs_core::{ config::{ collector::{ConfigCollector, ConfigExtractor, ConfigField, ConfigLocation}, pools::{PoolConfig, PoolGroupConfig}, + preset::PresetInfo, + tuning::TuningConfig, }, data::{ board::{BoardData, ChipData, MinerControlBoard}, @@ -1102,6 +1104,38 @@ fn parse_profile_watts(profiles: &Value) -> Vec<(String, f64)> { .unwrap_or_default() } +/// Parse a LuxOS `profiles` RPC reply into the firmware's tunable presets, one +/// per dynamic profile (round 18 / roadmap G3). The `Profile Name` is the +/// identifier `profileset` expects; the pretty string summarises the profile's +/// watt / hashrate / frequency operating point, and `status` reflects `IsTuned`. +fn parse_profiles_to_presets(profiles: &Value) -> Vec { + profiles + .get("PROFILES") + .and_then(Value::as_array) + .map(|arr| { + arr.iter() + .filter_map(|p| { + let name = p.get("Profile Name").and_then(Value::as_str)?.to_string(); + let watts = p.get("Watts").and_then(Value::as_f64); + let hashrate = p.get("Hashrate").and_then(Value::as_f64); + let freq = p.get("Frequency").and_then(Value::as_f64); + let pretty = match (watts, hashrate, freq) { + (Some(w), Some(h), Some(f)) => Some(format!("{w:.0} W ~ {h:.1} TH @ {f:.0} MHz")), + (Some(w), Some(h), None) => Some(format!("{w:.0} W ~ {h:.1} TH")), + (Some(w), None, _) => Some(format!("{w:.0} W")), + _ => None, + }; + let status = p + .get("IsTuned") + .and_then(Value::as_bool) + .map(|t| if t { "tuned" } else { "untuned" }.to_string()); + Some(PresetInfo { name, pretty, status }) + }) + .collect() + }) + .unwrap_or_default() +} + /// Choose the LuxOS profile name to satisfy a watts power limit: the highest-watt /// profile that does not exceed `target_w`, or -- when the target is below every /// profile -- the lowest-watt profile. Returns None only when there are no @@ -1284,7 +1318,38 @@ impl Validate for LuxMinerV1 { #[async_trait] impl SupportsTuningConfig for LuxMinerV1 { fn supports_tuning_config(&self) -> bool { - false + true + } + + /// LuxOS tunes by named profile (roadmap G3). A `Preset` target is applied + /// straight through `profileset`; a `Power` target reuses the watts->profile + /// mapping in `set_power_limit`. LuxOS has no hashrate/mining-mode targets and + /// per-board manual tuning is not wired, so those targets are refused. + async fn set_tuning_config( + &self, + config: TuningConfig, + _scaling_config: Option, + ) -> anyhow::Result { + match config.target { + TuningTarget::Preset(name) => { + let resp = self.rpc.profileset(&name).await?; + Ok(resp + .pointer("/STATUS/0/STATUS") + .and_then(Value::as_str) + .map(|s| matches!(s, "S" | "I")) + .unwrap_or(true)) + } + TuningTarget::Power(p) => self.set_power_limit(p).await, + TuningTarget::HashRate(_) => { + anyhow::bail!("LuxOS does not tune by hashrate target; select a named profile") + } + TuningTarget::MiningMode(_) => { + anyhow::bail!("LuxOS has no mining modes; select a named profile") + } + TuningTarget::Manual { .. } => { + anyhow::bail!("Per-board manual tuning is not wired for LuxOS") + } + } } } @@ -1299,7 +1364,21 @@ impl SupportsTemperatureConfig for LuxMinerV1 {} impl GetTuningPercent for LuxMinerV1 {} impl SetTuningPercent for LuxMinerV1 {} -impl SupportsPresets for LuxMinerV1 {} +#[async_trait] +impl SupportsPresets for LuxMinerV1 { + fn supports_presets(&self) -> bool { + true + } + + /// The firmware's tunable profiles, read live from the `profiles` RPC (roadmap + /// G3). Never hardcoded -- the step list varies by model and tune state. + async fn get_presets(&self) -> Vec { + match self.rpc.profiles().await { + Ok(profiles) => parse_profiles_to_presets(&profiles), + Err(_) => Vec::new(), + } + } +} #[cfg(test)] mod tests { use std::sync::{Arc, Mutex}; @@ -1361,6 +1440,22 @@ mod tests { assert!(select_profile_at_or_below(&parsed, 2500.0).is_some()); } + #[test] + fn profiles_parse_to_presets() { + // The `profiles` reply becomes one PresetInfo per profile (roadmap G3). + let profiles: Value = serde_json::from_str(PROFILES).unwrap(); + let presets = parse_profiles_to_presets(&profiles); + assert_eq!(presets.len(), 25, "one preset per fixture profile"); + // The factory point is named "default"; its pretty string carries the + // watt / hashrate / frequency operating point. + let default = presets.iter().find(|p| p.name == "default").unwrap(); + assert_eq!(default.pretty.as_deref(), Some("2794 W ~ 121.8 TH @ 590 MHz")); + // IsTuned maps to the status string. + let tuned = presets.iter().find(|p| p.name == "290MHz").unwrap(); + assert_eq!(tuned.status.as_deref(), Some("tuned")); + assert_eq!(default.status.as_deref(), Some("untuned")); + } + #[tokio::test] async fn test_luxminer_v1() -> anyhow::Result<()> {