This commit is contained in:
@@ -59,6 +59,12 @@ The pool connection applies difficulty and job messages in stream order,
|
||||
dispatches work to the BM1366 mining session, and tracks up to 32 verified
|
||||
share submissions by request ID. It counts accepted and rejected pool replies
|
||||
separately. Continuous scheduling and live pool acceptance remain unverified.
|
||||
The SDK's strict loopback pool replay test reconstructs the exact first
|
||||
cv.106 BM1366 captured job from Stratum subscription and notify fields. It
|
||||
delivers that job through the OS pool client and HAL simulator, replays the
|
||||
real ASIC nonce, verifies its proof of work independently, and receives a
|
||||
matching pool ACCEPT. This is host-only evidence for one captured job, not a
|
||||
stock-firmware boot or a production board adapter.
|
||||
Its cycle helper reads one pool event, drains up to 256 ASIC reports, and sends
|
||||
verified shares when present. A share reply unanswered for 30 seconds closes
|
||||
the connection so a caller can reconnect instead of filling the pending
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
// 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<String>) -> io::Error {
|
||||
io::Error::other(message.into())
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
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())
|
||||
}
|
||||
+16
-3
@@ -154,8 +154,8 @@ pub fn parse_configure_response(
|
||||
}
|
||||
}
|
||||
|
||||
/// Decode both offered BIP310 extensions. The response must explicitly
|
||||
/// acknowledge each advertised extension before its notifications are used.
|
||||
/// Decode both offered BIP310 extensions. An omitted extranonce extension is
|
||||
/// unsupported; its notifications cannot be used without an explicit grant.
|
||||
pub fn parse_configure_result(
|
||||
line: &[u8],
|
||||
request_id: u64,
|
||||
@@ -168,7 +168,7 @@ pub fn parse_configure_result(
|
||||
.ok_or(PoolMessageError::InvalidField)?;
|
||||
let subscribe_extranonce = match result.get("subscribe-extranonce") {
|
||||
Some(Value::Bool(value)) => *value,
|
||||
Some(Value::String(_)) => false,
|
||||
Some(Value::String(_)) | None => false,
|
||||
_ => return Err(PoolMessageError::InvalidField),
|
||||
};
|
||||
Ok(ConfigureResult {
|
||||
@@ -293,3 +293,16 @@ pub fn parse_notify(line: &[u8], subscription: &Subscription) -> Result<PoolJob,
|
||||
work,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod configure_tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn omitted_extranonce_extension_is_unsupported() {
|
||||
let line = br#"{"id":1,"result":{"version-rolling":true,"version-rolling.mask":"1fffe000"},"error":null}"#;
|
||||
let result = parse_configure_result(line, 1).unwrap();
|
||||
assert!(result.version_mask.is_some());
|
||||
assert!(!result.subscribe_extranonce);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,6 +126,16 @@ fn both_bip310_extensions_and_boolean_responses_are_checked() {
|
||||
br#"{"id":3,"result":{"version-rolling":false},"error":null}"#,
|
||||
3
|
||||
),
|
||||
Ok(alkane_os::stratum_v1::ConfigureResult {
|
||||
version_mask: None,
|
||||
subscribe_extranonce: false,
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
parse_configure_result(
|
||||
br#"{"id":3,"result":{"version-rolling":false,"subscribe-extranonce":null},"error":null}"#,
|
||||
3
|
||||
),
|
||||
Err(PoolMessageError::InvalidField)
|
||||
);
|
||||
assert_eq!(
|
||||
|
||||
Reference in New Issue
Block a user