Bounty
XE-6119 · Bounty

dao: GET /v1/health recomputes the 30-day uptime aggregation on every request — unauthenticated, unmetered, uncached (~98 ms CPU per hit)

Patched Minorclaimed Medium web filed 2026-11-11 12:46 UTC by xe:bce9914e

Report

Summary

GET /v1/health on the DAO portal recomputes the full 30-day uptime aggregation on every request. The route is unauthenticated, has no rate-limit bucket, and no response cache — unlike every other expensive public read in this codebase, which is either metered or cached.

Evidence (repo xeprotocol/dao @ 2efbfee)

  • dao/api/public.py:339 — async def health(...) calls records.uptime_30d(ctx, db) inline; the handler makes no rate-limit call (contrast the snapshot/legal handlers in the same file).
  • dao/services/records.py:347 — uptime_30d selects all HealthCheck rows of the last 30 days (10-minute cadence ⇒ up to ~4,320 rows) on every call.
  • dao/services/records.py:364 — expected_checks performs Fraction arithmetic (gcd-heavy rational adds) per row/edge over the whole window.

Measurement of the pure function at a full synthetic window:

from dao.services.records import expected_checks
rows = [(i * 600 * 10**9, 600) for i in range(4320)]   # 30 days of 10-min checks
expected_checks(rows, rows[0][0], rows[0][0] + 30*86400*10**9, 600)
# -> 4320 expected, ~98 ms CPU per call (measured in a sandbox)

So roughly 10 requests/second to a public, unauthenticated endpoint saturates about one CPU core, before counting the ~4,320-row database scan and JSONB extraction per request.

Why this is the odd one out

  • /v1/snapshot and other node-costly GETs use the SNAPSHOT / NODE_READ rate buckets (dao/ratelimit.py).
  • /v1/log/verify is cached for 60 s precisely "so the route cannot be used to make the database re-read the whole chain on demand" (dao/services/records.py) — the codebase's own stated rule for exactly this shape of route. /v1/health follows neither pattern.

Impact

A cheap, unauthenticated CPU-exhaustion lever on the DAO portal: a trickle of requests pins a worker core and repeatedly scans a month of health rows. The fix is small and changes no payload: cache the response briefly (the existing verify_cached 60 s pattern) or place the route in the existing NODE_READ bucket.

Dedup note

Existing health tickets (XE-0891, XE-0908, XE-1618, XE-1620, XE-1639, XE-2374) all concern the correctness of the figure — none concerns the per-request cost of computing it. XE-0227 is a closed volume-test pre-notice, not this code finding.

Reporter payout address (XE, at mainnet genesis): bce9914ea94de329cebc38d288e927dd8e70b1057133f697f1f230f8f42b469c

Thread

Joseph Denneteam2026-11-15 10:18 UTCdesk

Thanks for the report. We have confirmed the reading against the current tree and it is being handled. The assessment and any award follow the fix.

XE deskteam2026-11-15 12:17 UTCdesk

Thanks for the report. This is fixed in xeprotocol/dao@e6a0eca. The desk entry is https://bounty.xe.network/XE-6119. If you can, re-run your reproduction against the next testnet build and say so here; if it still reproduces, reopen with what you saw.