code wiki / _hdl_build / nx_ecomat_domledger.nx
nx_ecomat_domledger.nx source
↩ module page · 56 lines · 2489 B
1// nx_ecomat_domledger.nx -- append one PER-DOMAIN beat to knowledge/status/ecomat_domains.log.
2//
3// This is the write half of the fix for debt 1785514540: the aggregate ledger cannot say who earned
4// a level, so nx_ecomat_trend can only attribute 406 permil of observed movement. Once this runs on
5// the same cadence as the rollup, every span becomes exactly attributable and that number goes to
6// 1000 -- advancement and expansion stop being a judgement call.
7//
8// Additive by construction (rule 19): a NEW log, a NEW organ. It does not touch the rollup, so the
9// crown-jewel maturity path carries zero regression risk from this change.
10// argv[1]=store argv[2]=out_log. license_tier: ORIGINAL No hw writes (Rule 26).
11import "nx_ecomat_domledger_lib.nx"
12
13func main(argc: i64, argv: *i64) -> i64 {
14 var store: *u8 = ECOMAT_STORE
15 var outlog: *u8 = EDL_LOG
16 if argc >= 2 { store = argv[1] as *u8 }
17 if argc >= 3 { outlog = argv[2] as *u8 }
18
19 _p("=== NX-ECOMAT-DOMLEDGER: per-domain maturity beat ===\n" as *u8)
20
21 let sums: *i64 = sys_mmap(EDL_SUMS * 8) as *i64
22 let probe: i64 = edl_walk(store, 0 - 1, 0, sums)
23 if probe < 0 {
24 _p("NX-ECOMAT-DOMLEDGER verdict=RED reason=no-store (run nx_ecomat_seed first)\n" as *u8)
25 sys_exit(101)
26 return 101
27 }
28 if probe == 0 {
29 _p("NX-ECOMAT-DOMLEDGER verdict=RED reason=empty-store (refusing to append a beat that says nothing)\n" as *u8)
30 sys_exit(102)
31 return 102
32 }
33
34 let fd: i64 = sys_openat_append(outlog, EDL_MODE)
35 if fd < 0 {
36 _p("NX-ECOMAT-DOMLEDGER verdict=RED reason=log-unwritable path=" as *u8); _p(outlog); _p("\n" as *u8)
37 sys_exit(103)
38 return 103
39 }
40
41 let now: i64 = sys_now_realtime_sec()
42 let n: i64 = edl_walk(store, fd, now, sums)
43 edl_end(fd, now, n, sums)
44 sys_close(fd)
45
46 _p(" wrote " as *u8); _fn(1, n); _p(" domain rows + END terminator to " as *u8); _p(outlog); _p("\n" as *u8)
47 _p(" sum_cur=" as *u8); _fn(1, sums[0]); _p(" sum_bar=" as *u8); _fn(1, sums[1]); _p(" epoch=" as *u8); _fn(1, now); _p("\n" as *u8)
48 if n != probe {
49 _p("NX-ECOMAT-DOMLEDGER verdict=RED reason=walk-unstable (dry run saw " as *u8); _fn(1, probe); _p(" domains, write saw " as *u8); _fn(1, n); _p(")\n" as *u8)
50 sys_exit(104)
51 return 104
52 }
53 _p("NX-ECOMAT-DOMLEDGER verdict=GREEN (beat appended; attribution for future spans is now exact)\n" as *u8)
54 sys_exit(0)
55 return 0
56}