// SPDX-License-Identifier: MIT //! Bounded host-only check: captured BM1366 report through HAL to a strict pool. use alkane_os::hal_wire::HalClient; use alkane_os::miner::Bm1366Miner; use alkane_os::stratum_client::{PoolConnection, PoolEvent, ReportEvent}; use std::error::Error; use std::io; use std::net::SocketAddr; use std::time::{Duration, Instant}; const CAPTURED_HEADER: [u8; 80] = [ 0x00, 0x00, 0x00, 0x20, 0xfc, 0x3a, 0xb8, 0xd4, 0x30, 0x21, 0xf4, 0x5e, 0xb6, 0x62, 0x38, 0x9d, 0x0f, 0x79, 0x1f, 0x65, 0x7d, 0xbf, 0x75, 0xa5, 0xcb, 0x93, 0x67, 0x0b, 0x57, 0xb6, 0xc2, 0x25, 0x03, 0xb4, 0x21, 0x3a, 0x43, 0xae, 0x10, 0x52, 0xeb, 0xd4, 0x44, 0x43, 0x06, 0x8f, 0xe1, 0x78, 0xe2, 0xc6, 0x1c, 0xa4, 0x99, 0x48, 0x46, 0xfd, 0x13, 0x3a, 0xdd, 0xb0, 0x4a, 0xab, 0x2b, 0x38, 0x2c, 0x5b, 0x4c, 0x74, 0xc1, 0x01, 0x2e, 0x6a, 0x8f, 0x06, 0x02, 0x17, 0x00, 0x00, 0x00, 0x00, ]; fn failure(message: impl Into) -> io::Error { io::Error::other(message.into()) } fn main() -> Result<(), Box> { let mut args = std::env::args().skip(1); let socket = args .next() .ok_or_else(|| failure("usage: simulator_pool_replay_probe HAL_SOCKET POOL_ADDRESS"))?; let address: SocketAddr = args .next() .ok_or_else(|| failure("missing pool address"))? .parse()?; if args.next().is_some() { return Err(failure("unexpected argument").into()); } if !address.ip().is_loopback() { return Err(failure("probe pool must be on loopback").into()); } let mut backend = HalClient::connect(socket)?; let mut miner = Bm1366Miner::new(&mut backend, 0, 0, 0, 100, 80_000) .ok_or_else(|| failure("invalid simulator configuration"))?; let mut pool = PoolConnection::connect( address, "alkane-simulator-probe", "alkane.test", "x", Duration::from_secs(2), Duration::from_secs(5), ) .map_err(|error| failure(format!("pool handshake: {error:?}")))?; miner.start()?; let deadline = Instant::now() + Duration::from_secs(10); let mut saw_work = false; let mut saw_submit = false; while Instant::now() < deadline { let (event, reports) = pool .cycle(&mut miner) .map_err(|error| failure(format!("mining cycle: {error:?}")))?; if reports .iter() .any(|report| matches!(report, ReportEvent::Submitted(_))) { saw_submit = true; } match event { PoolEvent::Work(work) => { if work.header != CAPTURED_HEADER { return Err(failure("pool job differs from real-silicon capture").into()); } saw_work = true; } PoolEvent::ShareAccepted(_) if saw_work && saw_submit => { miner.stop()?; println!("BM1366 real captured nonce accepted by strict loopback pool"); return Ok(()); } PoolEvent::ShareAccepted(_) => { return Err(failure("unattributed pool acceptance").into()) } PoolEvent::ShareRejected(_) => return Err(failure("pool rejected share").into()), _ => {} } } Err(failure("captured share was not accepted before deadline").into()) }