code wiki / (root) / nx_commons_ledger.nx

nx_commons_ledger.nx

buildroot/runtime/nx_commons_ledger.nx

9575 B221 linesdepth 2pulls 2 transitivereach 2 importersview sourcekind librarytopic commons
docsdependenciesstructsconstsfunctions

about

nx_commons_ledger.nx -- the LEDGER->STANDING bridge. Turns a plane of transfer rows into the per-member quantities nx_commons_lib scores. WHY: nx_mycorrhiza held flows in sys_mmap and nothing else. A currency whose record of who-gave-what dies with the process is not a currency. Persistence itself is SOLVED and not rebuilt here -- nx_plane_append is the known good (original bytes held for restore, absent plane REFUSED rather than conjured, prefix-preservation checked BEFORE commit, row count re-verified AFTER, and it states its own honest limit: it serialises only the appends made through it). This organ supplies the two things that were missing: the row GRAMMAR and the AGGREGATOR. ★★★★★★ THE REAL WIN: TWO OF THE BENCH'S MAGIC INPUTS BECOME DERIVED QUANTITIES. nx_commonsbench_gate had to be TOLD each member's passed_outside and outside_partners. A number a fixture hands you is an assumption; a number the ledger computes is a measurement. From transfer rows alone: gave[i] = sum of units where i is the giver took[i] = sum of units where i is the receiver passed[i] = units i gave to parties i NEVER RECEIVED FROM -- onward circulation, not return trips partners[i] = distinct counterparties The passed[] rule is what makes the sybil ring fall out of the arithmetic instead of being asserted: a ring trades 2000 in and 2000 out but every counterparty is one it also received from, so its onward circulation is ZERO by measurement. A janitor gives to twelve people he never took from, so nearly all of his giving counts. NOBODY HAD TO LABEL EITHER OF THEM. IDEMPOTENCY (law 10): appending the same contribution twice would mint standing from nothing. Dedup is by record id, and the comparator and the writer share ONE canonical-form function by construction -- the estate has already paid for the alternative, where nx_debt's deduper compared the raw text while its writer appended a suffix afterwards, so the two never converged. Integer only. license_tier: ORIGINAL No hw writes (Rule 26).

dependencies 1 imports · 2 importers

nx_syscalls.nx nx_commons_ledger.nx nx_commons_ledger_e2e_gate.nx nx_commons_ledger_gate.nx

imports: nx_syscalls.nx

imported by: nx_commons_ledger_e2e_gate.nxnx_commons_ledger_gate.nx

structs

none

consts

31const CL_MAGIC_1469598103934665603: i64 = 1469598103934665603
33const CL_MAX_M: i64 = 64 // members per aggregation window
34const CL_NOSLOT: i64 = 0 - 1
71const CL_TAB: i64 = 9
72const CL_NL: i64 = 10
73const CL_MINUS: i64 = 45
74const CL_ZERO: i64 = 48

functions

39func cl_row_key(giver: i64, receiver: i64, kind: i64, units: i64, at: i64) -> i64
called by 2: cl_parse_rowsmain
51func cl_is_dup(keys: *i64, i: i64) -> i64
called by 1: cl_aggregate
60func cl_slot(ids: *i64, m: i64, id: i64) -> i64
called by 1: cl_aggregate
76func cl_ndigits(m: i64) -> i64
called by 1: cl_putn
86func cl_putn(dst: *u8, off: i64, v: i64) -> i64
called by 1: cl_emit_row calls 1: cl_ndigits
97func cl_emit_row(giver: i64, receiver: i64, kind: i64, units: i64, at: i64,
called by 1: main calls 1: cl_putn
113func cl_field(buf: *u8, n: i64, pos: *i64) -> i64
called by 1: cl_parse_rows
132func cl_parse_rows(buf: *u8, n: i64, giver: *i64, receiver: *i64, units: *i64, at: *i64,
called by 1: main calls 3: sys_mmapcl_fieldcl_row_key
159func cl_aggregate(giver: *i64, receiver: *i64, units: *i64, keys: *i64, n: i64,
called by 2: mainmain calls 3: sys_mmapcl_is_dupcl_slot
214func cl_conserved(gave: *i64, took: *i64, m: i64) -> i64
called by 2: mainmain