Reserve ASIC work IDs until hardware flush and fault on failed shutdown
main-release-gate / verify-and-release (push) Failing after 3m31s
main-release-gate / verify-and-release (push) Failing after 3m31s
This commit is contained in:
+34
-3
@@ -12,6 +12,8 @@ pub enum MinerError<E> {
|
||||
Backend(E),
|
||||
AlreadyRunning,
|
||||
NotRunning,
|
||||
Faulted,
|
||||
WorkIdInUse(u8),
|
||||
UnsafeTemperature(i32),
|
||||
InvalidWork,
|
||||
InvalidReport(ReportError),
|
||||
@@ -25,6 +27,8 @@ impl<E: fmt::Display> fmt::Display for MinerError<E> {
|
||||
Self::Backend(error) => write!(f, "hardware backend: {error}"),
|
||||
Self::AlreadyRunning => f.write_str("miner is already running"),
|
||||
Self::NotRunning => f.write_str("miner is not running"),
|
||||
Self::Faulted => f.write_str("miner shutdown is unconfirmed"),
|
||||
Self::WorkIdInUse(id) => write!(f, "BM1366 work ID {id} is still in use"),
|
||||
Self::UnsafeTemperature(value) => write!(f, "unsafe temperature: {value} mC"),
|
||||
Self::InvalidWork => f.write_str("invalid BM1366 work"),
|
||||
Self::InvalidReport(error) => write!(f, "invalid BM1366 report: {error:?}"),
|
||||
@@ -59,7 +63,9 @@ pub struct Bm1366Miner<'a, B: HardwareBackend> {
|
||||
fan_percent: u8,
|
||||
max_temperature_mc: i32,
|
||||
running: bool,
|
||||
faulted: bool,
|
||||
work: [Option<Work>; 32],
|
||||
used_work_ids: [bool; 32],
|
||||
}
|
||||
|
||||
impl<'a, B: HardwareBackend> Bm1366Miner<'a, B> {
|
||||
@@ -83,7 +89,9 @@ impl<'a, B: HardwareBackend> Bm1366Miner<'a, B> {
|
||||
fan_percent,
|
||||
max_temperature_mc,
|
||||
running: false,
|
||||
faulted: false,
|
||||
work: [None; 32],
|
||||
used_work_ids: [false; 32],
|
||||
})
|
||||
}
|
||||
|
||||
@@ -92,11 +100,14 @@ impl<'a, B: HardwareBackend> Bm1366Miner<'a, B> {
|
||||
match self.backend.set_psu_enabled(false) {
|
||||
Ok(()) => {
|
||||
self.running = false;
|
||||
self.faulted = false;
|
||||
self.used_work_ids = [false; 32];
|
||||
Ok(())
|
||||
}
|
||||
Err(error) => {
|
||||
// The backend may have left power on. Drop retries shutdown.
|
||||
self.running = true;
|
||||
self.faulted = true;
|
||||
Err(error)
|
||||
}
|
||||
}
|
||||
@@ -152,6 +163,9 @@ impl<'a, B: HardwareBackend> Bm1366Miner<'a, B> {
|
||||
if !self.running {
|
||||
return Err(MinerError::NotRunning);
|
||||
}
|
||||
if self.faulted {
|
||||
return Err(MinerError::Faulted);
|
||||
}
|
||||
self.work = [None; 32];
|
||||
self.check_temperature()?;
|
||||
if let Err(error) = self.backend.set_chain_reset(self.chain, true) {
|
||||
@@ -162,6 +176,7 @@ impl<'a, B: HardwareBackend> Bm1366Miner<'a, B> {
|
||||
let _ = self.power_off();
|
||||
return Err(MinerError::Backend(error));
|
||||
}
|
||||
self.used_work_ids = [false; 32];
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -174,13 +189,22 @@ impl<'a, B: HardwareBackend> Bm1366Miner<'a, B> {
|
||||
if !self.running {
|
||||
return Err(MinerError::NotRunning);
|
||||
}
|
||||
let frame = encode_work(&header, work_id).ok_or(MinerError::InvalidWork)?;
|
||||
if self.faulted {
|
||||
return Err(MinerError::Faulted);
|
||||
}
|
||||
self.check_temperature()?;
|
||||
let frame = encode_work(&header, work_id).ok_or(MinerError::InvalidWork)?;
|
||||
let slot = usize::from(work_id >> 3);
|
||||
if self.used_work_ids[slot] {
|
||||
return Err(MinerError::WorkIdInUse(work_id));
|
||||
}
|
||||
// A failed send may still have reached the ASIC, so reserve first.
|
||||
self.used_work_ids[slot] = true;
|
||||
if let Err(error) = self.backend.send_frame(self.chain, &frame) {
|
||||
let _ = self.power_off();
|
||||
return Err(MinerError::Backend(error));
|
||||
}
|
||||
self.work[usize::from(work_id >> 3)] = Some(Work {
|
||||
self.work[slot] = Some(Work {
|
||||
header,
|
||||
target_le,
|
||||
id: work_id,
|
||||
@@ -189,7 +213,8 @@ impl<'a, B: HardwareBackend> Bm1366Miner<'a, B> {
|
||||
}
|
||||
|
||||
/// Forget prior pool jobs after `clean_jobs`, while leaving the ASIC powered.
|
||||
/// Reports already in flight are then classified as stale.
|
||||
/// Reports already in flight are then classified as stale. Their work IDs
|
||||
/// remain reserved until a confirmed chain reset or PSU shutdown.
|
||||
pub fn clear_work(&mut self) {
|
||||
self.work = [None; 32];
|
||||
}
|
||||
@@ -198,6 +223,9 @@ impl<'a, B: HardwareBackend> Bm1366Miner<'a, B> {
|
||||
if !self.running {
|
||||
return Err(MinerError::NotRunning);
|
||||
}
|
||||
if self.faulted {
|
||||
return Err(MinerError::Faulted);
|
||||
}
|
||||
self.check_temperature()?;
|
||||
let mut frame = [0_u8; REPORT_BYTES];
|
||||
let length = match self.backend.receive_frame(self.chain, &mut frame) {
|
||||
@@ -249,6 +277,9 @@ impl<'a, B: HardwareBackend> Bm1366Miner<'a, B> {
|
||||
if !self.running {
|
||||
return Err(MinerError::NotRunning);
|
||||
}
|
||||
if self.faulted {
|
||||
return Err(MinerError::Faulted);
|
||||
}
|
||||
self.check_temperature()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user