From 4040b0234f472893056e19d1e5ebbe8366d6c30d Mon Sep 17 00:00:00 2001 From: Teodor Calin Date: Sun, 7 Jun 2026 16:00:20 +0300 Subject: [PATCH] polo: switch to /api/public-stats + drop growth-% + lifetime requests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Companion to pilot-protocol/rendezvous#50. /api/stats is now admin- gated on polo.pilotprotocol.network; this page consumes the new /api/public-stats endpoint instead. The new payload is intentionally minimal — server_time, uptime_seconds, active_nodes, total_nodes, components{}. No daily/hourly history, no total_requests lifetime counter, no per-IP breakdown, no badge values, no trust links, no networks count. Consequence on the live page: - Hero stats: 'agents' figure stays (driven by total_nodes/active_nodes). - 'requests' figure: was driven by stats.total_requests. Lifetime count is no longer published. The static fallback ('5B+') stays in the markup; the JS no longer overwrites it because the data is gone. Acceptable until we ship a curated rate metric. - 'Growth +X% in the past 7 days' tile: removed. Was computed client-side from stats.daily[] which is no longer published. - 'Growth, past 7 days' big-number tile: removed. - growth7d() helper + fmtRequests() helper: removed (now unused). Both pages tested with 'npm install && npx astro build' — 297 pages generated in 17.4s, no errors. --- src/pages/for/networks.astro | 6 ++- src/pages/index.astro | 96 ++++++++---------------------------- 2 files changed, 24 insertions(+), 78 deletions(-) diff --git a/src/pages/for/networks.astro b/src/pages/for/networks.astro index c8fef30..0b60df2 100644 --- a/src/pages/for/networks.astro +++ b/src/pages/for/networks.astro @@ -8,10 +8,12 @@ const title = "Networks - Live Networks on Pilot Protocol"; const description = "30+ networks running on Pilot Protocol - each with its own membership rules, trust model, and purpose."; const canonicalUrl = "https://pilotprotocol.network/for/networks"; -// Live Backbone count = total network (every agent starts there) +// Live Backbone count = total network (every agent starts there). +// 2026-06-07: switched from /api/stats (now admin-gated) to +// /api/public-stats, which exposes total_nodes + active_nodes only. let backboneCount = '~60K'; try { - const res = await fetch('https://polo.pilotprotocol.network/api/stats', { + const res = await fetch('https://polo.pilotprotocol.network/api/public-stats', { headers: { 'User-Agent': 'pilotprotocol-web' }, }); if (res.ok) { diff --git a/src/pages/index.astro b/src/pages/index.astro index 0725689..cde3a21 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -4,14 +4,22 @@ import Nav from '../components/Nav.astro'; import Footer from '../components/Footer.astro'; import '../styles/system.css'; -// Live stats - graceful fallback at build time +// Live stats - graceful fallback at build time. +// +// 2026-06-07: switched from /api/stats (now admin-gated as part of the +// polo public-stats lockdown) to /api/public-stats, which exposes only +// a curated payload — server_time, uptime_seconds, active_nodes, +// total_nodes, components{}. No 30-day history, no total_requests +// counter, so growth-% and lifetime-request-count headline figures +// were removed from the page. liveRequests is kept as a static +// "5B+" fallback purely because the page copy still references it +// in places; the dynamic figure is no longer fetched. let liveAgents = '~35,000'; let liveAgentsExact = '34,812'; let liveRequests = '5B+'; -let growthPct = '+50%'; try { - const res = await fetch('https://polo.pilotprotocol.network/api/stats', { + const res = await fetch('https://polo.pilotprotocol.network/api/public-stats', { headers: { 'User-Agent': 'pilotprotocol-web' }, }); if (res.ok) { @@ -26,38 +34,6 @@ try { else liveAgents = `${activeN}`; liveAgentsExact = activeN.toLocaleString('en-US'); } - - // total requests → "X.YB+" - if (typeof s.total_requests === 'number') { - const n = s.total_requests; - if (n >= 1_000_000_000) liveRequests = `${(n / 1_000_000_000).toFixed(1).replace(/\.0$/, '')}B+`; - else if (n >= 1_000_000) liveRequests = `${Math.round(n / 1_000_000)}M+`; - else liveRequests = `${n}`; - } - - // growth - 7-day: compare the daily[] entry ~7 days ago to the latest - if (Array.isArray(s.daily) && s.daily.length >= 2) { - const last = s.daily[s.daily.length - 1]; - const targetTs = Number(last?.ts) - 7 * 86400; - let ref = s.daily[Math.max(0, s.daily.length - 8)]; - let bestDelta = Infinity; - for (const e of s.daily) { - const d = Math.abs(Number(e?.ts) - targetTs); - if (Number.isFinite(d) && d < bestDelta) { bestDelta = d; ref = e; } - } - // Per-day rows carry `online_nodes` (not `total_nodes`); fall back to - // current top-level total_nodes as the latest if the last row is missing it. - const aField = (e: any) => Number(e?.online_nodes ?? e?.total_nodes); - const a = aField(ref); - const bRaw = aField(last); - const b = Number.isFinite(bRaw) && bRaw > 0 - ? bRaw - : (typeof s.total_nodes === 'number' ? s.total_nodes : NaN); - if (Number.isFinite(a) && Number.isFinite(b) && a > 0) { - const pct = ((b - a) / a) * 100; - if (Number.isFinite(pct) && pct > 0) growthPct = `+${Math.round(pct)}%`; - } - } } } catch {} --- @@ -120,7 +96,6 @@ try {
Network
{liveAgents} agents · {liveRequests} requests live
-
Growth
{growthPct} in the past 7 days
@@ -449,12 +424,6 @@ try {
Requests routed
-
-
{growthPct}
-
-
Growth, past 7 days
-
-
350+
@@ -845,52 +814,27 @@ try { if (n >= 1_000) return '~' + (n / 1000).toFixed(1).replace(/\.0$/, '') + 'K'; return String(n); } - function fmtRequests(n){ - if (n >= 1_000_000_000) return (n / 1_000_000_000).toFixed(1).replace(/\.0$/, '') + 'B+'; - if (n >= 1_000_000) return Math.round(n / 1_000_000) + 'M+'; - return String(n); - } - function growth7d(daily, fallbackTotal){ - if (!Array.isArray(daily) || daily.length < 2) return null; - var last = daily[daily.length - 1]; - var targetTs = Number(last && last.ts) - 7 * 86400; - var ref = daily[Math.max(0, daily.length - 8)]; - var best = Infinity; - for (var i = 0; i < daily.length; i++) { - var d = Math.abs(Number(daily[i] && daily[i].ts) - targetTs); - if (Number.isFinite(d) && d < best) { best = d; ref = daily[i]; } - } - // Per-day rows carry `online_nodes` (not `total_nodes`); fall back to - // the top-level total_nodes for the latest if the last row is missing it. - var fieldOf = function(e){ if (!e) return NaN; var v = e.online_nodes; return Number.isFinite(v) ? Number(v) : Number(e.total_nodes); }; - var a = fieldOf(ref); - var bRaw = fieldOf(last); - var b = Number.isFinite(bRaw) && bRaw > 0 ? bRaw : Number(fallbackTotal); - if (!Number.isFinite(a) || !Number.isFinite(b) || a <= 0) return null; - var pct = ((b - a) / a) * 100; - return Number.isFinite(pct) && pct > 0 ? ('+' + Math.round(pct) + '%') : null; - } function setAll(sel, value){ document.querySelectorAll(sel).forEach(function(el){ el.textContent = value; }); } + // 2026-06-07: polo public-stats lockdown. /api/stats is now admin- + // gated; this page consumes /api/public-stats which carries only the + // curated payload (server_time, uptime_seconds, active_nodes, + // total_nodes, components{}). Lifetime request count and 30-day + // history are deliberately not in the new payload, so the dynamic + // "requests" badge and the growth-% widget are no longer updated + // client-side. The fallback values rendered at build time are kept. function refresh(){ - fetch('https://polo.pilotprotocol.network/api/stats', { cache: 'no-store' }) + fetch('https://polo.pilotprotocol.network/api/public-stats', { cache: 'no-store' }) .then(function(r){ return r.ok ? r.json() : null; }) .then(function(s){ if (!s) return; var activeN = typeof s.total_nodes === 'number' ? s.total_nodes : typeof s.active_nodes === 'number' ? s.active_nodes : null; if (activeN != null) { - var longStr = fmtAgentsLong(activeN); - setAll('[data-live="agents-long"]', longStr); + setAll('[data-live="agents-long"]', fmtAgentsLong(activeN)); setAll('[data-live="agents-exact"]', activeN.toLocaleString('en-US')); - - } - if (typeof s.total_requests === 'number') { - setAll('[data-live="requests"]', fmtRequests(s.total_requests)); } - var g = growth7d(s.daily, s.total_nodes); - if (g) setAll('[data-live="growth"]', g); }) .catch(function(){}); }