code wiki / _hdl_build / nx_adnet_reconcile.nx
nx_adnet_reconcile.nx
buildroot/runtime/_hdl_build/nx_adnet_reconcile.nx
about
nx_adnet_reconcile.nx -- LIB: the BEAT that owns campaign field 7 (spent_milli).
WHY IT EXISTS: camp_may_serve enforces a budget ceiling by reading spend from the campaign ROW, so the
serve path stays O(1) and never scans a journal. Something has to WRITE that field, and it must not be
the serve path -- ainv_spent_milli walks three journals, which with 158k served rows is a per-request
table scan on the hot path. Putting that behind an ad impression is how an ad network takes its own
site down. So: a beat reconciles, serving reads.
★ PURE TRANSFORM, no IO. Takes the confs as buffers and emits the NEW conf into out. The caller owns
reading and the atomic write, which keeps this gateable with fixtures and keeps the dangerous part
(overwriting a live conf) in one reviewable place.
★ PRESERVES EVERYTHING IT DOES NOT UNDERSTAND. Comment rows, blank lines and rows whose spend cannot be
computed pass through BYTE-IDENTICAL. A reconciler that drops what it cannot parse is a data-loss bug
wearing a maintenance-task costume.
★ AN UNMEASURABLE SPEND IS LEFT ALONE, NEVER ZEROED. ainv_spent_milli returns -1 when a campaign is
unpriced, its id is malformed, or viewable > served (a forged beacon). Writing 0 there would silently
REVIVE an exhausted campaign -- the exact failure the ceiling exists to prevent. The old value stands
and camp_may_serve keeps refusing.
license_tier: ORIGINAL
dependencies 3 imports · 2 importers
imports: nx_syscalls.nxnx_adnet_campaign.nxnx_adnet_invoice.nx
imported by: nx_adnet_recbeat.nxnx_adnet_reconcile_gate.nx
structs
| none |
consts
| none |
functions
| 23 | func arec_catd(dst: *u8, off: i64, v: i64) -> i64 |
| 37 | func arec_row_with_spend(row: *u8, rlen: i64, spent: i64, out: *u8, cap: i64) -> i64 |
| 57 | func arec_refresh(camps: *u8, clen: i64, rates: *u8, rlen: i64, slog: *u8, sl: i64, vlog: *u8, vl: i64, clog: *u8, cl: i64, out: *u8, cap: i64) -> i64 called by 3: arb_dryrunmainmain calls 6: sys_mmapad_eolaslot_field_baslot_id_okainv_spent_milliarec_row_with_spend |