This commit is contained in:
+10
-1
@@ -3,7 +3,7 @@ use alkane_os::miner::Bm1366Miner;
|
||||
use alkane_os::pow::verify_sha256_report;
|
||||
use alkane_os::pow::VersionMask;
|
||||
use alkane_os::stratum_submit::{format_submission, Submission};
|
||||
use alkane_os::stratum_v1::{parse_notify, Subscription};
|
||||
use alkane_os::stratum_v1::{parse_control_notification, parse_notify, Subscription};
|
||||
use alkane_os::stratum_work::Sha256Job;
|
||||
use alkane_os::{power_decision, target_matrix, HardwareBackend};
|
||||
use std::hint::black_box;
|
||||
@@ -136,6 +136,15 @@ fn bench_stratum_notify_parse() {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "microbenchmark"]
|
||||
fn bench_stratum_control_parse() {
|
||||
let line = br#"{"id":null,"method":"mining.set_difficulty","params":[2048.5]}"#;
|
||||
measure("stratum_control_parse", 20_000, || {
|
||||
black_box(parse_control_notification(black_box(line), false, false).unwrap());
|
||||
});
|
||||
}
|
||||
|
||||
struct BenchBackend;
|
||||
|
||||
impl HardwareBackend for BenchBackend {
|
||||
|
||||
+78
-1
@@ -1,5 +1,8 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
use alkane_os::stratum_v1::{parse_notify, parse_subscription, PoolMessageError};
|
||||
use alkane_os::stratum_v1::{
|
||||
parse_configure_response, parse_control_notification, parse_notify, parse_subscription,
|
||||
PoolMessageError, PoolNotification, Subscription,
|
||||
};
|
||||
|
||||
const SUBSCRIBE: &str =
|
||||
r#"{"id":1,"result":[[["mining.notify","session"]],"01020304",4],"error":null}"#;
|
||||
@@ -68,3 +71,77 @@ fn malformed_pool_messages_fail_before_work_issuance() {
|
||||
Err(PoolMessageError::TooLarge)
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_rolling_negotiation_and_immediate_mask_change() {
|
||||
let response = br#"{"id":3,"result":{"version-rolling":true,"version-rolling.mask":"1fffe000"},"error":null}"#;
|
||||
let mask = parse_configure_response(response, 3).unwrap().unwrap();
|
||||
assert_eq!(mask.bits(), 0x1fff_e000);
|
||||
let update = br#"{"id":null,"method":"mining.set_version_mask","params":["00006000"]}"#;
|
||||
assert_eq!(
|
||||
parse_control_notification(update, true, false).unwrap(),
|
||||
PoolNotification::SetVersionMask(alkane_os::pow::VersionMask::new(0x6000).unwrap())
|
||||
);
|
||||
assert_eq!(
|
||||
parse_control_notification(update, false, false),
|
||||
Err(PoolMessageError::Unnegotiated)
|
||||
);
|
||||
assert_eq!(
|
||||
parse_configure_response(response, 4),
|
||||
Err(PoolMessageError::WrongMessage)
|
||||
);
|
||||
let declined = br#"{"id":3,"result":{"version-rolling":false},"error":null}"#;
|
||||
assert_eq!(parse_configure_response(declined, 3), Ok(None));
|
||||
let unsafe_mask = br#"{"id":3,"result":{"version-rolling":true,"version-rolling.mask":"ffffffff"},"error":null}"#;
|
||||
assert_eq!(
|
||||
parse_configure_response(unsafe_mask, 3),
|
||||
Err(PoolMessageError::InvalidField)
|
||||
);
|
||||
let absent_mask = br#"{"id":3,"result":{"version-rolling":true},"error":null}"#;
|
||||
assert_eq!(
|
||||
parse_configure_response(absent_mask, 3),
|
||||
Err(PoolMessageError::InvalidField)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn difficulty_and_extranonce_notifications_validate_shape_and_negotiation() {
|
||||
let difficulty = br#"{"id":null,"method":"mining.set_difficulty","params":[2048.5]}"#;
|
||||
assert_eq!(
|
||||
parse_control_notification(difficulty, false, false),
|
||||
Ok(PoolNotification::SetDifficulty(2048.5))
|
||||
);
|
||||
let extranonce = br#"{"id":null,"method":"mining.set_extranonce","params":["aabbccdd",4]}"#;
|
||||
assert_eq!(
|
||||
parse_control_notification(extranonce, false, true),
|
||||
Ok(PoolNotification::SetExtranonce(Subscription {
|
||||
extranonce1: vec![0xaa, 0xbb, 0xcc, 0xdd],
|
||||
extranonce2_size: 4,
|
||||
}))
|
||||
);
|
||||
assert_eq!(
|
||||
parse_control_notification(extranonce, false, false),
|
||||
Err(PoolMessageError::Unnegotiated)
|
||||
);
|
||||
for value in ["0", "-1", "\"2\"", "null"] {
|
||||
let line =
|
||||
format!("{{\"id\":null,\"method\":\"mining.set_difficulty\",\"params\":[{value}]}}");
|
||||
assert_eq!(
|
||||
parse_control_notification(line.as_bytes(), false, false),
|
||||
Err(PoolMessageError::InvalidField)
|
||||
);
|
||||
}
|
||||
let oversize = format!(
|
||||
"{{\"id\":null,\"method\":\"mining.set_extranonce\",\"params\":[\"{}\",1]}}",
|
||||
"ab".repeat(33)
|
||||
);
|
||||
assert_eq!(
|
||||
parse_control_notification(oversize.as_bytes(), false, true),
|
||||
Err(PoolMessageError::InvalidField)
|
||||
);
|
||||
let response_id = br#"{"id":5,"method":"mining.set_difficulty","params":[2]}"#;
|
||||
assert_eq!(
|
||||
parse_control_notification(response_id, false, false),
|
||||
Err(PoolMessageError::WrongMessage)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user