Compare commits

...
Author SHA1 Message Date
noah 7fd9c8eee3 Keep buffered Stratum partial line deadline across drains
next-build / build (push) Successful in 13s
2026-10-16 04:01:56 -06:00
noah f302bbbb24 Attach OS quality gate evidence to metrics
next-build / build (push) Successful in 14s
2026-10-16 02:06:01 -06:00
noah b22b494ede Grade OS code quality from static checks
next-build / build (push) Successful in 15s
2026-10-16 02:02:53 -06:00
noah 6c23ce847d Coalesce pending CI badge updates
next-build / build (push) Successful in 15s
2026-10-16 01:02:52 -06:00
noah 6a466a611f Reject invalid BM1362 geometry and baud requests
next-build / build (push) Successful in 18s
2026-10-15 22:07:45 -06:00
noah 1300d7e372 Benchmark BM1362 frame encoding
next-build / build (push) Successful in 18s
2026-10-15 22:06:01 -06:00
9 changed files with 130 additions and 32 deletions
+4
View File
@@ -5,6 +5,10 @@ on:
workflows: [main-release-gate, next-build]
types: [completed]
concurrency:
group: alkane-os-completed-ci-badge
cancel-in-progress: false
jobs:
publish:
runs-on: alkane-ci
+5 -2
View File
@@ -33,7 +33,9 @@ jobs:
- name: CI cleanup containment checks
run: python3 ci/test-cleanup-generated.py
- name: Quality
run: cargo clippy --all-targets --locked -- -D warnings
run: |
cargo clippy --all-targets --locked -- -D warnings
printf '{"format":true,"clippy_warnings_denied":true}\n' > quality-current.json
- name: Build
run: cargo build --release --locked
- name: Unit and workflow tests
@@ -67,12 +69,13 @@ jobs:
run: |
python3 ci/metrics.py --tests-output tests-current.txt \
--tests-coverage coverage/tests.json --bench-output bench-current.txt \
--bench-coverage coverage/bench.json
--bench-coverage coverage/bench.json --quality-gate quality-current.json
- uses: https://github.com/ChristopherHX/gitea-upload-artifact@81f940d004763f986ba3582c007fd842dd5cb0d7
with:
name: alkane-os-metrics
path: |
badges/metrics.json
quality-current.json
coverage/tests.json
coverage/bench.json
bench-current.txt
+1 -1
View File
@@ -10,7 +10,7 @@ import sys
ROOT = Path(__file__).resolve().parents[1]
DIRECTORIES = ("target", "coverage", "dist", "bench-site")
FILES = ("tests-current.txt", "bench-current.txt")
FILES = ("tests-current.txt", "bench-current.txt", "quality-current.json")
def cleanup() -> None:
+11 -14
View File
@@ -20,6 +20,13 @@ def bench_results(path):
return {name: float(ns) for name, ns in re.findall(r"BENCH (\w+) ([0-9.]+) ns/op", text)}
def quality_grade(path):
checks = json.loads(pathlib.Path(path).read_text())
if checks != {"format": True, "clippy_warnings_denied": True}:
raise ValueError("format and strict Clippy must pass before publishing quality")
return "A"
def compact(number):
value = float(number)
units = ("", "K", "M", "G")
@@ -34,19 +41,6 @@ def compact(number):
return number + units[index]
def quality_grade(line_coverage):
# Main CI reaches this publisher only after warnings-denied Clippy passes.
if line_coverage >= 90:
return "A"
if line_coverage >= 80:
return "B"
if line_coverage >= 70:
return "C"
if line_coverage >= 60:
return "D"
return "F"
def svg(label, value, color):
label, value = html.escape(label), html.escape(value)
lw, vw = 12 + 7 * len(label), 12 + 7 * len(value)
@@ -65,6 +59,7 @@ def main():
parser.add_argument("--tests-coverage", required=True)
parser.add_argument("--bench-output", required=True)
parser.add_argument("--bench-coverage", required=True)
parser.add_argument("--quality-gate", required=True)
parser.add_argument("--bench-baseline", default="badges/bench-baseline.json")
args = parser.parse_args()
test_output = pathlib.Path(args.tests_output).read_text()
@@ -90,7 +85,9 @@ def main():
"bench_ns_per_op": current, "bench_improvement_pct": delta,
"bench_host": benchmark_host(),
"lines_of_code": loc, "dependencies": dependencies,
"code_quality": quality_grade(line_coverage), "license": "MIT"}
"code_quality": quality_grade(args.quality_gate),
"quality_scope": "main CI passed cargo fmt and warnings-denied Clippy on all targets",
"license": "MIT"}
pathlib.Path("badges").mkdir(exist_ok=True)
pathlib.Path("badges/metrics.json").write_text(json.dumps(metrics, indent=2) + "\n")
badges = {
+9 -6
View File
@@ -3,6 +3,7 @@
"""Regression checks for measured benchmark and quality badges."""
import sys
import json
from pathlib import Path
from tempfile import TemporaryDirectory
import unittest
@@ -12,12 +13,14 @@ from metrics import bench_results, compact, quality_grade
class MetricTests(unittest.TestCase):
def test_quality_grade_depends_on_measured_coverage(self):
self.assertEqual(quality_grade(92), "A")
self.assertEqual(quality_grade(88), "B")
self.assertEqual(quality_grade(72), "C")
self.assertEqual(quality_grade(65), "D")
self.assertEqual(quality_grade(40), "F")
def test_quality_requires_both_static_checks(self):
with TemporaryDirectory() as directory:
path = Path(directory) / "quality.json"
path.write_text(json.dumps({"format": True, "clippy_warnings_denied": True}))
self.assertEqual(quality_grade(path), "A")
path.write_text(json.dumps({"format": True, "clippy_warnings_denied": False}))
with self.assertRaises(ValueError):
quality_grade(path)
def test_benchmark_parser_and_short_si_badge(self):
with TemporaryDirectory() as directory:
+29 -7
View File
@@ -11,8 +11,8 @@ pub const CHIP_ADDRESS_STEP: u8 = 2;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ModelGeometry {
pub chips_per_chain: u8,
pub ticket_mask: u8,
chips_per_chain: u8,
ticket_mask: u8,
}
pub const S19J_PRO: ModelGeometry = ModelGeometry {
@@ -29,6 +29,24 @@ pub const S19_88: ModelGeometry = ModelGeometry {
};
impl ModelGeometry {
pub const fn new(chips_per_chain: u8, ticket_mask: u8) -> Option<Self> {
if chips_per_chain == 0 || chips_per_chain > 128 {
return None;
}
Some(Self {
chips_per_chain,
ticket_mask,
})
}
pub const fn chips_per_chain(self) -> u8 {
self.chips_per_chain
}
pub const fn ticket_mask(self) -> u8 {
self.ticket_mask
}
/// Addresses for an observed two-address-step enumeration walk.
pub fn chip_addresses(self) -> impl Iterator<Item = u8> {
(0..self.chips_per_chain).map(|index| index * CHIP_ADDRESS_STEP)
@@ -105,13 +123,10 @@ pub fn encode_job(job: &Job) -> [u8; JOB_BYTES] {
/// BT8D for a 25 MHz input clock with BCLK_SEL=0. A model must still choose
/// the actual target baud and confirm switching on silicon.
pub fn bt8d_for_baud(baud: u32) -> Option<u8> {
if baud == 0 {
if baud == 0 || baud > 3_125_000 {
return None;
}
let divider = 25_000_000_u64 / (8 * u64::from(baud));
if divider == 0 {
return Some(0);
}
u8::try_from(divider - 1).ok()
}
@@ -141,6 +156,12 @@ mod tests {
#[test]
fn model_address_limits() {
assert_eq!(ModelGeometry::new(0, 0), None);
assert_eq!(ModelGeometry::new(129, 0), None);
assert_eq!(
ModelGeometry::new(128, 0).unwrap().chip_addresses().last(),
Some(0xfe)
);
assert_eq!(S19J_PRO.chip_addresses().last(), Some(0xfa));
assert_eq!(S19J.chip_addresses().last(), Some(0xd6));
assert_eq!(S19_88.chip_addresses().last(), Some(0xae));
@@ -187,6 +208,7 @@ mod tests {
assert_eq!(bt8d_for_baud(3_000_000), Some(0));
assert_eq!(bt8d_for_baud(115_200), Some(26));
assert_eq!(bt8d_for_baud(1), None);
assert_eq!(bt8d_for_baud(u32::MAX), Some(0));
assert_eq!(bt8d_for_baud(3_125_001), None);
assert_eq!(bt8d_for_baud(u32::MAX), None);
}
}
+10 -2
View File
@@ -120,7 +120,11 @@ impl StratumWire {
return Err(WireError::LineTooLong);
}
let line = self.buffered.drain(..=end).collect();
self.partial_started = (!self.buffered.is_empty()).then(Instant::now);
self.partial_started = if self.buffered.is_empty() {
None
} else {
self.partial_started.or_else(|| Some(Instant::now()))
};
return Ok(line);
}
if self.buffered.len() >= MAX_POOL_LINE_BYTES {
@@ -221,7 +225,11 @@ impl StratumWire {
return Err(WireError::LineTooLong);
}
let line = self.buffered.drain(..=end).collect();
self.partial_started = (!self.buffered.is_empty()).then(Instant::now);
self.partial_started = if self.buffered.is_empty() {
None
} else {
self.partial_started.or_else(|| Some(Instant::now()))
};
return Ok(Some(line));
}
if self.buffered.len() >= MAX_POOL_LINE_BYTES {
+37
View File
@@ -1,3 +1,7 @@
use alkane_os::bm1362::{
bt8d_for_baud, chain_inactive, encode_job, read_register, read_register_all, set_chip_address,
write_register, write_register_all, Job, S19J_PRO,
};
use alkane_os::bm1366::{decode_nonce_report, encode_work};
use alkane_os::difficulty::PoolDifficulty;
use alkane_os::miner::Bm1366Miner;
@@ -94,6 +98,39 @@ fn bench_bm1366_work_encoding() {
});
}
#[test]
#[ignore = "microbenchmark"]
fn bench_bm1362_commands() {
measure("bm1362_commands", 20_000, || {
black_box(chain_inactive());
black_box(set_chip_address(black_box(8)));
black_box(read_register(black_box(0x40), 0x1c));
black_box(read_register_all(0));
black_box(write_register(black_box(0x40), 0x18, 0x7a31));
black_box(write_register_all(0x80, 0));
black_box(bt8d_for_baud(black_box(115_200)));
black_box(S19J_PRO.chip_addresses().last());
});
}
#[test]
#[ignore = "microbenchmark"]
fn bench_bm1362_job_encoding() {
let job = Job {
work_id: 8,
num_midstates: 1,
start_nonce: 0,
nbits: 0x1a1f_2c34,
ntime: 0x5e9b_3cd4,
merkle_root: [0xa5; 32],
previous_hash: [0x5a; 32],
version: 0x2000_0000,
};
measure("bm1362_job_encoding", 20_000, || {
black_box(encode_job(black_box(&job)));
});
}
#[test]
#[ignore = "microbenchmark"]
fn bench_bm1366_report_decode() {
+24
View File
@@ -90,6 +90,30 @@ fn trickled_pool_line_hits_the_absolute_deadline() {
server.join().unwrap();
}
#[test]
fn buffered_complete_lines_do_not_extend_a_partial_line_deadline() {
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
let address = listener.local_addr().unwrap();
let server = thread::spawn(move || {
let (mut stream, _) = listener.accept().unwrap();
stream.write_all(b"first\nsecond\nunfinished").unwrap();
thread::sleep(Duration::from_secs(3));
});
let mut wire = StratumWire::connect(address, Duration::from_secs(2)).unwrap();
let first = loop {
if let Some(line) = wire.try_read_line().unwrap() {
break line;
}
};
assert_eq!(first, b"first\n");
thread::sleep(Duration::from_millis(1300));
assert_eq!(wire.try_read_line().unwrap(), Some(b"second\n".to_vec()));
thread::sleep(Duration::from_millis(800));
assert!(matches!(wire.try_read_line(), Err(WireError::Timeout)));
assert!(wire.is_closed());
server.join().unwrap();
}
#[test]
fn idle_timeout_keeps_connection_available_for_later_messages() {
let listener = TcpListener::bind("127.0.0.1:0").unwrap();