Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da0d1582be | ||
|
|
7f802c568f | ||
|
|
86338062a5 |
@@ -62,6 +62,18 @@ async fn scan(cidrs: &[String]) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
// Cap identification concurrency to match the GUI (see
|
||||||
|
// scan::SCAN_CONCURRENCY_LIMIT). asic-rs defaults to 1000, which over a real
|
||||||
|
// link starves the per-responder get_data -- Braiins miners drop most values
|
||||||
|
// (watts=0, no best-share) and some responders are missed entirely. 128 is the
|
||||||
|
// highest cap that stayed fully reliable on the live fleet. ALKANE_PROBE_CONCURRENCY
|
||||||
|
// overrides it for diagnostics.
|
||||||
|
let concurrency = std::env::var("ALKANE_PROBE_CONCURRENCY")
|
||||||
|
.ok()
|
||||||
|
.and_then(|c| c.parse::<usize>().ok())
|
||||||
|
.unwrap_or(128);
|
||||||
|
eprintln!("(scan concurrency = {concurrency})");
|
||||||
|
f = f.with_concurrent_limit(concurrency);
|
||||||
println!("ip\tmake\tfirmware\tfw_version\tmodel_id\tcontrol_board\twatts\tsupports_power_limit\tsupports_tuning\tbest_share\tsession_best_share");
|
println!("ip\tmake\tfirmware\tfw_version\tmodel_id\tcontrol_board\twatts\tsupports_power_limit\tsupports_tuning\tbest_share\tsession_best_share");
|
||||||
let mut stream = f.scan_stream_with_ip();
|
let mut stream = f.scan_stream_with_ip();
|
||||||
let mut found = 0usize;
|
let mut found = 0usize;
|
||||||
@@ -263,6 +275,9 @@ async fn msgs(ip_s: &str) {
|
|||||||
match f.scan_miner(ip).await {
|
match f.scan_miner(ip).await {
|
||||||
Ok(Some(m)) => {
|
Ok(Some(m)) => {
|
||||||
let d = m.get_data().await;
|
let d = m.get_data().await;
|
||||||
|
let th = |h: &Option<asic_rs::core::data::hashrate::HashRate>| {
|
||||||
|
h.clone().map(|x| x.as_unit(asic_rs::core::data::hashrate::HashRateUnit::TeraHash).value)
|
||||||
|
};
|
||||||
println!(
|
println!(
|
||||||
"{ip}: {} {} hashboards={:?} expected={:?}",
|
"{ip}: {} {} hashboards={:?} expected={:?}",
|
||||||
d.device_info.firmware,
|
d.device_info.firmware,
|
||||||
@@ -270,13 +285,28 @@ async fn msgs(ip_s: &str) {
|
|||||||
d.hashboards.len(),
|
d.hashboards.len(),
|
||||||
d.expected_hashboards,
|
d.expected_hashboards,
|
||||||
);
|
);
|
||||||
|
println!(
|
||||||
|
" TOTAL hashrate={:?} TH wattage={:?} W fluid/env_temp={:?} best_share={:?}",
|
||||||
|
th(&d.hashrate),
|
||||||
|
d.wattage.as_ref().map(|p| p.as_watts()),
|
||||||
|
d.fluid_temperature.as_ref().map(|t| t.as_celsius()),
|
||||||
|
d.best_share,
|
||||||
|
);
|
||||||
|
let fans: Vec<i64> = d
|
||||||
|
.fans
|
||||||
|
.iter()
|
||||||
|
.map(|f| f.rpm.as_ref().map(|r| r.as_rpm() as i64).unwrap_or(-1))
|
||||||
|
.collect();
|
||||||
|
println!(" fans(rpm)={fans:?} psu_fans={}", d.psu_fans.len());
|
||||||
for b in d.hashboards.iter() {
|
for b in d.hashboards.iter() {
|
||||||
println!(
|
println!(
|
||||||
" board position={} hashrate={:?} chips={:?}/{:?}",
|
" board pos={} hr={:?}TH chips={:?}/{:?} board_temp={:?} outlet_temp={:?}",
|
||||||
b.position,
|
b.position,
|
||||||
b.hashrate.clone().map(|h| h.as_unit(asic_rs::core::data::hashrate::HashRateUnit::TeraHash).value),
|
th(&b.hashrate),
|
||||||
b.working_chips,
|
b.working_chips,
|
||||||
b.expected_chips,
|
b.expected_chips,
|
||||||
|
b.board_temperature.as_ref().map(|t| t.as_celsius()),
|
||||||
|
b.outlet_chip_temperature.as_ref().map(|t| t.as_celsius()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if d.messages.is_empty() {
|
if d.messages.is_empty() {
|
||||||
|
|||||||
@@ -159,6 +159,9 @@ impl Board {
|
|||||||
tuning: self.mining,
|
tuning: self.mining,
|
||||||
firmware_flash,
|
firmware_flash,
|
||||||
pools: true,
|
pools: true,
|
||||||
|
timezone: self.mining,
|
||||||
|
change_password: true,
|
||||||
|
factory_reset: true,
|
||||||
},
|
},
|
||||||
// Demo values for the round-8/9 columns (synthetic, so the columns
|
// Demo values for the round-8/9 columns (synthetic, so the columns
|
||||||
// show variety offline). control_board is derived above via naming.
|
// show variety offline). control_board is derived above via naming.
|
||||||
|
|||||||
@@ -219,6 +219,11 @@ pub struct MinerCaps {
|
|||||||
/// Whether this miner's driver supports writing pool configuration (probed
|
/// Whether this miner's driver supports writing pool configuration (probed
|
||||||
/// via `supports_pools_config()` at scan time; round 14 #7).
|
/// via `supports_pools_config()` at scan time; round 14 #7).
|
||||||
pub pools: bool,
|
pub pools: bool,
|
||||||
|
/// Round 17 B: supports setting the timezone / changing the web password /
|
||||||
|
/// factory reset (probed via the matching `supports_*()` at scan time).
|
||||||
|
pub timezone: bool,
|
||||||
|
pub change_password: bool,
|
||||||
|
pub factory_reset: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MinerCaps {
|
impl MinerCaps {
|
||||||
@@ -233,6 +238,9 @@ impl MinerCaps {
|
|||||||
tuning: self.tuning && other.tuning,
|
tuning: self.tuning && other.tuning,
|
||||||
firmware_flash: self.firmware_flash && other.firmware_flash,
|
firmware_flash: self.firmware_flash && other.firmware_flash,
|
||||||
pools: self.pools && other.pools,
|
pools: self.pools && other.pools,
|
||||||
|
timezone: self.timezone && other.timezone,
|
||||||
|
change_password: self.change_password && other.change_password,
|
||||||
|
factory_reset: self.factory_reset && other.factory_reset,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,6 +270,9 @@ impl MinerCaps {
|
|||||||
|| self.tuning
|
|| self.tuning
|
||||||
|| self.firmware_flash
|
|| self.firmware_flash
|
||||||
|| self.pools
|
|| self.pools
|
||||||
|
|| self.timezone
|
||||||
|
|| self.change_password
|
||||||
|
|| self.factory_reset
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2244,6 +2255,9 @@ mod tests {
|
|||||||
tuning: true,
|
tuning: true,
|
||||||
firmware_flash: true,
|
firmware_flash: true,
|
||||||
pools: true,
|
pools: true,
|
||||||
|
timezone: true,
|
||||||
|
change_password: true,
|
||||||
|
factory_reset: true,
|
||||||
};
|
};
|
||||||
let idle = MinerCaps { fault_light: true, restart: true, ..Default::default() };
|
let idle = MinerCaps { fault_light: true, restart: true, ..Default::default() };
|
||||||
// Two full miners keep every action.
|
// Two full miners keep every action.
|
||||||
|
|||||||
@@ -34,6 +34,11 @@ pub const AUTO_FILE: &str = "auto-rescan-secs.txt";
|
|||||||
pub const SCAN_TIMEOUT_FILE: &str = "scan-timeout-secs.txt";
|
pub const SCAN_TIMEOUT_FILE: &str = "scan-timeout-secs.txt";
|
||||||
/// Default per-miner scan timeout (matches asic-rs' identification timeout).
|
/// Default per-miner scan timeout (matches asic-rs' identification timeout).
|
||||||
pub const DEFAULT_SCAN_TIMEOUT_SECS: u64 = 10;
|
pub const DEFAULT_SCAN_TIMEOUT_SECS: u64 = 10;
|
||||||
|
/// Maximum in-flight address probes during a scan. asic-rs would otherwise use
|
||||||
|
/// 1000 for any range up to /22, saturating a real link and starving the
|
||||||
|
/// per-responder get_data (Braiins miners drop most values under that burst).
|
||||||
|
/// 128 was the highest cap that stayed fully reliable on the live fleet.
|
||||||
|
pub const SCAN_CONCURRENCY_LIMIT: usize = 128;
|
||||||
pub const DEFAULT_RANGE: &str = "10.255.1.0/24";
|
pub const DEFAULT_RANGE: &str = "10.255.1.0/24";
|
||||||
/// Default seconds between automatic rescans.
|
/// Default seconds between automatic rescans.
|
||||||
pub const DEFAULT_AUTO_SECS: u64 = 300;
|
pub const DEFAULT_AUTO_SECS: u64 = 300;
|
||||||
@@ -377,7 +382,18 @@ pub fn start_scan(lines: Vec<String>, timeout_secs: u64) -> ScanHandle {
|
|||||||
};
|
};
|
||||||
rt.block_on(async move {
|
rt.block_on(async move {
|
||||||
let mut factory = crate::credentials::configured_factory()
|
let mut factory = crate::credentials::configured_factory()
|
||||||
.with_identification_timeout_secs(timeout_secs.max(1));
|
.with_identification_timeout_secs(timeout_secs.max(1))
|
||||||
|
// Cap identification concurrency. asic-rs defaults to 1000 for any
|
||||||
|
// range up to /22, so a /24 fires all 254 probes at once. Over a
|
||||||
|
// real link (VPN, or a subnet full of dead IPs whose TCP connects
|
||||||
|
// sit open for the whole identification timeout) that burst starves
|
||||||
|
// the per-responder get_data -- a Braiins miner fans out ~12
|
||||||
|
// authenticated REST calls and drops most of its values (watts=0,
|
||||||
|
// no best-share/temps), and some responders are missed entirely.
|
||||||
|
// 128 is the highest cap that stayed fully reliable on the live
|
||||||
|
// fleet (192 already dropped responders); a /24 still finishes in
|
||||||
|
// ~35s. Larger ranges just take proportionally longer, still correct.
|
||||||
|
.with_concurrent_limit(SCAN_CONCURRENCY_LIMIT);
|
||||||
for (ip, prefix) in &cidrs {
|
for (ip, prefix) in &cidrs {
|
||||||
factory = match factory.with_subnet(&format!("{ip}/{prefix}")) {
|
factory = match factory.with_subnet(&format!("{ip}/{prefix}")) {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
@@ -391,7 +407,10 @@ pub fn start_scan(lines: Vec<String>, timeout_secs: u64) -> ScanHandle {
|
|||||||
// get accurate progress plus the responders.
|
// get accurate progress plus the responders.
|
||||||
let mut stream = factory.scan_stream_with_ip();
|
let mut stream = factory.scan_stream_with_ip();
|
||||||
let mut done = 0usize;
|
let mut done = 0usize;
|
||||||
let step = (total / 100).max(1); // throttle progress messages
|
// Emit progress per address for a smoothly-climbing counter; only a
|
||||||
|
// very large scan (> 5000 addresses) is throttled, to bound channel
|
||||||
|
// traffic. The UI coalesces these to one gauge update per refresh.
|
||||||
|
let step = (total / 5000).max(1);
|
||||||
while let Some((ip, miner)) = stream.next().await {
|
while let Some((ip, miner)) = stream.next().await {
|
||||||
if thread_cancel.load(Ordering::Relaxed) {
|
if thread_cancel.load(Ordering::Relaxed) {
|
||||||
return; // Stop / re-scan requested
|
return; // Stop / re-scan requested
|
||||||
@@ -651,6 +670,9 @@ async fn to_row(miner: &dyn Miner) -> MinerRow {
|
|||||||
tuning: miner.supports_set_tuning_percent(),
|
tuning: miner.supports_set_tuning_percent(),
|
||||||
firmware_flash: miner.supports_upgrade_firmware(),
|
firmware_flash: miner.supports_upgrade_firmware(),
|
||||||
pools: miner.supports_pools_config(),
|
pools: miner.supports_pools_config(),
|
||||||
|
timezone: miner.supports_timezone_config(),
|
||||||
|
change_password: miner.supports_change_password(),
|
||||||
|
factory_reset: miner.supports_factory_reset(),
|
||||||
};
|
};
|
||||||
// PIC vs noPIC (round 14 #2 rework). No firmware exposes a PIC flag over the
|
// 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
|
// network -- it's a fixed hardware property of the hashboard type -- so infer
|
||||||
@@ -770,6 +792,9 @@ pub enum ConfigAction {
|
|||||||
Resume,
|
Resume,
|
||||||
PowerLimit(f64), // watts
|
PowerLimit(f64), // watts
|
||||||
TuningPercent(u8),
|
TuningPercent(u8),
|
||||||
|
Timezone(String), // IANA zone, e.g. "America/Edmonton" (round 17 B / G10)
|
||||||
|
ChangePassword(String), // new web/API password (round 17 B / G11)
|
||||||
|
FactoryReset, // round 17 B / G12
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConfigAction {
|
impl ConfigAction {
|
||||||
@@ -783,6 +808,9 @@ impl ConfigAction {
|
|||||||
ConfigAction::Resume => "resume".into(),
|
ConfigAction::Resume => "resume".into(),
|
||||||
ConfigAction::PowerLimit(w) => format!("power limit {w:.0} W"),
|
ConfigAction::PowerLimit(w) => format!("power limit {w:.0} W"),
|
||||||
ConfigAction::TuningPercent(p) => format!("tuning {p}%"),
|
ConfigAction::TuningPercent(p) => format!("tuning {p}%"),
|
||||||
|
ConfigAction::Timezone(tz) => format!("timezone {tz}"),
|
||||||
|
ConfigAction::ChangePassword(_) => "change password".into(),
|
||||||
|
ConfigAction::FactoryReset => "factory reset".into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -797,6 +825,9 @@ impl ConfigAction {
|
|||||||
ConfigAction::Resume => "resuming…".into(),
|
ConfigAction::Resume => "resuming…".into(),
|
||||||
ConfigAction::PowerLimit(_) => "setting power…".into(),
|
ConfigAction::PowerLimit(_) => "setting power…".into(),
|
||||||
ConfigAction::TuningPercent(_) => "tuning…".into(),
|
ConfigAction::TuningPercent(_) => "tuning…".into(),
|
||||||
|
ConfigAction::Timezone(_) => "setting timezone…".into(),
|
||||||
|
ConfigAction::ChangePassword(_) => "changing password…".into(),
|
||||||
|
ConfigAction::FactoryReset => "factory resetting…".into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -828,6 +859,25 @@ async fn apply_action(miner: &dyn Miner, action: &ConfigAction) -> Result<bool,
|
|||||||
ConfigAction::Resume => miner.resume(None).await,
|
ConfigAction::Resume => miner.resume(None).await,
|
||||||
ConfigAction::PowerLimit(w) => miner.set_power_limit(Power::from_watts(*w)).await,
|
ConfigAction::PowerLimit(w) => miner.set_power_limit(Power::from_watts(*w)).await,
|
||||||
ConfigAction::TuningPercent(p) => miner.set_tuning_percent(*p).await,
|
ConfigAction::TuningPercent(p) => miner.set_tuning_percent(*p).await,
|
||||||
|
ConfigAction::Timezone(tz) => {
|
||||||
|
use asic_rs::core::config::timezone::{Tz, TimezoneConfig};
|
||||||
|
match tz.parse::<Tz>() {
|
||||||
|
Ok(zone) => {
|
||||||
|
miner
|
||||||
|
.set_timezone_config(TimezoneConfig {
|
||||||
|
timezone: Some(zone),
|
||||||
|
available: Vec::new(),
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
Err(_) => return Err(format!("invalid IANA timezone '{tz}'")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ConfigAction::FactoryReset => miner.factory_reset().await,
|
||||||
|
// ChangePassword takes &mut self; handled in the run loop, not here.
|
||||||
|
ConfigAction::ChangePassword(_) => {
|
||||||
|
return Err("internal: change-password handled separately".to_string());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
result.map_err(|e| e.to_string())
|
result.map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
@@ -883,11 +933,21 @@ pub fn start_config_action(ips: Vec<String>, action: ConfigAction) -> ActionHand
|
|||||||
let (success, detail) = match ip_s.parse::<std::net::IpAddr>() {
|
let (success, detail) = match ip_s.parse::<std::net::IpAddr>() {
|
||||||
Err(_) => (false, "bad IP".to_string()),
|
Err(_) => (false, "bad IP".to_string()),
|
||||||
Ok(ip) => match factory.scan_miner(ip).await {
|
Ok(ip) => match factory.scan_miner(ip).await {
|
||||||
Ok(Some(miner)) => match apply_action(&*miner, &action).await {
|
Ok(Some(mut miner)) => {
|
||||||
Ok(true) => (true, "ok".to_string()),
|
// change_password takes &mut self, so it can't go through
|
||||||
Ok(false) => (false, "refused".to_string()),
|
// apply_action(&dyn Miner); run it on the owned miner here.
|
||||||
Err(e) => (false, format!("{e}")),
|
let outcome = match &action {
|
||||||
},
|
ConfigAction::ChangePassword(p) => {
|
||||||
|
miner.change_password(p).await.map_err(|e| e.to_string())
|
||||||
|
}
|
||||||
|
other => apply_action(&*miner, other).await,
|
||||||
|
};
|
||||||
|
match outcome {
|
||||||
|
Ok(true) => (true, "ok".to_string()),
|
||||||
|
Ok(false) => (false, "refused".to_string()),
|
||||||
|
Err(e) => (false, format!("{e}")),
|
||||||
|
}
|
||||||
|
}
|
||||||
Ok(None) => (false, "no miner at IP".to_string()),
|
Ok(None) => (false, "no miner at IP".to_string()),
|
||||||
Err(e) => (false, format!("{e}")),
|
Err(e) => (false, format!("{e}")),
|
||||||
},
|
},
|
||||||
|
|||||||
+111
-29
@@ -67,6 +67,10 @@ const ID_CTX_RESUME: i32 = 726;
|
|||||||
const ID_CTX_TUNING: i32 = 727;
|
const ID_CTX_TUNING: i32 = 727;
|
||||||
const ID_CTX_POWER: i32 = 728;
|
const ID_CTX_POWER: i32 = 728;
|
||||||
const ID_CTX_RESTART: i32 = 729;
|
const ID_CTX_RESTART: i32 = 729;
|
||||||
|
// Round 17 B: timezone / change-password / factory-reset config actions.
|
||||||
|
const ID_CTX_TIMEZONE: i32 = 737;
|
||||||
|
const ID_CTX_PASSWORD: i32 = 738;
|
||||||
|
const ID_CTX_FACTORY_RESET: i32 = 739;
|
||||||
const ID_CTX_ACCESS_PROBE: i32 = 731;
|
const ID_CTX_ACCESS_PROBE: i32 = 731;
|
||||||
// View a miner's log fetched over its firmware API (round 12 #12).
|
// View a miner's log fetched over its firmware API (round 12 #12).
|
||||||
const ID_CTX_VIEW_LOG: i32 = 734;
|
const ID_CTX_VIEW_LOG: i32 = 734;
|
||||||
@@ -85,9 +89,18 @@ const ID_POOL_PLUS_BASE: i32 = 800;
|
|||||||
const ID_POOL_MENU_ADD: i32 = 819; // "add new" (adds current box value to the dropdown)
|
const ID_POOL_MENU_ADD: i32 = 819; // "add new" (adds current box value to the dropdown)
|
||||||
const ID_POOL_MENU_BASE: i32 = 820; // one id per dropdown entry (820 + index)
|
const ID_POOL_MENU_BASE: i32 = 820; // one id per dropdown entry (820 + index)
|
||||||
const ID_POOL_MENU_REMOVE_BASE: i32 = 1000; // one id per removable saved entry (round 16 #5)
|
const ID_POOL_MENU_REMOVE_BASE: i32 = 1000; // one id per removable saved entry (round 16 #5)
|
||||||
// Value-prompt dialog for power-limit / tuning-percent actions.
|
// Value-prompt dialog for power-limit / tuning-percent / timezone / password.
|
||||||
const ID_ACTION_OK: i32 = 740;
|
const ID_ACTION_OK: i32 = 740;
|
||||||
const ID_ACTION_CANCEL: i32 = 741;
|
const ID_ACTION_CANCEL: i32 = 741;
|
||||||
|
|
||||||
|
/// Which value the shared text/number prompt is collecting (round 17 B).
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
enum PromptKind {
|
||||||
|
Power,
|
||||||
|
Tuning,
|
||||||
|
Timezone,
|
||||||
|
Password,
|
||||||
|
}
|
||||||
// Confirmation dialog for disruptive actions (restart / pause / resume).
|
// Confirmation dialog for disruptive actions (restart / pause / resume).
|
||||||
const ID_CONFIRM_OK: i32 = 742;
|
const ID_CONFIRM_OK: i32 = 742;
|
||||||
const ID_CONFIRM_CANCEL: i32 = 743;
|
const ID_CONFIRM_CANCEL: i32 = 743;
|
||||||
@@ -115,6 +128,11 @@ const ID_HDR_SORT_REL_DESC: i32 = 766;
|
|||||||
const ID_FILTER_COL: i32 = 730;
|
const ID_FILTER_COL: i32 = 730;
|
||||||
const ID_FILTER_OP: i32 = 731;
|
const ID_FILTER_OP: i32 = 731;
|
||||||
const TIMER_SCAN: i32 = 1;
|
const TIMER_SCAN: i32 = 1;
|
||||||
|
/// The scan/drain timer fires this often (ms). A fast tick drains the scan channel
|
||||||
|
/// several times a second so the progress counter climbs smoothly instead of
|
||||||
|
/// jumping ~1%/s; the once-per-second scheduler work runs every `TICKS_PER_SEC`.
|
||||||
|
const TICK_MS: i32 = 200;
|
||||||
|
const TICKS_PER_SEC: u64 = 1000 / TICK_MS as u64;
|
||||||
// Deferred-rebuild ids: run a rebuild from outside the triggering widget's own
|
// Deferred-rebuild ids: run a rebuild from outside the triggering widget's own
|
||||||
// event (destroying a control mid-event is unsafe). See `wx_rs::call_after`.
|
// event (destroying a control mid-event is unsafe). See `wx_rs::call_after`.
|
||||||
const DEFER_TABLE: i32 = 1;
|
const DEFER_TABLE: i32 = 1;
|
||||||
@@ -627,6 +645,9 @@ pub struct App {
|
|||||||
// Per-miner scan timeout in seconds (round 14 #2).
|
// Per-miner scan timeout in seconds (round 14 #2).
|
||||||
scan_timeout_secs: u64,
|
scan_timeout_secs: u64,
|
||||||
countdown: u64,
|
countdown: u64,
|
||||||
|
/// Counts fast timer ticks; the once-per-second scheduler runs every
|
||||||
|
/// `TICKS_PER_SEC` of these (the drains run every tick for smooth progress).
|
||||||
|
tick_accum: u64,
|
||||||
// selection (replaces the old checkbox column), tracked by IP so it
|
// selection (replaces the old checkbox column), tracked by IP so it
|
||||||
// survives table refreshes during a scan.
|
// survives table refreshes during a scan.
|
||||||
selected_ips: HashSet<String>,
|
selected_ips: HashSet<String>,
|
||||||
@@ -659,7 +680,7 @@ pub struct App {
|
|||||||
action_ips: Vec<String>,
|
action_ips: Vec<String>,
|
||||||
action_prompt: Widget,
|
action_prompt: Widget,
|
||||||
action_input: Widget,
|
action_input: Widget,
|
||||||
action_is_power: bool,
|
action_kind: PromptKind,
|
||||||
action_total: usize,
|
action_total: usize,
|
||||||
action_done: usize,
|
action_done: usize,
|
||||||
// IPs the current config action targets, re-probed after it completes so the
|
// IPs the current config action targets, re-probed after it completes so the
|
||||||
@@ -970,6 +991,7 @@ pub fn build(frame: Widget) -> App {
|
|||||||
auto_secs: scan::load_auto_secs(),
|
auto_secs: scan::load_auto_secs(),
|
||||||
scan_timeout_secs: scan::load_scan_timeout(),
|
scan_timeout_secs: scan::load_scan_timeout(),
|
||||||
countdown: 0,
|
countdown: 0,
|
||||||
|
tick_accum: 0,
|
||||||
selected_ips: HashSet::new(),
|
selected_ips: HashSet::new(),
|
||||||
pal,
|
pal,
|
||||||
kpi_cards,
|
kpi_cards,
|
||||||
@@ -984,7 +1006,7 @@ pub fn build(frame: Widget) -> App {
|
|||||||
action_ips: Vec::new(),
|
action_ips: Vec::new(),
|
||||||
action_prompt: frame,
|
action_prompt: frame,
|
||||||
action_input: frame,
|
action_input: frame,
|
||||||
action_is_power: false,
|
action_kind: PromptKind::Power,
|
||||||
action_total: 0,
|
action_total: 0,
|
||||||
action_done: 0,
|
action_done: 0,
|
||||||
action_targets: Vec::new(),
|
action_targets: Vec::new(),
|
||||||
@@ -1044,7 +1066,7 @@ pub fn build(frame: Widget) -> App {
|
|||||||
app.view = p.view.to_view();
|
app.view = p.view.to_view();
|
||||||
}
|
}
|
||||||
app.rebuild_table();
|
app.rebuild_table();
|
||||||
Widget::timer(TIMER_SCAN, 1000);
|
Widget::timer(TIMER_SCAN, TICK_MS);
|
||||||
app
|
app
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1469,6 +1491,19 @@ impl App {
|
|||||||
if caps.pools {
|
if caps.pools {
|
||||||
menu.menu_append(ID_CTX_POOLS, &format!("Configure pools...{sfx}"));
|
menu.menu_append(ID_CTX_POOLS, &format!("Configure pools...{sfx}"));
|
||||||
}
|
}
|
||||||
|
if caps.timezone {
|
||||||
|
menu.menu_append(ID_CTX_TIMEZONE, &format!("Set timezone...{sfx}"));
|
||||||
|
}
|
||||||
|
// Destructive / credential-changing actions, set apart (round 17 B).
|
||||||
|
if caps.change_password || caps.factory_reset {
|
||||||
|
menu.menu_append_separator();
|
||||||
|
if caps.change_password {
|
||||||
|
menu.menu_append(ID_CTX_PASSWORD, &format!("Change password...{sfx}"));
|
||||||
|
}
|
||||||
|
if caps.factory_reset {
|
||||||
|
menu.menu_append(ID_CTX_FACTORY_RESET, &format!("Factory reset...{sfx}"));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Firmware flash is intentionally not offered for now (round 16 #6): the
|
// Firmware flash is intentionally not offered for now (round 16 #6): the
|
||||||
// in-app flash path is disabled while it is reworked. Restore-to-stock +
|
// in-app flash path is disabled while it is reworked. Restore-to-stock +
|
||||||
@@ -2079,8 +2114,13 @@ impl App {
|
|||||||
ID_CTX_RESUME => return Some(self.build_confirm_dialog(scan::ConfigAction::Resume)),
|
ID_CTX_RESUME => return Some(self.build_confirm_dialog(scan::ConfigAction::Resume)),
|
||||||
ID_CTX_RESTART => return Some(self.build_confirm_dialog(scan::ConfigAction::Restart)),
|
ID_CTX_RESTART => return Some(self.build_confirm_dialog(scan::ConfigAction::Restart)),
|
||||||
// Value entry is itself the confirmation.
|
// Value entry is itself the confirmation.
|
||||||
ID_CTX_POWER => return Some(self.build_action_prompt(true)),
|
ID_CTX_POWER => return Some(self.build_action_prompt(PromptKind::Power)),
|
||||||
ID_CTX_TUNING => return Some(self.build_action_prompt(false)),
|
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)),
|
||||||
|
ID_CTX_FACTORY_RESET => {
|
||||||
|
return Some(self.build_confirm_dialog(scan::ConfigAction::FactoryReset))
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
@@ -2095,9 +2135,17 @@ impl App {
|
|||||||
scan::ConfigAction::Restart => ("Restart", "Restart"),
|
scan::ConfigAction::Restart => ("Restart", "Restart"),
|
||||||
scan::ConfigAction::Pause => ("Pause mining on", "Pause"),
|
scan::ConfigAction::Pause => ("Pause mining on", "Pause"),
|
||||||
scan::ConfigAction::Resume => ("Resume mining on", "Resume"),
|
scan::ConfigAction::Resume => ("Resume mining on", "Resume"),
|
||||||
|
scan::ConfigAction::FactoryReset => ("Factory reset", "Factory reset"),
|
||||||
_ => ("Apply to", "Confirm"),
|
_ => ("Apply to", "Confirm"),
|
||||||
};
|
};
|
||||||
let msg = format!("{verb} {n} selected miner(s)? This affects running hardware.");
|
let msg = if matches!(action, scan::ConfigAction::FactoryReset) {
|
||||||
|
format!(
|
||||||
|
"Factory reset {n} selected miner(s)? This WIPES their configuration (pools, \
|
||||||
|
tuning, network) and reboots -- a miner may return on DHCP and change IP."
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
format!("{verb} {n} selected miner(s)? This affects running hardware.")
|
||||||
|
};
|
||||||
self.pending_confirm = Some((ips, action));
|
self.pending_confirm = Some((ips, action));
|
||||||
let frame = Widget::main_frame();
|
let frame = Widget::main_frame();
|
||||||
let dlg = Widget::dialog(frame, "Confirm action");
|
let dlg = Widget::dialog(frame, "Confirm action");
|
||||||
@@ -2117,17 +2165,24 @@ impl App {
|
|||||||
|
|
||||||
/// A small modal to enter a power limit (watts) or tuning percent for the
|
/// 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.
|
/// selection. Built here, shown modally by `dispatch` outside the App borrow.
|
||||||
fn build_action_prompt(&mut self, is_power: bool) -> Widget {
|
fn build_action_prompt(&mut self, kind: PromptKind) -> Widget {
|
||||||
self.action_ips = self.selected_ip_list();
|
self.action_ips = self.selected_ip_list();
|
||||||
self.action_is_power = is_power;
|
self.action_kind = kind;
|
||||||
let n = self.action_ips.len();
|
let n = self.action_ips.len();
|
||||||
let frame = Widget::main_frame();
|
let frame = Widget::main_frame();
|
||||||
let dlg = Widget::dialog(frame, if is_power { "Set power limit" } else { "Set tuning percent" });
|
let title = match kind {
|
||||||
|
PromptKind::Power => "Set power limit",
|
||||||
|
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);
|
let root = Widget::box_sizer(true);
|
||||||
let lbl = if is_power {
|
let lbl = match kind {
|
||||||
format!("Power limit in watts for {n} miner(s):")
|
PromptKind::Power => format!("Power limit in watts for {n} miner(s):"),
|
||||||
} else {
|
PromptKind::Tuning => format!("Tuning percent (0-100) for {n} miner(s):"),
|
||||||
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):"),
|
||||||
};
|
};
|
||||||
root.add(Widget::static_text(dlg, &lbl), 0, sf::BORDER_ALL, 8);
|
root.add(Widget::static_text(dlg, &lbl), 0, sf::BORDER_ALL, 8);
|
||||||
let input = Widget::text_ctrl(dlg, false);
|
let input = Widget::text_ctrl(dlg, false);
|
||||||
@@ -2151,15 +2206,27 @@ impl App {
|
|||||||
/// captured selection) so the operator can correct it.
|
/// captured selection) so the operator can correct it.
|
||||||
fn apply_action_prompt(&mut self) {
|
fn apply_action_prompt(&mut self) {
|
||||||
let val = self.action_input.get_value();
|
let val = self.action_input.get_value();
|
||||||
let action = if self.action_is_power {
|
let action = match self.action_kind {
|
||||||
match val.trim().parse::<f64>() {
|
PromptKind::Power => match val.trim().parse::<f64>() {
|
||||||
Ok(w) if w > 0.0 && w.is_finite() => Some(scan::ConfigAction::PowerLimit(w)),
|
Ok(w) if w > 0.0 && w.is_finite() => Some(scan::ConfigAction::PowerLimit(w)),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
},
|
||||||
} else {
|
PromptKind::Tuning => match val.trim().parse::<u8>() {
|
||||||
match val.trim().parse::<u8>() {
|
|
||||||
Ok(p) if p <= 100 => Some(scan::ConfigAction::TuningPercent(p)),
|
Ok(p) if p <= 100 => Some(scan::ConfigAction::TuningPercent(p)),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
},
|
||||||
|
PromptKind::Timezone => {
|
||||||
|
let tz = val.trim();
|
||||||
|
// Validate as an IANA zone before firing so a typo doesn't hit the fleet.
|
||||||
|
if !tz.is_empty() && tz.parse::<asic_rs::core::config::timezone::Tz>().is_ok() {
|
||||||
|
Some(scan::ConfigAction::Timezone(tz.to_string()))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PromptKind::Password => {
|
||||||
|
let p = val.trim();
|
||||||
|
(!p.is_empty()).then(|| scan::ConfigAction::ChangePassword(p.to_string()))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
match action {
|
match action {
|
||||||
@@ -2169,10 +2236,11 @@ impl App {
|
|||||||
self.start_action(ips, a);
|
self.start_action(ips, a);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let hint = if self.action_is_power {
|
let hint = match self.action_kind {
|
||||||
"enter a positive number of watts"
|
PromptKind::Power => "enter a positive number of watts",
|
||||||
} else {
|
PromptKind::Tuning => "enter a percent from 0 to 100",
|
||||||
"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",
|
||||||
};
|
};
|
||||||
wx_rs::set_status_text(&format!("invalid value - {hint}"));
|
wx_rs::set_status_text(&format!("invalid value - {hint}"));
|
||||||
}
|
}
|
||||||
@@ -2561,6 +2629,9 @@ impl App {
|
|||||||
pub fn drain_scan(&mut self) {
|
pub fn drain_scan(&mut self) {
|
||||||
let Some(handle) = &self.scan else { return };
|
let Some(handle) = &self.scan else { return };
|
||||||
let mut changed = false;
|
let mut changed = false;
|
||||||
|
// Coalesce progress: a fast drain may pull many per-address updates; apply
|
||||||
|
// only the latest to the gauge/status once, after the loop.
|
||||||
|
let mut latest_progress: Option<(usize, usize, String)> = None;
|
||||||
loop {
|
loop {
|
||||||
match handle.rx.try_recv() {
|
match handle.rx.try_recv() {
|
||||||
Ok(ScanMsg::Started { total, targets }) => {
|
Ok(ScanMsg::Started { total, targets }) => {
|
||||||
@@ -2584,12 +2655,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
Ok(ScanMsg::Progress { done, total, ip }) => {
|
Ok(ScanMsg::Progress { done, total, ip }) => {
|
||||||
self.scan_total = total;
|
self.scan_total = total;
|
||||||
self.progress.gauge_set_value(done.min(total) as i32);
|
latest_progress = Some((done, total, ip));
|
||||||
let where_ = if ip.is_empty() { String::new() } else { format!(" - scanning {ip}") };
|
|
||||||
wx_rs::set_status_text(&format!(
|
|
||||||
"{done}/{total}{where_} ({} found)",
|
|
||||||
self.rows.len()
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
Ok(ScanMsg::Row(row)) => {
|
Ok(ScanMsg::Row(row)) => {
|
||||||
// Ignore stray rows outside the current target set.
|
// Ignore stray rows outside the current target set.
|
||||||
@@ -2633,6 +2699,15 @@ impl App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Apply the coalesced progress once (only while still scanning -- a Done/
|
||||||
|
// Failed in this same drain already finalised the gauge).
|
||||||
|
if self.scanning {
|
||||||
|
if let Some((done, total, ip)) = latest_progress {
|
||||||
|
self.progress.gauge_set_value(done.min(total) as i32);
|
||||||
|
let where_ = if ip.is_empty() { String::new() } else { format!(" - scanning {ip}") };
|
||||||
|
wx_rs::set_status_text(&format!("{done}/{total}{where_} ({} found)", self.rows.len()));
|
||||||
|
}
|
||||||
|
}
|
||||||
if changed {
|
if changed {
|
||||||
self.fill_rows();
|
self.fill_rows();
|
||||||
}
|
}
|
||||||
@@ -2646,6 +2721,13 @@ impl App {
|
|||||||
self.drain_refresh();
|
self.drain_refresh();
|
||||||
self.drain_access_probe();
|
self.drain_access_probe();
|
||||||
self.drain_restore();
|
self.drain_restore();
|
||||||
|
// The drains above run every fast tick (smooth scan progress); the
|
||||||
|
// auto-rescan scheduler + idle status only need ~1 Hz, so run them once
|
||||||
|
// per second.
|
||||||
|
self.tick_accum = self.tick_accum.wrapping_add(1);
|
||||||
|
if self.tick_accum % TICKS_PER_SEC != 0 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// The bottom-left status is for the scan only (round 15 #8): per-miner
|
// The bottom-left status is for the scan only (round 15 #8): per-miner
|
||||||
// operation progress lives in the Health column, so operations no longer
|
// operation progress lives in the Health column, so operations no longer
|
||||||
// hold or overwrite this line -- only an active scan does.
|
// hold or overwrite this line -- only an active scan does.
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
Subject: [PATCH 0015] braiins v26_04: treat an empty 2xx body as success (not a parse error)
|
||||||
|
|
||||||
|
Found live verifying change-password (round 17 B / G11). The BOS REST setters like
|
||||||
|
PUT auth/password answer 2xx with an empty body; send_command tried
|
||||||
|
response.json() on it, which fails, so change_password (which does `.is_ok()`)
|
||||||
|
reported Ok(false) even though the password DID change. Read the body as text
|
||||||
|
first: an empty body on a success status is Null (success), a non-empty body must
|
||||||
|
still parse. Verified live on 10.4.1.27: change root->bftest2 now returns Ok(true),
|
||||||
|
the new password authenticates, and restore -> root returns Ok(true).
|
||||||
|
diff --git a/vendor/asic-rs-firmwares-braiins/src/backends/v26_04/web.rs b/vendor/asic-rs-firmwares-braiins/src/backends/v26_04/web.rs
|
||||||
|
index 624eca4c..3e06b682 100644
|
||||||
|
--- a/vendor/asic-rs-firmwares-braiins/src/backends/v26_04/web.rs
|
||||||
|
+++ b/vendor/asic-rs-firmwares-braiins/src/backends/v26_04/web.rs
|
||||||
|
@@ -57,11 +57,20 @@ impl WebAPIClient for BraiinsWebAPI {
|
||||||
|
|
||||||
|
let status = response.status();
|
||||||
|
if status.is_success() {
|
||||||
|
- let json_data = response
|
||||||
|
- .json()
|
||||||
|
+ // Some setters (e.g. PUT auth/password) answer 2xx with an empty or
|
||||||
|
+ // non-JSON body. An empty body is success, not a parse error -- treat
|
||||||
|
+ // it as Null so callers using `.is_ok()` don't read a real success as
|
||||||
|
+ // failure. A non-empty body must still parse.
|
||||||
|
+ let body = response
|
||||||
|
+ .text()
|
||||||
|
.await
|
||||||
|
.map_err(|e| BraiinsError::ParseError(e.to_string()))?;
|
||||||
|
- Ok(json_data)
|
||||||
|
+ if body.trim().is_empty() {
|
||||||
|
+ Ok(Value::Null)
|
||||||
|
+ } else {
|
||||||
|
+ Ok(serde_json::from_str(&body)
|
||||||
|
+ .map_err(|e| BraiinsError::ParseError(e.to_string()))?)
|
||||||
|
+ }
|
||||||
|
} else {
|
||||||
|
// The API reports why it rejected a request in the body.
|
||||||
|
let status = status.as_u16();
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
Subject: [PATCH 0016] braiins v26_04: single-flight auth + defensive get_data timeout
|
||||||
|
|
||||||
|
Round 17 R4 support. Braiins get_data fans out to ~12 authenticated REST calls
|
||||||
|
concurrently. Two hardening changes so a Braiins miner survives a busy scan:
|
||||||
|
|
||||||
|
- ensure_authenticated single-flights the login. Previously all ~12 concurrent
|
||||||
|
commands could see no token and each POST /auth/login -- a thundering herd that
|
||||||
|
doubled the connection load. Now the write lock is held across the login with a
|
||||||
|
double-check, so exactly one call authenticates and the rest reuse the token.
|
||||||
|
- The per-call timeout goes 5s -> 15s as defensive headroom (a healthy miner still
|
||||||
|
answers well under a second) so a call queued behind a scan burst completes
|
||||||
|
instead of dropping miner/stats.
|
||||||
|
|
||||||
|
Neither is the primary fix for the fleet-scan value dropout -- that is the
|
||||||
|
app-side scan concurrency cap (scan::SCAN_CONCURRENCY_LIMIT = 128), which keeps
|
||||||
|
the identification burst from starving these calls. These are the belt to that
|
||||||
|
suspenders. Verified live: a 10.4.1.0/24 scan now populates both Braiins corpus
|
||||||
|
miners (.27, .83) fully (watts, best-share, fw/control-board) and misses no
|
||||||
|
responders.
|
||||||
|
diff --git a/vendor/asic-rs-firmwares-braiins/src/backends/v26_04/web.rs b/vendor/asic-rs-firmwares-braiins/src/backends/v26_04/web.rs
|
||||||
|
index 3e06b682..ae433d98 100644
|
||||||
|
--- a/vendor/asic-rs-firmwares-braiins/src/backends/v26_04/web.rs
|
||||||
|
+++ b/vendor/asic-rs-firmwares-braiins/src/backends/v26_04/web.rs
|
||||||
|
@@ -87,7 +87,13 @@ impl BraiinsWebAPI {
|
||||||
|
client: OnceCell::new(),
|
||||||
|
ip,
|
||||||
|
port: 80,
|
||||||
|
- timeout: Duration::from_secs(5),
|
||||||
|
+ // Braiins get_data fans out to ~12 authenticated REST calls that run
|
||||||
|
+ // concurrently. A healthy miner answers well under a second; the extra
|
||||||
|
+ // headroom over the old 5 s is defensive so a call that queues behind a
|
||||||
|
+ // scan burst still completes instead of dropping miner/stats
|
||||||
|
+ // (hashrate/watts/best-share). The real fix for the fleet-scan dropout
|
||||||
|
+ // is the app-side scan concurrency cap (see scan::SCAN_CONCURRENCY_LIMIT).
|
||||||
|
+ timeout: Duration::from_secs(15),
|
||||||
|
bearer_token: RwLock::new(None),
|
||||||
|
auth,
|
||||||
|
}
|
||||||
|
@@ -122,13 +128,22 @@ impl BraiinsWebAPI {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
+ // Single-flight the login: get_data fires ~12 commands concurrently, and
|
||||||
|
+ // without this they would ALL see no token and each POST /auth/login (a
|
||||||
|
+ // thundering herd that doubles the connection load and races under a
|
||||||
|
+ // high-concurrency fleet scan, dropping most values). Hold the write lock
|
||||||
|
+ // across the login so exactly one call authenticates and the rest reuse it.
|
||||||
|
+ let mut guard = self.bearer_token.write().await;
|
||||||
|
+ if guard.is_some() {
|
||||||
|
+ return Ok(());
|
||||||
|
+ }
|
||||||
|
let token = match &self.auth {
|
||||||
|
MinerAuth::TokenAuth(token) => token.expose_secret().to_string(),
|
||||||
|
MinerAuth::UserAndPass(creds) => {
|
||||||
|
self.authenticate(creds.password.expose_secret()).await?
|
||||||
|
}
|
||||||
|
};
|
||||||
|
- *self.bearer_token.write().await = Some(token);
|
||||||
|
+ *guard = Some(token);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
+1
-1
File diff suppressed because one or more lines are too long
+29
-5
@@ -57,11 +57,20 @@ impl WebAPIClient for BraiinsWebAPI {
|
|||||||
|
|
||||||
let status = response.status();
|
let status = response.status();
|
||||||
if status.is_success() {
|
if status.is_success() {
|
||||||
let json_data = response
|
// Some setters (e.g. PUT auth/password) answer 2xx with an empty or
|
||||||
.json()
|
// non-JSON body. An empty body is success, not a parse error -- treat
|
||||||
|
// it as Null so callers using `.is_ok()` don't read a real success as
|
||||||
|
// failure. A non-empty body must still parse.
|
||||||
|
let body = response
|
||||||
|
.text()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| BraiinsError::ParseError(e.to_string()))?;
|
.map_err(|e| BraiinsError::ParseError(e.to_string()))?;
|
||||||
Ok(json_data)
|
if body.trim().is_empty() {
|
||||||
|
Ok(Value::Null)
|
||||||
|
} else {
|
||||||
|
Ok(serde_json::from_str(&body)
|
||||||
|
.map_err(|e| BraiinsError::ParseError(e.to_string()))?)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// The API reports why it rejected a request in the body.
|
// The API reports why it rejected a request in the body.
|
||||||
let status = status.as_u16();
|
let status = status.as_u16();
|
||||||
@@ -78,7 +87,13 @@ impl BraiinsWebAPI {
|
|||||||
client: OnceCell::new(),
|
client: OnceCell::new(),
|
||||||
ip,
|
ip,
|
||||||
port: 80,
|
port: 80,
|
||||||
timeout: Duration::from_secs(5),
|
// Braiins get_data fans out to ~12 authenticated REST calls that run
|
||||||
|
// concurrently. A healthy miner answers well under a second; the extra
|
||||||
|
// headroom over the old 5 s is defensive so a call that queues behind a
|
||||||
|
// scan burst still completes instead of dropping miner/stats
|
||||||
|
// (hashrate/watts/best-share). The real fix for the fleet-scan dropout
|
||||||
|
// is the app-side scan concurrency cap (see scan::SCAN_CONCURRENCY_LIMIT).
|
||||||
|
timeout: Duration::from_secs(15),
|
||||||
bearer_token: RwLock::new(None),
|
bearer_token: RwLock::new(None),
|
||||||
auth,
|
auth,
|
||||||
}
|
}
|
||||||
@@ -113,13 +128,22 @@ impl BraiinsWebAPI {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Single-flight the login: get_data fires ~12 commands concurrently, and
|
||||||
|
// without this they would ALL see no token and each POST /auth/login (a
|
||||||
|
// thundering herd that doubles the connection load and races under a
|
||||||
|
// high-concurrency fleet scan, dropping most values). Hold the write lock
|
||||||
|
// across the login so exactly one call authenticates and the rest reuse it.
|
||||||
|
let mut guard = self.bearer_token.write().await;
|
||||||
|
if guard.is_some() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
let token = match &self.auth {
|
let token = match &self.auth {
|
||||||
MinerAuth::TokenAuth(token) => token.expose_secret().to_string(),
|
MinerAuth::TokenAuth(token) => token.expose_secret().to_string(),
|
||||||
MinerAuth::UserAndPass(creds) => {
|
MinerAuth::UserAndPass(creds) => {
|
||||||
self.authenticate(creds.password.expose_secret()).await?
|
self.authenticate(creds.password.expose_secret()).await?
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
*self.bearer_token.write().await = Some(token);
|
*guard = Some(token);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user