Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ba3211371 | ||
|
|
c8d5cd71c4 |
Generated
+6
@@ -76,13 +76,19 @@ dependencies = [
|
|||||||
name = "alkane-gui"
|
name = "alkane-gui"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"aes",
|
||||||
"alkane-core",
|
"alkane-core",
|
||||||
"alkane-discovery",
|
"alkane-discovery",
|
||||||
"asic-rs",
|
"asic-rs",
|
||||||
|
"base64 0.21.7",
|
||||||
|
"ecb",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
|
"hex",
|
||||||
|
"md5crypt",
|
||||||
"measurements",
|
"measurements",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"sha2",
|
||||||
"tokio",
|
"tokio",
|
||||||
"wx-rs",
|
"wx-rs",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -19,3 +19,11 @@ tokio = { version = "1", features = ["rt"] }
|
|||||||
futures-util = "0.3"
|
futures-util = "0.3"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
|
# WhatsMiner :4028 token-auth access check (round 12 #8b) -- same crates the
|
||||||
|
# vendored asic-rs whatsminer backend uses, so no new versions enter the lock.
|
||||||
|
md5crypt = "1"
|
||||||
|
sha2 = "0.10"
|
||||||
|
aes = "0.8"
|
||||||
|
ecb = "0.1"
|
||||||
|
base64 = "0.21"
|
||||||
|
hex = "0.4"
|
||||||
|
|||||||
@@ -14,10 +14,29 @@
|
|||||||
//! rather than add an HTTP+digest crate, so the offline/vendored build is
|
//! rather than add an HTTP+digest crate, so the offline/vendored build is
|
||||||
//! unaffected. `Some(true)` = locked, `Some(false)` = unlocked, `None` =
|
//! unaffected. `Some(true)` = locked, `Some(false)` = unlocked, `None` =
|
||||||
//! indeterminate (unreachable, or an endpoint/vendor this probe doesn't cover).
|
//! indeterminate (unreachable, or an endpoint/vendor this probe doesn't cover).
|
||||||
|
//!
|
||||||
|
//! WhatsMiner has no such digest-gated web endpoint (it returns a 307 redirect
|
||||||
|
//! for the Antminer paths, so the curl probe always read "indeterminate" and the
|
||||||
|
//! table fell back to a capability guess that marked older units "locked" even
|
||||||
|
//! with the default login -- round 12 #8b). Instead we run the WhatsMiner
|
||||||
|
//! :4028 token handshake: `get_token` (unauthenticated) yields a salt, we derive
|
||||||
|
//! the AES key from the password, and send a NON-mutating encrypted `summary`.
|
||||||
|
//! An encrypted reply means the key (hence password) was accepted -> unlocked;
|
||||||
|
//! a plaintext `enc json load err` means it was rejected -> locked.
|
||||||
|
|
||||||
|
use std::io::{Read, Write};
|
||||||
|
use std::net::{SocketAddr, TcpStream};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use aes::Aes256;
|
||||||
|
use aes::cipher::{BlockEncryptMut, KeyInit, block_padding::ZeroPadding};
|
||||||
|
use base64::Engine;
|
||||||
|
use base64::engine::general_purpose::STANDARD as BASE64;
|
||||||
|
use sha2::{Digest, Sha256};
|
||||||
|
|
||||||
|
type Aes256EcbEnc = ecb::Encryptor<Aes256>;
|
||||||
|
|
||||||
/// Classify a miner's access state from an HTTP status code string (curl's
|
/// Classify a miner's access state from an HTTP status code string (curl's
|
||||||
/// `%{http_code}` output). Conservative: anything other than a clear
|
/// `%{http_code}` output). Conservative: anything other than a clear
|
||||||
/// authenticated/unauthorized answer is `None`.
|
/// authenticated/unauthorized answer is `None`.
|
||||||
@@ -35,12 +54,16 @@ fn endpoint(_firmware: &str) -> &'static str {
|
|||||||
"/cgi-bin/get_miner_conf.cgi"
|
"/cgi-bin/get_miner_conf.cgi"
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Probe one miner's access state over its web API with the given credentials.
|
/// Probe one miner's access state. `make` is the miner brand ("Whatsminer" /
|
||||||
/// Returns `Ok(Some(true/false))` on a decisive lock/unlock answer, `Ok(None)`
|
/// "Antminer"): WhatsMiner uses the :4028 token handshake, everything else the
|
||||||
/// if reachable-but-indeterminate or a vendor this probe doesn't cover, or
|
/// digest-auth web probe. Returns `Ok(Some(true/false))` on a decisive
|
||||||
/// `Err` only on a failure to run curl at all.
|
/// lock/unlock answer, `Ok(None)` if indeterminate, `Err` only on a probe that
|
||||||
pub fn probe_access(ip: &str, firmware: &str, user: &str, pass: &str) -> Result<Option<bool>, String> {
|
/// could not run at all.
|
||||||
let url = format!("http://{ip}{}", endpoint(firmware));
|
pub fn probe_access(ip: &str, make: &str, user: &str, pass: &str) -> Result<Option<bool>, String> {
|
||||||
|
if make.eq_ignore_ascii_case("whatsminer") {
|
||||||
|
return Ok(probe_whatsminer_access(ip, &whatsminer_password_candidates()));
|
||||||
|
}
|
||||||
|
let url = format!("http://{ip}{}", endpoint(make));
|
||||||
let userpass = format!("{user}:{pass}");
|
let userpass = format!("{user}:{pass}");
|
||||||
let mut cmd = Command::new("curl");
|
let mut cmd = Command::new("curl");
|
||||||
cmd.args([
|
cmd.args([
|
||||||
@@ -96,6 +119,114 @@ fn wait_with_timeout(mut cmd: Command, timeout: Duration) -> Result<std::process
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Passwords to try for a WhatsMiner access check: a user-set per-firmware
|
||||||
|
/// override (round 12 #13) wins; otherwise the two factory defaults ("admin" for
|
||||||
|
/// V1/V2, "super" for V3). All attempts are non-mutating, so trying both is safe.
|
||||||
|
fn whatsminer_password_candidates() -> Vec<String> {
|
||||||
|
if let Some((_, pass)) = crate::credentials::load_firmware_credentials().get("WhatsMiner Stock") {
|
||||||
|
if !pass.is_empty() {
|
||||||
|
return vec![pass.clone()];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vec!["admin".to_string(), "super".to_string()]
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One WhatsMiner :4028 request/response (the miner closes the socket after it
|
||||||
|
/// replies). Returns the NUL-trimmed body.
|
||||||
|
fn wm_rpc(ip: &str, payload: &str, timeout: Duration) -> Result<String, String> {
|
||||||
|
let addr: SocketAddr = format!("{ip}:4028")
|
||||||
|
.parse()
|
||||||
|
.map_err(|e| format!("bad address {ip}: {e}"))?;
|
||||||
|
let mut stream = TcpStream::connect_timeout(&addr, timeout).map_err(|e| e.to_string())?;
|
||||||
|
stream.set_read_timeout(Some(timeout)).ok();
|
||||||
|
stream.set_write_timeout(Some(timeout)).ok();
|
||||||
|
stream.write_all(payload.as_bytes()).map_err(|e| e.to_string())?;
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
let mut chunk = [0u8; 4096];
|
||||||
|
loop {
|
||||||
|
match stream.read(&mut chunk) {
|
||||||
|
Ok(0) => break,
|
||||||
|
Ok(n) => {
|
||||||
|
buf.extend_from_slice(&chunk[..n]);
|
||||||
|
if buf.len() > 1 << 20 {
|
||||||
|
break; // cap a runaway response
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(_) => break,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(String::from_utf8_lossy(&buf).trim_matches('\u{0}').to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// AES-256-ECB encrypt `data` under SHA256(pwd_md5), base64-encoded -- the exact
|
||||||
|
/// scheme the WhatsMiner btminer API expects (mirrors the vendored asic-rs
|
||||||
|
/// whatsminer v2 backend).
|
||||||
|
fn wm_aes_ecb_enc(pwd_md5: &str, data: &str) -> Option<String> {
|
||||||
|
let key = Sha256::digest(pwd_md5.as_bytes()); // 32 bytes
|
||||||
|
let mut buffer = data.as_bytes().to_vec();
|
||||||
|
while !buffer.len().is_multiple_of(16) {
|
||||||
|
buffer.push(0);
|
||||||
|
}
|
||||||
|
let ct = Aes256EcbEnc::new_from_slice(&key)
|
||||||
|
.ok()?
|
||||||
|
.encrypt_padded_mut::<ZeroPadding>(&mut buffer, data.len())
|
||||||
|
.ok()?;
|
||||||
|
Some(BASE64.encode(ct))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check a WhatsMiner's access via the :4028 token handshake, trying each
|
||||||
|
/// candidate password. Returns `Some(false)` (unlocked) on the first password
|
||||||
|
/// the miner accepts, `Some(true)` (locked) if all are rejected, `None` if the
|
||||||
|
/// miner is unreachable or speaks an unexpected dialect. Non-mutating: only
|
||||||
|
/// `get_token` and a read-only `summary` are ever sent.
|
||||||
|
fn probe_whatsminer_access(ip: &str, passwords: &[String]) -> Option<bool> {
|
||||||
|
let timeout = Duration::from_secs(6);
|
||||||
|
let mut reachable = false;
|
||||||
|
for pass in passwords {
|
||||||
|
// 1. get_token (no auth) -> salt / newsalt / time.
|
||||||
|
let tok_resp = match wm_rpc(ip, "{\"command\":\"get_token\"}", timeout) {
|
||||||
|
Ok(s) => s,
|
||||||
|
Err(_) => return None,
|
||||||
|
};
|
||||||
|
let v: serde_json::Value = match serde_json::from_str(&tok_resp) {
|
||||||
|
Ok(v) => v,
|
||||||
|
Err(_) => return None,
|
||||||
|
};
|
||||||
|
let Some(msg) = v.get("Msg") else { return None };
|
||||||
|
let (Some(salt), Some(newsalt), Some(time)) = (
|
||||||
|
msg.get("salt").and_then(|s| s.as_str()),
|
||||||
|
msg.get("newsalt").and_then(|s| s.as_str()),
|
||||||
|
msg.get("time").and_then(|s| s.as_str()),
|
||||||
|
) else {
|
||||||
|
return None;
|
||||||
|
};
|
||||||
|
reachable = true;
|
||||||
|
// 2. Derive the md5crypt password hash + write-token from the password.
|
||||||
|
let crypted = md5crypt::md5crypt(pass.as_bytes(), salt.as_bytes());
|
||||||
|
let full = String::from_utf8_lossy(&crypted);
|
||||||
|
let Some(pwd_md5) = full.split('$').nth(3) else { continue };
|
||||||
|
let sign_crypted = md5crypt::md5crypt(format!("{pwd_md5}{time}").as_bytes(), newsalt.as_bytes());
|
||||||
|
let sign_full = String::from_utf8_lossy(&sign_crypted);
|
||||||
|
let host_sign = sign_full.split('$').nth(3).unwrap_or("");
|
||||||
|
// 3. Send an encrypted, read-only `summary`. If the AES key (from the
|
||||||
|
// password) is right the miner replies encrypted; if wrong it returns
|
||||||
|
// a plaintext "enc json load err".
|
||||||
|
let cmd = format!("{{\"command\":\"summary\",\"token\":\"{host_sign}\"}}");
|
||||||
|
let Some(enc) = wm_aes_ecb_enc(pwd_md5, &cmd) else { continue };
|
||||||
|
let payload = format!("{{\"enc\":1,\"data\":\"{enc}\"}}");
|
||||||
|
let resp = match wm_rpc(ip, &payload, timeout) {
|
||||||
|
Ok(s) => s,
|
||||||
|
Err(_) => return None,
|
||||||
|
};
|
||||||
|
if resp.contains("\"enc\"") {
|
||||||
|
return Some(false); // accepted -> unlocked/writable
|
||||||
|
}
|
||||||
|
// rejected -> try the next candidate password
|
||||||
|
}
|
||||||
|
// Reached the miner and every candidate password was rejected -> locked.
|
||||||
|
if reachable { Some(true) } else { None }
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -112,4 +243,15 @@ mod tests {
|
|||||||
assert_eq!(classify_http_code(" 200 "), Some(false), "whitespace tolerated");
|
assert_eq!(classify_http_code(" 200 "), Some(false), "whitespace tolerated");
|
||||||
assert_eq!(classify_http_code(""), None);
|
assert_eq!(classify_http_code(""), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn whatsminer_aes_ecb_matches_reference() {
|
||||||
|
// Deterministic vector from the verified btminer scheme: AES-256-ECB over
|
||||||
|
// SHA256(pwd_md5), zero-padded, base64. Guards the WhatsMiner access
|
||||||
|
// handshake crypto (round 12 #8b) without needing a live miner.
|
||||||
|
assert_eq!(
|
||||||
|
wm_aes_ecb_enc("abc123def456", "{\"command\":\"summary\"}").as_deref(),
|
||||||
|
Some("jn5Wru/5hhMtU1IgamxLoUd/YTxaLTxEeiCQxu5pO+Q=")
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,24 @@ fn main() {
|
|||||||
std::process::exit(run_selftest());
|
std::process::exit(run_selftest());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Headless access-probe check: `ALKANE_ACCESS_PROBE="<ip> <make>"` prints the
|
||||||
|
// lock state the real access probe computes (no GUI, no wx), so the WhatsMiner
|
||||||
|
// :4028 token check and the Antminer digest check can be verified directly.
|
||||||
|
if let Some(spec) = std::env::var_os("ALKANE_ACCESS_PROBE") {
|
||||||
|
let spec = spec.to_string_lossy();
|
||||||
|
let mut it = spec.split_whitespace();
|
||||||
|
let ip = it.next().unwrap_or("");
|
||||||
|
let make = it.next().unwrap_or("");
|
||||||
|
let (user, pass) = credentials::load_credentials().unwrap_or_default();
|
||||||
|
match access_probe::probe_access(ip, make, &user, &pass) {
|
||||||
|
Ok(Some(true)) => println!("ACCESS {ip} {make}: LOCKED"),
|
||||||
|
Ok(Some(false)) => println!("ACCESS {ip} {make}: UNLOCKED"),
|
||||||
|
Ok(None) => println!("ACCESS {ip} {make}: INDETERMINATE"),
|
||||||
|
Err(e) => println!("ACCESS {ip} {make}: ERROR {e}"),
|
||||||
|
}
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
// Bootstrap the wx app + main frame (upstream bridge).
|
// Bootstrap the wx app + main frame (upstream bridge).
|
||||||
wx_rs::init_app("alkane-toolkit", 1280, 800);
|
wx_rs::init_app("alkane-toolkit", 1280, 800);
|
||||||
// Follow the system light/dark appearance.
|
// Follow the system light/dark appearance.
|
||||||
|
|||||||
@@ -568,9 +568,17 @@ async fn to_row(miner: &dyn Miner) -> MinerRow {
|
|||||||
// on-board SSH/I2C probe -- a separate feature).
|
// on-board SSH/I2C probe -- a separate feature).
|
||||||
let pic_present = if model.to_lowercase().contains("nopic") { Some(false) } else { None };
|
let pic_present = if model.to_lowercase().contains("nopic") { Some(false) } else { None };
|
||||||
// Access: locked/view-only when the miner exposes no writable control at
|
// Access: locked/view-only when the miner exposes no writable control at
|
||||||
// all, otherwise unlocked. Inferred from capabilities (asic-rs has no direct
|
// all, otherwise unlocked. Inferred from asic-rs capabilities (there is no
|
||||||
// lock-state field).
|
// direct lock-state field). WhatsMiner is the exception: it is controllable
|
||||||
let write_locked = Some(!caps.any_control());
|
// over its :4028 token API regardless of which commands the matched asic-rs
|
||||||
|
// backend implements, so this heuristic falsely marks older units "locked".
|
||||||
|
// Leave it unknown and let the real access probe (the :4028 token check)
|
||||||
|
// decide (round 12 #8b).
|
||||||
|
let write_locked = if brand.eq_ignore_ascii_case("whatsminer") {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(!caps.any_control())
|
||||||
|
};
|
||||||
// Per-hashboard health for the Boards status dots (round 11 #10): green =
|
// Per-hashboard health for the Boards status dots (round 11 #10): green =
|
||||||
// present & hashing, red = present but idle/faulty, grey = expected but not
|
// present & hashing, red = present but idle/faulty, grey = expected but not
|
||||||
// detected. Boards keep asic-rs's reported order (board 1 first); any boards
|
// detected. Boards keep asic-rs's reported order (board 1 first); any boards
|
||||||
@@ -1146,11 +1154,11 @@ pub fn start_access_probe(
|
|||||||
let thread_cancel = cancel.clone();
|
let thread_cancel = cancel.clone();
|
||||||
let err_tx = tx.clone();
|
let err_tx = tx.clone();
|
||||||
let res = std::thread::Builder::new().name("access-probe".into()).spawn(move || {
|
let res = std::thread::Builder::new().name("access-probe".into()).spawn(move || {
|
||||||
for (ip, fw) in targets {
|
for (ip, make) in targets {
|
||||||
if thread_cancel.load(Ordering::Relaxed) {
|
if thread_cancel.load(Ordering::Relaxed) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let (locked, error) = match crate::access_probe::probe_access(&ip, &fw, &user, &pass) {
|
let (locked, error) = match crate::access_probe::probe_access(&ip, &make, &user, &pass) {
|
||||||
Ok(v) => (v, None),
|
Ok(v) => (v, None),
|
||||||
Err(e) => (None, Some(e)),
|
Err(e) => (None, Some(e)),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1455,10 +1455,13 @@ impl App {
|
|||||||
wx_rs::set_status_text("an access check is already running");
|
wx_rs::set_status_text("an access check is already running");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Pass the brand (make), not the firmware family: the access probe picks
|
||||||
|
// its strategy by make (WhatsMiner :4028 token vs Antminer web digest),
|
||||||
|
// and "Stock" alone can't tell them apart (round 12 #8b).
|
||||||
let targets: Vec<(String, String)> = self
|
let targets: Vec<(String, String)> = self
|
||||||
.selected_rows()
|
.selected_rows()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|r| (r.ip.clone(), r.firmware.clone()))
|
.map(|r| (r.ip.clone(), r.brand.clone()))
|
||||||
.collect();
|
.collect();
|
||||||
if targets.is_empty() {
|
if targets.is_empty() {
|
||||||
return;
|
return;
|
||||||
|
|||||||
+243
@@ -0,0 +1,243 @@
|
|||||||
|
Subject: [PATCH 0006] antminer: route old models to the right backend + read the Z15 control board
|
||||||
|
|
||||||
|
Round-12 #10. Three fixes for stock Antminer Z15/Z15J (fw 2020), all verified
|
||||||
|
live on 10.5.1.x:
|
||||||
|
|
||||||
|
1. Backend routing: the version detector only read summary.cgi, which older
|
||||||
|
models (Z15) do not serve (404) -> version None -> AntMiner::new defaulted to
|
||||||
|
the newest backend, which mis-parsed the miner (empty control board, no
|
||||||
|
expected hashrate/wattage/fans). Fall back to the cgminer :4028 `version`
|
||||||
|
RPC's CompileTime so the Z15 (2020) routes to the v2020 backend.
|
||||||
|
|
||||||
|
2. Control board "read, not guess": the Z15 has no miner_type.cgi, so its
|
||||||
|
control-board subtype is unreadable there. Read the kernel build string from
|
||||||
|
get_system_info.cgi instead ("Linux 4.6.0-xilinx-..." -> Xilinx); the
|
||||||
|
ControlBoardVersion field now carries both the subtype and the kernel, and the
|
||||||
|
parser prefers the subtype and falls back to the kernel marker.
|
||||||
|
|
||||||
|
3. Malformed cgminer stats: the Z15 emits a stats array whose objects are not
|
||||||
|
comma-separated (`...}{"STATS":0...`), invalid JSON that serde rejected,
|
||||||
|
dropping the whole stats command and every stats-derived field. Insert the
|
||||||
|
missing separators before parsing (a no-op on well-formed responses); this
|
||||||
|
restores expected hashrate, fans, hashboards and uptime. The expected
|
||||||
|
hashrate also gets the same Equihash Sol/s reinterpretation as the realtime
|
||||||
|
rate, so both read on one scale (e.g. 144k / 320k) instead of the expected
|
||||||
|
reading ~1e6x larger.
|
||||||
|
|
||||||
|
diff --git a/vendor/asic-rs-firmwares-antminer/src/backends/v2020/mod.rs b/vendor/asic-rs-firmwares-antminer/src/backends/v2020/mod.rs
|
||||||
|
index 5b9f77b3..a02bdf9d 100644
|
||||||
|
--- a/vendor/asic-rs-firmwares-antminer/src/backends/v2020/mod.rs
|
||||||
|
+++ b/vendor/asic-rs-firmwares-antminer/src/backends/v2020/mod.rs
|
||||||
|
@@ -434,14 +434,29 @@ impl GetDataLocations for AntMinerV2020 {
|
||||||
|
tag: None,
|
||||||
|
},
|
||||||
|
)],
|
||||||
|
- DataField::ControlBoardVersion => vec![(
|
||||||
|
- WEB_MINER_TYPE,
|
||||||
|
- DataExtractor {
|
||||||
|
- func: get_by_pointer,
|
||||||
|
- key: Some("/subtype"),
|
||||||
|
- tag: None,
|
||||||
|
- },
|
||||||
|
- )],
|
||||||
|
+ // Prefer the explicit control-board subtype from miner_type.cgi, but
|
||||||
|
+ // carry the kernel build string from get_system_info.cgi too: older
|
||||||
|
+ // models (e.g. Z15/Z15J) have no miner_type.cgi, and their kernel
|
||||||
|
+ // string ("...-xilinx-...") names the control board we can actually
|
||||||
|
+ // read instead of guessing from the model (round 12 #10).
|
||||||
|
+ DataField::ControlBoardVersion => vec![
|
||||||
|
+ (
|
||||||
|
+ WEB_MINER_TYPE,
|
||||||
|
+ DataExtractor {
|
||||||
|
+ func: get_by_pointer,
|
||||||
|
+ key: Some("/subtype"),
|
||||||
|
+ tag: Some("subtype"),
|
||||||
|
+ },
|
||||||
|
+ ),
|
||||||
|
+ (
|
||||||
|
+ WEB_SYSTEM_INFO,
|
||||||
|
+ DataExtractor {
|
||||||
|
+ func: get_by_pointer,
|
||||||
|
+ key: Some("/system_kernel_version"),
|
||||||
|
+ tag: Some("kernel"),
|
||||||
|
+ },
|
||||||
|
+ ),
|
||||||
|
+ ],
|
||||||
|
// cgminer names its summary keys after the unit they are in —
|
||||||
|
// `GHS 5s` on SHA-256 models, `MHS 5s` on Scrypt ones — so keep
|
||||||
|
// the whole entry and let the parse pick the key that is present.
|
||||||
|
@@ -748,16 +763,33 @@ impl GetExpectedHashrate for AntMinerV2020 {
|
||||||
|
let value = field?
|
||||||
|
.pointer("/hashrate")
|
||||||
|
.and_then(Self::parse_f64_field)?;
|
||||||
|
+ // Equihash miners (Z15/Z15J) report `total_rateideal` as a Sol/s count in
|
||||||
|
+ // the same (mislabelled) scale as the realtime "GHS" rate, so reinterpret
|
||||||
|
+ // it as the base Hash unit -- matching parse_hashrate. Without this,
|
||||||
|
+ // expected reads ~1e6x larger than realtime and the realtime figure looks
|
||||||
|
+ // absent next to it (round 12 #10).
|
||||||
|
+ let is_equihash = self.device_info.algo == HashAlgorithm::Equihash
|
||||||
|
+ || self
|
||||||
|
+ .device_info
|
||||||
|
+ .model
|
||||||
|
+ .to_string()
|
||||||
|
+ .to_ascii_uppercase()
|
||||||
|
+ .contains("Z15");
|
||||||
|
+ let unit = if is_equihash {
|
||||||
|
+ HashRateUnit::Hash
|
||||||
|
+ } else {
|
||||||
|
+ // `total_rateideal` does not name its own scale, so take it from
|
||||||
|
+ // STATS' `rate_unit` (`"GH"` / `"MH"`).
|
||||||
|
+ field
|
||||||
|
+ .and_then(|v| v.pointer("/unit"))
|
||||||
|
+ .and_then(|v| v.as_str())
|
||||||
|
+ .and_then(|s| HashRateUnit::from_str(s).ok())
|
||||||
|
+ .unwrap_or(HashRateUnit::GigaHash)
|
||||||
|
+ };
|
||||||
|
Some(
|
||||||
|
HashRate {
|
||||||
|
value,
|
||||||
|
- // `total_rateideal` does not name its own scale, so take it
|
||||||
|
- // from STATS' `rate_unit` (`"GH"` / `"MH"`).
|
||||||
|
- unit: field
|
||||||
|
- .and_then(|v| v.pointer("/unit"))
|
||||||
|
- .and_then(|v| v.as_str())
|
||||||
|
- .and_then(|s| HashRateUnit::from_str(s).ok())
|
||||||
|
- .unwrap_or(HashRateUnit::GigaHash),
|
||||||
|
+ unit,
|
||||||
|
algo: self.device_info.algo,
|
||||||
|
}
|
||||||
|
.as_unit(HashRateUnit::default()),
|
||||||
|
@@ -888,11 +920,34 @@ impl GetControlBoardVersion for AntMinerV2020 {
|
||||||
|
&self,
|
||||||
|
data: &HashMap<DataField, Value>,
|
||||||
|
) -> Option<MinerControlBoard> {
|
||||||
|
- let cb_type = data.extract::<String>(DataField::ControlBoardVersion)?;
|
||||||
|
- match cb_type.as_str() {
|
||||||
|
- s if s.to_uppercase().contains("AML") => Some(AntMinerControlBoard::AMLogic.into()),
|
||||||
|
- _ => AntMinerControlBoard::parse(cb_type.split("_").collect::<Vec<&str>>()[0])
|
||||||
|
- .map(|cb| cb.into()),
|
||||||
|
+ let field = data.get(&DataField::ControlBoardVersion)?;
|
||||||
|
+ // Explicit control-board subtype (miner_type.cgi) wins when present.
|
||||||
|
+ let subtype = field
|
||||||
|
+ .pointer("/subtype")
|
||||||
|
+ .and_then(|v| v.as_str())
|
||||||
|
+ .unwrap_or("");
|
||||||
|
+ if !subtype.is_empty() {
|
||||||
|
+ return match subtype {
|
||||||
|
+ s if s.to_uppercase().contains("AML") => Some(AntMinerControlBoard::AMLogic.into()),
|
||||||
|
+ _ => AntMinerControlBoard::parse(subtype.split('_').next().unwrap_or(subtype))
|
||||||
|
+ .map(|cb| cb.into()),
|
||||||
|
+ };
|
||||||
|
+ }
|
||||||
|
+ // No subtype (older models): read the control board from the kernel build
|
||||||
|
+ // string instead of guessing from the model (round 12 #10). Bitmain names
|
||||||
|
+ // the SoC in the kernel version, e.g. "Linux 4.6.0-xilinx-..." (Z15) or an
|
||||||
|
+ // AMLogic/Meson kernel on newer AMLogic boards.
|
||||||
|
+ let kernel = field
|
||||||
|
+ .pointer("/kernel")
|
||||||
|
+ .and_then(|v| v.as_str())
|
||||||
|
+ .unwrap_or("")
|
||||||
|
+ .to_ascii_lowercase();
|
||||||
|
+ if kernel.contains("xilinx") || kernel.contains("zynq") {
|
||||||
|
+ Some(AntMinerControlBoard::Xilinx.into())
|
||||||
|
+ } else if kernel.contains("aml") || kernel.contains("meson") {
|
||||||
|
+ Some(AntMinerControlBoard::AMLogic.into())
|
||||||
|
+ } else {
|
||||||
|
+ None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
diff --git a/vendor/asic-rs-firmwares-antminer/src/backends/v2020/rpc.rs b/vendor/asic-rs-firmwares-antminer/src/backends/v2020/rpc.rs
|
||||||
|
index 23962f35..52232c1f 100644
|
||||||
|
--- a/vendor/asic-rs-firmwares-antminer/src/backends/v2020/rpc.rs
|
||||||
|
+++ b/vendor/asic-rs-firmwares-antminer/src/backends/v2020/rpc.rs
|
||||||
|
@@ -71,7 +71,17 @@ impl AntMinerRPCAPI {
|
||||||
|
read_stream_response(&mut stream, DEFAULT_RPC_TIMEOUT).await
|
||||||
|
};
|
||||||
|
let response = response?;
|
||||||
|
- self.parse_rpc_result(&response)
|
||||||
|
+ self.parse_rpc_result(&Self::sanitize_cgminer(&response))
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /// Antminer's cgminer `stats` sometimes emits an array whose objects are not
|
||||||
|
+ /// comma-separated (`...}{"STATS":0,...` on the Z15/Z15J), which is invalid
|
||||||
|
+ /// JSON that serde rejects -- dropping the whole stats command and with it
|
||||||
|
+ /// every stats-derived field (expected hashrate, wattage, fans, hashboards,
|
||||||
|
+ /// uptime). Insert the missing separators. Well-formed JSON never contains an
|
||||||
|
+ /// unseparated `}{`, so this is a no-op on valid responses (round 12 #10).
|
||||||
|
+ fn sanitize_cgminer(response: &str) -> String {
|
||||||
|
+ response.replace("}{", "},{")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_rpc_result(&self, response: &str) -> anyhow::Result<Value> {
|
||||||
|
diff --git a/vendor/asic-rs-firmwares-antminer/src/firmware.rs b/vendor/asic-rs-firmwares-antminer/src/firmware.rs
|
||||||
|
index fce5e8ff..46abbc9d 100644
|
||||||
|
--- a/vendor/asic-rs-firmwares-antminer/src/firmware.rs
|
||||||
|
+++ b/vendor/asic-rs-firmwares-antminer/src/firmware.rs
|
||||||
|
@@ -142,18 +142,9 @@ async fn get_model_with_auth(
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-/// Fetch the firmware version from a miner using digest auth.
|
||||||
|
-async fn get_version_with_auth(ip: IpAddr, auth: &MinerAuth) -> Option<semver::Version> {
|
||||||
|
- let client = build_discovery_client().ok()?;
|
||||||
|
- let data: Response = client
|
||||||
|
- .get(format!("http://{ip}/cgi-bin/summary.cgi"))
|
||||||
|
- .send_digest_auth((auth.username(), auth.password()))
|
||||||
|
- .await
|
||||||
|
- .ok()?;
|
||||||
|
-
|
||||||
|
- let json_data = data.json::<serde_json::Value>().await.ok()?;
|
||||||
|
- let fw_version = json_data["INFO"]["CompileTime"].as_str().unwrap_or("");
|
||||||
|
-
|
||||||
|
+/// Parse an Antminer cgminer `CompileTime` string ("Mon Dec 14 18:01:42 CST
|
||||||
|
+/// 2020") into a date-based semver (year.month.day) used to pick the backend.
|
||||||
|
+fn parse_antminer_compile_time(fw_version: &str) -> Option<semver::Version> {
|
||||||
|
let cleaned: String = {
|
||||||
|
let mut parts: Vec<&str> = fw_version.split_whitespace().collect();
|
||||||
|
if parts.len() > 4 {
|
||||||
|
@@ -161,9 +152,7 @@ async fn get_version_with_auth(ip: IpAddr, auth: &MinerAuth) -> Option<semver::V
|
||||||
|
}
|
||||||
|
parts.join(" ")
|
||||||
|
};
|
||||||
|
-
|
||||||
|
let dt = NaiveDateTime::parse_from_str(&cleaned, "%a %b %e %H:%M:%S %Y").ok()?;
|
||||||
|
-
|
||||||
|
Some(semver::Version::new(
|
||||||
|
dt.year() as u64,
|
||||||
|
dt.month() as u64,
|
||||||
|
@@ -171,6 +160,34 @@ async fn get_version_with_auth(ip: IpAddr, auth: &MinerAuth) -> Option<semver::V
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
+/// Fetch the firmware version (as a date-based semver) to pick the backend.
|
||||||
|
+async fn get_version_with_auth(ip: IpAddr, auth: &MinerAuth) -> Option<semver::Version> {
|
||||||
|
+ // Newer Antminers expose the firmware CompileTime via summary.cgi.
|
||||||
|
+ if let Ok(client) = build_discovery_client()
|
||||||
|
+ && let Ok(data) = client
|
||||||
|
+ .get(format!("http://{ip}/cgi-bin/summary.cgi"))
|
||||||
|
+ .send_digest_auth((auth.username(), auth.password()))
|
||||||
|
+ .await
|
||||||
|
+ && let Ok(json_data) = data.json::<serde_json::Value>().await
|
||||||
|
+ && let Some(v) =
|
||||||
|
+ parse_antminer_compile_time(json_data["INFO"]["CompileTime"].as_str().unwrap_or(""))
|
||||||
|
+ {
|
||||||
|
+ return Some(v);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ // Older models (e.g. Z15/Z15J) have no summary.cgi, so summary-based version
|
||||||
|
+ // detection returns nothing and the miner would default to the newest
|
||||||
|
+ // backend and be mis-parsed. Fall back to the cgminer :4028 `version` RPC,
|
||||||
|
+ // which still reports the CompileTime, so the right (older) backend is picked
|
||||||
|
+ // (round 12 #10).
|
||||||
|
+ let rpc = asic_rs_core::util::send_rpc_command(&ip, "version").await?;
|
||||||
|
+ parse_antminer_compile_time(
|
||||||
|
+ rpc.pointer("/VERSION/0/CompileTime")
|
||||||
|
+ .and_then(|v| v.as_str())
|
||||||
|
+ .unwrap_or(""),
|
||||||
|
+ )
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
#[async_trait]
|
||||||
|
impl MinerFirmware for AntMinerStockFirmware {
|
||||||
|
/// Uses default credentials. For custom credentials, use `build_miner`
|
||||||
+1
-1
@@ -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":"6e42d50107b1a43fd7cf4a4c4f538468a337ed219ad8d6b23bd9abdabd123bd5","Cargo.lock":"7f984c7231c91f2def8f3e2e923a85c2e0b3239492f5ce23400881ea4de1aa16","Cargo.toml":"8a447efc18cd97d019a9771fb258b06f694499500561564eec75480e46bcc554","Cargo.toml.orig":"6c9e7b86804255debe03545c6358eb975d3d470810a19e6c40c680299a686b1f","src/backends/mod.rs":"65cdc60cdf38968f5a7e197338f4cf6173406ce69a4f0aaa96a9e29f4f581b6e","src/backends/v2020/firmware.rs":"5a41bfb8f42f17523e68f8702e87d75bcdb268bd4950bb66227f6966ef3576a9","src/backends/v2020/mod.rs":"f1972769a1b4811d5772e96b2e6c45b461cdcb4175355dba2b586b9df776fc1d","src/backends/v2020/rpc.rs":"2b24bbb432b302dd15f7a354054fc96c6a75cac2c8e75b8bcc11da37255a05a3","src/backends/v2020/web.rs":"d39b67ed83781b2c4fa84a445b9ffe785ae3001941f800ad9860e050c61c6506","src/backends/v2023_07/firmware.rs":"c07668e351d48dab3e24511b1aa9ab5e408bbcb5a438fdb0542a1377f94b9bbb","src/backends/v2023_07/mod.rs":"278e4dd04a753858e12df96ead3522aef0616ebf6f27b3da4f1a12b064c19ee6","src/backends/v2023_07/rpc.rs":"2b24bbb432b302dd15f7a354054fc96c6a75cac2c8e75b8bcc11da37255a05a3","src/backends/v2023_07/web.rs":"d39b67ed83781b2c4fa84a445b9ffe785ae3001941f800ad9860e050c61c6506","src/firmware.rs":"55d5b722632c0a5cfcf1f8c8252a88c5a1ece887173bb513cca0b22b874d628f","src/lib.rs":"53f7acddeff8f7d82f80d09e0a9f91962011f9ccf2e441c4ca05cd7fc4eb292e","src/test/json/mod.rs":"a3ef4d6805bb4f8ea087e3a9b875e5a1664580e1ff3e3cd2015bb0c5c18ae7bb","src/test/json/v2020/devs.json":"df17cdfc9522e23450702b93f70ff701892db54c6ce6d986300453ad5e0d22db","src/test/json/v2020/mod.rs":"4c2512d36af834d400a865a94c2e8b1919f9d8dcbf54ab2530c73861c51af67d","src/test/json/v2020/pools.json":"4c4d19ad3ef0de84bfb18daaa48428b5f7917d23287c0196eacf3a6e389e7634","src/test/json/v2020/stats.json":"6d3cb463abb7539ae77aa44ef38e62a5dc0db54670aeacf3bbd01e83f49aa1fd","src/test/json/v2020/summary.json":"2f18c81f989b7c5f70dcb0ddac0520e56ec98b6da25c24e59354a6126c965dae","src/test/json/v2020/system_info.json":"51d1ce922e39a254518a24be56ca86ef1b5843582fb26c1ff0ec4ff6f8f91ccf","src/test/json/v2020/version.json":"ae898c4c9ea3462c3e79f9de755f1fccb4ef122b94a4a512e61aa74491c1a8e9","src/test/json/v2023_07/l11_stats.json":"2eab324f253ced9a0ea4e46466691e0e71fc6fde7558fec86bd5acf6bb9c717d","src/test/json/v2023_07/l11_summary.json":"1e0fdb61b968005d0ec5393d9dc889b09efb1398ffa427629bcc0a98d1b67c22","src/test/json/v2023_07/l11_version.json":"d116921a71731c6e492aed109731c39561e34a24c7df2a88d11ac52b80f6100a","src/test/json/v2023_07/l9_stats.json":"731ee545f16dafd356d22703248b91a37f74585ad73cc27441eb3461ce53dca0","src/test/json/v2023_07/l9_summary.json":"b32b5131ad46859b270d2dbb6bdba3c4e5d7301298daee4ce56332c98faaf81d","src/test/json/v2023_07/l9_version.json":"82f03ca6ea8873f12c4d9455f21b98c547801b58fbff1dcd83c837c0f337a129","src/test/json/v2023_07/mod.rs":"1360a8b155b120f2e755ede0736bcc0d76a9d1d693b984a1b51a16e6c0413791","src/test/mod.rs":"ed52c3d613eabc4a0346bb38bcfdf7a94933d61e368d3c9094821edeab92f81b"},"package":"0c06e3ecbf95ae3fe5e30aacae55cf6e7ad3d965f4a93b2f85c7b64f61fc75e2"}
|
{"$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":"6e42d50107b1a43fd7cf4a4c4f538468a337ed219ad8d6b23bd9abdabd123bd5","Cargo.lock":"7f984c7231c91f2def8f3e2e923a85c2e0b3239492f5ce23400881ea4de1aa16","Cargo.toml":"8a447efc18cd97d019a9771fb258b06f694499500561564eec75480e46bcc554","Cargo.toml.orig":"6c9e7b86804255debe03545c6358eb975d3d470810a19e6c40c680299a686b1f","src/backends/mod.rs":"65cdc60cdf38968f5a7e197338f4cf6173406ce69a4f0aaa96a9e29f4f581b6e","src/backends/v2020/firmware.rs":"5a41bfb8f42f17523e68f8702e87d75bcdb268bd4950bb66227f6966ef3576a9","src/backends/v2020/mod.rs":"4018fbe6d907231746b1eb44c8027688b64e9cdb4ba722e0d54c2467786b9afd","src/backends/v2020/rpc.rs":"b517f88b9125fe1d8a20d5167f5d0d105b1339fce3d1a9fad5592e00470f46fb","src/backends/v2020/web.rs":"d39b67ed83781b2c4fa84a445b9ffe785ae3001941f800ad9860e050c61c6506","src/backends/v2023_07/firmware.rs":"c07668e351d48dab3e24511b1aa9ab5e408bbcb5a438fdb0542a1377f94b9bbb","src/backends/v2023_07/mod.rs":"278e4dd04a753858e12df96ead3522aef0616ebf6f27b3da4f1a12b064c19ee6","src/backends/v2023_07/rpc.rs":"2b24bbb432b302dd15f7a354054fc96c6a75cac2c8e75b8bcc11da37255a05a3","src/backends/v2023_07/web.rs":"d39b67ed83781b2c4fa84a445b9ffe785ae3001941f800ad9860e050c61c6506","src/firmware.rs":"e75c21d63218204b61bfab067599402e5c0b20452beaf0b16bfa79bf8afb6b35","src/lib.rs":"53f7acddeff8f7d82f80d09e0a9f91962011f9ccf2e441c4ca05cd7fc4eb292e","src/test/json/mod.rs":"a3ef4d6805bb4f8ea087e3a9b875e5a1664580e1ff3e3cd2015bb0c5c18ae7bb","src/test/json/v2020/devs.json":"df17cdfc9522e23450702b93f70ff701892db54c6ce6d986300453ad5e0d22db","src/test/json/v2020/mod.rs":"4c2512d36af834d400a865a94c2e8b1919f9d8dcbf54ab2530c73861c51af67d","src/test/json/v2020/pools.json":"4c4d19ad3ef0de84bfb18daaa48428b5f7917d23287c0196eacf3a6e389e7634","src/test/json/v2020/stats.json":"6d3cb463abb7539ae77aa44ef38e62a5dc0db54670aeacf3bbd01e83f49aa1fd","src/test/json/v2020/summary.json":"2f18c81f989b7c5f70dcb0ddac0520e56ec98b6da25c24e59354a6126c965dae","src/test/json/v2020/system_info.json":"51d1ce922e39a254518a24be56ca86ef1b5843582fb26c1ff0ec4ff6f8f91ccf","src/test/json/v2020/version.json":"ae898c4c9ea3462c3e79f9de755f1fccb4ef122b94a4a512e61aa74491c1a8e9","src/test/json/v2023_07/l11_stats.json":"2eab324f253ced9a0ea4e46466691e0e71fc6fde7558fec86bd5acf6bb9c717d","src/test/json/v2023_07/l11_summary.json":"1e0fdb61b968005d0ec5393d9dc889b09efb1398ffa427629bcc0a98d1b67c22","src/test/json/v2023_07/l11_version.json":"d116921a71731c6e492aed109731c39561e34a24c7df2a88d11ac52b80f6100a","src/test/json/v2023_07/l9_stats.json":"731ee545f16dafd356d22703248b91a37f74585ad73cc27441eb3461ce53dca0","src/test/json/v2023_07/l9_summary.json":"b32b5131ad46859b270d2dbb6bdba3c4e5d7301298daee4ce56332c98faaf81d","src/test/json/v2023_07/l9_version.json":"82f03ca6ea8873f12c4d9455f21b98c547801b58fbff1dcd83c837c0f337a129","src/test/json/v2023_07/mod.rs":"1360a8b155b120f2e755ede0736bcc0d76a9d1d693b984a1b51a16e6c0413791","src/test/mod.rs":"ed52c3d613eabc4a0346bb38bcfdf7a94933d61e368d3c9094821edeab92f81b"},"package":"0c06e3ecbf95ae3fe5e30aacae55cf6e7ad3d965f4a93b2f85c7b64f61fc75e2"}
|
||||||
+75
-20
@@ -434,14 +434,29 @@ impl GetDataLocations for AntMinerV2020 {
|
|||||||
tag: None,
|
tag: None,
|
||||||
},
|
},
|
||||||
)],
|
)],
|
||||||
DataField::ControlBoardVersion => vec![(
|
// Prefer the explicit control-board subtype from miner_type.cgi, but
|
||||||
WEB_MINER_TYPE,
|
// carry the kernel build string from get_system_info.cgi too: older
|
||||||
DataExtractor {
|
// models (e.g. Z15/Z15J) have no miner_type.cgi, and their kernel
|
||||||
func: get_by_pointer,
|
// string ("...-xilinx-...") names the control board we can actually
|
||||||
key: Some("/subtype"),
|
// read instead of guessing from the model (round 12 #10).
|
||||||
tag: None,
|
DataField::ControlBoardVersion => vec![
|
||||||
},
|
(
|
||||||
)],
|
WEB_MINER_TYPE,
|
||||||
|
DataExtractor {
|
||||||
|
func: get_by_pointer,
|
||||||
|
key: Some("/subtype"),
|
||||||
|
tag: Some("subtype"),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
WEB_SYSTEM_INFO,
|
||||||
|
DataExtractor {
|
||||||
|
func: get_by_pointer,
|
||||||
|
key: Some("/system_kernel_version"),
|
||||||
|
tag: Some("kernel"),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
// cgminer names its summary keys after the unit they are in —
|
// cgminer names its summary keys after the unit they are in —
|
||||||
// `GHS 5s` on SHA-256 models, `MHS 5s` on Scrypt ones — so keep
|
// `GHS 5s` on SHA-256 models, `MHS 5s` on Scrypt ones — so keep
|
||||||
// the whole entry and let the parse pick the key that is present.
|
// the whole entry and let the parse pick the key that is present.
|
||||||
@@ -748,16 +763,33 @@ impl GetExpectedHashrate for AntMinerV2020 {
|
|||||||
let value = field?
|
let value = field?
|
||||||
.pointer("/hashrate")
|
.pointer("/hashrate")
|
||||||
.and_then(Self::parse_f64_field)?;
|
.and_then(Self::parse_f64_field)?;
|
||||||
|
// Equihash miners (Z15/Z15J) report `total_rateideal` as a Sol/s count in
|
||||||
|
// the same (mislabelled) scale as the realtime "GHS" rate, so reinterpret
|
||||||
|
// it as the base Hash unit -- matching parse_hashrate. Without this,
|
||||||
|
// expected reads ~1e6x larger than realtime and the realtime figure looks
|
||||||
|
// absent next to it (round 12 #10).
|
||||||
|
let is_equihash = self.device_info.algo == HashAlgorithm::Equihash
|
||||||
|
|| self
|
||||||
|
.device_info
|
||||||
|
.model
|
||||||
|
.to_string()
|
||||||
|
.to_ascii_uppercase()
|
||||||
|
.contains("Z15");
|
||||||
|
let unit = if is_equihash {
|
||||||
|
HashRateUnit::Hash
|
||||||
|
} else {
|
||||||
|
// `total_rateideal` does not name its own scale, so take it from
|
||||||
|
// STATS' `rate_unit` (`"GH"` / `"MH"`).
|
||||||
|
field
|
||||||
|
.and_then(|v| v.pointer("/unit"))
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.and_then(|s| HashRateUnit::from_str(s).ok())
|
||||||
|
.unwrap_or(HashRateUnit::GigaHash)
|
||||||
|
};
|
||||||
Some(
|
Some(
|
||||||
HashRate {
|
HashRate {
|
||||||
value,
|
value,
|
||||||
// `total_rateideal` does not name its own scale, so take it
|
unit,
|
||||||
// from STATS' `rate_unit` (`"GH"` / `"MH"`).
|
|
||||||
unit: field
|
|
||||||
.and_then(|v| v.pointer("/unit"))
|
|
||||||
.and_then(|v| v.as_str())
|
|
||||||
.and_then(|s| HashRateUnit::from_str(s).ok())
|
|
||||||
.unwrap_or(HashRateUnit::GigaHash),
|
|
||||||
algo: self.device_info.algo,
|
algo: self.device_info.algo,
|
||||||
}
|
}
|
||||||
.as_unit(HashRateUnit::default()),
|
.as_unit(HashRateUnit::default()),
|
||||||
@@ -888,11 +920,34 @@ impl GetControlBoardVersion for AntMinerV2020 {
|
|||||||
&self,
|
&self,
|
||||||
data: &HashMap<DataField, Value>,
|
data: &HashMap<DataField, Value>,
|
||||||
) -> Option<MinerControlBoard> {
|
) -> Option<MinerControlBoard> {
|
||||||
let cb_type = data.extract::<String>(DataField::ControlBoardVersion)?;
|
let field = data.get(&DataField::ControlBoardVersion)?;
|
||||||
match cb_type.as_str() {
|
// Explicit control-board subtype (miner_type.cgi) wins when present.
|
||||||
s if s.to_uppercase().contains("AML") => Some(AntMinerControlBoard::AMLogic.into()),
|
let subtype = field
|
||||||
_ => AntMinerControlBoard::parse(cb_type.split("_").collect::<Vec<&str>>()[0])
|
.pointer("/subtype")
|
||||||
.map(|cb| cb.into()),
|
.and_then(|v| v.as_str())
|
||||||
|
.unwrap_or("");
|
||||||
|
if !subtype.is_empty() {
|
||||||
|
return match subtype {
|
||||||
|
s if s.to_uppercase().contains("AML") => Some(AntMinerControlBoard::AMLogic.into()),
|
||||||
|
_ => AntMinerControlBoard::parse(subtype.split('_').next().unwrap_or(subtype))
|
||||||
|
.map(|cb| cb.into()),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// No subtype (older models): read the control board from the kernel build
|
||||||
|
// string instead of guessing from the model (round 12 #10). Bitmain names
|
||||||
|
// the SoC in the kernel version, e.g. "Linux 4.6.0-xilinx-..." (Z15) or an
|
||||||
|
// AMLogic/Meson kernel on newer AMLogic boards.
|
||||||
|
let kernel = field
|
||||||
|
.pointer("/kernel")
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.unwrap_or("")
|
||||||
|
.to_ascii_lowercase();
|
||||||
|
if kernel.contains("xilinx") || kernel.contains("zynq") {
|
||||||
|
Some(AntMinerControlBoard::Xilinx.into())
|
||||||
|
} else if kernel.contains("aml") || kernel.contains("meson") {
|
||||||
|
Some(AntMinerControlBoard::AMLogic.into())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-1
@@ -71,7 +71,17 @@ impl AntMinerRPCAPI {
|
|||||||
read_stream_response(&mut stream, DEFAULT_RPC_TIMEOUT).await
|
read_stream_response(&mut stream, DEFAULT_RPC_TIMEOUT).await
|
||||||
};
|
};
|
||||||
let response = response?;
|
let response = response?;
|
||||||
self.parse_rpc_result(&response)
|
self.parse_rpc_result(&Self::sanitize_cgminer(&response))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Antminer's cgminer `stats` sometimes emits an array whose objects are not
|
||||||
|
/// comma-separated (`...}{"STATS":0,...` on the Z15/Z15J), which is invalid
|
||||||
|
/// JSON that serde rejects -- dropping the whole stats command and with it
|
||||||
|
/// every stats-derived field (expected hashrate, wattage, fans, hashboards,
|
||||||
|
/// uptime). Insert the missing separators. Well-formed JSON never contains an
|
||||||
|
/// unseparated `}{`, so this is a no-op on valid responses (round 12 #10).
|
||||||
|
fn sanitize_cgminer(response: &str) -> String {
|
||||||
|
response.replace("}{", "},{")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_rpc_result(&self, response: &str) -> anyhow::Result<Value> {
|
fn parse_rpc_result(&self, response: &str) -> anyhow::Result<Value> {
|
||||||
|
|||||||
+31
-14
@@ -142,18 +142,9 @@ async fn get_model_with_auth(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch the firmware version from a miner using digest auth.
|
/// Parse an Antminer cgminer `CompileTime` string ("Mon Dec 14 18:01:42 CST
|
||||||
async fn get_version_with_auth(ip: IpAddr, auth: &MinerAuth) -> Option<semver::Version> {
|
/// 2020") into a date-based semver (year.month.day) used to pick the backend.
|
||||||
let client = build_discovery_client().ok()?;
|
fn parse_antminer_compile_time(fw_version: &str) -> Option<semver::Version> {
|
||||||
let data: Response = client
|
|
||||||
.get(format!("http://{ip}/cgi-bin/summary.cgi"))
|
|
||||||
.send_digest_auth((auth.username(), auth.password()))
|
|
||||||
.await
|
|
||||||
.ok()?;
|
|
||||||
|
|
||||||
let json_data = data.json::<serde_json::Value>().await.ok()?;
|
|
||||||
let fw_version = json_data["INFO"]["CompileTime"].as_str().unwrap_or("");
|
|
||||||
|
|
||||||
let cleaned: String = {
|
let cleaned: String = {
|
||||||
let mut parts: Vec<&str> = fw_version.split_whitespace().collect();
|
let mut parts: Vec<&str> = fw_version.split_whitespace().collect();
|
||||||
if parts.len() > 4 {
|
if parts.len() > 4 {
|
||||||
@@ -161,9 +152,7 @@ async fn get_version_with_auth(ip: IpAddr, auth: &MinerAuth) -> Option<semver::V
|
|||||||
}
|
}
|
||||||
parts.join(" ")
|
parts.join(" ")
|
||||||
};
|
};
|
||||||
|
|
||||||
let dt = NaiveDateTime::parse_from_str(&cleaned, "%a %b %e %H:%M:%S %Y").ok()?;
|
let dt = NaiveDateTime::parse_from_str(&cleaned, "%a %b %e %H:%M:%S %Y").ok()?;
|
||||||
|
|
||||||
Some(semver::Version::new(
|
Some(semver::Version::new(
|
||||||
dt.year() as u64,
|
dt.year() as u64,
|
||||||
dt.month() as u64,
|
dt.month() as u64,
|
||||||
@@ -171,6 +160,34 @@ async fn get_version_with_auth(ip: IpAddr, auth: &MinerAuth) -> Option<semver::V
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Fetch the firmware version (as a date-based semver) to pick the backend.
|
||||||
|
async fn get_version_with_auth(ip: IpAddr, auth: &MinerAuth) -> Option<semver::Version> {
|
||||||
|
// Newer Antminers expose the firmware CompileTime via summary.cgi.
|
||||||
|
if let Ok(client) = build_discovery_client()
|
||||||
|
&& let Ok(data) = client
|
||||||
|
.get(format!("http://{ip}/cgi-bin/summary.cgi"))
|
||||||
|
.send_digest_auth((auth.username(), auth.password()))
|
||||||
|
.await
|
||||||
|
&& let Ok(json_data) = data.json::<serde_json::Value>().await
|
||||||
|
&& let Some(v) =
|
||||||
|
parse_antminer_compile_time(json_data["INFO"]["CompileTime"].as_str().unwrap_or(""))
|
||||||
|
{
|
||||||
|
return Some(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Older models (e.g. Z15/Z15J) have no summary.cgi, so summary-based version
|
||||||
|
// detection returns nothing and the miner would default to the newest
|
||||||
|
// backend and be mis-parsed. Fall back to the cgminer :4028 `version` RPC,
|
||||||
|
// which still reports the CompileTime, so the right (older) backend is picked
|
||||||
|
// (round 12 #10).
|
||||||
|
let rpc = asic_rs_core::util::send_rpc_command(&ip, "version").await?;
|
||||||
|
parse_antminer_compile_time(
|
||||||
|
rpc.pointer("/VERSION/0/CompileTime")
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.unwrap_or(""),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl MinerFirmware for AntMinerStockFirmware {
|
impl MinerFirmware for AntMinerStockFirmware {
|
||||||
/// Uses default credentials. For custom credentials, use `build_miner`
|
/// Uses default credentials. For custom credentials, use `build_miner`
|
||||||
|
|||||||
Reference in New Issue
Block a user