nx_commons_ledger.nx
buildroot/runtime/nx_commons_ledger.nx
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
imports: nx_syscalls.nx
imported by: nx_commons_ledger_e2e_gate.nxnx_commons_ledger_gate.nx
structs
| none |
consts
| 31 | const CL_MAGIC_1469598103934665603: i64 = 1469598103934665603 |
| 33 | const CL_MAX_M: i64 = 64 // members per aggregation window |
| 34 | const CL_NOSLOT: i64 = 0 - 1 |
| 71 | const CL_TAB: i64 = 9 |
| 72 | const CL_NL: i64 = 10 |
| 73 | const CL_MINUS: i64 = 45 |
| 74 | const CL_ZERO: i64 = 48 |
functions
| 39 | func cl_row_key(giver: i64, receiver: i64, kind: i64, units: i64, at: i64) -> i64 |
| 51 | func cl_is_dup(keys: *i64, i: i64) -> i64 called by 1: cl_aggregate |
| 60 | func cl_slot(ids: *i64, m: i64, id: i64) -> i64 called by 1: cl_aggregate |
| 76 | func cl_ndigits(m: i64) -> i64 called by 1: cl_putn |
| 86 | func cl_putn(dst: *u8, off: i64, v: i64) -> i64 |
| 97 | func cl_emit_row(giver: i64, receiver: i64, kind: i64, units: i64, at: i64, |
| 113 | func cl_field(buf: *u8, n: i64, pos: *i64) -> i64 called by 1: cl_parse_rows |
| 132 | func cl_parse_rows(buf: *u8, n: i64, giver: *i64, receiver: *i64, units: *i64, at: *i64, |
| 159 | func cl_aggregate(giver: *i64, receiver: *i64, units: *i64, keys: *i64, n: i64, |
| 214 | func cl_conserved(gave: *i64, took: *i64, m: i64) -> i64 |