code wiki / _hdl_build / nx_wiki_versioned_rollback_observe.nx
nx_wiki_versioned_rollback_observe.nx source
↩ module page · 51 lines · 2718 B
1// nx_wiki_versioned_rollback_observe.nx -- A4a LIVE round-trip OBSERVER (uses the already-retained
2// rollback points). Proves the live page can be rolled to ANY retained point and back, ending at v1:
3// restore(nist_stem, 2) -> push v2 LIVE (operator then fetch-verifies 9504 B served)
4// restore(nist_stem, 1) -> push v1 LIVE (operator then fetch-verifies 9450 B = original)
5// Additive + guarded (pub_publish via restore). Reads nothing from the network itself; the operator
6// fetch-verifies between/after. license_tier: ORIGINAL
7import "nx_wiki_restore.nx"
8import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc)
9import "nx_syscalls.nx"
10
11func o_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
12// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer
13// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the
14// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls).
15// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign.
16func o_num(v: i64) -> i64 { nxi_out(v); return 0 }
17
18func main(argc: i64, argv: *i64) -> i64 {
19 // which retained version to restore LIVE this invocation (argv[1]; default 1).
20 var ver: i64 = 1
21 if argc >= 2 {
22 let s: *u8 = argv[1] as *u8
23 var v: i64 = 0; var i: i64 = 0
24 while s[i] != (0 as u8) { v = v * 10 + (s[i] - 48); i = i + 1 }
25 if v >= 1 { ver = v }
26 }
27
28 let cs_ptr: *i64 = sys_mmap(8 * 8) as *i64
29 let cs_len: *i64 = sys_mmap(8 * 8) as *i64
30 cs_ptr[0] = "start" as *u8 as i64; cs_len[0] = 5
31 cs_ptr[1] = "charter" as *u8 as i64; cs_len[1] = 7
32 cs_ptr[2] = "board" as *u8 as i64; cs_len[2] = 5
33 cs_ptr[3] = "devlog" as *u8 as i64; cs_len[3] = 6
34 cs_ptr[4] = "nist_stem" as *u8 as i64; cs_len[4] = 9
35 cs_ptr[5] = "roadmap" as *u8 as i64; cs_len[5] = 7
36 cs_ptr[6] = "search" as *u8 as i64; cs_len[6] = 6
37 let ncorpus: i64 = 7
38
39 let res: *PubResult = sys_mmap(64) as *PubResult
40 let nout: *i64 = sys_mmap(16) as *i64
41 let rstage: *u8 = "/tmp/nist_stem_obs_restore.html" as *u8
42
43 o_w("=== restore(nist_stem, v" as *u8); o_num(ver); o_w(") -> push LIVE ===\n" as *u8)
44 let rr: i64 = restore("nist_stem" as *u8, ver, rstage, cs_ptr, cs_len, ncorpus, 1, res, nout)
45 o_w(" rc=" as *u8); o_w(vr_status_name(rr))
46 o_w(" restored_bytes=" as *u8); o_num(nout[0])
47 o_w(" | push status=" as *u8); o_w(pub_status_name(res.status))
48 o_w(" push_invoked=" as *u8); o_num(res.push_invoked)
49 o_w(" push_rc=" as *u8); o_num(res.push_rc); o_w("\n" as *u8)
50 sys_exit(0); return 0
51}