This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
//! Exercise the SDK's host-only BM1366 HAL simulator with a captured job.
|
||||
|
||||
use alkane_os::bm1366::{decode_nonce_report, encode_work, REPORT_BYTES};
|
||||
use alkane_os::hal_wire::HalClient;
|
||||
use alkane_os::pow::verify_sha256_report;
|
||||
use alkane_os::HardwareBackend;
|
||||
use alkane_os::miner::Bm1366Miner;
|
||||
use std::error::Error;
|
||||
|
||||
const HEADER: [u8; 80] = [
|
||||
@@ -20,26 +18,15 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
.nth(1)
|
||||
.ok_or("usage: simulator_replay_probe SOCKET_PATH")?;
|
||||
let mut backend = HalClient::connect(path)?;
|
||||
backend.set_psu_enabled(true)?;
|
||||
backend.set_chain_reset(0, true)?;
|
||||
backend.set_chain_reset(0, false)?;
|
||||
backend.send_frame(0, &encode_work(&HEADER, 0x18).ok_or("invalid work header")?)?;
|
||||
let mut buffer = [0_u8; REPORT_BYTES];
|
||||
let length = backend.receive_frame(0, &mut buffer)?;
|
||||
if length != REPORT_BYTES {
|
||||
return Err("missing BM1366 nonce report".into());
|
||||
}
|
||||
let report = decode_nonce_report(&buffer).map_err(|_| "invalid BM1366 nonce report")?;
|
||||
if report.work_id != 0x18 {
|
||||
return Err("stale BM1366 work ID".into());
|
||||
}
|
||||
let mut miner = Bm1366Miner::new(&mut backend, 0, 0, 0, 100, 80_000)
|
||||
.ok_or("invalid simulator probe configuration")?;
|
||||
miner.start()?;
|
||||
let mut target = [0_u8; 32];
|
||||
target[26..28].fill(0xff);
|
||||
let result = verify_sha256_report(&HEADER, report.nonce, report.version_field, &target);
|
||||
backend.set_psu_enabled(false)?;
|
||||
if !result.meets_target {
|
||||
return Err("captured nonce does not meet difficulty 1".into());
|
||||
}
|
||||
miner.submit(HEADER, target, 0x18)?;
|
||||
let share = miner.poll()?.ok_or("missing BM1366 nonce report")?;
|
||||
miner.stop()?;
|
||||
assert_eq!(share.nonce, 0xedad_ff38);
|
||||
println!("BM1366 captured report verified at difficulty 1");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user