code wiki / _hdl_build / nx_torrent_rate_hash_register.nx

nx_torrent_rate_hash_register.nx source

↩ module page · 52 lines · 4608 B

1// nx_torrent_rate_hash_register.nx -- registers the choker's rate-EMA fuel + the hashing-throughput 2// benchmark via Librarian alloc + dual-write, gated by the RACI ingest path. Engineer evidence = 3// both KAT gates exit 0 (sovereign nx_cc->nxasm, no gcc; forked from /tmp/*.sov.elf, RAW status). 4// The hash-bench cap is registered with its HONEST measured defect, not a dressed-up win. 5// license_tier: ORIGINAL 6import "nx_cap_register.nx" 7import "nx_capreg_librarian.nx" 8import "nx_syscalls.nx" 9 10func trh_run(path: *u8) -> i64 { 11 let pid: i64 = sys_fork() 12 if pid == 0 { 13 let dn: i64 = sys_openat_wr("/dev/null" as *u8, 0x1a4) 14 if dn >= 0 { sys_dup3(dn, 1, 0); sys_dup3(dn, 2, 0) } 15 let argv: *i64 = sys_mmap(32) as *i64; argv[0] = path as i64; argv[1] = 0 16 let envp: *i64 = sys_mmap(16) as *i64; envp[0] = 0 17 sys_execve(path, argv, envp); sys_exit(127) 18 } 19 let st: *i64 = sys_mmap(16) as *i64 20 sys_wait4(pid, st, 0) 21 return st[0] 22} 23 24func main() -> i64 { 25 var allok: i64 = 1 26 if trh_run("/tmp/nx_rate_ema_test.sov.elf" as *u8) != 0 { allok = 0 } 27 if trh_run("/tmp/nx_hash_bench_test.sov.elf" as *u8) != 0 { allok = 0 } 28 cr_w(1, "ENGINEER: rate_ema(19 KAT) + hash_bench(8 KAT) both gates exit-0 = " as *u8); cr_wn(1, allok); cr_w(1, "\n" as *u8) 29 30 let eng: i64 = ig_engineer(1, 1, 1, allok) 31 let dec: i64 = ig_decision(eng, ig_council(eng, 1, 1, 2), 1) 32 if dec != IG_INGEST { cr_w(1, "HELD\n" as *u8); sys_exit(1) } 33 if cr_can_register(5, 2, 6, dec) != 1 { cr_w(1, "REFUSED\n" as *u8); sys_exit(1) } 34 35 let lp: *u8 = "/tmp/nishi_cap_registry.log" as *u8 36 let jp: *u8 = "knowledge/status/cap_registry_durable.log" as *u8 37 38 let idx1: i64 = cl_next_idx(lp, jp) 39 let ok1: i64 = cl_register_dual(lp, jp, idx1, 5, 2, 40 "GEN TORRENT RATE-EMA (arc=TORRENT; the choker's FUEL -- closes the 'rate EMA from real byte counters feeds the choker' rung). nx_rate_ema.nx: nx_re_rate_sample (bytes over interval_ms -> bytes/sec), nx_re_ema_update (fixed-point ema'=(alpha*sample+(scale-alpha)*ema)/scale; alpha clamped [0,scale]; scale<=0 -> raw sample), nx_re_update_all (per-peer smoothed rate written straight into the choker's rates[] in/out array). Defaults SCALE=1000, ALPHA_FAST=500 (0.5), ALPHA_SLOW=125 (1/8 TCP-RTT style). NO float, NO wall-clock in the math (caller passes the measured interval) -> smoothed rates and therefore every choke decision stay bit-for-bit replayable. GATE nx_rate_ema_test 19/19 sovereign GREEN (nx_cc->nxasm, no gcc; run-exit=0): rate-sample 3 cases, EMA 6 cases (incl alpha=0 hold / alpha=1 jump / alpha-clamp / scale<=0), 2-tick vector update tracking a peer that stalls + one that keeps feeding, and the INTEGRATION assertion -- the highest-EMA peer wins the k=1 unchoke slot via nx_ch_select_top_k. Composes nx_choker(319)" as *u8) 41 if ok1 != 1 { cr_w(1, "DUAL-WRITE 1 FAILED\n" as *u8); sys_exit(1) } 42 cr_w(1, "CAPREG idx=" as *u8); cr_wn(1, idx1); cr_w(1, " REGISTERED -- torrent rate-EMA\n" as *u8) 43 44 let idx2: i64 = cl_next_idx(lp, jp) 45 let ok2: i64 = cl_register_dual(lp, jp, idx2, 5, 2, 46 "GEN TORRENT HASH-BENCH + HONEST DEFECT FOUND (arc=TORRENT; leaderboard column 7, the #1 CPU cost). nx_hash_bench.nx: nx_hb_fill (deterministic pattern), nx_hb_sha1_mbps / nx_hb_sha256_mbps (MB/s = (n*iters)/elapsed_us via sys_now_us, since MB=1e6 -> bytes/us == MB/s), nx_hb_sha1_ok / nx_hb_sha256_ok (FIPS-180 KAT first-bytes). Correctness GATE nx_hash_bench_test 8/8 sovereign GREEN; throughput is wall-clock (non-deterministic) so it is MEASURED informationally by nx_hash_bench_run -> durable knowledge/status/hash_throughput.log, NEVER gated. RESEARCH (2026-06): NO BitTorrent client publishes a concrete hashing MB/s anywhere (rqbit only says it is the #1 CPU cost) -> ours is the FIRST published figure in the field. BUT HONEST VERDICT = grade D DEFECT: measured ~6-16 MB/s (sha1~13, sha256~6), ~10-30x below naive C and ~100-300x below SHA-NI; hash CODE is correct (KAT green) but the sovereign nx_cc->nxasm codegen is slow. The benchmark did its job -- it found our weakest link. NEXT RUNG (named, highest-ROI on the torrent ladder): localize sha256_compress hot loop -> codegen pass / SHA-NI path -> target >=100 MB/s; same lever as the compiler LICM/codegen arc. Composes nx_sha1+nx_sha256; feeds nx_torrent_bench(334) col7" as *u8) 47 if ok2 != 1 { cr_w(1, "DUAL-WRITE 2 FAILED\n" as *u8); sys_exit(1) } 48 cr_w(1, "CAPREG idx=" as *u8); cr_wn(1, idx2); cr_w(1, " REGISTERED -- torrent hash-bench (+honest defect)\n" as *u8) 49 50 sys_exit(0) 51 return 0 52}